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