[420] | 1 | var headerMsgLock = false; |
---|
| 2 | function write_msg (message){ |
---|
| 3 | if (headerMsgLock){ |
---|
| 4 | setTimeout('write_msg("'+message+'");', 300); |
---|
| 5 | return; |
---|
| 6 | } |
---|
| 7 | headerMsgLock = true; |
---|
| 8 | headerDiv = document.getElementById("divAppboxHeader"); |
---|
| 9 | var labelBefore = headerDiv.innerHTML; |
---|
| 10 | headerDiv.innerHTML = '<table width=100% cellspacing="0" cellpadding="0" border="0"><tbody><tr><th width="40%"></th><th noWrap class="action_info_th">'+message+'</th><th width="40%"></th></tr></tbody></table>'; |
---|
| 11 | setTimeout('headerMsgLock = false; document.getElementById("divAppboxHeader").innerHTML = \"'+labelBefore+'\";', 2000); |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | // This array stores the events in table to avoid conflict in screen |
---|
| 15 | var screenTable = new Array(); |
---|
| 16 | var today = new Date(); |
---|
| 17 | var weekDay = today.getDay(); |
---|
| 18 | function createEventDiv(eventDiv){ |
---|
| 19 | eventDiv.className = "event_div"; |
---|
| 20 | eventDiv.style.height = parseInt(eventDiv.childNodes[2].id-eventDiv.childNodes[1].id)/120000+"px"; |
---|
| 21 | var end_ = timeStamp2id(eventDiv.childNodes[2].id).substr(8); |
---|
| 22 | var start_ = parseInt(timeStamp2id(eventDiv.childNodes[1].id).substr(8),10); |
---|
| 23 | if (viewType == "Day"){ |
---|
| 24 | if (!screenTable[weekDay]) |
---|
| 25 | screenTable[weekDay] = new Array(); |
---|
| 26 | eventDiv.style.width = "190px"; |
---|
| 27 | |
---|
| 28 | currentPos = 1; |
---|
| 29 | for (var hour = parseInt(start_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30){ |
---|
| 30 | if (!screenTable[weekDay][hour]) |
---|
| 31 | screenTable[weekDay][hour] = 0; |
---|
| 32 | |
---|
| 33 | if (currentPos <= screenTable[weekDay][hour]) |
---|
| 34 | currentPos = screenTable[weekDay][hour]+1; |
---|
| 35 | } |
---|
| 36 | for (var hour = parseInt(start_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30) |
---|
| 37 | screenTable[weekDay][hour] = currentPos; |
---|
| 38 | eventDiv.style.left = 90+(205*(currentPos-1)) + "px" ; |
---|
| 39 | eventDiv.onmouseover = function(){ createButtons(eventDiv); }; |
---|
| 40 | eventDiv.onmouseout = function(){ removeButtons(eventDiv); }; |
---|
| 41 | var resizeDiv = document.createElement('DIV'); |
---|
| 42 | resizeDiv.id = "resize_" + eventDiv.id; |
---|
| 43 | resizeDiv.className = 'resize_div'; |
---|
| 44 | resizeDiv.style.right = (parseInt(eventDiv.style.width)-10)*-1+"px;"; |
---|
| 45 | resizeDiv.style.bottom = ((parseInt(eventDiv.style.height)-24)*-1)+"px;"; |
---|
| 46 | resizeDiv.onmousedown = function() { resizeEvent(eventDiv); }; |
---|
| 47 | eventDiv.appendChild(resizeDiv); |
---|
| 48 | } |
---|
| 49 | if (viewType == "Week"){ |
---|
| 50 | var tempDate = new Date; |
---|
| 51 | tempDate.setTime(eventDiv.childNodes[2].id); |
---|
| 52 | if (!screenTable[tempDate.getDay()]) |
---|
| 53 | screenTable[tempDate.getDay()] = new Array(); |
---|
| 54 | currentPos = 1; |
---|
| 55 | if (!screenTable[tempDate.getDay()][start_]) |
---|
| 56 | screenTable[tempDate.getDay()][start_] = 0; |
---|
| 57 | |
---|
| 58 | if (currentPos <= screenTable[tempDate.getDay()][start_]) |
---|
| 59 | currentPos = screenTable[tempDate.getDay()][start_]+1; |
---|
| 60 | screenTable[tempDate.getDay()][start_] = currentPos; |
---|
| 61 | |
---|
| 62 | var widthValue = 100; |
---|
| 63 | eventDiv.style.width = widthValue+"px"; |
---|
| 64 | |
---|
| 65 | var headerElement = document.getElementById('weekHeader_'+timeStamp2id(eventDiv.childNodes[2].id).substr(0,8)); |
---|
| 66 | if (currentPos > 1) |
---|
| 67 | eventDiv.style.left = (10+(tempDate.getDay()*122)+(widthValue*currentPos))+"px"; |
---|
| 68 | headerElement.style.width = (widthValue*currentPos)+"px"; |
---|
| 69 | eventDiv.style.height = "20px"; |
---|
| 70 | eventDiv.style.cursor = "pointer"; |
---|
| 71 | eventDiv.onmouseover = function () { this.style.height = (parseInt(this.style.height)+40)+"px"; }; |
---|
| 72 | eventDiv.onmouseout = function () { this.style.height = (parseInt(this.style.height)-40)+"px"; }; |
---|
| 73 | eventDiv.onclick = function () { calendar.getView('div_main','Day','&time='+timeStamp2id(eventDiv.childNodes[2].id).substr(0,8)); }; |
---|
| 74 | } |
---|
| 75 | var tdElement = document.getElementById(timeStamp2id(eventDiv.childNodes[1].id)); |
---|
| 76 | |
---|
| 77 | if (viewType == "Month"){ |
---|
| 78 | eventDiv.style.width = "90px"; |
---|
| 79 | eventDiv.style.heigth = "20px"; |
---|
| 80 | var tdElement = document.getElementById(timeStamp2id(eventDiv.childNodes[1].id).substr(0,8)+'0000'); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | eventDiv.style.top = (tdElement.offsetTop + 145) + "px" ; |
---|
| 84 | tdElement.appendChild(eventDiv); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | function createButtons(eventDiv) { |
---|
| 88 | var lnk = document.getElementById('remove_'+eventDiv.id); |
---|
| 89 | var lnk2 = document.getElementById('details_'+eventDiv.id); |
---|
| 90 | if (!lnk){ |
---|
| 91 | var removeLink = document.createElement('a'); |
---|
| 92 | removeLink.id = "remove_" + eventDiv.id; |
---|
| 93 | removeLink.href = "javascript:removeEvent("+eventDiv.id.substr(6)+");"; |
---|
| 94 | removeLink.innerHTML = '<img onmouseover="this.setAttribute(\'width\', \'15\');"'+ |
---|
| 95 | 'onmouseout="this.setAttribute(\'width\', \'10\');"'+ |
---|
| 96 | ' title="'+get_lang('remove')+'" alt="'+get_lang('remove')+'"'+ |
---|
| 97 | ' src="templates/default/images/min.png"></img>'; |
---|
| 98 | removeLink.style.position = "absolute"; |
---|
| 99 | removeLink.style.top = "0px"; |
---|
| 100 | removeLink.style.left = "175px"; |
---|
| 101 | var showDetailLink = document.createElement('a'); |
---|
| 102 | showDetailLink.id = "details_" + eventDiv.id; |
---|
| 103 | showDetailLink.href = "javascript:alert('show details');"; |
---|
| 104 | showDetailLink.innerHTML = '<img onmouseover="this.setAttribute(\'width\', \'15\');"'+ |
---|
| 105 | 'onmouseout="this.setAttribute(\'width\', \'10\');"'+ |
---|
| 106 | ' title="'+get_lang('details')+'" alt="'+get_lang('details')+'"'+ |
---|
| 107 | ' src="templates/default/images/plus.png"></img>'; |
---|
| 108 | showDetailLink.style.position = "absolute"; |
---|
| 109 | showDetailLink.style.top = "0px"; |
---|
| 110 | showDetailLink.style.left = "160px"; |
---|
| 111 | |
---|
| 112 | eventDiv.appendChild(showDetailLink); |
---|
| 113 | eventDiv.appendChild(removeLink); |
---|
| 114 | } |
---|
| 115 | else{ |
---|
| 116 | lnk.style.visibility="visible"; |
---|
| 117 | lnk2.style.visibility="visible"; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | function removeButtons(eventDiv){ |
---|
| 121 | var lnk = document.getElementById('remove_'+eventDiv.id); |
---|
| 122 | var lnk2 = document.getElementById('details_'+eventDiv.id); |
---|
| 123 | if (lnk){ |
---|
| 124 | lnk.style.visibility="hidden"; |
---|
| 125 | lnk2.style.visibility="hidden"; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | function removeEvent (id) { |
---|
| 130 | var handler_removeEvent = function (data) { |
---|
| 131 | var serverRet = data.firstChild.childNodes[0]; |
---|
| 132 | var retStatus = serverRet.substringData(0,4); |
---|
| 133 | if (retStatus == "false") |
---|
| 134 | write_msg(get_lang("Error") + ": " + serverRet.data) |
---|
| 135 | else{ |
---|
| 136 | var eventDiv = document.getElementById("event_"+id); |
---|
| 137 | if (viewType == "Day"){ |
---|
| 138 | init_ = timeStamp2id(eventDiv.childNodes[1].id).substr(8); |
---|
| 139 | end_ = timeStamp2id(eventDiv.childNodes[2].id).substr(8); |
---|
| 140 | for (var hour = parseInt(init_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30) |
---|
| 141 | screenTable[weekDay][hour]--; |
---|
| 142 | } |
---|
| 143 | eventDiv.parentNode.removeChild(eventDiv); |
---|
| 144 | write_msg(get_lang("Event were deleted")); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | XMLTools.request('$this.uicalendar.removeEvent&id='+id, 'GET', handler_removeEvent); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | function quickAddEvent (description, startTime, endTime) |
---|
| 151 | { |
---|
| 152 | var endDate = new Date(); |
---|
| 153 | endDate.setTime(id2timeStamp(endTime)+1800000); |
---|
| 154 | |
---|
| 155 | var handler_quickAdd = function (data) { |
---|
| 156 | calendar.dialog('infowindow'); |
---|
| 157 | |
---|
| 158 | var serverRet = data.firstChild.childNodes[0]; |
---|
| 159 | var retStatus = serverRet.substringData(0,5); |
---|
| 160 | |
---|
| 161 | if (retStatus == "false") |
---|
| 162 | write_msg(get_lang("Error") + ": " + get_lang(serverRet.data.substr(6))); |
---|
| 163 | else{ |
---|
| 164 | var tdElement = document.getElementById(startTime); |
---|
| 165 | var eventDiv = document.createElement('DIV'); |
---|
| 166 | eventDiv.id = "event_" + serverRet.substringData(6,serverRet.data.length); |
---|
| 167 | eventDiv.innerHTML = description; |
---|
| 168 | var endDateDiv = document.createElement('DIV'); |
---|
| 169 | var startDateDiv = document.createElement('DIV'); |
---|
| 170 | endDateDiv.id = endDate.getTime(); |
---|
| 171 | startDateDiv.id = id2timeStamp(startTime); |
---|
| 172 | eventDiv.appendChild(startDateDiv); |
---|
| 173 | eventDiv.appendChild(endDateDiv); |
---|
| 174 | |
---|
| 175 | createEventDiv(eventDiv); |
---|
| 176 | write_msg(get_lang("Event were added successfully!")); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | XMLTools.request('$this.uicalendar.quickAdd&start='+parseInt(id2timeStamp(startTime)/1000)+'&end='+parseInt(endDate.getTime()/1000)+'&desc='+description, 'GET', handler_quickAdd); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | function changeEvent(objEvent,field,value){ |
---|
| 184 | init_ = timeStamp2id(objEvent.childNodes[1].id).substr(8); |
---|
| 185 | end_ = timeStamp2id(objEvent.childNodes[2].id).substr(8); |
---|
| 186 | |
---|
| 187 | var handler_changeEvent = function (data){ |
---|
| 188 | var serverRet = data.firstChild.childNodes[0]; |
---|
| 189 | var retStatus = serverRet.substringData(1,5); |
---|
| 190 | if (retStatus == "false") |
---|
| 191 | write_msg(get_lang("Error") + ": " + serverRet.data) |
---|
| 192 | else |
---|
| 193 | switch (field) { |
---|
| 194 | case 'edatetime': |
---|
| 195 | for (var hour = parseInt(init_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30) |
---|
| 196 | screenTable[weekDay][hour]--; |
---|
| 197 | |
---|
| 198 | objEvent.childNodes[2].id = value*1000; |
---|
| 199 | var resizeIcon = document.getElementById("resize_"+objEvent.id); |
---|
| 200 | resizeIcon.parentNode.removeChild(resizeIcon); |
---|
| 201 | |
---|
| 202 | createEventDiv(objEvent); |
---|
| 203 | break; |
---|
| 204 | default: |
---|
| 205 | alert('not implemented'); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | XMLTools.request('$this.uicalendar.changeEvent&cal_id='+objEvent.id.substr(6)+'&field='+field+'&value='+value, 'GET', handler_changeEvent); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | // Convert Unix Time Stamp to Div Id used in calendar |
---|
| 212 | function timeStamp2id(timeStamp){ |
---|
| 213 | var tmpDate = new Date(); |
---|
| 214 | tmpDate.setTime(timeStamp); |
---|
| 215 | return (tmpDate.getYear()+1900)+""+ |
---|
| 216 | (tmpDate.getDate()<10?"0"+tmpDate.getDate():tmpDate.getDate())+ |
---|
| 217 | (tmpDate.getMonth()<9?"0"+(tmpDate.getMonth()+1):(tmpDate.getMonth()+1))+ |
---|
| 218 | (tmpDate.getHours()<10?"0"+tmpDate.getHours():tmpDate.getHours())+ |
---|
| 219 | (tmpDate.getMinutes()<10?"0"+tmpDate.getMinutes():tmpDate.getMinutes()); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // Convert the opposite of function above |
---|
| 223 | function id2timeStamp(id){ |
---|
| 224 | objDate = new Date(); |
---|
| 225 | objDate.setYear(id.substr(0,4)); |
---|
| 226 | objDate.setMonth(id.substr(6,2)-1); |
---|
| 227 | objDate.setDate(id.substr(4,2)); |
---|
| 228 | objDate.setHours(id.substr(8,2)); |
---|
| 229 | objDate.setMinutes(id.substr(10,2)); |
---|
| 230 | return objDate.getTime(); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | function get_lang(_key,_arg1,_arg2,_arg3,_arg4){ |
---|
| 235 | if (_key.length == 0) |
---|
| 236 | return ''; |
---|
| 237 | if(!array_lang[0]){ |
---|
| 238 | return _key+"*"; |
---|
| 239 | } |
---|
| 240 | _value = ""; |
---|
| 241 | for(i = 0; i < array_lang[0].length;i++){ |
---|
| 242 | if(array_lang[0][i] == _key.toLowerCase()) { |
---|
| 243 | _value = array_lang[1][i]; |
---|
| 244 | break; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if(!_value) |
---|
| 249 | return _key+"*"; |
---|
| 250 | |
---|
| 251 | if(_arg1 || _arg2 ||_arg3 || _arg4) { |
---|
| 252 | for(j = 1; j <= 4; j++){ |
---|
| 253 | if(eval("_arg"+j)) { |
---|
| 254 | var regExp = new RegExp("%"+j+""); |
---|
| 255 | _value = _value.replace(regExp,eval("_arg"+j)); |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | return _value; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | function resizeEvent (eventDiv) { |
---|
| 263 | _dragArea.pressed = 1; |
---|
| 264 | _dragArea.initEvent = eventDiv.parentNode.id; |
---|
| 265 | _dragArea.resizing = 1; |
---|
| 266 | _dragArea.currentEvent = eventDiv; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | refreshLang(); |
---|