[5341] | 1 | User = { |
---|
| 2 | |
---|
| 3 | init: function(){ |
---|
[5715] | 4 | this.moduleName = 'expressoCalendar'; |
---|
[5409] | 5 | this.me = DataLayer.dispatch( "me" ); |
---|
| 6 | |
---|
[5468] | 7 | |
---|
| 8 | this.timezones = Timezone.timezones; |
---|
| 9 | this.isDaylightSaving = Timezone.daylightSaving; |
---|
[5409] | 10 | this.load(); |
---|
[5715] | 11 | }, |
---|
[5341] | 12 | |
---|
| 13 | load: function(){ |
---|
| 14 | |
---|
[5409] | 15 | var defaultPreferences = { dateFormat: "dd/MM/yyyy", |
---|
| 16 | hourFormat: "HH:mm", |
---|
| 17 | defaultCalView: "month", |
---|
| 18 | defaultDuration: 30, |
---|
| 19 | backgroundColor: "36C", |
---|
| 20 | borderColor: "36C", |
---|
| 21 | fontColor: "fff", |
---|
| 22 | timezone: 'America/Sao_Paulo', |
---|
| 23 | weekStart: 'SUN' |
---|
| 24 | }; |
---|
[5341] | 25 | |
---|
[5409] | 26 | var pref = DataLayer.get( "modulePreference:detail", ['and',[ "=", "user", this.me.id ], [ "=", "module", this.moduleName ]] ); |
---|
| 27 | |
---|
| 28 | this.preferences = DataLayer.merge( defaultPreferences, pref.values || {} ); |
---|
| 29 | this.preferenceIds = pref.ids; |
---|
[5341] | 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
[5514] | 33 | constantsParticipant = { |
---|
| 34 | 'o' : 'organization', |
---|
| 35 | 'w' : 'write', |
---|
| 36 | 'p' : 'participationRequired', |
---|
| 37 | 'i' : 'inviteGuests', |
---|
| 38 | 'r' : 'read' |
---|
| 39 | } |
---|
| 40 | |
---|
[5592] | 41 | constantsCalendarShared = { |
---|
| 42 | 'r' : 'read', |
---|
| 43 | 'w' : 'write', |
---|
| 44 | 'd' : 'remove', |
---|
| 45 | 'b' : 'busy', |
---|
[5804] | 46 | 's' : 'shared', |
---|
| 47 | 'p' : 'required' |
---|
[5592] | 48 | } |
---|
| 49 | |
---|
[5341] | 50 | UI = { |
---|
| 51 | dialogs: { |
---|
| 52 | addEvent: null, |
---|
[5529] | 53 | importCalendar: null, |
---|
[5592] | 54 | sharedCalendar: null, |
---|
| 55 | copyCalendar: null |
---|
[5341] | 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | DataLayer.codec( "calendarSignature", "calendar", { |
---|
| 60 | |
---|
[5409] | 61 | decoder: function(){}, |
---|
[5341] | 62 | |
---|
[5409] | 63 | encoder: function( signatures ){ |
---|
| 64 | return $.map( signatures, function( signature ){ |
---|
| 65 | return { events: function( start, end, callback ){ |
---|
[5341] | 66 | var viewKey = start + ':' + end; |
---|
[5409] | 67 | if( Calendar.currentViewKey !== viewKey ){ |
---|
[5341] | 68 | Calendar.currentViewKey = viewKey; |
---|
| 69 | Calendar.currentView = DataLayer.get( 'schedulable:calendar', { start: start, end: end } ); |
---|
| 70 | } |
---|
| 71 | var view = Calendar.currentView[ signature.calendar.id ]; |
---|
| 72 | callback( view && !view.hidden ? view : [] ); |
---|
| 73 | }, |
---|
| 74 | |
---|
| 75 | backgroundColor: '#' + signature.backgroundColor || User.preferences.backgroundColor, |
---|
| 76 | borderColor: '#' + signature.borderColor || User.preferences.borderColor, |
---|
| 77 | textColor: '#' + signature.fontColor || User.preferences.fontColor, |
---|
| 78 | editable: signature.isOwner } |
---|
| 79 | }); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | }); |
---|
| 84 | |
---|
[5592] | 85 | DataLayer.codec( "calendarToPermission", "detail", { |
---|
| 86 | decoder: function( evtObj ){ |
---|
| 87 | /* Encoder.EncodeType = "entity"; |
---|
| 88 | |
---|
| 89 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 90 | evtObj = [ evtObj ]; |
---|
| 91 | |
---|
| 92 | var res = $.map(evtObj, function( form){ |
---|
| 93 | return [$.map(form.user , function( user, i){ |
---|
| 94 | return { |
---|
| 95 | calendar: form.calendar, |
---|
| 96 | user: user, |
---|
| 97 | acl: form.attendeeAcl[i], |
---|
| 98 | type: 0 |
---|
| 99 | }; |
---|
| 100 | })]; |
---|
| 101 | }); |
---|
| 102 | |
---|
| 103 | return notArray ? res[0] : res; |
---|
| 104 | */ |
---|
| 105 | }, |
---|
| 106 | |
---|
| 107 | encoder: function( evtObj ){ |
---|
| 108 | |
---|
| 109 | if(evtObj == "") |
---|
| 110 | return ""; |
---|
| 111 | |
---|
| 112 | var notArray = false; |
---|
| 113 | |
---|
| 114 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 115 | evtObj = [ evtObj ]; |
---|
| 116 | |
---|
| 117 | var constantAcl = function(acl){ |
---|
| 118 | var returns = {}; |
---|
| 119 | for (var i in constantsCalendarShared){ |
---|
| 120 | returns[constantsCalendarShared[i]] = acl.indexOf(i) >= 0 ? true : false |
---|
| 121 | } |
---|
| 122 | return returns; |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 126 | return { |
---|
| 127 | id: objEvent.id, |
---|
| 128 | type: objEvent.type, |
---|
| 129 | calendar: objEvent.calendar, |
---|
| 130 | user: objEvent.user, |
---|
| 131 | acl: constantAcl(objEvent.acl) , |
---|
| 132 | aclValues: objEvent.acl |
---|
| 133 | }; |
---|
| 134 | }); |
---|
| 135 | return notArray ? res[0] : res; |
---|
| 136 | } |
---|
| 137 | }); |
---|
| 138 | |
---|
| 139 | |
---|
[5341] | 140 | Calendar = { |
---|
| 141 | |
---|
[5409] | 142 | load: function(){ |
---|
| 143 | this.lastView = 0; |
---|
[5804] | 144 | var filter = ['=', 'user', User.me.id]; |
---|
| 145 | if(!!User.me.gidNumber){ |
---|
| 146 | if(!$.isArray(User.me.gidNumber)) |
---|
| 147 | User.me.gidNumber = [User.me.gidNumber]; |
---|
| 148 | |
---|
| 149 | filter = ['OR', filter, ['IN', 'user', User.me.gidNumber]]; |
---|
| 150 | } |
---|
[5807] | 151 | |
---|
| 152 | //var descart = DataLayer.get("calendarSignature", {filter: filter, criteria: {deepness: 2}}); |
---|
| 153 | this.signatures = DataLayer.get("calendarSignature", {filter: filter, criteria: {deepness: 2}}); |
---|
[5341] | 154 | |
---|
[5409] | 155 | var prevSources = this.sources; |
---|
[5341] | 156 | |
---|
[5409] | 157 | this.sources = DataLayer.encode( "calendarSignature:calendar", this.signatures ); |
---|
[5341] | 158 | |
---|
[5409] | 159 | if( prevSources ){ |
---|
| 160 | var newSources = DataLayer.diff( { 'diff': prevSources }, { 'diff': this.sources } ).diff; |
---|
[5341] | 161 | |
---|
[5409] | 162 | for( var i = 0; i < newSources.length; i++ ) |
---|
| 163 | $('#calendar').fullCalendar( 'addEventSource', newSources[i] ); |
---|
[5341] | 164 | |
---|
[5409] | 165 | var removeSources = DataLayer.diff( { 'diff': newSources }, { 'diff': prevSources } ).diff; |
---|
[5341] | 166 | |
---|
[5409] | 167 | for( var i = 0; i < removeSources.length; i++ ) |
---|
| 168 | $('#calendar').fullCalendar( 'removeEventSource', removeSources[i] ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | this.calendarIds = [], this.signatureOf = {}, this.calendars = [], this.calendarOf= {}; |
---|
| 172 | |
---|
| 173 | for( var i = 0; i < this.signatures.length; i++ ){ |
---|
[5592] | 174 | if(this.signatures[i].isOwner == "0") |
---|
| 175 | this.signatures[i].permission = DataLayer.encode('calendarToPermission:detail', this.signatures[i].permission); |
---|
[5437] | 176 | this.signatureOf[ this.calendarIds[i] = ( this.calendars[ this.calendars.length ] = this.calendarOf[ this.signatures[i].id ] = this.signatures[i].calendar ).id ] = this.signatures[i]; |
---|
[5409] | 177 | } |
---|
| 178 | |
---|
[5384] | 179 | delete Calendar.currentViewKey; |
---|
[5409] | 180 | }, |
---|
| 181 | |
---|
| 182 | rerenderView: function(force){ |
---|
| 183 | |
---|
| 184 | if(force){ |
---|
[5746] | 185 | delete Calendar.currentViewKey; |
---|
| 186 | |
---|
[5409] | 187 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | var calendarNotSelected = getSelectedCalendars( true ); |
---|
[5384] | 191 | for(var i = 0; i < calendarNotSelected.length; i++) |
---|
| 192 | if(!!Calendar.currentView[ calendarNotSelected[i] ]) |
---|
| 193 | Calendar.currentView[ calendarNotSelected[i] ].hidden = true; |
---|
[5409] | 194 | |
---|
[5384] | 195 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
[5746] | 196 | |
---|
| 197 | contentMenu(); |
---|
[5409] | 198 | } |
---|
[5341] | 199 | } |
---|
| 200 | |
---|
| 201 | Alarms = { |
---|
| 202 | load: function(){ |
---|
[5592] | 203 | var eventsDay = DataLayer.get('alarm:schedulable',['=', 'date', Date.today().getTime()]); |
---|
[5341] | 204 | for(var i = 0; i < eventsDay.length; i++){ |
---|
| 205 | this.addAlarm( eventsDay[i] ); |
---|
| 206 | } |
---|
[5729] | 207 | }, |
---|
[5341] | 208 | |
---|
[5729] | 209 | addAlarm: function( eventDay ){ |
---|
[5724] | 210 | if(!DataLayer.tasks[parseInt(eventDay.sendTime)]){ |
---|
| 211 | DataLayer.task( parseInt(eventDay.sendTime) , function( timestamp ){ |
---|
[5729] | 212 | var path = User.moduleName == 'expressoCalendar' ? '' : '../prototype/modules/calendar/'; |
---|
| 213 | DataLayer.render(path+'templates/alarm.ejs',{event: eventDay}, function( html ){ |
---|
| 214 | $.Zebra_Dialog(html , { |
---|
| 215 | 'type': 'question', |
---|
| 216 | 'overlay_opacity': '0.5', |
---|
| 217 | 'buttons': ['Fechar'], |
---|
| 218 | 'onClose': function(clicked) {} |
---|
| 219 | }); |
---|
[5341] | 220 | }); |
---|
[5724] | 221 | }); |
---|
| 222 | } |
---|
[5341] | 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | DataLayer.codec( "modulePreference", "detail", { |
---|
| 227 | decoder: function( evtObj ){ |
---|
| 228 | |
---|
| 229 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 230 | evtObj = [ evtObj ]; |
---|
| 231 | |
---|
| 232 | var res = $.map(evtObj, function( form ){ |
---|
[5409] | 233 | |
---|
[5341] | 234 | var returns = []; |
---|
[5409] | 235 | |
---|
| 236 | for (var name in form) |
---|
| 237 | returns[ returns.length ] = { |
---|
[5341] | 238 | name: name, |
---|
| 239 | user: User.me.id, |
---|
| 240 | value: form[name], |
---|
[5409] | 241 | module: User.moduleName, |
---|
| 242 | id: User.preferenceIds[ name ] || undefined |
---|
[5341] | 243 | }; |
---|
[5409] | 244 | |
---|
| 245 | return [returns]; |
---|
[5341] | 246 | }); |
---|
| 247 | |
---|
| 248 | return notArray ? res[0] : res; |
---|
| 249 | }, |
---|
| 250 | |
---|
| 251 | encoder: function( evtObj ){ |
---|
[5409] | 252 | var val = {}, id = {}; |
---|
[5341] | 253 | for (var i in evtObj){ |
---|
[5409] | 254 | |
---|
| 255 | if( evtObj[i].value && evtObj[i].id ) |
---|
| 256 | { |
---|
| 257 | val[evtObj[i].name] = evtObj[i].value; |
---|
| 258 | id[evtObj[i].name] = evtObj[i].id; |
---|
| 259 | } |
---|
[5341] | 260 | } |
---|
| 261 | return {values: val,ids: id}; |
---|
| 262 | |
---|
| 263 | } |
---|
| 264 | }); |
---|
| 265 | |
---|
| 266 | User.init(); |
---|
| 267 | Calendar.load(); |
---|
| 268 | |
---|
[5409] | 269 | /*Todo Melhorias serão feitas na API*/ |
---|
[5376] | 270 | //DataLayer.poll( "schedulable" ); |
---|
[5341] | 271 | |
---|
[5381] | 272 | DataLayer.listen( "schedulable", function( status, updateData){ |
---|
[5341] | 273 | |
---|
| 274 | if( status === 'serverclient' ){ |
---|
[5384] | 275 | DataLayer.commit( false, false, function(){ |
---|
[5641] | 276 | if((typeof($tabs) != "undefined") && $tabs.tabs('option' ,'selected') == 0){ |
---|
[5746] | 277 | Calendar.rerenderView(true); |
---|
[5641] | 278 | }else if((typeof($tabs) != "undefined") && $tabs.tabs('option' ,'selected') != 0) |
---|
[5409] | 279 | pageselectCallback($('.events-list-win.active [name=keyword]').val(), 0); |
---|
[5724] | 280 | //Recarrega os alarmes de eventos |
---|
| 281 | Alarms.load(); |
---|
[5341] | 282 | }); |
---|
[5384] | 283 | } |
---|
[5341] | 284 | }); |
---|
| 285 | |
---|
[5615] | 286 | //TODO - Voltar quando tratado put de varios items de um mesmo conceito, |
---|
| 287 | /* |
---|
[5341] | 288 | DataLayer.listen( "calendarSignature", function( status ){ |
---|
| 289 | |
---|
[5409] | 290 | switch( status ){ |
---|
| 291 | case 'serverclient': DataLayer.commit( false, false, function( received ){ |
---|
| 292 | delete Calendar.currentViewKey; |
---|
| 293 | Calendar.load(); |
---|
| 294 | refresh_calendars(); |
---|
| 295 | }); |
---|
| 296 | break; |
---|
| 297 | case 'client': |
---|
| 298 | break; |
---|
[5341] | 299 | } |
---|
| 300 | }); |
---|
[5615] | 301 | */ |
---|
[5341] | 302 | |
---|
| 303 | DataLayer.listen( "modulePreference", function( status ){ |
---|
| 304 | |
---|
[5409] | 305 | switch( status ){ |
---|
| 306 | case 'serverclient': DataLayer.commit( false, false, function(){ |
---|
| 307 | User.load(); |
---|
| 308 | }); |
---|
| 309 | break; |
---|
| 310 | case 'client': |
---|
| 311 | break; |
---|
[5341] | 312 | } |
---|
| 313 | |
---|
| 314 | }); |
---|
| 315 | |
---|
| 316 | DataLayer.listen( "alarm", function( created, updated, deleted ){ |
---|
| 317 | |
---|
| 318 | }); |
---|
| 319 | |
---|
[5409] | 320 | /*DataLayer.listen( "calendar", function( status, updateData ){ |
---|
[5341] | 321 | |
---|
[5409] | 322 | if (updateData === false) |
---|
| 323 | switch( status ){ |
---|
| 324 | case 'serverclient': DataLayer.commit( false, false, function(){ |
---|
[5341] | 325 | |
---|
[5409] | 326 | Calendar.load(); |
---|
| 327 | refresh_calendars(); |
---|
[5341] | 328 | |
---|
[5409] | 329 | }); |
---|
| 330 | break; |
---|
| 331 | case 'client': |
---|
| 332 | break; |
---|
[5341] | 333 | } |
---|
[5409] | 334 | });*/ |
---|
[5341] | 335 | |
---|
| 336 | DataLayer.codec( "calendarSignature", "configure", { |
---|
| 337 | decoder: function( evtObj ){ |
---|
| 338 | Encoder.EncodeType = "entity"; |
---|
| 339 | |
---|
| 340 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 341 | evtObj = [ evtObj ]; |
---|
| 342 | |
---|
| 343 | var res = $.map(evtObj, function( form ){ |
---|
| 344 | return{ |
---|
| 345 | id: form.signature, |
---|
| 346 | user: User.me.id, |
---|
| 347 | calendar: { |
---|
[5437] | 348 | id: Calendar.calendarOf[form.signature].id, |
---|
[5341] | 349 | name: Encoder.htmlEncode(form.name), |
---|
| 350 | description: Encoder.htmlEncode(form.description), |
---|
| 351 | timezone: form.timezone, |
---|
| 352 | defaultDuration: form.duration != "" ? form.duration : 30, |
---|
| 353 | location: form.location |
---|
| 354 | }, |
---|
[5615] | 355 | // isOwner: 1, |
---|
[5341] | 356 | fontColor: Encoder.htmlEncode(form.fontColor.substring(1)), |
---|
| 357 | backgroundColor: Encoder.htmlEncode(form.backgroundColor.substring(1)), |
---|
| 358 | borderColor: Encoder.htmlEncode(form.borderColor.substring(1)), |
---|
| 359 | msgAdd: Encoder.htmlEncode(form.msgAdd), |
---|
| 360 | msgCancel: Encoder.htmlEncode(form.msgCancel), |
---|
| 361 | msgUpdate: Encoder.htmlEncode(form.msgUpdate), |
---|
| 362 | msgReply: Encoder.htmlEncode(form.msgReply), |
---|
| 363 | msgAlarm: Encoder.htmlEncode(form.msgAlarm), |
---|
| 364 | calendarSignatureAlarms: $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
[5409] | 365 | return (!!form.alarmId[i] ? |
---|
| 366 | {type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i]} : |
---|
| 367 | {type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i]}); |
---|
[5341] | 368 | }) |
---|
| 369 | }; |
---|
| 370 | |
---|
| 371 | }); |
---|
| 372 | |
---|
| 373 | return notArray ? res[0] : res; |
---|
| 374 | }, |
---|
| 375 | |
---|
[5409] | 376 | encoder: function( evtObj ){} |
---|
[5341] | 377 | }); |
---|
| 378 | |
---|
| 379 | DataLayer.codec( "alarm", "schedulable", { |
---|
| 380 | |
---|
[5409] | 381 | decoder: function( evtObj ){}, |
---|
[5341] | 382 | |
---|
| 383 | encoder: function (evtObjt){ |
---|
[5376] | 384 | |
---|
| 385 | if(notArray = typeof(evtObjt) == 'array' ) |
---|
| 386 | evtObjt = [evtObjt]; |
---|
| 387 | |
---|
[5341] | 388 | var res = $.map(evtObjt, function( objEvent ){ |
---|
[5409] | 389 | |
---|
| 390 | var time = parseInt(objEvent.schedulable.startTime); |
---|
| 391 | |
---|
[5341] | 392 | return{ |
---|
| 393 | id: objEvent.id, |
---|
[5409] | 394 | event_start: new Date( time ).setTimezoneOffset(Timezone.timezones[objEvent.schedulable.timezone]).toString( User.preferences.dateFormat), |
---|
[5341] | 395 | sendTime: objEvent.sendTime, |
---|
| 396 | schedulable: { |
---|
[5592] | 397 | startTime: dateCalendar.formatDate(Timezone.getDateEvent(new Date(time), objEvent.schedulable.timezone, objEvent.schedulable.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
[5341] | 398 | id: objEvent.schedulable.id, |
---|
| 399 | summary: objEvent.schedulable.summary, |
---|
| 400 | time: objEvent.time, |
---|
[5409] | 401 | unit: dateCalendar.timeunit[objEvent.unit.toLowerCase()] + ( parseInt(objEvent.time) > 1 ? 's' : '' ) |
---|
[5341] | 402 | } |
---|
| 403 | } |
---|
| 404 | }); |
---|
| 405 | return notArray ? res[0] : res; |
---|
| 406 | } |
---|
| 407 | }); |
---|
| 408 | |
---|
[5514] | 409 | DataLayer.codec( "suggestion", "duration", { |
---|
| 410 | |
---|
| 411 | decoder: function( evtObj ){ |
---|
| 412 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 413 | evtObj = [ evtObj ]; |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | var meAttendee = function(attendees){ |
---|
| 418 | for(var i = 0; i < attendees.length; i++) |
---|
| 419 | if(DataLayer.get('participant', attendees[i]).user == User.me.id) |
---|
| 420 | return attendee; |
---|
| 421 | }; |
---|
| 422 | |
---|
| 423 | var res = $.map(evtObj, function( form ){ |
---|
| 424 | return { |
---|
| 425 | participant : meAttendee(form.attendee), |
---|
[5636] | 426 | startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 427 | endTime: Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
[5514] | 428 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 429 | schedulable: form.idEvent |
---|
| 430 | } |
---|
| 431 | }); |
---|
| 432 | |
---|
| 433 | |
---|
| 434 | return notArray ? res[0] : res; |
---|
| 435 | }, |
---|
| 436 | |
---|
| 437 | encoder: function( evtObj ){} |
---|
| 438 | |
---|
| 439 | }); |
---|
| 440 | |
---|
| 441 | DataLayer.codec( "attachment", "detail", { |
---|
| 442 | |
---|
| 443 | decoder: function(evtObj){ |
---|
| 444 | |
---|
| 445 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 446 | evtObj = [ evtObj ]; |
---|
| 447 | |
---|
| 448 | var res = $.map(evtObj, function( form){ |
---|
| 449 | return [$.map(form.files , function( files){ |
---|
| 450 | return { source: files }; |
---|
| 451 | })]; |
---|
| 452 | }); |
---|
| 453 | return notArray ? res[0] : res; |
---|
| 454 | }, |
---|
| 455 | |
---|
| 456 | encoder: function(){} |
---|
| 457 | |
---|
| 458 | |
---|
| 459 | }); |
---|
| 460 | |
---|
[5341] | 461 | DataLayer.codec( "schedulable", "preview", { |
---|
| 462 | |
---|
| 463 | decoder: function( evtObj ){ |
---|
| 464 | Encoder.EncodeType = "entity"; |
---|
| 465 | |
---|
| 466 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 467 | evtObj = [ evtObj ]; |
---|
| 468 | |
---|
| 469 | var pref = User.preferences; |
---|
[5947] | 470 | |
---|
| 471 | var Owner = decodeOwnerCalendar(evtObj.calendar); |
---|
[5341] | 472 | |
---|
| 473 | var res = $.map(evtObj, function( form ){ |
---|
| 474 | |
---|
[5376] | 475 | return { |
---|
| 476 | id: form.idEvent, |
---|
| 477 | calendar: form.calendar, |
---|
[5514] | 478 | participants : $.map(form.attendee, function( attendee, i ){ |
---|
| 479 | if(isNaN(attendee)){ |
---|
[5947] | 480 | return{ |
---|
| 481 | id: attendee, |
---|
| 482 | acl: form.attendeeAcl[i], |
---|
| 483 | delegatedFrom: !!form.delegatedFrom[i] ? form.delegatedFrom[i] : 0, |
---|
| 484 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 485 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, |
---|
| 486 | acl: form.attendeeAcl[i].replace('o', '') |
---|
| 487 | }; |
---|
[5514] | 488 | }else{ |
---|
[5947] | 489 | if(DataLayer.get('participant', attendee).user == Owner.id){ |
---|
[5514] | 490 | var me = { |
---|
[5947] | 491 | user: User.id, |
---|
| 492 | status: form.status, |
---|
| 493 | id: attendee, |
---|
| 494 | isOrganizer: 0, |
---|
| 495 | receiveNotification : (!!form.receiveNotification ? 1 : 0), |
---|
| 496 | alarms: typeof(form.alarmTime) != 'undefined' ? |
---|
| 497 | $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
[5341] | 498 | |
---|
[5947] | 499 | if( alarmTime === "" ) |
---|
| 500 | return( null ); |
---|
[5341] | 501 | |
---|
[5947] | 502 | return !!form.alarmId[i] ? |
---|
| 503 | { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] } : |
---|
| 504 | { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; |
---|
| 505 | }) : [] |
---|
| 506 | }; |
---|
[5514] | 507 | |
---|
| 508 | if(form.startDate){ |
---|
| 509 | var tzId = DataLayer.get('schedulable', form.idEvent).timezone || User.preferences.timezone, |
---|
| 510 | formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? pref.dateFormat+" HH:mm" : pref.dateFormat + " " + pref.hourFormat; |
---|
| 511 | |
---|
| 512 | DataLayer.put('notification', { |
---|
[5947] | 513 | participant: me.id, |
---|
| 514 | type: 'suggestion', |
---|
| 515 | startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 516 | endTime: Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 517 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 518 | schedulable: form.idEvent |
---|
[5514] | 519 | }); |
---|
| 520 | |
---|
| 521 | } |
---|
| 522 | return me; |
---|
| 523 | }else return(null); |
---|
| 524 | }; |
---|
| 525 | }) |
---|
[5341] | 526 | } |
---|
| 527 | }); |
---|
[5376] | 528 | return notArray ? res[0] : res; |
---|
[5341] | 529 | }, |
---|
| 530 | |
---|
| 531 | encoder: function( evtObj ){ |
---|
| 532 | |
---|
| 533 | var notArray = false; |
---|
| 534 | |
---|
| 535 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 536 | evtObj = [ evtObj ]; |
---|
| 537 | |
---|
[5409] | 538 | var statusParticipants = {}, |
---|
| 539 | |
---|
| 540 | statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ]; |
---|
| 541 | |
---|
[5514] | 542 | var delegateAttendee = {}; |
---|
| 543 | |
---|
[5409] | 544 | for( var i = 0; i < statusLabels.length; i++ ) |
---|
| 545 | statusParticipants[ statusLabels[i] ] = 0; |
---|
[5358] | 546 | |
---|
[5341] | 547 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 548 | |
---|
[5592] | 549 | if(!(typeof(objEvent) == 'object')) |
---|
| 550 | return (null); |
---|
[5947] | 551 | |
---|
| 552 | var Owner = decodeOwnerCalendar(objEvent.calendar); |
---|
| 553 | |
---|
| 554 | var participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy( Owner ); |
---|
[5592] | 555 | |
---|
[5514] | 556 | var constantAcl = function(acl){ |
---|
[5947] | 557 | var returns = {}; |
---|
| 558 | for (var i in constantsParticipant){ |
---|
| 559 | returns[constantsParticipant[i]] = acl.indexOf(i) >= 0 ? true : false |
---|
| 560 | } |
---|
| 561 | return returns; |
---|
[5514] | 562 | }; |
---|
[5947] | 563 | |
---|
[5341] | 564 | return { |
---|
[5409] | 565 | "class": objEvent["class"], |
---|
| 566 | id: objEvent.id, |
---|
[5715] | 567 | repeat: encodeRepeat( objEvent.repeat ), |
---|
[5409] | 568 | location: objEvent.location, |
---|
| 569 | category: objEvent.category, |
---|
| 570 | calendars: Calendar.calendars, |
---|
| 571 | calendar: objEvent.calendar, |
---|
| 572 | summary: objEvent.summary, |
---|
| 573 | description: objEvent.description, |
---|
| 574 | timezone: objEvent.timezone, |
---|
| 575 | timezones: Timezone.timezones, |
---|
| 576 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
[5592] | 577 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
[5409] | 578 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
[5592] | 579 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
[5409] | 580 | allDay: !!parseInt( objEvent.allDay ), |
---|
[5947] | 581 | attachments: $.map(objEvent.attachments || [], function( attachment, i ){ |
---|
[5514] | 582 | var attach = DataLayer.get('schedulableToAttachment', attachment, false); |
---|
[5720] | 583 | var ext = attach.name.split('.'); |
---|
| 584 | attach.name = attach.name.length < 10 ? attach.name : ( ext.length == 1 ? attach.name.substr(0, 10) : (attach.name.substr(0, 6) + '.' + ext[ext.length -1])); |
---|
[5515] | 585 | attach.size = formatBytes(attach.size); |
---|
[5514] | 586 | return attach; |
---|
| 587 | }), |
---|
[5409] | 588 | attendee: $.map(objEvent.participants || [], function( participant, i ){ |
---|
[5947] | 589 | |
---|
| 590 | if(delegateAttendee[participant]) |
---|
| 591 | return(null); |
---|
| 592 | |
---|
| 593 | var attend = DataLayer.get('participant', (participant.id || participant)); |
---|
| 594 | attend.user = DataLayer.get('user', attend.user); |
---|
| 595 | |
---|
| 596 | statusParticipants[ statusLabels[attend.status] ]++; |
---|
| 597 | |
---|
| 598 | if( attend.user.id === me.id ){ |
---|
| 599 | participantInfo.user = { |
---|
| 600 | id: attend.id, |
---|
| 601 | status : attend.status, |
---|
| 602 | delegatedFrom: attend.delegatedFrom || '0', |
---|
| 603 | acl: attend.acl, |
---|
| 604 | receiveNotification : attend.receiveNotification, |
---|
| 605 | alarms : $.map(attend.alarms || [], function( alarm ){ |
---|
| 606 | var alarm = DataLayer.get('alarm', alarm); |
---|
| 607 | return (alarm == "" ? (null) : alarm); |
---|
| 608 | }) |
---|
| 609 | }; |
---|
| 610 | me.id = attend.id; |
---|
| 611 | return(null); |
---|
| 612 | }; |
---|
| 613 | |
---|
| 614 | var person = { |
---|
| 615 | id: attend.id, |
---|
| 616 | name: attend.user.name != 'false' ? attend.user.name : '', |
---|
| 617 | mail: attend.user.mail, |
---|
| 618 | status : attend.status, |
---|
| 619 | isExternal: attend.isExternal, |
---|
| 620 | acl: attend.acl, |
---|
| 621 | delegatedFrom: attend.delegatedFrom |
---|
| 622 | }; |
---|
| 623 | |
---|
| 624 | if(!!parseInt(attend.delegatedFrom)){ |
---|
| 625 | delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); |
---|
| 626 | return(null); |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | if( !!parseInt(attend.isOrganizer )){ |
---|
| 630 | participantInfo.organizer = DataLayer.copy(person); |
---|
| 631 | return(null); |
---|
| 632 | }; |
---|
| 633 | |
---|
| 634 | return (person); |
---|
| 635 | }), |
---|
[5409] | 636 | organizer: participantInfo.organizer || me, |
---|
[5514] | 637 | alarms: !!participantInfo.user ? participantInfo.user.alarms : [], |
---|
| 638 | status: !!participantInfo.user ? participantInfo.user.status : 1, |
---|
[5592] | 639 | acl: !!participantInfo.user ? constantAcl(participantInfo.user.acl) : constantAcl( 'rowi' ), |
---|
[5608] | 640 | isShared: !this.id ? false : (!!objEvent.calendar) && parseInt(Calendar.signatureOf[objEvent.calendar].isOwner) ? false : true, |
---|
[5596] | 641 | me: !!participantInfo.user ? DataLayer.merge(participantInfo.user, me) : DataLayer.merge(this.isShared ? this.organizer : me, {acl: !this.isShared ? 'rowi' : Calendar.signatureOf[objEvent.calendar].permission.aclValues, delegatedFrom: 0, receiveNotification: 1}), |
---|
[5514] | 642 | delegatedFrom: delegatedFrom, |
---|
[5715] | 643 | |
---|
[5409] | 644 | statusParticipants: statusParticipants |
---|
| 645 | }; |
---|
[5947] | 646 | }); |
---|
| 647 | return (notArray ? res[0] : res); |
---|
[5341] | 648 | } |
---|
| 649 | }); |
---|
| 650 | |
---|
[5947] | 651 | |
---|
| 652 | function decodeOwnerCalendar(calendar){ |
---|
| 653 | if(calendar && !parseInt(Calendar.signatureOf[calendar].isOwner)){ |
---|
| 654 | var Owner = DataLayer.get('calendarSignature', {filter: ['AND', ['=','calendar', calendar], ['=','isOwner','1']], criteria: {deepness: 2}}); |
---|
| 655 | |
---|
| 656 | if($.isArray(Owner)) |
---|
| 657 | Owner = Owner[0]; |
---|
| 658 | |
---|
| 659 | return Owner.user; |
---|
| 660 | } |
---|
| 661 | return User.me; |
---|
| 662 | |
---|
| 663 | |
---|
| 664 | } |
---|
| 665 | |
---|
[5715] | 666 | function decodeRepeat ( form ) { |
---|
[5341] | 667 | |
---|
[5715] | 668 | var patati = {}; |
---|
| 669 | |
---|
| 670 | if( form.repeatId ) |
---|
| 671 | patati['id'] = form.repeatId; |
---|
[5341] | 672 | |
---|
[5715] | 673 | patati['frequency'] = form.frequency; |
---|
| 674 | |
---|
| 675 | patati['bymonthday'] = patati['byyearday'] = patati['byday'] = ''; |
---|
| 676 | |
---|
| 677 | patati['interval'] = patati['endTime'] = patati['count'] = patati['startTime'] = 0; |
---|
| 678 | |
---|
| 679 | if( form.frequency === 'none' ) |
---|
| 680 | return( patati ); |
---|
| 681 | |
---|
| 682 | var day = []; |
---|
| 683 | |
---|
| 684 | $("input[type=checkbox][name='repeatweekly[]']:checked").each(function() { |
---|
| 685 | day[ day.length ] = $(this).val(); |
---|
| 686 | }); |
---|
| 687 | |
---|
| 688 | patati['byday'] = day.join(','); |
---|
| 689 | |
---|
| 690 | var formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
| 691 | |
---|
[5807] | 692 | var date = Date.parseExact( form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ); |
---|
[5715] | 693 | |
---|
| 694 | patati['startTime'] = date.toString('yyyy-MM-dd HH:mm:00'); |
---|
| 695 | |
---|
| 696 | if( !patati['byday'] ) |
---|
| 697 | switch(form.frequency) { |
---|
| 698 | case 'weekly': |
---|
| 699 | break; |
---|
| 700 | case 'daily': |
---|
| 701 | break; |
---|
| 702 | case 'monthly': |
---|
| 703 | patati['bymonthday'] = date.getDate(); |
---|
| 704 | break; |
---|
| 705 | case 'yearly': |
---|
| 706 | patati['byyearday'] = date.getDayOfYear(); |
---|
| 707 | break; |
---|
| 708 | default : |
---|
| 709 | return patati; |
---|
| 710 | } |
---|
| 711 | |
---|
| 712 | if (($(".endRepeat").val() == 'occurrences')) |
---|
| 713 | patati['count'] = $(".occurrencesEnd").val(); |
---|
| 714 | |
---|
| 715 | if (($(".endRepeat").val() == 'customDate')) |
---|
| 716 | patati['endTime'] = Date.parseExact( $(".customDateEnd").val() + (!!form.allDay ? " 00:00": " "+$.trim(form.endHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'); |
---|
| 717 | |
---|
| 718 | patati['interval'] = $(".eventInterval").val(); |
---|
| 719 | |
---|
| 720 | /** |
---|
| 721 | wkst = [ 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU' ] |
---|
| 722 | weekno = number |
---|
| 723 | minute = number |
---|
| 724 | second = number |
---|
| 725 | yearday = number |
---|
| 726 | monthday = number |
---|
| 727 | setpos = number |
---|
| 728 | day = number |
---|
| 729 | hour = number |
---|
| 730 | interval = number |
---|
| 731 | frequency = [ 'monthly', 'daily', 'weekly', 'yearly', 'hourly', 'minutely', 'secondly' ] |
---|
| 732 | endTime = milliseconds |
---|
| 733 | */ |
---|
| 734 | return( patati ); |
---|
| 735 | |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | |
---|
| 739 | |
---|
| 740 | function encodeRepeat( repeat ){ |
---|
| 741 | |
---|
| 742 | if( !repeat ) |
---|
| 743 | return( false ); |
---|
[5835] | 744 | if(typeof(repeat) == "object") |
---|
| 745 | return repeat; |
---|
[5715] | 746 | |
---|
| 747 | return DataLayer.get( 'repeat', repeat ); |
---|
| 748 | } |
---|
| 749 | |
---|
[5341] | 750 | DataLayer.codec( "schedulable", "detail", { |
---|
| 751 | |
---|
| 752 | decoder: function( evtObj ){ |
---|
[5409] | 753 | |
---|
[5341] | 754 | Encoder.EncodeType = "entity"; |
---|
| 755 | |
---|
| 756 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 757 | evtObj = [ evtObj ]; |
---|
| 758 | |
---|
| 759 | var pref = User.preferences; |
---|
| 760 | |
---|
| 761 | var res = $.map(evtObj, function( form ){ |
---|
[5409] | 762 | |
---|
[5437] | 763 | var tzId = form.timezone || Calendar.signatureOf[form.calendar].calendar.timezone || User.preferences.timezone, |
---|
[5341] | 764 | |
---|
[5947] | 765 | formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? pref.dateFormat+" HH:mm" : pref.dateFormat + " " + pref.hourForma; |
---|
| 766 | |
---|
| 767 | var Owner = decodeOwnerCalendar(form.calendar); |
---|
| 768 | |
---|
[5341] | 769 | return { |
---|
[5947] | 770 | "class": form["class"], |
---|
| 771 | startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 772 | endTime: Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'), //+ (!!form.allDay ? 86400000 : 0) , |
---|
| 773 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 774 | id: form.idEvent, |
---|
| 775 | location: form.location, |
---|
| 776 | category: form.category, |
---|
| 777 | calendar: form.calendar, |
---|
| 778 | summary: form.summary, |
---|
| 779 | description: form.description, |
---|
| 780 | timezone: tzId, |
---|
| 781 | attachments: $.map(form.attachment || [], function( attachment, i ){ |
---|
| 782 | return {attachment: attachment} |
---|
| 783 | }), |
---|
| 784 | repeat: this.decodeRepeat( form ), |
---|
| 785 | participants: $.map( form.attendee || [], function( attendee, i ){ |
---|
[5341] | 786 | |
---|
[5947] | 787 | if( !attendee || attendee === "" ) |
---|
| 788 | return( null ); |
---|
[5341] | 789 | |
---|
[5947] | 790 | var participant = {}; |
---|
| 791 | participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ; |
---|
| 792 | |
---|
| 793 | if( participant.user === Owner.id ){ |
---|
| 794 | return DataLayer.merge({ |
---|
| 795 | id: attendee, |
---|
| 796 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 797 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''), |
---|
| 798 | alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 799 | if( alarmTime === "" ) |
---|
| 800 | return( null ); |
---|
| 801 | return !!form.alarmId[i] ? { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] }: |
---|
| 802 | { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; |
---|
| 803 | }), |
---|
| 804 | status: !!form.status ? form.status : 3 |
---|
| 805 | }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {}); |
---|
| 806 | }else{ |
---|
| 807 | return DataLayer.merge({ |
---|
| 808 | id: attendee, |
---|
| 809 | acl: form.attendeeAcl[i], |
---|
| 810 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 811 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, |
---|
| 812 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '') |
---|
| 813 | }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {}); |
---|
| 814 | }; |
---|
| 815 | }) |
---|
| 816 | }; |
---|
[5341] | 817 | }); |
---|
| 818 | |
---|
| 819 | return notArray ? res[0] : res; |
---|
| 820 | }, |
---|
| 821 | |
---|
[5715] | 822 | |
---|
[5341] | 823 | encoder: function( evtObj ){ |
---|
[5409] | 824 | |
---|
[5715] | 825 | if(!(!!evtObj)) |
---|
| 826 | return undefined; |
---|
[5341] | 827 | |
---|
[5715] | 828 | var notArray = false; |
---|
| 829 | |
---|
| 830 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 831 | evtObj = [ evtObj ]; |
---|
[5341] | 832 | |
---|
[5715] | 833 | var pref = User.preferences; |
---|
[5341] | 834 | |
---|
[5715] | 835 | var res = DataLayer.encode('schedulable:preview', evtObj); |
---|
[5341] | 836 | |
---|
[5715] | 837 | if( !notArray ){ |
---|
| 838 | var dates = {}; |
---|
[5835] | 839 | var typeRepeat = {'none': false, |
---|
| 840 | 'daily': 'Repetição diária', |
---|
| 841 | 'weekly': 'Repetição semanal', |
---|
| 842 | 'monthly': 'Repetição mensal', |
---|
| 843 | 'yearly': 'repetição anual'} |
---|
[5341] | 844 | |
---|
[5715] | 845 | for (var i=0; i < res.length; i++) { |
---|
| 846 | |
---|
| 847 | var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat ); |
---|
| 848 | var endDate = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat ); |
---|
| 849 | |
---|
| 850 | var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() ); |
---|
| 851 | |
---|
| 852 | var occurrences = [ startDate.getTime() ]; |
---|
| 853 | |
---|
| 854 | if( res[i].occurrences ) |
---|
| 855 | { |
---|
| 856 | occurrences = res[i].occurrences; |
---|
| 857 | } |
---|
[5341] | 858 | |
---|
[5715] | 859 | for( var ii = 0; ii < occurrences.length; ii++ ) |
---|
| 860 | { |
---|
| 861 | var currentDate = new Date( occurrences[ii] ); |
---|
| 862 | var counter = currentDate.clone(); |
---|
| 863 | |
---|
| 864 | var res2 = $.extend( {}, res[i], {'startDate': currentDate.toString( User.preferences.dateFormat ), 'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat ) } ); |
---|
| 865 | |
---|
[5835] | 866 | |
---|
| 867 | |
---|
| 868 | |
---|
| 869 | res2.repeat = typeRepeat[res[i].repeat.frequency]; |
---|
| 870 | |
---|
[5715] | 871 | while (counter.compareTo( currentDate ) == 0) { |
---|
[5341] | 872 | |
---|
[5715] | 873 | if (!dates[counter.toString(User.preferences.dateFormat)]) |
---|
| 874 | dates[counter.toString(User.preferences.dateFormat)] = { startDate:false, events:[] }; |
---|
| 875 | if (!dates[counter.toString(User.preferences.dateFormat)].startDate) |
---|
| 876 | dates[counter.toString(User.preferences.dateFormat)].startDate = counter.toString(User.preferences.dateFormat); |
---|
[5341] | 877 | |
---|
[5715] | 878 | dates[counter.toString(User.preferences.dateFormat)].events.push(res2); |
---|
| 879 | counter.addDays(-1); |
---|
| 880 | } |
---|
| 881 | } |
---|
| 882 | } |
---|
| 883 | res = { events_list: dates, |
---|
| 884 | count : res.length |
---|
| 885 | }; |
---|
| 886 | } |
---|
[5341] | 887 | |
---|
[5715] | 888 | return notArray ? res[0] : res; |
---|
[5341] | 889 | } |
---|
| 890 | |
---|
| 891 | }); |
---|
| 892 | |
---|
| 893 | DataLayer.codec( "participant", "detail", { |
---|
| 894 | |
---|
| 895 | encoder: function( participants ){ |
---|
| 896 | |
---|
[5409] | 897 | var result = {}; |
---|
| 898 | for( var i = 0; i< participants.length; i++ ){ |
---|
| 899 | result[ participants[i].user.id || participants[i].user ] = participants[i]; |
---|
| 900 | } |
---|
| 901 | return( result ); |
---|
[5341] | 902 | } |
---|
| 903 | }); |
---|
| 904 | |
---|
| 905 | DataLayer.codec( "calendar", "list", { |
---|
| 906 | |
---|
| 907 | encoder: function( calendars ){ |
---|
| 908 | |
---|
[5409] | 909 | var result = { my_calendars: [], others_calendars: [] }; |
---|
[5341] | 910 | |
---|
[5409] | 911 | for( var i = 0; i < calendars.length; i++ ) |
---|
| 912 | { |
---|
| 913 | !!Calendar.signatureOf[ calendars[i].id ].isOwner ? |
---|
| 914 | result.my_calendars.push( calendars[i] ) : |
---|
| 915 | result.others_calendars.push( calendars[i] ); |
---|
| 916 | } |
---|
[5341] | 917 | |
---|
[5409] | 918 | return { agendas_usuario: result }; |
---|
[5341] | 919 | |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | }); |
---|
| 923 | |
---|
| 924 | DataLayer.codec( "schedulable", "calendar", { |
---|
| 925 | |
---|
| 926 | decoder:function( evtObj ){ |
---|
| 927 | |
---|
| 928 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 929 | evtObj = [ evtObj ]; |
---|
| 930 | |
---|
| 931 | var res = $.map(evtObj, function( evt ){ |
---|
| 932 | |
---|
| 933 | return { id: evt.id, |
---|
| 934 | summary: evt.title, |
---|
| 935 | startTime: evt.start.getTime(), |
---|
| 936 | endTime: ( !!evt.allDay ? (( evt.end || evt.start ).getTime() + 86400000) :( evt.end || evt.start ).getTime()), |
---|
| 937 | allDay: ( !!evt.allDay ? 1 : 0 ) |
---|
| 938 | /*calendar: evt.id && User.calendarOf[ evt.id ].id*/ }; |
---|
| 939 | }); |
---|
| 940 | |
---|
| 941 | return notArray ? res[0] : res; |
---|
| 942 | }, |
---|
| 943 | |
---|
| 944 | encoder: function( evtObj, filter ){ |
---|
[5947] | 945 | |
---|
[5341] | 946 | if( !evtObj ) |
---|
| 947 | return( false ); |
---|
| 948 | |
---|
| 949 | var filtered = evtObj; |
---|
| 950 | // |
---|
| 951 | var grouped = {}; |
---|
| 952 | |
---|
| 953 | $.map(filtered, function( evt ){ |
---|
[5592] | 954 | |
---|
| 955 | if(!(typeof(evt) == 'object') || (evt.id.indexOf('java') >= 0)) |
---|
| 956 | return (null); |
---|
[5341] | 957 | |
---|
| 958 | evt.calendar = evt.calendar || "1"; |
---|
| 959 | |
---|
| 960 | if( !grouped[ evt.calendar ] ) |
---|
| 961 | grouped[ evt.calendar ] = []; |
---|
| 962 | |
---|
| 963 | var calendar = DataLayer.get('calendar', evt.calendar); |
---|
[5442] | 964 | |
---|
[5746] | 965 | var eventEditable = function(idEvent, isRecurrence, Recurrence){ |
---|
[5592] | 966 | if(Calendar.signatureOf[calendar.id].isOwner == "1"){ |
---|
| 967 | var attendee = {}; |
---|
| 968 | for(var i = 0; i < evt.participants.length; i++){ |
---|
| 969 | attendee = DataLayer.get('participant', evt.participants[i]); |
---|
| 970 | if(attendee.user == User.me.id) |
---|
[5746] | 971 | return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? {selectable: true, className: 'fullcalendar-context-menu event-id-'+idEvent+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '')} : { editable: false, selectable: true ,className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent}; |
---|
[5592] | 972 | } |
---|
[5715] | 973 | return {editable: false, className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent, selectable: true, disableDragging: isRecurrence }; |
---|
[5442] | 974 | } |
---|
[5592] | 975 | else{ |
---|
| 976 | var aclSignature = Calendar.signatureOf[calendar.id].permission; |
---|
| 977 | |
---|
| 978 | var mountClass = function(acl){ |
---|
| 979 | var returns = "" |
---|
| 980 | returns += acl['write'] ? "" : 'blocked-event-permision '; |
---|
[5746] | 981 | returns += acl['busy'] ? 'fullcalendar-not-context-menu ' : (acl['read'] ? 'fullcalendar-context-menu '+ idEvent + (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') : ''); |
---|
[5592] | 982 | returns += 'event-id-'+idEvent; |
---|
| 983 | return returns; |
---|
| 984 | } |
---|
| 985 | return DataLayer.merge({ |
---|
[5715] | 986 | editable: aclSignature.acl['write'] && !isRecurrence, |
---|
[5592] | 987 | disableResizing : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true : false), |
---|
| 988 | disableDragging : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true: false), |
---|
| 989 | className: mountClass(aclSignature.acl) |
---|
| 990 | }, aclSignature.acl['busy'] ? {title: 'Ocupado', selectable: false } : {selectable: true}); |
---|
| 991 | } |
---|
| 992 | |
---|
[5442] | 993 | } |
---|
[5715] | 994 | |
---|
| 995 | var duration = parseInt( evt.endTime ) - parseInt( evt.startTime ), isRepeat = false; |
---|
| 996 | |
---|
[5737] | 997 | var occurrences = []; |
---|
[5715] | 998 | |
---|
| 999 | if( evt.occurrences ) |
---|
| 1000 | { |
---|
| 1001 | isRepeat = true; |
---|
| 1002 | occurrences = evt.occurrences; |
---|
[5752] | 1003 | }else |
---|
| 1004 | occurrences[ occurrences.length ] = evt.startTime; |
---|
[5737] | 1005 | |
---|
[5752] | 1006 | //occurrences = DataLayer.unique( occurrences ).sort(); |
---|
[5409] | 1007 | |
---|
[5715] | 1008 | for( var i = 0; i < occurrences.length; i++ ) |
---|
[5746] | 1009 | grouped[ evt.calendar ].push( DataLayer.merge({ id: evt.URI || evt.id+ '-' + i, |
---|
| 1010 | title: Encoder.htmlDecode(evt.summary), |
---|
| 1011 | start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1012 | end: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1013 | allDay: parseInt( evt.allDay ), |
---|
| 1014 | isRepeat: isRepeat, |
---|
[5947] | 1015 | occurrence: i, |
---|
| 1016 | calendar: evt.calendar}, eventEditable(evt.id, isRepeat, i ) ) ); |
---|
[5341] | 1017 | }); |
---|
| 1018 | |
---|
| 1019 | return(/* notArray ? filtered[0] :*/ grouped ); |
---|
| 1020 | }, |
---|
| 1021 | |
---|
| 1022 | criteria: function( filter ){ |
---|
| 1023 | |
---|
[5409] | 1024 | if( $.type(filter.start) !== 'date' ) |
---|
| 1025 | filter.start = new Date( filter.start * 1000 ); |
---|
| 1026 | if( $.type(filter.end) !== 'date' ) |
---|
| 1027 | filter.end = new Date( filter.end * 1000 ); |
---|
[5341] | 1028 | |
---|
[5592] | 1029 | var timezone = {}; |
---|
| 1030 | for(var i in Calendar.signatureOf) |
---|
| 1031 | timezone[i] = Calendar.signatureOf[i].calendar.timezone; |
---|
| 1032 | |
---|
[5409] | 1033 | return { filter: ["AND", |
---|
[5341] | 1034 | |
---|
[5592] | 1035 | [ ">=", "rangeStart", filter.start.getTime() ], |
---|
| 1036 | [ "<=", "rangeEnd", filter.end.getTime() ], |
---|
[5409] | 1037 | [ "IN", "calendar", Calendar.calendarIds ] |
---|
[5341] | 1038 | |
---|
[5409] | 1039 | ], |
---|
[5592] | 1040 | criteria: { deepness: 2, timezones: timezone } } |
---|
[5341] | 1041 | } |
---|
| 1042 | }); |
---|
| 1043 | |
---|
| 1044 | |
---|
| 1045 | DataLayer.codec( "preference", "detail", { |
---|
| 1046 | |
---|
[5409] | 1047 | decoder:function( pref ){ |
---|
[5341] | 1048 | |
---|
[5409] | 1049 | var res = []; |
---|
[5341] | 1050 | |
---|
[5409] | 1051 | pref.defaultAlarm = $.map( pref.alarmTime || [], function( alarmTime, i ){ |
---|
| 1052 | |
---|
| 1053 | return { type: pref.alarmType[i], |
---|
| 1054 | time: alarmTime, |
---|
| 1055 | unit: pref.alarmUnit[i] }; |
---|
| 1056 | }); |
---|
[5341] | 1057 | |
---|
[5409] | 1058 | $.each( pref, function( i, el ){ |
---|
[5341] | 1059 | |
---|
[5409] | 1060 | res[ res.length ] = { name: i, value: el }; |
---|
[5341] | 1061 | |
---|
[5409] | 1062 | }); |
---|
| 1063 | |
---|
| 1064 | return( res ); |
---|
| 1065 | |
---|
| 1066 | }, |
---|
[5341] | 1067 | |
---|
[5409] | 1068 | encoder:function( pref ){ |
---|
| 1069 | return( pref ); |
---|
| 1070 | } |
---|
[5341] | 1071 | |
---|
| 1072 | }); |
---|
| 1073 | |
---|
| 1074 | DataLayer.codec( "schedulable", "export", { |
---|
| 1075 | |
---|
[5409] | 1076 | decoder: function(){}, |
---|
[5341] | 1077 | |
---|
[5409] | 1078 | encoder: function( signatures ){}, |
---|
[5341] | 1079 | |
---|
[5409] | 1080 | criteria: function( filter ){ |
---|
[5341] | 1081 | |
---|
[5409] | 1082 | if( isCal = filter && filter.calendar ) |
---|
| 1083 | filter = filter.calendar; |
---|
| 1084 | return { |
---|
| 1085 | filter: filter ? [ "=", ( isCal ? "calendar" : "id" ), filter ] : false, |
---|
| 1086 | criteria: { format: 'iCal', deepness: 2 } |
---|
| 1087 | }; |
---|
| 1088 | } |
---|
[5341] | 1089 | }); |
---|
| 1090 | |
---|
| 1091 | Alarms.load(); |
---|
| 1092 | |
---|
| 1093 | // DataLayer.decoder( "participant", "detail", function( form ){ |
---|
| 1094 | // |
---|
| 1095 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1096 | // // notArray = true; |
---|
| 1097 | // // attObj = [ attObj ]; |
---|
| 1098 | // // } |
---|
| 1099 | // |
---|
| 1100 | // |
---|
| 1101 | // |
---|
| 1102 | // return( participants ); |
---|
| 1103 | // |
---|
| 1104 | // }); |
---|
| 1105 | |
---|
| 1106 | // DataLayer.decoder( "alarm", "detail", function( form ){ |
---|
| 1107 | // |
---|
| 1108 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1109 | // // notArray = true; |
---|
| 1110 | // // attObj = [ attObj ]; |
---|
| 1111 | // // } |
---|
| 1112 | // |
---|
| 1113 | // var alarms = []; |
---|
| 1114 | // |
---|
| 1115 | // if( form.alarmType /*&& !form.*/ ) |
---|
| 1116 | // for( var i = 0; i < form.alarmType.length; i++ ) |
---|
| 1117 | // { |
---|
| 1118 | // if( form.alarmTime[i] === "" ) |
---|
| 1119 | // continue; |
---|
| 1120 | // |
---|
| 1121 | // alarms[i] = { type: form.alarmType[i], |
---|
| 1122 | // unit: form.alarmUnit[i], |
---|
| 1123 | // time: form.alarmTime[i] }; |
---|
| 1124 | // } |
---|
| 1125 | // |
---|
| 1126 | // return( alarms ); |
---|
| 1127 | // |
---|
| 1128 | // }); |
---|
| 1129 | |
---|