diff -r 53cff4b4a802 -r bde1974c263b web/wp-content/plugins/event-calendar/edit_form.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/event-calendar/edit_form.js Wed Feb 03 15:37:20 2010 +0000 @@ -0,0 +1,202 @@ +/* EventCalendar. $Revision: 255 $ + * Copyright (C) 2005 2006, Alex Tingle. + * This file is licensed under the GNU GPL. See LICENSE file for details. + */ + +/** Register an onload function. */ +function WindowOnload(f) +{ + var prev=window.onload; + window.onload=function(){ if(prev)prev(); f(); } +} + +/*** + *** Set elsewhere: Ec3EditForm.event_cat_id + *** Ec3EditForm.start_of_week + ***/ + +// namespace +function Ec3EditForm() +{ + var fmt="%Y-%m-%d %H:%M"; + + WindowOnload( function() + { + var ELEMENT_NODE=1; + var TEXT_NODE=3; + + Ec3EditForm.fieldset_se=document.getElementById('ec3_schedule_editor'); + Ec3EditForm.rows=document.getElementById('ec3_rows'); + Ec3EditForm.catinput=document.getElementById(Ec3EditForm.event_cat_id); + + if(Ec3EditForm.fieldset_se && Ec3EditForm.rows && Ec3EditForm.catinput) + { + // Perform some sleight of hand.... + // What I WANT to do, is set Ec3EditForm.catinput to read only, however + // that's not possible for a checkbox. Disabled is good, but disabled + // checkboxes are never submitted with the form. So, we HIDE the real + // checkbox, and make a new dummy one that is shown but disabled. + Ec3EditForm.dummyinput=Ec3EditForm.catinput.cloneNode(true); + Ec3EditForm.dummyinput.id='ec3_dummy'; + Ec3EditForm.dummyinput.name='ec3_dummy'; + Ec3EditForm.dummyinput.disabled=true; + Ec3EditForm.catinput.parentNode.insertBefore( + Ec3EditForm.dummyinput, Ec3EditForm.catinput + ); + Ec3EditForm.catinput.style.display='none'; + update_category(); + add_row_listeners(Ec3EditForm.fieldset_se); + } + } ); + + function add_row_listeners(e) + { + var buttons=e.getElementsByTagName('button'); + for(var i=0; i0) + { + Ec3EditForm.catinput.checked=true; + Ec3EditForm.dummyinput.checked=true; + } + else + { + Ec3EditForm.catinput.checked=false; + Ec3EditForm.dummyinput.checked=false; + } + } + + Ec3EditForm.add_row=function() + { + // Get the second-from-last TR + var trs=Ec3EditForm.fieldset_se.getElementsByTagName('tr'); + var tr=trs[trs.length-2]; + // Make a new row, based on it & add it into the table. + var new_tr=tr.cloneNode(1); + + var selects=new_tr.getElementsByTagName('select'); + for(var i=0; i=0) + { + // Change the end time to preserve the event duration. + var start=input; + var end=document.getElementById(start.id.replace('_start_','_end_')); + var start_date0=parseInt(start.getAttribute('ec3_date')); + var end_date0=parseInt(end.getAttribute('ec3_date')); + var start_date1=Date.parseDate(start.value,fmt).getTime(); + start.setAttribute('ec3_date',start_date1); + var delta=start_date1 - start_date0; + var end_date1=end_date0+delta; + end.setAttribute('ec3_date',end_date1); + end.value=(new Date(end_date1)).print(fmt); + } + else if(input.id.indexOf('ec3_end_')>=0) + { + // Make sure that the start time is before the end time. + var start=document.getElementById(input.id.replace('_end_','_start_')); + var end=input; + var start_date0=parseInt(start.getAttribute('ec3_date')); + var end_date0=parseInt(end.getAttribute('ec3_date')); + var end_date1=Date.parseDate(end.value,fmt).getTime(); + end.setAttribute('ec3_date',end_date1); + if(start_date0>end_date1) + { + var start_date1=end_date1; + start.setAttribute('ec3_date',start_date1); + start.value=(new Date(start_date1)).print(fmt); + } + } + } + + function cal_changed(cal) + { + input_changed(cal.params.inputField); + } + +} // end namespace Ec3EditForm + + +// Export public functions from namespace. +Ec3EditForm();