1// ======================================== 2 3var scheduleDoCkeck = false; 4 5function scheduleForceCheckInputs () { 6 scheduleDoCkeck = true; 7 return scheduleCheckInputs (); 8} 9 10function scheduleCheckSelect (select) { 11 var warning = select.find ('option:selected').val () == ""; 12 select.prev (".warningPlace").toggleClass ("warning", warning); 13 return warning; 14} 15function scheduleCheckInput (input) { 16 var warning = input.val () == ""; 17 input.toggleClass ("warning", warning); 18 return warning; 19} 20function scheduleCheckUL (ul) { 21 var warning = ul.children ().length == 0; 22 ul.toggleClass ("warning", warning); 23 return warning; 24} 25/* 26 * highlight missing input fields 27 */ 28function scheduleCheckInputs () { 29 if (!scheduleDoCkeck) 30 return false; 31 var tab = jQuery (".scheduleTabForm"); 32 var tabs = tab.find ("li a.warningPlace"); 33 var checked = true; 34 var warning = false; 35 warning = scheduleCheckSelect (tab.find ('select[name="schd[audience]"]')); 36 warning = scheduleCheckSelect (tab.find ('select.members')) || warning; 37 tabs.slice (0,1).toggleClass ("warning", warning); 38 if (warning) 39 checked = false; 40 warning = scheduleCheckSelect (tab.find ('select[name="schd[what]"]')); 41 warning = scheduleCheckInput (tab.find ('input[name="schd[title]"]')) || warning; 42 tabs.slice (1,2).toggleClass ("warning", warning); 43 if (warning) 44 checked = false; 45 warning = scheduleCheckUL (tab.find ('ul.cities')); 46 tabs.slice (2,3).toggleClass ("warning", warning); 47 if (warning) 48 checked = false; 49 warning = scheduleCheckInput (tab.find ('input[name="schd[from]"]')); 50 tabs.slice (3,4).toggleClass ("warning", warning); 51 if (warning) 52 checked = false; 53 warning = scheduleCheckInput (tab.find ('input.edit')); 54 tabs.slice (4,5).toggleClass ("warning", warning); 55 if (warning) 56 checked = false; 57 return checked; 58} 59 60/** 61 * switch all selected events for delete. 62 */ 63function scheduleSwitchSelection (form) { 64 for (var i = 0; i < form.elements.length; i++) 65 form.elements[i].checked = !form.elements[i].checked; 66} 67 68/* 69 * change member selection mode according share status 70 */ 71function scheduleSharedEvent (form) { 72 var form = jQuery (form); 73 var shared = null; 74 75 form.find ('select[name="schd[shared]"]').each (function () { 76 if (this.options [this.selectedIndex].text != "") 77 shared = "true"; 78 }); 79 form.find ('select[name="schd[member]"]').each (function () { 80 this.multiple = shared; 81 this.size = shared ? 9 : 1; 82 }); 83} 84 85/* 86 * display repeat input according selection 87 */ 88function scheduleUpdateRepeatType (repeatSelection) { 89 var selectedValue = repeatSelection.options [repeatSelection.selectedIndex].value; 90 var inputs = repeatSelection.form.elements; 91 var disabledWeek = (selectedValue != "week"); 92 var disabledDay = (selectedValue != "dayMonth"); 93 var disabledDate = (selectedValue != "dateMonth"); 94 var checkedDay = 0; 95 // XXX jquery ? 96 for (var i = 0; i < inputs.length; i++) { 97 var name = inputs[i].name; 98 if (name == "schd[weekDays][]") { 99 inputs[i].disabled = disabledWeek; 100 if (inputs[i].checked) 101 checkedDay++; 102 } else if (name == "schd[weekRank]") 103 inputs[i].disabled = disabledDay; 104 else if (name == "schd[dayInWeek]") 105 inputs[i].disabled = disabledDay; 106 else if (name == "schd[dayRank]") 107 inputs[i].disabled = disabledDate; 108 } 109 if (!disabledWeek && checkedDay == 0) 110 scheduleForceDay (inputs); 111 // XXX forcer le Ie jour du mois 112} 113 114/* 115 * display repeat input according selection 116 */ 117function scheduleUpdateWeekDays (DaySelection) { 118 var inputs = DaySelection.form.elements; 119 var checkedDay = 0; 120 // XXX jquery 121 for (var i = 0; i < inputs.length; i++) { 122 if (inputs[i].name == "schd[weekDays][]") 123 if (inputs[i].checked) 124 checkedDay++; 125 } 126 if (checkedDay == 0) 127 scheduleForceDay (inputs); 128} 129 130function scheduleForceDay (inputs) { 131 var date = document.getElementById ("scheduleFrom").value; 132 if (!date) 133 date = new Date (); 134 else { 135 date = date.split ('/'); // XXX bug format FR seulement 136 date [1] = parseInt (date [1]) - 1; 137 if (date[2] < 100) 138 date [2] = parseInt (date [2]) + 2000; 139 date = new Date (date[2], date [1], date [0]); 140 } 141 var rankDay = date.getDay(); 142 for (var i = 0; i < inputs.length; i++) 143 if (inputs[i].name == "schd[weekDays][]" && inputs[i].value == rankDay) 144 inputs[i].checked = true; 145} 146