[5341] | 1 | User = { |
---|
| 2 | |
---|
| 3 | init: function(){ |
---|
[6066] | 4 | this.moduleName = 'expressoCalendar'; |
---|
| 5 | this.me = DataLayer.dispatch( "me" ); |
---|
[5409] | 6 | |
---|
[5468] | 7 | |
---|
[6066] | 8 | this.timezones = Timezone.timezones; |
---|
| 9 | this.isDaylightSaving = Timezone.daylightSaving; |
---|
| 10 | this.load(); |
---|
[5715] | 11 | }, |
---|
[5341] | 12 | |
---|
| 13 | load: function(){ |
---|
| 14 | |
---|
[6066] | 15 | var defaultPreferences = { |
---|
| 16 | dateFormat: "dd/MM/yyyy", |
---|
| 17 | hourFormat: "HH:mm", |
---|
| 18 | defaultCalView: "month", |
---|
| 19 | defaultDuration: 30, |
---|
| 20 | backgroundColor: "36C", |
---|
| 21 | borderColor: "36C", |
---|
| 22 | fontColor: "fff", |
---|
| 23 | timezone: 'America/Sao_Paulo', |
---|
[6768] | 24 | weekStart: 'SUN', |
---|
| 25 | useDesktopNotification: 0 |
---|
[6066] | 26 | }; |
---|
[5341] | 27 | |
---|
[6066] | 28 | var pref = DataLayer.get( "modulePreference:detail", ['and',[ "=", "user", this.me.id ], [ "=", "module", this.moduleName ]] ); |
---|
[5409] | 29 | |
---|
[6066] | 30 | this.preferences = DataLayer.merge( defaultPreferences, pref.values || {} ); |
---|
| 31 | this.preferenceIds = pref.ids; |
---|
[5341] | 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
[6977] | 35 | updateActivity = false; |
---|
| 36 | |
---|
[5514] | 37 | constantsParticipant = { |
---|
[6066] | 38 | 'o' : 'organization', |
---|
| 39 | 'w' : 'write', |
---|
| 40 | 'p' : 'participationRequired', |
---|
| 41 | 'i' : 'inviteGuests', |
---|
| 42 | 'r' : 'read' |
---|
[5514] | 43 | } |
---|
| 44 | |
---|
[5592] | 45 | constantsCalendarShared = { |
---|
[6066] | 46 | 'r' : 'read', |
---|
| 47 | 'w' : 'write', |
---|
| 48 | 'd' : 'remove', |
---|
| 49 | 'b' : 'busy', |
---|
| 50 | 's' : 'shared', |
---|
| 51 | 'p' : 'required' |
---|
[5592] | 52 | } |
---|
| 53 | |
---|
[5341] | 54 | UI = { |
---|
[6066] | 55 | dialogs: { |
---|
| 56 | addEvent: null, |
---|
| 57 | importCalendar: null, |
---|
| 58 | sharedCalendar: null, |
---|
| 59 | copyCalendar: null |
---|
| 60 | } |
---|
[5341] | 61 | } |
---|
| 62 | |
---|
| 63 | DataLayer.codec( "calendarSignature", "calendar", { |
---|
| 64 | |
---|
[6066] | 65 | decoder: function(){}, |
---|
[5341] | 66 | |
---|
[6066] | 67 | encoder: function( signatures ){ |
---|
| 68 | return $.map( signatures, function( signature ){ |
---|
| 69 | return { |
---|
| 70 | events: function( start, end, callback ){ |
---|
| 71 | var viewKey = start + ':' + end; |
---|
| 72 | if( Calendar.currentViewKey !== viewKey ){ |
---|
| 73 | Calendar.currentViewKey = viewKey; |
---|
| 74 | Calendar.currentView = DataLayer.get( 'schedulable:calendar', { |
---|
| 75 | start: start, |
---|
| 76 | end: end |
---|
| 77 | } ); |
---|
| 78 | } |
---|
| 79 | var view = Calendar.currentView[ signature.calendar.id ]; |
---|
| 80 | callback( view && !view.hidden ? view : [] ); |
---|
| 81 | }, |
---|
[5341] | 82 | |
---|
[6066] | 83 | backgroundColor: '#' + signature.backgroundColor || User.preferences.backgroundColor, |
---|
| 84 | borderColor: '#' + signature.borderColor || User.preferences.borderColor, |
---|
| 85 | textColor: '#' + signature.fontColor || User.preferences.fontColor, |
---|
[6169] | 86 | className: [], |
---|
[6066] | 87 | editable: signature.isOwner |
---|
| 88 | } |
---|
| 89 | }); |
---|
| 90 | } |
---|
[5341] | 91 | |
---|
| 92 | |
---|
| 93 | }); |
---|
| 94 | |
---|
[5592] | 95 | DataLayer.codec( "calendarToPermission", "detail", { |
---|
[6066] | 96 | decoder: function( evtObj ){ |
---|
| 97 | /* Encoder.EncodeType = "entity"; |
---|
[5592] | 98 | |
---|
| 99 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 100 | evtObj = [ evtObj ]; |
---|
| 101 | |
---|
| 102 | var res = $.map(evtObj, function( form){ |
---|
| 103 | return [$.map(form.user , function( user, i){ |
---|
| 104 | return { |
---|
| 105 | calendar: form.calendar, |
---|
| 106 | user: user, |
---|
| 107 | acl: form.attendeeAcl[i], |
---|
| 108 | type: 0 |
---|
| 109 | }; |
---|
| 110 | })]; |
---|
| 111 | }); |
---|
| 112 | |
---|
| 113 | return notArray ? res[0] : res; |
---|
| 114 | */ |
---|
[6066] | 115 | }, |
---|
[5592] | 116 | |
---|
| 117 | encoder: function( evtObj ){ |
---|
| 118 | |
---|
[6066] | 119 | if(evtObj == "") |
---|
| 120 | return ""; |
---|
[5592] | 121 | |
---|
[6066] | 122 | var notArray = false; |
---|
[5592] | 123 | |
---|
[6066] | 124 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 125 | evtObj = [ evtObj ]; |
---|
[5592] | 126 | |
---|
[6066] | 127 | var constantAcl = function(acl){ |
---|
| 128 | var returns = {}; |
---|
| 129 | for (var i in constantsCalendarShared){ |
---|
| 130 | returns[constantsCalendarShared[i]] = acl.indexOf(i) >= 0 ? true : false |
---|
| 131 | } |
---|
| 132 | return returns; |
---|
| 133 | }; |
---|
[5592] | 134 | |
---|
[6066] | 135 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 136 | return { |
---|
| 137 | id: objEvent.id, |
---|
| 138 | type: objEvent.type, |
---|
| 139 | calendar: objEvent.calendar, |
---|
| 140 | user: objEvent.user, |
---|
| 141 | acl: constantAcl(objEvent.acl) , |
---|
| 142 | aclValues: objEvent.acl |
---|
| 143 | }; |
---|
| 144 | }); |
---|
[5592] | 145 | return notArray ? res[0] : res; |
---|
[6066] | 146 | } |
---|
[5592] | 147 | }); |
---|
| 148 | |
---|
[5341] | 149 | DataLayer.codec( "modulePreference", "detail", { |
---|
[6066] | 150 | decoder: function( evtObj ){ |
---|
[5341] | 151 | |
---|
| 152 | if( notArray = $.type(evtObj) !== "array" ) |
---|
[6066] | 153 | evtObj = [ evtObj ]; |
---|
[5341] | 154 | |
---|
[6066] | 155 | var res = $.map(evtObj, function( form ){ |
---|
[5409] | 156 | |
---|
[6066] | 157 | var returns = []; |
---|
[5409] | 158 | |
---|
[6066] | 159 | for (var name in form) |
---|
| 160 | returns[ returns.length ] = { |
---|
| 161 | name: name, |
---|
| 162 | user: User.me.id, |
---|
| 163 | value: form[name], |
---|
| 164 | module: User.moduleName, |
---|
| 165 | id: User.preferenceIds[ name ] || undefined |
---|
| 166 | }; |
---|
[5409] | 167 | |
---|
[6066] | 168 | return [returns]; |
---|
| 169 | }); |
---|
[5341] | 170 | |
---|
| 171 | return notArray ? res[0] : res; |
---|
[6066] | 172 | }, |
---|
[5341] | 173 | |
---|
| 174 | encoder: function( evtObj ){ |
---|
[6066] | 175 | var val = {}, id = {}; |
---|
| 176 | for (var i in evtObj){ |
---|
[5409] | 177 | |
---|
[6066] | 178 | if( evtObj[i].value && evtObj[i].id ) |
---|
| 179 | { |
---|
| 180 | val[evtObj[i].name] = evtObj[i].value; |
---|
| 181 | id[evtObj[i].name] = evtObj[i].id; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | return { |
---|
| 185 | values: val, |
---|
| 186 | ids: id |
---|
| 187 | }; |
---|
[5341] | 188 | |
---|
[6066] | 189 | } |
---|
[5341] | 190 | }); |
---|
| 191 | |
---|
[5409] | 192 | /*Todo Melhorias serão feitas na API*/ |
---|
[5376] | 193 | //DataLayer.poll( "schedulable" ); |
---|
[5341] | 194 | |
---|
[5381] | 195 | DataLayer.listen( "schedulable", function( status, updateData){ |
---|
[5341] | 196 | |
---|
| 197 | if( status === 'serverclient' ){ |
---|
[6066] | 198 | DataLayer.commit( false, false, function(){ |
---|
[6359] | 199 | Calendar.rerenderView(true); |
---|
[6977] | 200 | if(updateActivity) |
---|
| 201 | refreshTaskActivity(); |
---|
[6066] | 202 | }); |
---|
[5384] | 203 | } |
---|
[5341] | 204 | }); |
---|
| 205 | |
---|
[5615] | 206 | //TODO - Voltar quando tratado put de varios items de um mesmo conceito, |
---|
| 207 | /* |
---|
[5341] | 208 | DataLayer.listen( "calendarSignature", function( status ){ |
---|
| 209 | |
---|
[5409] | 210 | switch( status ){ |
---|
| 211 | case 'serverclient': DataLayer.commit( false, false, function( received ){ |
---|
| 212 | delete Calendar.currentViewKey; |
---|
| 213 | Calendar.load(); |
---|
| 214 | refresh_calendars(); |
---|
| 215 | }); |
---|
| 216 | break; |
---|
| 217 | case 'client': |
---|
| 218 | break; |
---|
[5341] | 219 | } |
---|
| 220 | }); |
---|
[5615] | 221 | */ |
---|
[5341] | 222 | |
---|
| 223 | DataLayer.listen( "modulePreference", function( status ){ |
---|
| 224 | |
---|
[5409] | 225 | switch( status ){ |
---|
[6066] | 226 | case 'serverclient': |
---|
| 227 | DataLayer.commit( false, false, function(){ |
---|
| 228 | User.load(); |
---|
| 229 | }); |
---|
| 230 | break; |
---|
| 231 | case 'client': |
---|
| 232 | break; |
---|
[5341] | 233 | } |
---|
| 234 | |
---|
| 235 | }); |
---|
| 236 | |
---|
| 237 | DataLayer.listen( "alarm", function( created, updated, deleted ){ |
---|
| 238 | |
---|
[6066] | 239 | }); |
---|
[5341] | 240 | |
---|
[5409] | 241 | /*DataLayer.listen( "calendar", function( status, updateData ){ |
---|
[5341] | 242 | |
---|
[5409] | 243 | if (updateData === false) |
---|
| 244 | switch( status ){ |
---|
| 245 | case 'serverclient': DataLayer.commit( false, false, function(){ |
---|
[5341] | 246 | |
---|
[5409] | 247 | Calendar.load(); |
---|
| 248 | refresh_calendars(); |
---|
[5341] | 249 | |
---|
[5409] | 250 | }); |
---|
| 251 | break; |
---|
| 252 | case 'client': |
---|
| 253 | break; |
---|
[5341] | 254 | } |
---|
[5409] | 255 | });*/ |
---|
[5341] | 256 | |
---|
| 257 | DataLayer.codec( "calendarSignature", "configure", { |
---|
[6066] | 258 | decoder: function( evtObj ){ |
---|
| 259 | Encoder.EncodeType = "entity"; |
---|
[5341] | 260 | |
---|
[6066] | 261 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 262 | evtObj = [ evtObj ]; |
---|
[5341] | 263 | |
---|
[6066] | 264 | var res = $.map(evtObj, function( form ){ |
---|
| 265 | return{ |
---|
| 266 | id: form.signature, |
---|
| 267 | user: User.me.id, |
---|
| 268 | calendar: { |
---|
[6898] | 269 | id: !!!parseInt(form.type) ? Calendar.calendarOf[form.signature].id : Calendar.groupOf[form.signature].id, |
---|
[6066] | 270 | name: Encoder.htmlEncode(form.name), |
---|
| 271 | description: Encoder.htmlEncode(form.description), |
---|
| 272 | timezone: form.timezone, |
---|
| 273 | defaultDuration: form.duration != "" ? form.duration : 30, |
---|
| 274 | location: form.location |
---|
| 275 | }, |
---|
| 276 | // isOwner: 1, |
---|
| 277 | fontColor: Encoder.htmlEncode(form.fontColor.substring(1)), |
---|
| 278 | backgroundColor: Encoder.htmlEncode(form.backgroundColor.substring(1)), |
---|
| 279 | borderColor: Encoder.htmlEncode(form.borderColor.substring(1)), |
---|
| 280 | msgAdd: Encoder.htmlEncode(form.msgAdd), |
---|
| 281 | msgCancel: Encoder.htmlEncode(form.msgCancel), |
---|
| 282 | msgUpdate: Encoder.htmlEncode(form.msgUpdate), |
---|
| 283 | msgReply: Encoder.htmlEncode(form.msgReply), |
---|
| 284 | msgAlarm: Encoder.htmlEncode(form.msgAlarm), |
---|
| 285 | calendarSignatureAlarms: $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 286 | return (!!form.alarmId[i] ? |
---|
| 287 | { |
---|
| 288 | type: form.alarmType[i], |
---|
| 289 | unit: form.alarmUnit[i], |
---|
| 290 | time: form.alarmTime[i], |
---|
| 291 | id: form.alarmId[i] |
---|
| 292 | } : |
---|
| 293 | { |
---|
| 294 | type: form.alarmType[i], |
---|
| 295 | unit: form.alarmUnit[i], |
---|
| 296 | time: form.alarmTime[i] |
---|
| 297 | }); |
---|
| 298 | }) |
---|
| 299 | }; |
---|
[5341] | 300 | |
---|
[6066] | 301 | }); |
---|
[5341] | 302 | return notArray ? res[0] : res; |
---|
[6066] | 303 | }, |
---|
[5341] | 304 | |
---|
[5409] | 305 | encoder: function( evtObj ){} |
---|
[5341] | 306 | }); |
---|
| 307 | |
---|
| 308 | DataLayer.codec( "alarm", "schedulable", { |
---|
| 309 | |
---|
[5409] | 310 | decoder: function( evtObj ){}, |
---|
[5341] | 311 | |
---|
[6066] | 312 | encoder: function (evtObjt){ |
---|
[6151] | 313 | if(evtObjt == '') return false; |
---|
| 314 | |
---|
| 315 | if((notArray = typeof(evtObjt) !== 'array') && (!evtObjt.length)) |
---|
[6066] | 316 | evtObjt = [evtObjt]; |
---|
[5376] | 317 | |
---|
[6066] | 318 | var res = $.map(evtObjt, function( objEvent ){ |
---|
[5409] | 319 | |
---|
[6066] | 320 | var time = parseInt(objEvent.schedulable.startTime); |
---|
[5409] | 321 | |
---|
[6066] | 322 | return{ |
---|
[6151] | 323 | id: objEvent.schedulable.id, |
---|
[6066] | 324 | event_start: new Date( time ).setTimezoneOffset(Timezone.timezones[objEvent.schedulable.timezone]).toString( User.preferences.dateFormat), |
---|
[6151] | 325 | sendTime: parseInt(objEvent.schedulable.sendTime) / 1000, |
---|
[6066] | 326 | schedulable: { |
---|
| 327 | startTime: dateCalendar.formatDate(Timezone.getDateEvent(new Date(time), objEvent.schedulable.timezone, objEvent.schedulable.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 328 | id: objEvent.schedulable.id, |
---|
| 329 | summary: objEvent.schedulable.summary, |
---|
[6151] | 330 | time: objEvent.schedulable.time, |
---|
| 331 | unit: (dateCalendar.timeunit[objEvent.schedulable.unit.toLowerCase()]) + ( parseInt(objEvent.schedulable.time) > 1 ? 's' : '' ) |
---|
[6066] | 332 | } |
---|
| 333 | } |
---|
| 334 | }); |
---|
[6151] | 335 | return res; |
---|
[6066] | 336 | } |
---|
[5341] | 337 | }); |
---|
| 338 | |
---|
[5514] | 339 | DataLayer.codec( "suggestion", "duration", { |
---|
| 340 | |
---|
| 341 | decoder: function( evtObj ){ |
---|
[6066] | 342 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 343 | evtObj = [ evtObj ]; |
---|
[5514] | 344 | |
---|
| 345 | |
---|
| 346 | |
---|
[6066] | 347 | var meAttendee = function(attendees){ |
---|
| 348 | for(var i = 0; i < attendees.length; i++) |
---|
| 349 | if(DataLayer.get('participant', attendees[i]).user == User.me.id) |
---|
| 350 | return attendee; |
---|
| 351 | }; |
---|
[5514] | 352 | |
---|
[6066] | 353 | var res = $.map(evtObj, function( form ){ |
---|
| 354 | return { |
---|
| 355 | participant : meAttendee(form.attendee), |
---|
[6444] | 356 | startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 357 | endTime: Date.parseExact(form.endDate + " "+$.trim(form.endHour), formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
[6066] | 358 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 359 | schedulable: form.idEvent |
---|
| 360 | } |
---|
| 361 | }); |
---|
[5514] | 362 | |
---|
| 363 | |
---|
| 364 | return notArray ? res[0] : res; |
---|
[6066] | 365 | }, |
---|
[5514] | 366 | |
---|
[6066] | 367 | encoder: function( evtObj ){} |
---|
[5514] | 368 | |
---|
| 369 | }); |
---|
| 370 | |
---|
| 371 | DataLayer.codec( "attachment", "detail", { |
---|
| 372 | |
---|
[6066] | 373 | decoder: function(evtObj){ |
---|
[5514] | 374 | |
---|
[6066] | 375 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 376 | evtObj = [ evtObj ]; |
---|
[5514] | 377 | |
---|
[6066] | 378 | var res = $.map(evtObj, function( form){ |
---|
| 379 | return [$.map(form.files , function( files){ |
---|
| 380 | return { |
---|
| 381 | source: files |
---|
| 382 | }; |
---|
| 383 | })]; |
---|
| 384 | }); |
---|
[5514] | 385 | return notArray ? res[0] : res; |
---|
[6066] | 386 | }, |
---|
[5514] | 387 | |
---|
[6066] | 388 | encoder: function(){} |
---|
[5514] | 389 | |
---|
| 390 | |
---|
| 391 | }); |
---|
| 392 | |
---|
[5341] | 393 | DataLayer.codec( "schedulable", "preview", { |
---|
| 394 | |
---|
| 395 | decoder: function( evtObj ){ |
---|
[6066] | 396 | Encoder.EncodeType = "entity"; |
---|
[5341] | 397 | |
---|
[6066] | 398 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 399 | evtObj = [ evtObj ]; |
---|
[5341] | 400 | |
---|
[6066] | 401 | var pref = User.preferences; |
---|
[5947] | 402 | |
---|
[6331] | 403 | var Owner = decodeOwnerCalendar(evtObj[0].calendar); |
---|
[5341] | 404 | |
---|
[6066] | 405 | var res = $.map(evtObj, function( form ){ |
---|
[5341] | 406 | |
---|
[6331] | 407 | return DataLayer.merge({ |
---|
[6066] | 408 | id: form.idEvent, |
---|
| 409 | participants : $.map(form.attendee, function( attendee, i ){ |
---|
| 410 | if(isNaN(attendee)){ |
---|
| 411 | return{ |
---|
| 412 | id: attendee, |
---|
| 413 | acl: form.attendeeAcl[i], |
---|
| 414 | delegatedFrom: !!form.delegatedFrom[i] ? form.delegatedFrom[i] : 0, |
---|
| 415 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 416 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, |
---|
| 417 | acl: form.attendeeAcl[i].replace('o', '') |
---|
| 418 | }; |
---|
| 419 | }else{ |
---|
| 420 | if(DataLayer.get('participant', attendee).user == Owner.id){ |
---|
| 421 | var me = { |
---|
[6331] | 422 | user: Owner.id, |
---|
[6066] | 423 | status: form.status, |
---|
| 424 | id: attendee, |
---|
| 425 | isOrganizer: 0, |
---|
| 426 | receiveNotification : (!!form.receiveNotification ? 1 : 0), |
---|
| 427 | alarms: typeof(form.alarmTime) != 'undefined' ? |
---|
| 428 | $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
[5341] | 429 | |
---|
[6066] | 430 | if( alarmTime === "" ) |
---|
| 431 | return( null ); |
---|
[5341] | 432 | |
---|
[6066] | 433 | return !!form.alarmId[i] ? |
---|
| 434 | { |
---|
| 435 | type: form.alarmType[i], |
---|
| 436 | unit: form.alarmUnit[i], |
---|
| 437 | time: form.alarmTime[i], |
---|
| 438 | id: form.alarmId[i] |
---|
| 439 | } : |
---|
| 440 | { |
---|
| 441 | type: form.alarmType[i], |
---|
| 442 | unit: form.alarmUnit[i], |
---|
| 443 | time: form.alarmTime[i] |
---|
| 444 | }; |
---|
| 445 | }) : [] |
---|
| 446 | }; |
---|
[5514] | 447 | |
---|
[6066] | 448 | if(form.startDate){ |
---|
| 449 | var tzId = DataLayer.get('schedulable', form.idEvent).timezone || User.preferences.timezone, |
---|
[6444] | 450 | formatString = pref.dateFormat + " " + pref.hourFormat; |
---|
[5514] | 451 | |
---|
[6066] | 452 | DataLayer.put('notification', { |
---|
| 453 | participant: me.id, |
---|
| 454 | type: 'suggestion', |
---|
| 455 | startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 456 | endTime: Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'), |
---|
| 457 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 458 | schedulable: form.idEvent |
---|
| 459 | }); |
---|
[5514] | 460 | |
---|
[6066] | 461 | } |
---|
| 462 | return me; |
---|
| 463 | }else return(null); |
---|
| 464 | }; |
---|
| 465 | }) |
---|
[6331] | 466 | }, (Owner.id == User.me.id) ? (form.calendar != form.lastCalendar ? {calendar: form.calendar, lastCalendar: form.lastCalendar} : {}) : {}) |
---|
[6066] | 467 | }); |
---|
| 468 | return notArray ? res[0] : res; |
---|
[5341] | 469 | }, |
---|
| 470 | |
---|
| 471 | encoder: function( evtObj ){ |
---|
| 472 | |
---|
| 473 | var notArray = false; |
---|
| 474 | |
---|
| 475 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 476 | evtObj = [ evtObj ]; |
---|
| 477 | |
---|
[5409] | 478 | var statusParticipants = {}, |
---|
| 479 | |
---|
| 480 | statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ]; |
---|
| 481 | |
---|
[5514] | 482 | var delegateAttendee = {}; |
---|
| 483 | |
---|
[5409] | 484 | for( var i = 0; i < statusLabels.length; i++ ) |
---|
[6066] | 485 | statusParticipants[ statusLabels[i] ] = 0; |
---|
[5358] | 486 | |
---|
[5341] | 487 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 488 | |
---|
[6066] | 489 | if(!(typeof(objEvent) == 'object')) |
---|
| 490 | return (null); |
---|
[5947] | 491 | |
---|
[6066] | 492 | var isAttendee = false; |
---|
| 493 | var Owner = decodeOwnerCalendar(objEvent.calendar); |
---|
[5947] | 494 | |
---|
[6066] | 495 | var participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy( Owner ); |
---|
[5592] | 496 | |
---|
[6066] | 497 | var constantAcl = function(acl){ |
---|
| 498 | var returns = {}; |
---|
| 499 | for (var i in constantsParticipant){ |
---|
| 500 | returns[constantsParticipant[i]] = acl.indexOf(i) >= 0 ? true : false |
---|
| 501 | } |
---|
| 502 | return returns; |
---|
| 503 | }; |
---|
[5947] | 504 | |
---|
[6198] | 505 | var isShared = !objEvent.id ? false : (!!objEvent.calendar) && parseInt(Calendar.signatureOf[objEvent.calendar].isOwner) ? false : true; |
---|
[6476] | 506 | var limitAttendee = false; |
---|
[6198] | 507 | |
---|
[6066] | 508 | return { |
---|
| 509 | "class": objEvent["class"], |
---|
| 510 | id: objEvent.id, |
---|
| 511 | repeat: encodeRepeat( objEvent.repeat ), |
---|
| 512 | location: objEvent.location, |
---|
| 513 | category: objEvent.category, |
---|
| 514 | calendars: Calendar.calendars, |
---|
| 515 | calendar: objEvent.calendar, |
---|
| 516 | summary: objEvent.summary, |
---|
[6880] | 517 | type: !!objEvent.type ? objEvent.type : 1, |
---|
[6066] | 518 | description: objEvent.description, |
---|
| 519 | timezone: objEvent.timezone, |
---|
| 520 | timezones: Timezone.timezones, |
---|
| 521 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 522 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 523 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 524 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
| 525 | allDay: !!parseInt( objEvent.allDay ), |
---|
| 526 | attachments: $.map(objEvent.attachments || [], function( attachment, i ){ |
---|
| 527 | var attach = DataLayer.get('schedulableToAttachment', attachment, false); |
---|
[6331] | 528 | //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o |
---|
[6090] | 529 | if(!attach.name) return(null); |
---|
| 530 | |
---|
[6066] | 531 | var ext = attach.name.split('.'); |
---|
| 532 | 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])); |
---|
| 533 | attach.size = formatBytes(attach.size); |
---|
| 534 | return attach; |
---|
| 535 | }), |
---|
| 536 | attendee: $.map(objEvent.participants || [], function( participant, i ){ |
---|
[5947] | 537 | |
---|
[6066] | 538 | if(delegateAttendee[participant]) |
---|
| 539 | return(null); |
---|
[5947] | 540 | |
---|
[6066] | 541 | var attend = DataLayer.get('participant', (participant.id || participant)); |
---|
| 542 | attend.user = DataLayer.get('user', attend.user); |
---|
[5947] | 543 | |
---|
[6066] | 544 | statusParticipants[ statusLabels[attend.status] ]++; |
---|
[5947] | 545 | |
---|
[6066] | 546 | if(attend.user.mail == User.me.mail) |
---|
| 547 | isAttendee = true; |
---|
[5947] | 548 | |
---|
[6066] | 549 | if( attend.user.id === me.id ){ |
---|
| 550 | participantInfo.user = { |
---|
| 551 | id: attend.id, |
---|
| 552 | status : attend.status, |
---|
| 553 | delegatedFrom: attend.delegatedFrom || '0', |
---|
| 554 | acl: attend.acl, |
---|
| 555 | receiveNotification : attend.receiveNotification, |
---|
| 556 | alarms : $.map(attend.alarms || [], function( alarm ){ |
---|
| 557 | var alarm = DataLayer.get('alarm', alarm); |
---|
| 558 | return (alarm == "" ? (null) : alarm); |
---|
| 559 | }) |
---|
| 560 | }; |
---|
[6295] | 561 | me = attend; |
---|
[6066] | 562 | return(null); |
---|
| 563 | }; |
---|
[5947] | 564 | |
---|
[6066] | 565 | var person = { |
---|
| 566 | id: attend.id, |
---|
| 567 | name: attend.user.name != 'false' ? attend.user.name : '', |
---|
| 568 | mail: attend.user.mail, |
---|
| 569 | status : attend.status, |
---|
| 570 | isExternal: attend.isExternal, |
---|
| 571 | acl: attend.acl, |
---|
| 572 | delegatedFrom: attend.delegatedFrom |
---|
| 573 | }; |
---|
[5947] | 574 | |
---|
[6066] | 575 | if(!!parseInt(attend.delegatedFrom)){ |
---|
| 576 | delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); |
---|
| 577 | return(null); |
---|
| 578 | } |
---|
[5947] | 579 | |
---|
[6066] | 580 | if( !!parseInt(attend.isOrganizer )){ |
---|
| 581 | participantInfo.organizer = DataLayer.copy(person); |
---|
| 582 | return(null); |
---|
| 583 | }; |
---|
| 584 | |
---|
| 585 | return (person); |
---|
| 586 | }), |
---|
| 587 | organizer: participantInfo.organizer || me, |
---|
| 588 | alarms: !!participantInfo.user ? participantInfo.user.alarms : [], |
---|
| 589 | status: !!participantInfo.user ? participantInfo.user.status : 1, |
---|
[6295] | 590 | acl: constantAcl(me.acl || 'roiw'), |
---|
[6198] | 591 | isShared: isShared, |
---|
| 592 | isAttendee: (isAttendee ? true : (objEvent.id && isShared ? false : true)), |
---|
[6295] | 593 | me: me, |
---|
[6066] | 594 | delegatedFrom: delegatedFrom, |
---|
[6476] | 595 | statusParticipants: (objEvent.sizeAttendees != "") ? objEvent.statusAttendees : statusParticipants, |
---|
| 596 | sizeAttendeeLimit: (objEvent.sizeAttendees != "") ? objEvent.sizeAttendees : false |
---|
[6066] | 597 | }; |
---|
| 598 | }); |
---|
[5947] | 599 | return (notArray ? res[0] : res); |
---|
[5341] | 600 | } |
---|
| 601 | }); |
---|
| 602 | |
---|
[6876] | 603 | DataLayer.codec( "schedulable", "task", { |
---|
[5947] | 604 | |
---|
[6876] | 605 | decoder: function( evtObj ){ |
---|
| 606 | Encoder.EncodeType = "entity"; |
---|
| 607 | |
---|
| 608 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 609 | evtObj = [ evtObj ]; |
---|
| 610 | |
---|
| 611 | var pref = User.preferences; |
---|
| 612 | |
---|
| 613 | var res = $.map(evtObj, function( form ){ |
---|
| 614 | |
---|
| 615 | var tzId = form.timezone || Calendar.signatureOf[form.group].calendar.timezone || User.preferences.timezone, |
---|
| 616 | |
---|
| 617 | formatString = pref.dateFormat + " " + pref.hourFormat; |
---|
| 618 | |
---|
| 619 | return DataLayer.merge({ |
---|
| 620 | "class": form["class"], |
---|
| 621 | startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 622 | endTime: Date.parseExact(form.endDate + " "+$.trim(form.endHour), formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), //+ (!!form.allDay ? 86400000 : 0) , |
---|
| 623 | due: (form.dueDate == '' )? 0 : Date.parseExact(form.dueDate + " "+$.trim(form.dueTime) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 624 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 625 | status: form.taskStatus, |
---|
| 626 | id: form.idTask, |
---|
| 627 | location: form.location, |
---|
[6880] | 628 | type: !!form.type ? form.type : 2, |
---|
[6876] | 629 | percentage: form.percentage, |
---|
| 630 | priority: form.priority, |
---|
| 631 | category: form.category, |
---|
[6974] | 632 | summary: form.summary == '' ? 'Tarefa sem título' : form.summary, |
---|
[6876] | 633 | description: form.description, |
---|
| 634 | timezone: tzId, |
---|
| 635 | attachments: $.map(form.attachment || [], function( attachment, i ){ |
---|
| 636 | return { |
---|
| 637 | attachment: attachment |
---|
| 638 | } |
---|
| 639 | }), |
---|
| 640 | participants: $.map( form.attendee || [], function( attendee, i ){ |
---|
| 641 | |
---|
| 642 | if( !attendee || attendee === "" ) |
---|
| 643 | return( null ); |
---|
| 644 | |
---|
| 645 | var participant = {}; |
---|
| 646 | participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ; |
---|
| 647 | |
---|
| 648 | if( participant.user === User.me.id ){ |
---|
| 649 | return DataLayer.merge({ |
---|
| 650 | id: attendee, |
---|
| 651 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 652 | alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 653 | if( alarmTime === "" ) |
---|
| 654 | return( null ); |
---|
| 655 | return !!form.alarmId[i] ? { |
---|
| 656 | type: form.alarmType[i], |
---|
| 657 | unit: form.alarmUnit[i], |
---|
| 658 | time: form.alarmTime[i], |
---|
| 659 | id: form.alarmId[i] |
---|
| 660 | }: |
---|
| 661 | |
---|
| 662 | { |
---|
| 663 | type: form.alarmType[i], |
---|
| 664 | unit: form.alarmUnit[i], |
---|
| 665 | time: form.alarmTime[i] |
---|
| 666 | }; |
---|
| 667 | }), |
---|
| 668 | status: !!form.status ? form.status : 3 |
---|
| 669 | }, (form.delegatedFrom[i] != '0' && form.delegatedFrom[i] != '') ? { |
---|
| 670 | delegatedFrom: form.delegatedFrom[i] |
---|
| 671 | } : {}); |
---|
| 672 | }else{ |
---|
| 673 | return { |
---|
| 674 | id: attendee, |
---|
| 675 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
[6880] | 676 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0 |
---|
[6876] | 677 | }; |
---|
| 678 | }; |
---|
| 679 | }) |
---|
| 680 | }, form.lastGroup ? (( form.lastGroup == form.group ) ? {} : {calendar: form.group, lastGroup: form.lastGroup}) : {calendar: form.group}); |
---|
| 681 | }); |
---|
| 682 | |
---|
| 683 | return notArray ? res[0] : res; |
---|
| 684 | }, |
---|
| 685 | |
---|
| 686 | encoder: function( evtObj ){ |
---|
| 687 | |
---|
| 688 | var notArray = false; |
---|
| 689 | |
---|
| 690 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 691 | evtObj = [ evtObj ]; |
---|
| 692 | |
---|
| 693 | var statusParticipants = {}, isAttendee = false, |
---|
| 694 | |
---|
| 695 | statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ], |
---|
| 696 | |
---|
| 697 | participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy( User.me ); |
---|
| 698 | |
---|
| 699 | var delegateAttendee = {}; |
---|
| 700 | |
---|
| 701 | for( var i = 0; i < statusLabels.length; i++ ) |
---|
| 702 | statusParticipants[ statusLabels[i] ] = 0; |
---|
| 703 | |
---|
| 704 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 705 | |
---|
| 706 | if(!(typeof(objEvent) == 'object')) |
---|
| 707 | return (null); |
---|
| 708 | |
---|
| 709 | var limitAttendee = false; |
---|
| 710 | |
---|
| 711 | return { |
---|
| 712 | "class": objEvent["class"], |
---|
| 713 | id: objEvent.id, |
---|
| 714 | location: objEvent.location, |
---|
| 715 | category: objEvent.category, |
---|
| 716 | taskStatus: objEvent.status, |
---|
| 717 | groups: Calendar.groups, |
---|
[6885] | 718 | group: objEvent.group ? objEvent.group : objEvent.calendar, |
---|
[6876] | 719 | summary: objEvent.summary, |
---|
[6880] | 720 | type: !!objEvent.type ? objEvent.type : 2, |
---|
[6876] | 721 | description: objEvent.description, |
---|
| 722 | timezone: objEvent.timezone, |
---|
| 723 | timezones: Timezone.timezones, |
---|
| 724 | percentage: (objEvent.percentage) ? objEvent.percentage : '0', |
---|
| 725 | priority: objEvent.priority, |
---|
| 726 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 727 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 728 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 729 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
| 730 | dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 731 | dueTime: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.due)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 732 | allDay: !!parseInt( objEvent.allDay ), |
---|
[6968] | 733 | historic: !!objEvent.historic ? decodeHistotic(objEvent) : [] , |
---|
[6876] | 734 | attachments: $.map(objEvent.attachments || [], function( attachment, i ){ |
---|
| 735 | var attach = DataLayer.get('schedulableToAttachment', attachment, false); |
---|
| 736 | //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o |
---|
| 737 | if(!attach.name) return(null); |
---|
| 738 | |
---|
| 739 | var ext = attach.name.split('.'); |
---|
| 740 | 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])); |
---|
| 741 | attach.size = formatBytes(attach.size); |
---|
| 742 | return attach; |
---|
| 743 | }), |
---|
| 744 | attendee: $.map(objEvent.participants || [], function( participant, i ){ |
---|
| 745 | |
---|
| 746 | if(delegateAttendee[participant]) |
---|
| 747 | return(null); |
---|
| 748 | |
---|
| 749 | var attend = DataLayer.get('participant', (participant.id || participant)); |
---|
| 750 | attend.user = DataLayer.get('user', attend.user); |
---|
| 751 | |
---|
| 752 | statusParticipants[ statusLabels[attend.status] ]++; |
---|
| 753 | |
---|
| 754 | if(attend.user.mail == User.me.mail) |
---|
| 755 | isAttendee = true; |
---|
| 756 | |
---|
| 757 | if( attend.user.id === me.id ){ |
---|
| 758 | participantInfo.user = { |
---|
| 759 | id: attend.id, |
---|
| 760 | status : attend.status, |
---|
| 761 | delegatedFrom: attend.delegatedFrom || '0', |
---|
| 762 | acl: attend.acl, |
---|
| 763 | receiveNotification : attend.receiveNotification, |
---|
| 764 | alarms : $.map(attend.alarms || [], function( alarm ){ |
---|
| 765 | var alarm = DataLayer.get('alarm', alarm); |
---|
| 766 | return (alarm == "" ? (null) : alarm); |
---|
| 767 | }) |
---|
| 768 | }; |
---|
| 769 | me = attend; |
---|
| 770 | return(null); |
---|
| 771 | }; |
---|
| 772 | |
---|
| 773 | var person = { |
---|
| 774 | id: attend.id, |
---|
| 775 | name: attend.user.name != 'false' ? attend.user.name : '', |
---|
| 776 | mail: attend.user.mail, |
---|
| 777 | status : attend.status, |
---|
| 778 | isExternal: attend.isExternal, |
---|
| 779 | acl: attend.acl, |
---|
| 780 | delegatedFrom: attend.delegatedFrom |
---|
| 781 | }; |
---|
| 782 | |
---|
| 783 | if(!!parseInt(attend.delegatedFrom)){ |
---|
| 784 | delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); |
---|
| 785 | return(null); |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | if( !!parseInt(attend.isOrganizer)){ |
---|
| 789 | participantInfo.organizer = DataLayer.copy(person); |
---|
| 790 | return(null); |
---|
| 791 | }; |
---|
| 792 | |
---|
| 793 | return (person); |
---|
| 794 | }), |
---|
| 795 | organizer: participantInfo.organizer || me, |
---|
| 796 | alarms: !!participantInfo.user ? participantInfo.user.alarms : [], |
---|
| 797 | status: !!participantInfo.user ? participantInfo.user.status : 1, |
---|
| 798 | isAttendee: isAttendee, |
---|
| 799 | me: me, |
---|
| 800 | delegatedFrom: delegatedFrom, |
---|
| 801 | statusParticipants: (objEvent.sizeAttendees != "") ? objEvent.statusAttendees : statusParticipants, |
---|
| 802 | sizeAttendeeLimit: (objEvent.sizeAttendees != "") ? objEvent.sizeAttendees : false |
---|
| 803 | }; |
---|
| 804 | }); |
---|
[6945] | 805 | return (notArray ? res[0] : res); |
---|
| 806 | } |
---|
| 807 | }); |
---|
[6903] | 808 | |
---|
[6968] | 809 | function decodeHistotic ( evt ) { |
---|
| 810 | var historic = evt.historic; |
---|
| 811 | var decoded = []; |
---|
| 812 | var attributeDecoded = { |
---|
| 813 | 'startTime': 'Data de inicio', |
---|
| 814 | 'endTime' : 'Data de fim', |
---|
| 815 | 'summary' : 'Título', |
---|
| 816 | 'description': 'Descrição', |
---|
| 817 | 'status': 'Status', |
---|
| 818 | 'percentage': 'Porcentagem', |
---|
| 819 | 'priority': 'Priorudade', |
---|
| 820 | 'due' : 'Previsão de término' |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | var decodeDate = function(time){ |
---|
| 824 | return new Date( parseInt( time) ).setTimezoneOffset( Timezone.timezone( evt.timezone ) ).toString( User.preferences.dateFormat+' - '+User.preferences.hourFormat ); |
---|
| 825 | }; |
---|
| 826 | |
---|
| 827 | var decodeItem = function(historic){ |
---|
| 828 | switch(historic.attribute){ |
---|
| 829 | case 'startTime': |
---|
| 830 | case 'endTime' : |
---|
| 831 | case 'due': |
---|
| 832 | return { |
---|
[6974] | 833 | user :$.type(historic.user) == 'object' ? historic.user : DataLayer.get('user', historic.user), |
---|
[6968] | 834 | attribute : attributeDecoded[historic.attribute], |
---|
| 835 | beforeValue : decodeDate(historic.beforeValue), |
---|
| 836 | afterValue : decodeDate(historic.afterValue), |
---|
| 837 | time: decodeDate(historic.time) |
---|
| 838 | } |
---|
| 839 | break; |
---|
| 840 | case 'participant': |
---|
| 841 | return{ |
---|
[6974] | 842 | user :$.type(historic.user) == 'object' ? historic.user : DataLayer.get('user', historic.user), |
---|
[6968] | 843 | attribute : historic.beforeValue == '' ? ('Novo participante') : ('Rem. participante'), |
---|
| 844 | beforeValue : historic.beforeValue == '' ? '' : historic.beforeValue.mail, |
---|
| 845 | afterValue : historic.afterValue == '' ? '' : historic.afterValue.mail, |
---|
| 846 | time: decodeDate(historic.time) |
---|
| 847 | } |
---|
| 848 | break; |
---|
| 849 | case 'attachment': |
---|
| 850 | return{ |
---|
[6974] | 851 | user : $.type(historic.user) == 'object' ? historic.user : DataLayer.get('user', historic.user), |
---|
[6968] | 852 | attribute : historic.beforeValue == '' ? ('Novo anexo') : ('Rem. anexo'), |
---|
| 853 | beforeValue : historic.beforeValue, |
---|
| 854 | afterValue : historic.afterValue, |
---|
| 855 | time: decodeDate(historic.time) |
---|
| 856 | } |
---|
| 857 | case 'percentage': |
---|
| 858 | return{ |
---|
[6974] | 859 | user :$.type(historic.user) == 'object' ? historic.user : DataLayer.get('user', historic.user), |
---|
[6968] | 860 | attribute :attributeDecoded[historic.attribute], |
---|
| 861 | beforeValue : historic.beforeValue+' %', |
---|
| 862 | afterValue : historic.afterValue+' %', |
---|
| 863 | time: decodeDate(historic.time) |
---|
| 864 | } |
---|
| 865 | break; |
---|
| 866 | default: |
---|
| 867 | return { |
---|
[6974] | 868 | user : $.type(historic.user) == 'object' ? historic.user : DataLayer.get('user', historic.user), |
---|
[6968] | 869 | attribute : attributeDecoded[historic.attribute], |
---|
| 870 | beforeValue : historic.beforeValue, |
---|
| 871 | afterValue : historic.afterValue, |
---|
| 872 | time: decodeDate(historic.time) |
---|
| 873 | } |
---|
| 874 | break; |
---|
| 875 | |
---|
| 876 | } |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | for(var i = 0; i < historic.length; i++) |
---|
| 880 | decoded.push(decodeItem(historic[i])); |
---|
| 881 | |
---|
| 882 | return decoded; |
---|
| 883 | |
---|
| 884 | } |
---|
| 885 | |
---|
[6945] | 886 | DataLayer.codec( "schedulable", "taskSearch", { |
---|
| 887 | |
---|
| 888 | decoder: function( evtObj ){ |
---|
| 889 | |
---|
| 890 | }, |
---|
| 891 | |
---|
| 892 | encoder: function( evtObj ){ |
---|
| 893 | |
---|
| 894 | var notArray = false; |
---|
| 895 | |
---|
| 896 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 897 | evtObj = [ evtObj ]; |
---|
| 898 | |
---|
| 899 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 900 | |
---|
| 901 | if(!(typeof(objEvent) == 'object')) |
---|
| 902 | return (null); |
---|
| 903 | |
---|
| 904 | return { |
---|
| 905 | id: objEvent.id, |
---|
| 906 | description: !!objEvent.summary ? objEvent.summary : objEvent.description, |
---|
| 907 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 908 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 909 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 910 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
| 911 | dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 912 | dueTime: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.due)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 913 | allDay: !!parseInt( objEvent.allDay ), |
---|
[6954] | 914 | percentage: (objEvent.percentage) ? objEvent.percentage : '0', |
---|
| 915 | status: objEvent.status |
---|
[6945] | 916 | } |
---|
| 917 | }); |
---|
[6876] | 918 | return (notArray ? res[0] : res); |
---|
| 919 | } |
---|
| 920 | }); |
---|
| 921 | |
---|
[6945] | 922 | DataLayer.codec( "schedulable", "activity", { |
---|
| 923 | |
---|
| 924 | decoder: function( evtObj ){ |
---|
| 925 | Encoder.EncodeType = "entity"; |
---|
| 926 | |
---|
| 927 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 928 | evtObj = [ evtObj ]; |
---|
| 929 | |
---|
| 930 | var pref = User.preferences; |
---|
| 931 | |
---|
| 932 | var res = $.map(evtObj, function( form ){ |
---|
| 933 | |
---|
| 934 | var tzId = form.timezone || Calendar.signatureOf[form.group].calendar.timezone || User.preferences.timezone, |
---|
| 935 | formatString = pref.dateFormat + " " + pref.hourFormat; |
---|
| 936 | |
---|
| 937 | var decodeParticipants = function(attend){ |
---|
| 938 | return [DataLayer.merge( |
---|
| 939 | { |
---|
| 940 | user: User.me.id, |
---|
| 941 | isOrganizer: 1, |
---|
| 942 | acl: 'row', |
---|
| 943 | alarms: $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 944 | if( alarmTime === "" ) |
---|
| 945 | return( null ); |
---|
| 946 | return !!form.alarmId[i] ? { |
---|
| 947 | type: form.alarmType[i], |
---|
| 948 | unit: form.alarmUnit[i], |
---|
| 949 | time: form.alarmTime[i], |
---|
| 950 | id: form.alarmId[i] |
---|
| 951 | }: |
---|
| 952 | |
---|
| 953 | { |
---|
| 954 | type: form.alarmType[i], |
---|
| 955 | unit: form.alarmUnit[i], |
---|
| 956 | time: form.alarmTime[i] |
---|
| 957 | }; |
---|
| 958 | }) |
---|
| 959 | }, attend != '0' ? {id: attend} : {})]; |
---|
| 960 | }; |
---|
| 961 | |
---|
| 962 | return DataLayer.merge({ |
---|
| 963 | "class": form["class"], |
---|
| 964 | startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 965 | endTime: Date.parseExact(form.endDate + " "+$.trim(form.endHour), formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), //+ (!!form.allDay ? 86400000 : 0) , |
---|
| 966 | due: (form.dueDate == '' )? 0 : Date.parseExact(form.dueDate + " "+$.trim(form.dueHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 967 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
[6954] | 968 | status: form.activityStatus, |
---|
[6945] | 969 | id: form.idActivity, |
---|
| 970 | type: !!form.type ? form.type : 2, |
---|
| 971 | percentage: form.percentage, |
---|
| 972 | priority: form.priority, |
---|
| 973 | category: form.category, |
---|
[6974] | 974 | summary: form.summary == '' ? 'Atividade sem título' : form.summary, |
---|
[6945] | 975 | description: form.description, |
---|
| 976 | timezone: tzId, |
---|
| 977 | attachments: $.map(form.attachment || [], function( attachment, i ){ |
---|
| 978 | return { |
---|
| 979 | attachment: attachment |
---|
| 980 | } |
---|
| 981 | }), |
---|
| 982 | participants: decodeParticipants(form.idAttendee), |
---|
| 983 | taskToActivity:$.map( form.idtask || [], function( task, i ){ |
---|
| 984 | |
---|
| 985 | return DataLayer.merge({ |
---|
| 986 | task: task, |
---|
| 987 | owner: User.me.id |
---|
| 988 | }, form.idTaskToActivity[i] != '' ? {id: form.idTaskToActivity[i]} : {}); |
---|
| 989 | |
---|
| 990 | }) |
---|
| 991 | }, form.lastGroup ? (( form.lastGroup == form.group ) ? {} : {calendar: form.group, lastGroup: form.lastGroup}) : {calendar: form.group}); |
---|
| 992 | }); |
---|
| 993 | |
---|
| 994 | return notArray ? res[0] : res; |
---|
| 995 | }, |
---|
| 996 | |
---|
| 997 | encoder: function( evtObj ){ |
---|
| 998 | |
---|
| 999 | var notArray = false; |
---|
| 1000 | |
---|
| 1001 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 1002 | evtObj = [ evtObj ]; |
---|
| 1003 | |
---|
| 1004 | var res = $.map(evtObj, function( objEvent ){ |
---|
| 1005 | |
---|
| 1006 | if(!(typeof(objEvent) == 'object')) |
---|
| 1007 | return (null); |
---|
[6974] | 1008 | |
---|
| 1009 | var historic = []; |
---|
[6945] | 1010 | |
---|
| 1011 | var decodeTasks = function(obj){ |
---|
| 1012 | |
---|
| 1013 | var tasks = {}, task = {}; |
---|
| 1014 | |
---|
| 1015 | for(var i =0; i < obj.taskToActivity.length; i++){ |
---|
| 1016 | |
---|
| 1017 | taskToActivity = DataLayer.get('taskToActivity', obj.taskToActivity[i]); |
---|
| 1018 | task = taskToActivity.task; |
---|
| 1019 | |
---|
| 1020 | if($.type(task) != 'object') |
---|
| 1021 | task = DataLayer.get('schedulable', task); |
---|
| 1022 | |
---|
| 1023 | tasks[task.id] = { |
---|
| 1024 | taskToActivity: taskToActivity.id, |
---|
| 1025 | allDay: !!parseInt(task.allDay), |
---|
| 1026 | dueDate: (!task.due || task.due == '' || task.due == '0') ? '' : new Date( parseInt(task.due) ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 1027 | dueTime: (!task.due || task.due == '' || task.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(task.due)), task.timezone, obj.calendar, obj.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 1028 | startDate: new Date( parseInt(task.startTime) ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 1029 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(task.startTime)), task.timezone, task.calendar, obj.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 1030 | endDate: new Date( parseInt(task.endTime) - (!!parseInt(task.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( task.timezone ) ).toString( User.preferences.dateFormat ), |
---|
[6954] | 1031 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(task.endTime)), task.timezone, obj.calendar, obj.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
[6974] | 1032 | status: task.status, |
---|
| 1033 | percentage: task.percentage |
---|
[6945] | 1034 | } |
---|
| 1035 | |
---|
| 1036 | tasks[task.id].description = tasks[task.id].startDate + ' - ' + (!!task.summary ? task.summary : task.description); |
---|
| 1037 | |
---|
[6974] | 1038 | historic.push({'task': (!!task.summary ? task.summary : task.description) , 'historic': decodeHistotic(task)}); |
---|
[6945] | 1039 | } |
---|
| 1040 | |
---|
| 1041 | tasks.length = obj.taskToActivity.length; |
---|
| 1042 | return tasks; |
---|
| 1043 | |
---|
| 1044 | }; |
---|
| 1045 | |
---|
| 1046 | return { |
---|
| 1047 | "class": objEvent["class"], |
---|
| 1048 | id: objEvent.id, |
---|
| 1049 | location: objEvent.location, |
---|
| 1050 | category: objEvent.category, |
---|
| 1051 | activityStatus: objEvent.status, |
---|
| 1052 | groups: Calendar.groups, |
---|
| 1053 | group: objEvent.group ? objEvent.group : objEvent.calendar, |
---|
| 1054 | summary: objEvent.summary, |
---|
| 1055 | type: !!objEvent.type ? objEvent.type : 2, |
---|
| 1056 | description: objEvent.description, |
---|
| 1057 | timezone: objEvent.timezone, |
---|
| 1058 | timezones: Timezone.timezones, |
---|
| 1059 | percentage: (objEvent.percentage) ? objEvent.percentage : '0', |
---|
| 1060 | priority: objEvent.priority, |
---|
| 1061 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 1062 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 1063 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 1064 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
| 1065 | dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 1066 | dueTime: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.due)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 1067 | allDay: !!parseInt( objEvent.allDay ), |
---|
[6974] | 1068 | historic: historic, |
---|
[6945] | 1069 | tasks: objEvent.taskToActivity ? decodeTasks(objEvent) : {}, |
---|
| 1070 | attachments: $.map(objEvent.attachments || [], function( attachment, i ){ |
---|
| 1071 | var attach = DataLayer.get('schedulableToAttachment', attachment, false); |
---|
| 1072 | //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o |
---|
| 1073 | if(!attach.name) return(null); |
---|
| 1074 | |
---|
| 1075 | var ext = attach.name.split('.'); |
---|
| 1076 | 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])); |
---|
| 1077 | attach.size = formatBytes(attach.size); |
---|
| 1078 | return attach; |
---|
| 1079 | }), |
---|
| 1080 | me : User.me, |
---|
| 1081 | attendee: $.map(objEvent.participants || [], function( participant, i ){ |
---|
| 1082 | |
---|
| 1083 | var attend = DataLayer.get('participant', (participant.id || participant)); |
---|
| 1084 | attend.user = DataLayer.get('user', attend.user); |
---|
| 1085 | |
---|
| 1086 | return { |
---|
| 1087 | id: attend.id, |
---|
| 1088 | alarms : $.map(attend.alarms || [], function( alarm ){ |
---|
| 1089 | var alarm = DataLayer.get('alarm', alarm); |
---|
| 1090 | return (alarm == "" ? (null) : alarm); |
---|
| 1091 | }) |
---|
| 1092 | }; |
---|
[6951] | 1093 | }) |
---|
[6945] | 1094 | |
---|
| 1095 | }; |
---|
| 1096 | }); |
---|
| 1097 | return (notArray ? res[0] : res); |
---|
| 1098 | } |
---|
| 1099 | }); |
---|
| 1100 | |
---|
[5947] | 1101 | function decodeOwnerCalendar(calendar){ |
---|
| 1102 | if(calendar && !parseInt(Calendar.signatureOf[calendar].isOwner)){ |
---|
[6066] | 1103 | var Owner = DataLayer.get('calendarSignature', { |
---|
| 1104 | filter: ['AND', ['=','calendar', calendar], ['=','isOwner','1']], |
---|
| 1105 | criteria: { |
---|
| 1106 | deepness: 2 |
---|
| 1107 | } |
---|
| 1108 | }); |
---|
[5947] | 1109 | |
---|
[6066] | 1110 | if($.isArray(Owner)) |
---|
| 1111 | Owner = Owner[0]; |
---|
[5947] | 1112 | |
---|
[6066] | 1113 | return Owner.user; |
---|
| 1114 | } |
---|
| 1115 | return User.me; |
---|
[5947] | 1116 | |
---|
| 1117 | |
---|
| 1118 | } |
---|
| 1119 | |
---|
[5715] | 1120 | function decodeRepeat ( form ) { |
---|
[5341] | 1121 | |
---|
[6066] | 1122 | var patati = {}; |
---|
[5715] | 1123 | |
---|
[6066] | 1124 | if( form.repeatId ) |
---|
| 1125 | patati['id'] = form.repeatId; |
---|
[5341] | 1126 | |
---|
[6066] | 1127 | patati['frequency'] = form.frequency; |
---|
[5715] | 1128 | |
---|
[6066] | 1129 | patati['bymonthday'] = patati['byyearday'] = patati['byday'] = ''; |
---|
[5715] | 1130 | |
---|
[6346] | 1131 | patati['interval'] = 1 , |
---|
| 1132 | |
---|
| 1133 | patati['endTime'] = patati['count'] = patati['startTime'] = 0; |
---|
[5715] | 1134 | |
---|
[6066] | 1135 | if( form.frequency === 'none' ) |
---|
| 1136 | return( patati ); |
---|
[5715] | 1137 | |
---|
[6066] | 1138 | var day = []; |
---|
[5715] | 1139 | |
---|
[6066] | 1140 | $("input[type=checkbox][name='repeatweekly[]']:checked").each(function() { |
---|
| 1141 | day[ day.length ] = $(this).val(); |
---|
| 1142 | }); |
---|
[5715] | 1143 | |
---|
[6066] | 1144 | patati['byday'] = day.join(','); |
---|
[5715] | 1145 | |
---|
[6444] | 1146 | var formatString = User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
[5715] | 1147 | |
---|
[6533] | 1148 | var date = Date.parseExact( form.startDate + " "+$.trim(form.startHour) , formatString ) |
---|
| 1149 | |
---|
| 1150 | patati['startTime'] = date.toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'); |
---|
[5715] | 1151 | |
---|
[6066] | 1152 | if( !patati['byday'] ) |
---|
| 1153 | switch(form.frequency) { |
---|
| 1154 | case 'weekly': |
---|
| 1155 | break; |
---|
| 1156 | case 'daily': |
---|
| 1157 | break; |
---|
| 1158 | case 'monthly': |
---|
| 1159 | patati['bymonthday'] = date.getDate(); |
---|
| 1160 | break; |
---|
| 1161 | case 'yearly': |
---|
[6419] | 1162 | patati['byyearday'] = (1 + date.getDayOfYear()); |
---|
[6066] | 1163 | break; |
---|
| 1164 | default : |
---|
| 1165 | return patati; |
---|
| 1166 | } |
---|
[5715] | 1167 | |
---|
[6066] | 1168 | if (($(".endRepeat").val() == 'occurrences')) |
---|
| 1169 | patati['count'] = $(".occurrencesEnd").val(); |
---|
[5715] | 1170 | |
---|
[6066] | 1171 | if (($(".endRepeat").val() == 'customDate')) |
---|
[6444] | 1172 | patati['endTime'] = Date.parseExact( $(".customDateEnd").val() + (" "+$.trim(form.endHour)) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'); |
---|
[5715] | 1173 | |
---|
[6066] | 1174 | patati['interval'] = $(".eventInterval").val(); |
---|
[5715] | 1175 | |
---|
[6066] | 1176 | /** |
---|
[5715] | 1177 | wkst = [ 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU' ] |
---|
| 1178 | weekno = number |
---|
| 1179 | minute = number |
---|
| 1180 | second = number |
---|
| 1181 | yearday = number |
---|
| 1182 | monthday = number |
---|
| 1183 | setpos = number |
---|
| 1184 | day = number |
---|
| 1185 | hour = number |
---|
| 1186 | interval = number |
---|
| 1187 | frequency = [ 'monthly', 'daily', 'weekly', 'yearly', 'hourly', 'minutely', 'secondly' ] |
---|
| 1188 | endTime = milliseconds |
---|
| 1189 | */ |
---|
| 1190 | return( patati ); |
---|
| 1191 | |
---|
| 1192 | } |
---|
| 1193 | |
---|
| 1194 | |
---|
| 1195 | |
---|
| 1196 | function encodeRepeat( repeat ){ |
---|
| 1197 | |
---|
[6066] | 1198 | if( !repeat ) |
---|
| 1199 | return( false ); |
---|
| 1200 | if(typeof(repeat) == "object") |
---|
| 1201 | return repeat; |
---|
[5715] | 1202 | |
---|
[6066] | 1203 | return DataLayer.get( 'repeat', repeat ); |
---|
[5715] | 1204 | } |
---|
| 1205 | |
---|
[5341] | 1206 | DataLayer.codec( "schedulable", "detail", { |
---|
| 1207 | |
---|
| 1208 | decoder: function( evtObj ){ |
---|
[5409] | 1209 | |
---|
[5341] | 1210 | Encoder.EncodeType = "entity"; |
---|
| 1211 | |
---|
| 1212 | if( notArray = $.type(evtObj) !== "array" ) |
---|
[6066] | 1213 | evtObj = [ evtObj ]; |
---|
[5341] | 1214 | |
---|
| 1215 | var pref = User.preferences; |
---|
| 1216 | |
---|
| 1217 | var res = $.map(evtObj, function( form ){ |
---|
[5409] | 1218 | |
---|
[6066] | 1219 | var tzId = form.timezone || Calendar.signatureOf[form.calendar].calendar.timezone || User.preferences.timezone, |
---|
[5341] | 1220 | |
---|
[6444] | 1221 | formatString = pref.dateFormat + " " + pref.hourFormat; |
---|
[5947] | 1222 | |
---|
[6066] | 1223 | var Owner = decodeOwnerCalendar(form.calendar); |
---|
[5947] | 1224 | |
---|
[6331] | 1225 | return DataLayer.merge({ |
---|
[6066] | 1226 | "class": form["class"], |
---|
[6444] | 1227 | startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 1228 | endTime: Date.parseExact(form.endDate + " "+$.trim(form.endHour), formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), //+ (!!form.allDay ? 86400000 : 0) , |
---|
[6066] | 1229 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 1230 | id: form.idEvent, |
---|
| 1231 | location: form.location, |
---|
[6797] | 1232 | type: 1, |
---|
[6066] | 1233 | category: form.category, |
---|
[6974] | 1234 | summary: form.summary == '' ? 'Evento sem título' : form.summary, |
---|
[6066] | 1235 | description: form.description, |
---|
| 1236 | timezone: tzId, |
---|
| 1237 | attachments: $.map(form.attachment || [], function( attachment, i ){ |
---|
[5341] | 1238 | return { |
---|
[6066] | 1239 | attachment: attachment |
---|
| 1240 | } |
---|
| 1241 | }), |
---|
| 1242 | repeat: this.decodeRepeat( form ), |
---|
| 1243 | participants: $.map( form.attendee || [], function( attendee, i ){ |
---|
[5341] | 1244 | |
---|
[6066] | 1245 | if( !attendee || attendee === "" ) |
---|
| 1246 | return( null ); |
---|
| 1247 | |
---|
| 1248 | var participant = {}; |
---|
| 1249 | participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ; |
---|
| 1250 | |
---|
| 1251 | if( participant.user === Owner.id ){ |
---|
| 1252 | return DataLayer.merge({ |
---|
| 1253 | id: attendee, |
---|
| 1254 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 1255 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''), |
---|
| 1256 | alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 1257 | if( alarmTime === "" ) |
---|
[5947] | 1258 | return( null ); |
---|
[6066] | 1259 | return !!form.alarmId[i] ? { |
---|
| 1260 | type: form.alarmType[i], |
---|
| 1261 | unit: form.alarmUnit[i], |
---|
| 1262 | time: form.alarmTime[i], |
---|
| 1263 | id: form.alarmId[i] |
---|
| 1264 | }: |
---|
[5341] | 1265 | |
---|
[6066] | 1266 | { |
---|
| 1267 | type: form.alarmType[i], |
---|
| 1268 | unit: form.alarmUnit[i], |
---|
| 1269 | time: form.alarmTime[i] |
---|
| 1270 | }; |
---|
| 1271 | }), |
---|
| 1272 | status: !!form.status ? form.status : 3 |
---|
| 1273 | }, (form.delegatedFrom[i] != '0' && form.delegatedFrom[i] != '') ? { |
---|
| 1274 | delegatedFrom: form.delegatedFrom[i] |
---|
| 1275 | } : {}); |
---|
| 1276 | }else{ |
---|
| 1277 | return DataLayer.merge({ |
---|
| 1278 | id: attendee, |
---|
| 1279 | acl: form.attendeeAcl[i], |
---|
| 1280 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 1281 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, |
---|
| 1282 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '') |
---|
| 1283 | }, form.delegatedFrom[i] != '0' ? { |
---|
| 1284 | delegatedFrom: form.delegatedFrom[i] |
---|
| 1285 | } : {}); |
---|
| 1286 | }; |
---|
| 1287 | }) |
---|
[6331] | 1288 | }, form.lastCalendar ? (( form.lastCalendar == form.calendar ) ? {} : {calendar: form.calendar, lastCalendar: form.lastCalendar}) : {calendar: form.calendar}); |
---|
[6066] | 1289 | }); |
---|
[5947] | 1290 | |
---|
[5341] | 1291 | return notArray ? res[0] : res; |
---|
| 1292 | }, |
---|
| 1293 | |
---|
[5715] | 1294 | |
---|
[5341] | 1295 | encoder: function( evtObj ){ |
---|
[5409] | 1296 | |
---|
[6066] | 1297 | if(!(!!evtObj)) |
---|
| 1298 | return undefined; |
---|
[5341] | 1299 | |
---|
[6066] | 1300 | var notArray = false; |
---|
[5715] | 1301 | |
---|
[6066] | 1302 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 1303 | evtObj = [ evtObj ]; |
---|
[5341] | 1304 | |
---|
[6066] | 1305 | var pref = User.preferences; |
---|
[6880] | 1306 | var res = []; |
---|
[5341] | 1307 | |
---|
[6880] | 1308 | for(var i = 0; i < evtObj.length; i++){ |
---|
[6955] | 1309 | res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ? 'preview' : ( !!evtObj[i].taskToActivity ? 'activity': 'task')) , evtObj[i])); |
---|
[6880] | 1310 | } |
---|
[5341] | 1311 | |
---|
[6066] | 1312 | if( !notArray ){ |
---|
| 1313 | var dates = {}; |
---|
| 1314 | var typeRepeat = { |
---|
| 1315 | 'none': false, |
---|
| 1316 | 'daily': 'Repetição diária', |
---|
| 1317 | 'weekly': 'Repetição semanal', |
---|
| 1318 | 'monthly': 'Repetição mensal', |
---|
| 1319 | 'yearly': 'repetição anual' |
---|
| 1320 | } |
---|
[5341] | 1321 | |
---|
[6066] | 1322 | for (var i=0; i < res.length; i++) { |
---|
[6955] | 1323 | |
---|
| 1324 | res[i].type = (res[i].type == '2' && !!res[i].tasks) ? '3' : res[i].type; |
---|
[5715] | 1325 | |
---|
[6066] | 1326 | var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat ); |
---|
| 1327 | var endDate = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat ); |
---|
[5715] | 1328 | |
---|
[6066] | 1329 | var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() ); |
---|
[5715] | 1330 | |
---|
[6066] | 1331 | var occurrences = [ startDate.getTime() ]; |
---|
[5715] | 1332 | |
---|
[6066] | 1333 | if( res[i].occurrences ) |
---|
| 1334 | { |
---|
| 1335 | occurrences = res[i].occurrences; |
---|
| 1336 | } |
---|
[5341] | 1337 | |
---|
[6066] | 1338 | for( var ii = 0; ii < occurrences.length; ii++ ) |
---|
| 1339 | { |
---|
| 1340 | var currentDate = new Date( occurrences[ii] ); |
---|
| 1341 | var counter = currentDate.clone(); |
---|
[5715] | 1342 | |
---|
[6066] | 1343 | var res2 = $.extend( {}, res[i], { |
---|
| 1344 | 'startDate': currentDate.toString( User.preferences.dateFormat ), |
---|
| 1345 | 'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat ) |
---|
| 1346 | } ); |
---|
[6880] | 1347 | |
---|
| 1348 | if(res[i].repeat) |
---|
| 1349 | res2.repeat = typeRepeat[res[i].repeat.frequency]; |
---|
[5715] | 1350 | |
---|
[6066] | 1351 | while (counter.compareTo( currentDate ) == 0) { |
---|
[5341] | 1352 | |
---|
[6066] | 1353 | if (!dates[counter.toString(User.preferences.dateFormat)]) |
---|
| 1354 | dates[counter.toString(User.preferences.dateFormat)] = { |
---|
| 1355 | startDate:false, |
---|
| 1356 | events:[] |
---|
| 1357 | }; |
---|
| 1358 | if (!dates[counter.toString(User.preferences.dateFormat)].startDate) |
---|
| 1359 | dates[counter.toString(User.preferences.dateFormat)].startDate = counter.toString(User.preferences.dateFormat); |
---|
[5341] | 1360 | |
---|
[6066] | 1361 | dates[counter.toString(User.preferences.dateFormat)].events.push(res2); |
---|
| 1362 | counter.addDays(-1); |
---|
| 1363 | } |
---|
[5715] | 1364 | } |
---|
[6066] | 1365 | } |
---|
| 1366 | res = { |
---|
| 1367 | events_list: dates, |
---|
| 1368 | count : res.length |
---|
| 1369 | }; |
---|
| 1370 | } |
---|
[5341] | 1371 | |
---|
[6066] | 1372 | return notArray ? res[0] : res; |
---|
[5341] | 1373 | } |
---|
| 1374 | |
---|
| 1375 | }); |
---|
| 1376 | |
---|
[6891] | 1377 | |
---|
| 1378 | DataLayer.codec( "schedulable", "print", { |
---|
| 1379 | |
---|
| 1380 | decoder: function( evtObj ){ |
---|
| 1381 | |
---|
| 1382 | }, |
---|
| 1383 | |
---|
| 1384 | |
---|
| 1385 | encoder: function( evtObj ){ |
---|
| 1386 | |
---|
| 1387 | if(!(!!evtObj)) |
---|
[6945] | 1388 | evtObj = []; |
---|
[6891] | 1389 | |
---|
| 1390 | var notArray = false; |
---|
| 1391 | |
---|
| 1392 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 1393 | evtObj = [ evtObj ]; |
---|
| 1394 | |
---|
| 1395 | var pref = User.preferences; |
---|
| 1396 | var res = []; |
---|
| 1397 | |
---|
| 1398 | for(var i = 0; i < evtObj.length; i++){ |
---|
| 1399 | res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ? 'preview' : 'task'), evtObj[i])); |
---|
| 1400 | } |
---|
| 1401 | |
---|
| 1402 | if( !notArray ){ |
---|
| 1403 | var dates = {}; |
---|
| 1404 | |
---|
| 1405 | var typeRepeat = { |
---|
| 1406 | 'none': false, |
---|
| 1407 | 'daily': 'Repetição diária', |
---|
| 1408 | 'weekly': 'Repetição semanal', |
---|
| 1409 | 'monthly': 'Repetição mensal', |
---|
| 1410 | 'yearly': 'repetição anual' |
---|
| 1411 | } |
---|
| 1412 | |
---|
| 1413 | for (var i=0; i < res.length; i++) { |
---|
| 1414 | var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat ); |
---|
| 1415 | var endDate = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat ); |
---|
| 1416 | |
---|
| 1417 | var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() ); |
---|
| 1418 | |
---|
| 1419 | var occurrences = [ startDate.getTime() ]; |
---|
| 1420 | |
---|
| 1421 | if( res[i].occurrences ) |
---|
| 1422 | { |
---|
| 1423 | occurrences = res[i].occurrences; |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | for( var ii = 0; ii < occurrences.length; ii++ ) |
---|
| 1427 | { |
---|
| 1428 | var currentDate = new Date( occurrences[ii] ); |
---|
| 1429 | var counter = currentDate.clone(); |
---|
| 1430 | |
---|
| 1431 | var res2 = $.extend( {}, res[i], { |
---|
| 1432 | 'startDate': currentDate.toString( User.preferences.dateFormat ), |
---|
| 1433 | 'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat ) |
---|
| 1434 | }); |
---|
| 1435 | |
---|
| 1436 | if(res[i].repeat) |
---|
| 1437 | res2.repeat = typeRepeat[res[i].repeat.frequency]; |
---|
| 1438 | |
---|
| 1439 | var index = dateCalendar.dayNames[counter.getDay()] +' '+counter.toString('dd/MM'); |
---|
| 1440 | |
---|
| 1441 | if(!dates[index] || !$.isArray(dates[index].events)) |
---|
| 1442 | dates[index] = {events: []}; |
---|
| 1443 | |
---|
[6979] | 1444 | res2['isOneDay'] = res2.startDate == res2.endDate ? true : false; |
---|
[6974] | 1445 | |
---|
[6891] | 1446 | dates[index].events.push(res2); |
---|
| 1447 | |
---|
| 1448 | } |
---|
| 1449 | } |
---|
| 1450 | |
---|
| 1451 | var calendarView = $('#calendar').fullCalendar('getView'); |
---|
[6955] | 1452 | var start = calendarView.start.getTime(); |
---|
| 1453 | var end = (calendarView.end.getTime() - (calendarView.name == 'month' ? 86400000 : 0 )); |
---|
[6891] | 1454 | var next = start; |
---|
| 1455 | var response = []; |
---|
| 1456 | |
---|
| 1457 | while (next){ |
---|
| 1458 | var index = dateCalendar.dayNames[new Date(next).getDay()] +' '+ new Date(next).toString('dd/MM'); |
---|
| 1459 | |
---|
| 1460 | var event = {}; |
---|
| 1461 | event[index] = {events: dates[index] ? dates[index].events : false}; |
---|
| 1462 | |
---|
| 1463 | response[response.length] = event; |
---|
| 1464 | next = (next + 86400000) > end ? false : (next + 86400000); |
---|
| 1465 | } |
---|
| 1466 | res = {events: response}; |
---|
| 1467 | } |
---|
| 1468 | |
---|
| 1469 | return notArray ? res[0] : res; |
---|
| 1470 | } |
---|
| 1471 | |
---|
| 1472 | }); |
---|
| 1473 | |
---|
[5341] | 1474 | DataLayer.codec( "participant", "detail", { |
---|
| 1475 | |
---|
| 1476 | encoder: function( participants ){ |
---|
| 1477 | |
---|
[6066] | 1478 | var result = {}; |
---|
| 1479 | for( var i = 0; i< participants.length; i++ ){ |
---|
| 1480 | result[ participants[i].user.id || participants[i].user ] = participants[i]; |
---|
| 1481 | } |
---|
| 1482 | return( result ); |
---|
[5341] | 1483 | } |
---|
| 1484 | }); |
---|
| 1485 | |
---|
| 1486 | DataLayer.codec( "calendar", "list", { |
---|
| 1487 | |
---|
| 1488 | encoder: function( calendars ){ |
---|
| 1489 | |
---|
[6066] | 1490 | var result = { |
---|
| 1491 | my_calendars: [], |
---|
| 1492 | others_calendars: [] |
---|
| 1493 | }; |
---|
[5341] | 1494 | |
---|
[6066] | 1495 | for( var i = 0; i < calendars.length; i++ ) |
---|
| 1496 | { |
---|
| 1497 | !!Calendar.signatureOf[ calendars[i].id ].isOwner ? |
---|
| 1498 | result.my_calendars.push( calendars[i] ) : |
---|
| 1499 | result.others_calendars.push( calendars[i] ); |
---|
| 1500 | } |
---|
[5341] | 1501 | |
---|
[6066] | 1502 | return { |
---|
| 1503 | agendas_usuario: result |
---|
| 1504 | }; |
---|
[5341] | 1505 | |
---|
| 1506 | } |
---|
| 1507 | |
---|
| 1508 | }); |
---|
| 1509 | |
---|
| 1510 | DataLayer.codec( "schedulable", "calendar", { |
---|
| 1511 | |
---|
| 1512 | decoder:function( evtObj ){ |
---|
| 1513 | |
---|
| 1514 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 1515 | evtObj = [ evtObj ]; |
---|
| 1516 | |
---|
| 1517 | var res = $.map(evtObj, function( evt ){ |
---|
| 1518 | |
---|
[6066] | 1519 | return { |
---|
| 1520 | id: evt.id, |
---|
| 1521 | summary: evt.title, |
---|
| 1522 | startTime: evt.start.getTime(), |
---|
| 1523 | endTime: ( !!evt.allDay ? (( evt.end || evt.start ).getTime() + 86400000) :( evt.end || evt.start ).getTime()), |
---|
| 1524 | allDay: ( !!evt.allDay ? 1 : 0 ) |
---|
| 1525 | /*calendar: evt.id && User.calendarOf[ evt.id ].id*/ }; |
---|
[5341] | 1526 | }); |
---|
| 1527 | |
---|
| 1528 | return notArray ? res[0] : res; |
---|
| 1529 | }, |
---|
| 1530 | |
---|
| 1531 | encoder: function( evtObj, filter ){ |
---|
[5947] | 1532 | |
---|
[5341] | 1533 | if( !evtObj ) |
---|
| 1534 | return( false ); |
---|
| 1535 | |
---|
| 1536 | var filtered = evtObj; |
---|
[6066] | 1537 | // |
---|
[5341] | 1538 | var grouped = {}; |
---|
| 1539 | |
---|
| 1540 | $.map(filtered, function( evt ){ |
---|
[5592] | 1541 | |
---|
[6066] | 1542 | if(!(typeof(evt) == 'object') || (evt.id.indexOf('java') >= 0)) |
---|
| 1543 | return (null); |
---|
[5341] | 1544 | |
---|
[6066] | 1545 | evt.calendar = evt.calendar || "1"; |
---|
[5341] | 1546 | |
---|
[6066] | 1547 | if( !grouped[ evt.calendar ] ) |
---|
| 1548 | grouped[ evt.calendar ] = []; |
---|
[5341] | 1549 | |
---|
[6066] | 1550 | var calendar = DataLayer.get('calendar', evt.calendar); |
---|
[5442] | 1551 | |
---|
[6066] | 1552 | var eventEditable = function(idEvent, isRecurrence, Recurrence){ |
---|
| 1553 | if(Calendar.signatureOf[calendar.id].isOwner == "1"){ |
---|
| 1554 | var attendee = {}; |
---|
| 1555 | for(var i = 0; i < evt.participants.length; i++){ |
---|
| 1556 | attendee = DataLayer.get('participant', evt.participants[i]); |
---|
| 1557 | if(attendee.user == User.me.id) |
---|
[6797] | 1558 | return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? |
---|
| 1559 | { |
---|
[6066] | 1560 | selectable: true, |
---|
[6286] | 1561 | className: 'fullcalendar-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') |
---|
[6066] | 1562 | } : { |
---|
| 1563 | editable: false, |
---|
| 1564 | selectable: true , |
---|
| 1565 | className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent |
---|
| 1566 | }; |
---|
| 1567 | } |
---|
| 1568 | return { |
---|
| 1569 | editable: false, |
---|
[6286] | 1570 | className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id, |
---|
[6066] | 1571 | selectable: true, |
---|
| 1572 | disableDragging: isRecurrence |
---|
| 1573 | }; |
---|
| 1574 | } |
---|
| 1575 | else{ |
---|
| 1576 | var aclSignature = Calendar.signatureOf[calendar.id].permission; |
---|
[5592] | 1577 | |
---|
[6066] | 1578 | var mountClass = function(acl){ |
---|
| 1579 | var returns = "" |
---|
| 1580 | returns += acl['write'] ? "" : 'blocked-event-permision '; |
---|
[6286] | 1581 | returns += acl['busy'] ? 'fullcalendar-not-context-menu ' : (acl['read'] ? 'fullcalendar-context-menu '+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') : ''); |
---|
| 1582 | returns += 'event-id-'+idEvent+' calendar-id-'+calendar.id; |
---|
[6066] | 1583 | return returns; |
---|
| 1584 | } |
---|
[6797] | 1585 | return DataLayer.merge( |
---|
| 1586 | { |
---|
[6066] | 1587 | editable: aclSignature.acl['write'] && !isRecurrence, |
---|
| 1588 | disableResizing : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true : false), |
---|
| 1589 | disableDragging : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true: false), |
---|
| 1590 | className: mountClass(aclSignature.acl) |
---|
[6797] | 1591 | }, aclSignature.acl['busy'] ? |
---|
| 1592 | { |
---|
| 1593 | title: 'Ocupado', |
---|
| 1594 | selectable: false |
---|
| 1595 | } : { |
---|
| 1596 | selectable: true |
---|
| 1597 | }); |
---|
[6066] | 1598 | } |
---|
| 1599 | } |
---|
[5715] | 1600 | |
---|
[6066] | 1601 | var duration = parseInt( evt.endTime ) - parseInt( evt.startTime ), isRepeat = false; |
---|
[5715] | 1602 | |
---|
[6066] | 1603 | var occurrences = []; |
---|
[5715] | 1604 | |
---|
[6066] | 1605 | if( evt.occurrences ) |
---|
| 1606 | { |
---|
| 1607 | isRepeat = true; |
---|
| 1608 | occurrences = evt.occurrences; |
---|
| 1609 | }else |
---|
| 1610 | occurrences[ occurrences.length ] = evt.startTime; |
---|
[5737] | 1611 | |
---|
[6066] | 1612 | //occurrences = DataLayer.unique( occurrences ).sort(); |
---|
[6945] | 1613 | var typeEvent; |
---|
| 1614 | for( var i = 0; i < occurrences.length; i++ ){ |
---|
| 1615 | |
---|
| 1616 | typeEvent = (evt.type == 2 && evt.taskToActivity ? 3 : evt.type) |
---|
| 1617 | grouped[ evt.calendar ].push( DataLayer.merge( |
---|
| 1618 | { |
---|
| 1619 | id: evt.URI || evt.id+ '-' + i, |
---|
| 1620 | title: Encoder.htmlDecode(evt.summary), |
---|
| 1621 | start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1622 | end: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1623 | allDay: parseInt( evt.allDay ), |
---|
| 1624 | isRepeat: isRepeat, |
---|
| 1625 | occurrence: i, |
---|
| 1626 | type: typeEvent, |
---|
| 1627 | calendar: evt.calendar |
---|
| 1628 | }, (parseInt(typeEvent) == 1 ? eventEditable(evt.id, isRepeat, i ) : (parseInt(typeEvent) == 2 ? {editable: true, disableResizing: false, disableDragging: false} : {editable: false, disableResizing: true, disableDragging: true}) )) ); |
---|
| 1629 | } |
---|
[5341] | 1630 | }); |
---|
| 1631 | |
---|
| 1632 | return(/* notArray ? filtered[0] :*/ grouped ); |
---|
| 1633 | }, |
---|
| 1634 | |
---|
| 1635 | criteria: function( filter ){ |
---|
| 1636 | |
---|
[6066] | 1637 | if( $.type(filter.start) !== 'date' ) |
---|
| 1638 | filter.start = new Date( filter.start * 1000 ); |
---|
| 1639 | if( $.type(filter.end) !== 'date' ) |
---|
| 1640 | filter.end = new Date( filter.end * 1000 ); |
---|
[5341] | 1641 | |
---|
[6066] | 1642 | var timezone = {}; |
---|
| 1643 | for(var i in Calendar.signatureOf) |
---|
| 1644 | timezone[i] = Calendar.signatureOf[i].calendar.timezone; |
---|
[6151] | 1645 | |
---|
[6066] | 1646 | return { |
---|
[6151] | 1647 | filter: ['AND', |
---|
| 1648 | ['OR', |
---|
| 1649 | ['AND', |
---|
| 1650 | ['>=', 'rangeEnd', filter.start.getTime()], |
---|
| 1651 | ['<=', 'rangeEnd', filter.end.getTime()] , |
---|
| 1652 | ], |
---|
| 1653 | ['AND', |
---|
| 1654 | ['>=', 'rangeStart', filter.start.getTime()], |
---|
| 1655 | ['<=', 'rangeStart', filter.end.getTime()] , |
---|
| 1656 | ], |
---|
| 1657 | ['AND', |
---|
| 1658 | ['<=', 'rangeStart', filter.start.getTime()], |
---|
| 1659 | ['>=', 'rangeEnd', filter.end.getTime()] , |
---|
| 1660 | ] |
---|
| 1661 | ], |
---|
[6876] | 1662 | ['IN', 'calendar', $.merge( Calendar.calendarIds, Calendar.groupIds )] |
---|
[6151] | 1663 | ], |
---|
[6066] | 1664 | criteria: { |
---|
| 1665 | deepness: 2, |
---|
| 1666 | timezones: timezone |
---|
| 1667 | } |
---|
| 1668 | } |
---|
| 1669 | } |
---|
[5341] | 1670 | }); |
---|
| 1671 | |
---|
| 1672 | |
---|
| 1673 | DataLayer.codec( "preference", "detail", { |
---|
| 1674 | |
---|
[6066] | 1675 | decoder:function( pref ){ |
---|
[5341] | 1676 | |
---|
[6066] | 1677 | var res = []; |
---|
[5341] | 1678 | |
---|
[6066] | 1679 | pref.defaultAlarm = $.map( pref.alarmTime || [], function( alarmTime, i ){ |
---|
[5409] | 1680 | |
---|
[6066] | 1681 | return { |
---|
| 1682 | type: pref.alarmType[i], |
---|
| 1683 | time: alarmTime, |
---|
| 1684 | unit: pref.alarmUnit[i] |
---|
| 1685 | }; |
---|
| 1686 | }); |
---|
[5341] | 1687 | |
---|
[6066] | 1688 | $.each( pref, function( i, el ){ |
---|
[5341] | 1689 | |
---|
[6066] | 1690 | res[ res.length ] = { |
---|
| 1691 | name: i, |
---|
| 1692 | value: el |
---|
| 1693 | }; |
---|
[5341] | 1694 | |
---|
[6066] | 1695 | }); |
---|
[5409] | 1696 | |
---|
[6066] | 1697 | return( res ); |
---|
[5409] | 1698 | |
---|
[6066] | 1699 | }, |
---|
[5341] | 1700 | |
---|
[6066] | 1701 | encoder:function( pref ){ |
---|
| 1702 | return( pref ); |
---|
| 1703 | } |
---|
[5341] | 1704 | |
---|
| 1705 | }); |
---|
| 1706 | |
---|
| 1707 | DataLayer.codec( "schedulable", "export", { |
---|
| 1708 | |
---|
[6066] | 1709 | decoder: function(){}, |
---|
[5341] | 1710 | |
---|
[5409] | 1711 | encoder: function( signatures ){}, |
---|
[5341] | 1712 | |
---|
[5409] | 1713 | criteria: function( filter ){ |
---|
[5341] | 1714 | |
---|
[6066] | 1715 | if( isCal = filter && filter.calendar ) |
---|
| 1716 | filter = filter.calendar; |
---|
| 1717 | return { |
---|
| 1718 | filter: filter ? [ "=", ( isCal ? "calendar" : "id" ), filter ] : false, |
---|
| 1719 | criteria: { |
---|
| 1720 | format: 'iCal', |
---|
| 1721 | deepness: 2 |
---|
| 1722 | } |
---|
| 1723 | }; |
---|
| 1724 | } |
---|
[5341] | 1725 | }); |
---|
| 1726 | |
---|
[6444] | 1727 | User.init(); |
---|
[5341] | 1728 | |
---|
| 1729 | // DataLayer.decoder( "participant", "detail", function( form ){ |
---|
| 1730 | // |
---|
| 1731 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1732 | // // notArray = true; |
---|
| 1733 | // // attObj = [ attObj ]; |
---|
| 1734 | // // } |
---|
| 1735 | // |
---|
| 1736 | // |
---|
| 1737 | // |
---|
| 1738 | // return( participants ); |
---|
| 1739 | // |
---|
| 1740 | // }); |
---|
| 1741 | |
---|
| 1742 | // DataLayer.decoder( "alarm", "detail", function( form ){ |
---|
| 1743 | // |
---|
| 1744 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1745 | // // notArray = true; |
---|
| 1746 | // // attObj = [ attObj ]; |
---|
| 1747 | // // } |
---|
| 1748 | // |
---|
| 1749 | // var alarms = []; |
---|
| 1750 | // |
---|
| 1751 | // if( form.alarmType /*&& !form.*/ ) |
---|
| 1752 | // for( var i = 0; i < form.alarmType.length; i++ ) |
---|
| 1753 | // { |
---|
| 1754 | // if( form.alarmTime[i] === "" ) |
---|
| 1755 | // continue; |
---|
| 1756 | // |
---|
| 1757 | // alarms[i] = { type: form.alarmType[i], |
---|
| 1758 | // unit: form.alarmUnit[i], |
---|
| 1759 | // time: form.alarmTime[i] }; |
---|
| 1760 | // } |
---|
| 1761 | // |
---|
| 1762 | // return( alarms ); |
---|
| 1763 | // |
---|
| 1764 | // }); |
---|
| 1765 | |
---|