[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: { |
---|
| 265 | id: Calendar.calendarOf[form.signature].id, |
---|
| 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, |
---|
| 513 | description: objEvent.description, |
---|
| 514 | timezone: objEvent.timezone, |
---|
| 515 | timezones: Timezone.timezones, |
---|
| 516 | startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 517 | startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), |
---|
| 518 | endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), |
---|
| 519 | endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), |
---|
| 520 | allDay: !!parseInt( objEvent.allDay ), |
---|
| 521 | attachments: $.map(objEvent.attachments || [], function( attachment, i ){ |
---|
| 522 | var attach = DataLayer.get('schedulableToAttachment', attachment, false); |
---|
[6331] | 523 | //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o |
---|
[6090] | 524 | if(!attach.name) return(null); |
---|
| 525 | |
---|
[6066] | 526 | var ext = attach.name.split('.'); |
---|
| 527 | 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])); |
---|
| 528 | attach.size = formatBytes(attach.size); |
---|
| 529 | return attach; |
---|
| 530 | }), |
---|
| 531 | attendee: $.map(objEvent.participants || [], function( participant, i ){ |
---|
[5947] | 532 | |
---|
[6066] | 533 | if(delegateAttendee[participant]) |
---|
| 534 | return(null); |
---|
[5947] | 535 | |
---|
[6066] | 536 | var attend = DataLayer.get('participant', (participant.id || participant)); |
---|
| 537 | attend.user = DataLayer.get('user', attend.user); |
---|
[5947] | 538 | |
---|
[6066] | 539 | statusParticipants[ statusLabels[attend.status] ]++; |
---|
[5947] | 540 | |
---|
[6066] | 541 | if(attend.user.mail == User.me.mail) |
---|
| 542 | isAttendee = true; |
---|
[5947] | 543 | |
---|
[6066] | 544 | if( attend.user.id === me.id ){ |
---|
| 545 | participantInfo.user = { |
---|
| 546 | id: attend.id, |
---|
| 547 | status : attend.status, |
---|
| 548 | delegatedFrom: attend.delegatedFrom || '0', |
---|
| 549 | acl: attend.acl, |
---|
| 550 | receiveNotification : attend.receiveNotification, |
---|
| 551 | alarms : $.map(attend.alarms || [], function( alarm ){ |
---|
| 552 | var alarm = DataLayer.get('alarm', alarm); |
---|
| 553 | return (alarm == "" ? (null) : alarm); |
---|
| 554 | }) |
---|
| 555 | }; |
---|
[6295] | 556 | me = attend; |
---|
[6066] | 557 | return(null); |
---|
| 558 | }; |
---|
[5947] | 559 | |
---|
[6066] | 560 | var person = { |
---|
| 561 | id: attend.id, |
---|
| 562 | name: attend.user.name != 'false' ? attend.user.name : '', |
---|
| 563 | mail: attend.user.mail, |
---|
| 564 | status : attend.status, |
---|
| 565 | isExternal: attend.isExternal, |
---|
| 566 | acl: attend.acl, |
---|
| 567 | delegatedFrom: attend.delegatedFrom |
---|
| 568 | }; |
---|
[5947] | 569 | |
---|
[6066] | 570 | if(!!parseInt(attend.delegatedFrom)){ |
---|
| 571 | delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); |
---|
| 572 | return(null); |
---|
| 573 | } |
---|
[5947] | 574 | |
---|
[6066] | 575 | if( !!parseInt(attend.isOrganizer )){ |
---|
| 576 | participantInfo.organizer = DataLayer.copy(person); |
---|
| 577 | return(null); |
---|
| 578 | }; |
---|
| 579 | |
---|
| 580 | return (person); |
---|
| 581 | }), |
---|
| 582 | organizer: participantInfo.organizer || me, |
---|
| 583 | alarms: !!participantInfo.user ? participantInfo.user.alarms : [], |
---|
| 584 | status: !!participantInfo.user ? participantInfo.user.status : 1, |
---|
[6295] | 585 | acl: constantAcl(me.acl || 'roiw'), |
---|
[6198] | 586 | isShared: isShared, |
---|
| 587 | isAttendee: (isAttendee ? true : (objEvent.id && isShared ? false : true)), |
---|
[6295] | 588 | me: me, |
---|
[6066] | 589 | delegatedFrom: delegatedFrom, |
---|
[6476] | 590 | statusParticipants: (objEvent.sizeAttendees != "") ? objEvent.statusAttendees : statusParticipants, |
---|
| 591 | sizeAttendeeLimit: (objEvent.sizeAttendees != "") ? objEvent.sizeAttendees : false |
---|
[6066] | 592 | }; |
---|
| 593 | }); |
---|
[5947] | 594 | return (notArray ? res[0] : res); |
---|
[5341] | 595 | } |
---|
| 596 | }); |
---|
| 597 | |
---|
[5947] | 598 | |
---|
| 599 | function decodeOwnerCalendar(calendar){ |
---|
| 600 | if(calendar && !parseInt(Calendar.signatureOf[calendar].isOwner)){ |
---|
[6066] | 601 | var Owner = DataLayer.get('calendarSignature', { |
---|
| 602 | filter: ['AND', ['=','calendar', calendar], ['=','isOwner','1']], |
---|
| 603 | criteria: { |
---|
| 604 | deepness: 2 |
---|
| 605 | } |
---|
| 606 | }); |
---|
[5947] | 607 | |
---|
[6066] | 608 | if($.isArray(Owner)) |
---|
| 609 | Owner = Owner[0]; |
---|
[5947] | 610 | |
---|
[6066] | 611 | return Owner.user; |
---|
| 612 | } |
---|
| 613 | return User.me; |
---|
[5947] | 614 | |
---|
| 615 | |
---|
| 616 | } |
---|
| 617 | |
---|
[5715] | 618 | function decodeRepeat ( form ) { |
---|
[5341] | 619 | |
---|
[6066] | 620 | var patati = {}; |
---|
[5715] | 621 | |
---|
[6066] | 622 | if( form.repeatId ) |
---|
| 623 | patati['id'] = form.repeatId; |
---|
[5341] | 624 | |
---|
[6066] | 625 | patati['frequency'] = form.frequency; |
---|
[5715] | 626 | |
---|
[6066] | 627 | patati['bymonthday'] = patati['byyearday'] = patati['byday'] = ''; |
---|
[5715] | 628 | |
---|
[6346] | 629 | patati['interval'] = 1 , |
---|
| 630 | |
---|
| 631 | patati['endTime'] = patati['count'] = patati['startTime'] = 0; |
---|
[5715] | 632 | |
---|
[6066] | 633 | if( form.frequency === 'none' ) |
---|
| 634 | return( patati ); |
---|
[5715] | 635 | |
---|
[6066] | 636 | var day = []; |
---|
[5715] | 637 | |
---|
[6066] | 638 | $("input[type=checkbox][name='repeatweekly[]']:checked").each(function() { |
---|
| 639 | day[ day.length ] = $(this).val(); |
---|
| 640 | }); |
---|
[5715] | 641 | |
---|
[6066] | 642 | patati['byday'] = day.join(','); |
---|
[5715] | 643 | |
---|
[6444] | 644 | var formatString = User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
[5715] | 645 | |
---|
[6533] | 646 | var date = Date.parseExact( form.startDate + " "+$.trim(form.startHour) , formatString ) |
---|
| 647 | |
---|
| 648 | patati['startTime'] = date.toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'); |
---|
[5715] | 649 | |
---|
[6066] | 650 | if( !patati['byday'] ) |
---|
| 651 | switch(form.frequency) { |
---|
| 652 | case 'weekly': |
---|
| 653 | break; |
---|
| 654 | case 'daily': |
---|
| 655 | break; |
---|
| 656 | case 'monthly': |
---|
| 657 | patati['bymonthday'] = date.getDate(); |
---|
| 658 | break; |
---|
| 659 | case 'yearly': |
---|
[6419] | 660 | patati['byyearday'] = (1 + date.getDayOfYear()); |
---|
[6066] | 661 | break; |
---|
| 662 | default : |
---|
| 663 | return patati; |
---|
| 664 | } |
---|
[5715] | 665 | |
---|
[6066] | 666 | if (($(".endRepeat").val() == 'occurrences')) |
---|
| 667 | patati['count'] = $(".occurrencesEnd").val(); |
---|
[5715] | 668 | |
---|
[6066] | 669 | if (($(".endRepeat").val() == 'customDate')) |
---|
[6444] | 670 | 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] | 671 | |
---|
[6066] | 672 | patati['interval'] = $(".eventInterval").val(); |
---|
[5715] | 673 | |
---|
[6066] | 674 | /** |
---|
[5715] | 675 | wkst = [ 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU' ] |
---|
| 676 | weekno = number |
---|
| 677 | minute = number |
---|
| 678 | second = number |
---|
| 679 | yearday = number |
---|
| 680 | monthday = number |
---|
| 681 | setpos = number |
---|
| 682 | day = number |
---|
| 683 | hour = number |
---|
| 684 | interval = number |
---|
| 685 | frequency = [ 'monthly', 'daily', 'weekly', 'yearly', 'hourly', 'minutely', 'secondly' ] |
---|
| 686 | endTime = milliseconds |
---|
| 687 | */ |
---|
| 688 | return( patati ); |
---|
| 689 | |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | |
---|
| 693 | |
---|
| 694 | function encodeRepeat( repeat ){ |
---|
| 695 | |
---|
[6066] | 696 | if( !repeat ) |
---|
| 697 | return( false ); |
---|
| 698 | if(typeof(repeat) == "object") |
---|
| 699 | return repeat; |
---|
[5715] | 700 | |
---|
[6066] | 701 | return DataLayer.get( 'repeat', repeat ); |
---|
[5715] | 702 | } |
---|
| 703 | |
---|
[5341] | 704 | DataLayer.codec( "schedulable", "detail", { |
---|
| 705 | |
---|
| 706 | decoder: function( evtObj ){ |
---|
[5409] | 707 | |
---|
[5341] | 708 | Encoder.EncodeType = "entity"; |
---|
| 709 | |
---|
| 710 | if( notArray = $.type(evtObj) !== "array" ) |
---|
[6066] | 711 | evtObj = [ evtObj ]; |
---|
[5341] | 712 | |
---|
| 713 | var pref = User.preferences; |
---|
| 714 | |
---|
| 715 | var res = $.map(evtObj, function( form ){ |
---|
[5409] | 716 | |
---|
[6066] | 717 | var tzId = form.timezone || Calendar.signatureOf[form.calendar].calendar.timezone || User.preferences.timezone, |
---|
[5341] | 718 | |
---|
[6444] | 719 | formatString = pref.dateFormat + " " + pref.hourFormat; |
---|
[5947] | 720 | |
---|
[6066] | 721 | var Owner = decodeOwnerCalendar(form.calendar); |
---|
[5947] | 722 | |
---|
[6331] | 723 | return DataLayer.merge({ |
---|
[6066] | 724 | "class": form["class"], |
---|
[6444] | 725 | startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), |
---|
| 726 | 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] | 727 | allDay: ( !!form.allDay ? 1 : 0 ), |
---|
| 728 | id: form.idEvent, |
---|
| 729 | location: form.location, |
---|
| 730 | category: form.category, |
---|
| 731 | summary: form.summary, |
---|
| 732 | description: form.description, |
---|
| 733 | timezone: tzId, |
---|
| 734 | attachments: $.map(form.attachment || [], function( attachment, i ){ |
---|
[5341] | 735 | return { |
---|
[6066] | 736 | attachment: attachment |
---|
| 737 | } |
---|
| 738 | }), |
---|
| 739 | repeat: this.decodeRepeat( form ), |
---|
| 740 | participants: $.map( form.attendee || [], function( attendee, i ){ |
---|
[5341] | 741 | |
---|
[6066] | 742 | if( !attendee || attendee === "" ) |
---|
| 743 | return( null ); |
---|
| 744 | |
---|
| 745 | var participant = {}; |
---|
| 746 | participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ; |
---|
| 747 | |
---|
| 748 | if( participant.user === Owner.id ){ |
---|
| 749 | return DataLayer.merge({ |
---|
| 750 | id: attendee, |
---|
| 751 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 752 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''), |
---|
| 753 | alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ |
---|
| 754 | if( alarmTime === "" ) |
---|
[5947] | 755 | return( null ); |
---|
[6066] | 756 | return !!form.alarmId[i] ? { |
---|
| 757 | type: form.alarmType[i], |
---|
| 758 | unit: form.alarmUnit[i], |
---|
| 759 | time: form.alarmTime[i], |
---|
| 760 | id: form.alarmId[i] |
---|
| 761 | }: |
---|
[5341] | 762 | |
---|
[6066] | 763 | { |
---|
| 764 | type: form.alarmType[i], |
---|
| 765 | unit: form.alarmUnit[i], |
---|
| 766 | time: form.alarmTime[i] |
---|
| 767 | }; |
---|
| 768 | }), |
---|
| 769 | status: !!form.status ? form.status : 3 |
---|
| 770 | }, (form.delegatedFrom[i] != '0' && form.delegatedFrom[i] != '') ? { |
---|
| 771 | delegatedFrom: form.delegatedFrom[i] |
---|
| 772 | } : {}); |
---|
| 773 | }else{ |
---|
| 774 | return DataLayer.merge({ |
---|
| 775 | id: attendee, |
---|
| 776 | acl: form.attendeeAcl[i], |
---|
| 777 | isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), |
---|
| 778 | isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, |
---|
| 779 | acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '') |
---|
| 780 | }, form.delegatedFrom[i] != '0' ? { |
---|
| 781 | delegatedFrom: form.delegatedFrom[i] |
---|
| 782 | } : {}); |
---|
| 783 | }; |
---|
| 784 | }) |
---|
[6331] | 785 | }, form.lastCalendar ? (( form.lastCalendar == form.calendar ) ? {} : {calendar: form.calendar, lastCalendar: form.lastCalendar}) : {calendar: form.calendar}); |
---|
[6066] | 786 | }); |
---|
[5947] | 787 | |
---|
[5341] | 788 | return notArray ? res[0] : res; |
---|
| 789 | }, |
---|
| 790 | |
---|
[5715] | 791 | |
---|
[5341] | 792 | encoder: function( evtObj ){ |
---|
[5409] | 793 | |
---|
[6066] | 794 | if(!(!!evtObj)) |
---|
| 795 | return undefined; |
---|
[5341] | 796 | |
---|
[6066] | 797 | var notArray = false; |
---|
[5715] | 798 | |
---|
[6066] | 799 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 800 | evtObj = [ evtObj ]; |
---|
[5341] | 801 | |
---|
[6066] | 802 | var pref = User.preferences; |
---|
[5341] | 803 | |
---|
[6066] | 804 | var res = DataLayer.encode('schedulable:preview', evtObj); |
---|
[5341] | 805 | |
---|
[6066] | 806 | if( !notArray ){ |
---|
| 807 | var dates = {}; |
---|
| 808 | var typeRepeat = { |
---|
| 809 | 'none': false, |
---|
| 810 | 'daily': 'Repetição diária', |
---|
| 811 | 'weekly': 'Repetição semanal', |
---|
| 812 | 'monthly': 'Repetição mensal', |
---|
| 813 | 'yearly': 'repetição anual' |
---|
| 814 | } |
---|
[5341] | 815 | |
---|
[6066] | 816 | for (var i=0; i < res.length; i++) { |
---|
[5715] | 817 | |
---|
[6066] | 818 | var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat ); |
---|
| 819 | var endDate = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat ); |
---|
[5715] | 820 | |
---|
[6066] | 821 | var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() ); |
---|
[5715] | 822 | |
---|
[6066] | 823 | var occurrences = [ startDate.getTime() ]; |
---|
[5715] | 824 | |
---|
[6066] | 825 | if( res[i].occurrences ) |
---|
| 826 | { |
---|
| 827 | occurrences = res[i].occurrences; |
---|
| 828 | } |
---|
[5341] | 829 | |
---|
[6066] | 830 | for( var ii = 0; ii < occurrences.length; ii++ ) |
---|
| 831 | { |
---|
| 832 | var currentDate = new Date( occurrences[ii] ); |
---|
| 833 | var counter = currentDate.clone(); |
---|
[5715] | 834 | |
---|
[6066] | 835 | var res2 = $.extend( {}, res[i], { |
---|
| 836 | 'startDate': currentDate.toString( User.preferences.dateFormat ), |
---|
| 837 | 'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat ) |
---|
| 838 | } ); |
---|
[5715] | 839 | |
---|
[5835] | 840 | |
---|
| 841 | |
---|
| 842 | |
---|
[6066] | 843 | res2.repeat = typeRepeat[res[i].repeat.frequency]; |
---|
[5835] | 844 | |
---|
[6066] | 845 | while (counter.compareTo( currentDate ) == 0) { |
---|
[5341] | 846 | |
---|
[6066] | 847 | if (!dates[counter.toString(User.preferences.dateFormat)]) |
---|
| 848 | dates[counter.toString(User.preferences.dateFormat)] = { |
---|
| 849 | startDate:false, |
---|
| 850 | events:[] |
---|
| 851 | }; |
---|
| 852 | if (!dates[counter.toString(User.preferences.dateFormat)].startDate) |
---|
| 853 | dates[counter.toString(User.preferences.dateFormat)].startDate = counter.toString(User.preferences.dateFormat); |
---|
[5341] | 854 | |
---|
[6066] | 855 | dates[counter.toString(User.preferences.dateFormat)].events.push(res2); |
---|
| 856 | counter.addDays(-1); |
---|
| 857 | } |
---|
[5715] | 858 | } |
---|
[6066] | 859 | } |
---|
| 860 | res = { |
---|
| 861 | events_list: dates, |
---|
| 862 | count : res.length |
---|
| 863 | }; |
---|
| 864 | } |
---|
[5341] | 865 | |
---|
[6066] | 866 | return notArray ? res[0] : res; |
---|
[5341] | 867 | } |
---|
| 868 | |
---|
| 869 | }); |
---|
| 870 | |
---|
| 871 | DataLayer.codec( "participant", "detail", { |
---|
| 872 | |
---|
| 873 | encoder: function( participants ){ |
---|
| 874 | |
---|
[6066] | 875 | var result = {}; |
---|
| 876 | for( var i = 0; i< participants.length; i++ ){ |
---|
| 877 | result[ participants[i].user.id || participants[i].user ] = participants[i]; |
---|
| 878 | } |
---|
| 879 | return( result ); |
---|
[5341] | 880 | } |
---|
| 881 | }); |
---|
| 882 | |
---|
| 883 | DataLayer.codec( "calendar", "list", { |
---|
| 884 | |
---|
| 885 | encoder: function( calendars ){ |
---|
| 886 | |
---|
[6066] | 887 | var result = { |
---|
| 888 | my_calendars: [], |
---|
| 889 | others_calendars: [] |
---|
| 890 | }; |
---|
[5341] | 891 | |
---|
[6066] | 892 | for( var i = 0; i < calendars.length; i++ ) |
---|
| 893 | { |
---|
| 894 | !!Calendar.signatureOf[ calendars[i].id ].isOwner ? |
---|
| 895 | result.my_calendars.push( calendars[i] ) : |
---|
| 896 | result.others_calendars.push( calendars[i] ); |
---|
| 897 | } |
---|
[5341] | 898 | |
---|
[6066] | 899 | return { |
---|
| 900 | agendas_usuario: result |
---|
| 901 | }; |
---|
[5341] | 902 | |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | }); |
---|
| 906 | |
---|
| 907 | DataLayer.codec( "schedulable", "calendar", { |
---|
| 908 | |
---|
| 909 | decoder:function( evtObj ){ |
---|
| 910 | |
---|
| 911 | if( notArray = $.type(evtObj) !== "array" ) |
---|
| 912 | evtObj = [ evtObj ]; |
---|
| 913 | |
---|
| 914 | var res = $.map(evtObj, function( evt ){ |
---|
| 915 | |
---|
[6066] | 916 | return { |
---|
| 917 | id: evt.id, |
---|
| 918 | summary: evt.title, |
---|
| 919 | startTime: evt.start.getTime(), |
---|
| 920 | endTime: ( !!evt.allDay ? (( evt.end || evt.start ).getTime() + 86400000) :( evt.end || evt.start ).getTime()), |
---|
| 921 | allDay: ( !!evt.allDay ? 1 : 0 ) |
---|
| 922 | /*calendar: evt.id && User.calendarOf[ evt.id ].id*/ }; |
---|
[5341] | 923 | }); |
---|
| 924 | |
---|
| 925 | return notArray ? res[0] : res; |
---|
| 926 | }, |
---|
| 927 | |
---|
| 928 | encoder: function( evtObj, filter ){ |
---|
[5947] | 929 | |
---|
[5341] | 930 | if( !evtObj ) |
---|
| 931 | return( false ); |
---|
| 932 | |
---|
| 933 | var filtered = evtObj; |
---|
[6066] | 934 | // |
---|
[5341] | 935 | var grouped = {}; |
---|
| 936 | |
---|
| 937 | $.map(filtered, function( evt ){ |
---|
[5592] | 938 | |
---|
[6066] | 939 | if(!(typeof(evt) == 'object') || (evt.id.indexOf('java') >= 0)) |
---|
| 940 | return (null); |
---|
[5341] | 941 | |
---|
[6066] | 942 | evt.calendar = evt.calendar || "1"; |
---|
[5341] | 943 | |
---|
[6066] | 944 | if( !grouped[ evt.calendar ] ) |
---|
| 945 | grouped[ evt.calendar ] = []; |
---|
[5341] | 946 | |
---|
[6066] | 947 | var calendar = DataLayer.get('calendar', evt.calendar); |
---|
[5442] | 948 | |
---|
[6066] | 949 | var eventEditable = function(idEvent, isRecurrence, Recurrence){ |
---|
| 950 | if(Calendar.signatureOf[calendar.id].isOwner == "1"){ |
---|
| 951 | var attendee = {}; |
---|
| 952 | for(var i = 0; i < evt.participants.length; i++){ |
---|
| 953 | attendee = DataLayer.get('participant', evt.participants[i]); |
---|
| 954 | if(attendee.user == User.me.id) |
---|
| 955 | return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? { |
---|
| 956 | selectable: true, |
---|
[6286] | 957 | className: 'fullcalendar-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') |
---|
[6066] | 958 | } : { |
---|
| 959 | editable: false, |
---|
| 960 | selectable: true , |
---|
| 961 | className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent |
---|
| 962 | }; |
---|
| 963 | } |
---|
| 964 | return { |
---|
| 965 | editable: false, |
---|
[6286] | 966 | className: 'blocked-event-permision fullcalendar-not-context-menu event-id-'+idEvent+' calendar-id-'+calendar.id, |
---|
[6066] | 967 | selectable: true, |
---|
| 968 | disableDragging: isRecurrence |
---|
| 969 | }; |
---|
| 970 | } |
---|
| 971 | else{ |
---|
| 972 | var aclSignature = Calendar.signatureOf[calendar.id].permission; |
---|
[5592] | 973 | |
---|
[6066] | 974 | var mountClass = function(acl){ |
---|
| 975 | var returns = "" |
---|
| 976 | returns += acl['write'] ? "" : 'blocked-event-permision '; |
---|
[6286] | 977 | returns += acl['busy'] ? 'fullcalendar-not-context-menu ' : (acl['read'] ? 'fullcalendar-context-menu '+ (isRecurrence ? ' isRecurrence Recurrence-id-'+Recurrence : '') : ''); |
---|
| 978 | returns += 'event-id-'+idEvent+' calendar-id-'+calendar.id; |
---|
[6066] | 979 | return returns; |
---|
| 980 | } |
---|
| 981 | return DataLayer.merge({ |
---|
| 982 | editable: aclSignature.acl['write'] && !isRecurrence, |
---|
| 983 | disableResizing : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true : false), |
---|
| 984 | disableDragging : (((aclSignature.acl['busy'] && !aclSignature.acl['write']) || (!aclSignature.acl['write'] && aclSignature.acl['read'])) ? true: false), |
---|
| 985 | className: mountClass(aclSignature.acl) |
---|
| 986 | }, aclSignature.acl['busy'] ? { |
---|
| 987 | title: 'Ocupado', |
---|
| 988 | selectable: false |
---|
| 989 | } : { |
---|
| 990 | selectable: true |
---|
| 991 | }); |
---|
| 992 | } |
---|
[5592] | 993 | |
---|
[6066] | 994 | } |
---|
[5715] | 995 | |
---|
[6066] | 996 | var duration = parseInt( evt.endTime ) - parseInt( evt.startTime ), isRepeat = false; |
---|
[5715] | 997 | |
---|
[6066] | 998 | var occurrences = []; |
---|
[5715] | 999 | |
---|
[6066] | 1000 | if( evt.occurrences ) |
---|
| 1001 | { |
---|
| 1002 | isRepeat = true; |
---|
| 1003 | occurrences = evt.occurrences; |
---|
| 1004 | }else |
---|
| 1005 | occurrences[ occurrences.length ] = evt.startTime; |
---|
[5737] | 1006 | |
---|
[6066] | 1007 | //occurrences = DataLayer.unique( occurrences ).sort(); |
---|
[5409] | 1008 | |
---|
[6066] | 1009 | for( var i = 0; i < occurrences.length; i++ ) |
---|
| 1010 | grouped[ evt.calendar ].push( DataLayer.merge({ |
---|
| 1011 | id: evt.URI || evt.id+ '-' + i, |
---|
| 1012 | title: Encoder.htmlDecode(evt.summary), |
---|
| 1013 | start: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) ), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1014 | end: Timezone.getDateCalendar(new Date( parseInt( occurrences[i] ) + duration - (!!parseInt(evt.allDay) ? 86400000 : 0)), calendar.timezone, !!evt.DayLigth ? evt.DayLigth.calendar.startTime : Timezone.daylightSaving), |
---|
| 1015 | allDay: parseInt( evt.allDay ), |
---|
| 1016 | isRepeat: isRepeat, |
---|
| 1017 | occurrence: i, |
---|
| 1018 | calendar: evt.calendar |
---|
| 1019 | }, eventEditable(evt.id, isRepeat, i ) ) ); |
---|
[5341] | 1020 | }); |
---|
| 1021 | |
---|
| 1022 | return(/* notArray ? filtered[0] :*/ grouped ); |
---|
| 1023 | }, |
---|
| 1024 | |
---|
| 1025 | criteria: function( filter ){ |
---|
| 1026 | |
---|
[6066] | 1027 | if( $.type(filter.start) !== 'date' ) |
---|
| 1028 | filter.start = new Date( filter.start * 1000 ); |
---|
| 1029 | if( $.type(filter.end) !== 'date' ) |
---|
| 1030 | filter.end = new Date( filter.end * 1000 ); |
---|
[5341] | 1031 | |
---|
[6066] | 1032 | var timezone = {}; |
---|
| 1033 | for(var i in Calendar.signatureOf) |
---|
| 1034 | timezone[i] = Calendar.signatureOf[i].calendar.timezone; |
---|
[6151] | 1035 | |
---|
[6066] | 1036 | return { |
---|
[6151] | 1037 | filter: ['AND', |
---|
| 1038 | ['OR', |
---|
| 1039 | ['AND', |
---|
| 1040 | ['>=', 'rangeEnd', filter.start.getTime()], |
---|
| 1041 | ['<=', 'rangeEnd', filter.end.getTime()] , |
---|
| 1042 | ], |
---|
| 1043 | ['AND', |
---|
| 1044 | ['>=', 'rangeStart', filter.start.getTime()], |
---|
| 1045 | ['<=', 'rangeStart', filter.end.getTime()] , |
---|
| 1046 | ], |
---|
| 1047 | ['AND', |
---|
| 1048 | ['<=', 'rangeStart', filter.start.getTime()], |
---|
| 1049 | ['>=', 'rangeEnd', filter.end.getTime()] , |
---|
| 1050 | ] |
---|
| 1051 | ], |
---|
| 1052 | ['IN', 'calendar', Calendar.calendarIds] |
---|
| 1053 | ], |
---|
[6066] | 1054 | criteria: { |
---|
| 1055 | deepness: 2, |
---|
| 1056 | timezones: timezone |
---|
| 1057 | } |
---|
| 1058 | } |
---|
| 1059 | } |
---|
[5341] | 1060 | }); |
---|
| 1061 | |
---|
| 1062 | |
---|
| 1063 | DataLayer.codec( "preference", "detail", { |
---|
| 1064 | |
---|
[6066] | 1065 | decoder:function( pref ){ |
---|
[5341] | 1066 | |
---|
[6066] | 1067 | var res = []; |
---|
[5341] | 1068 | |
---|
[6066] | 1069 | pref.defaultAlarm = $.map( pref.alarmTime || [], function( alarmTime, i ){ |
---|
[5409] | 1070 | |
---|
[6066] | 1071 | return { |
---|
| 1072 | type: pref.alarmType[i], |
---|
| 1073 | time: alarmTime, |
---|
| 1074 | unit: pref.alarmUnit[i] |
---|
| 1075 | }; |
---|
| 1076 | }); |
---|
[5341] | 1077 | |
---|
[6066] | 1078 | $.each( pref, function( i, el ){ |
---|
[5341] | 1079 | |
---|
[6066] | 1080 | res[ res.length ] = { |
---|
| 1081 | name: i, |
---|
| 1082 | value: el |
---|
| 1083 | }; |
---|
[5341] | 1084 | |
---|
[6066] | 1085 | }); |
---|
[5409] | 1086 | |
---|
[6066] | 1087 | return( res ); |
---|
[5409] | 1088 | |
---|
[6066] | 1089 | }, |
---|
[5341] | 1090 | |
---|
[6066] | 1091 | encoder:function( pref ){ |
---|
| 1092 | return( pref ); |
---|
| 1093 | } |
---|
[5341] | 1094 | |
---|
| 1095 | }); |
---|
| 1096 | |
---|
| 1097 | DataLayer.codec( "schedulable", "export", { |
---|
| 1098 | |
---|
[6066] | 1099 | decoder: function(){}, |
---|
[5341] | 1100 | |
---|
[5409] | 1101 | encoder: function( signatures ){}, |
---|
[5341] | 1102 | |
---|
[5409] | 1103 | criteria: function( filter ){ |
---|
[5341] | 1104 | |
---|
[6066] | 1105 | if( isCal = filter && filter.calendar ) |
---|
| 1106 | filter = filter.calendar; |
---|
| 1107 | return { |
---|
| 1108 | filter: filter ? [ "=", ( isCal ? "calendar" : "id" ), filter ] : false, |
---|
| 1109 | criteria: { |
---|
| 1110 | format: 'iCal', |
---|
| 1111 | deepness: 2 |
---|
| 1112 | } |
---|
| 1113 | }; |
---|
| 1114 | } |
---|
[5341] | 1115 | }); |
---|
| 1116 | |
---|
[6444] | 1117 | User.init(); |
---|
[5341] | 1118 | |
---|
| 1119 | // DataLayer.decoder( "participant", "detail", function( form ){ |
---|
| 1120 | // |
---|
| 1121 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1122 | // // notArray = true; |
---|
| 1123 | // // attObj = [ attObj ]; |
---|
| 1124 | // // } |
---|
| 1125 | // |
---|
| 1126 | // |
---|
| 1127 | // |
---|
| 1128 | // return( participants ); |
---|
| 1129 | // |
---|
| 1130 | // }); |
---|
| 1131 | |
---|
| 1132 | // DataLayer.decoder( "alarm", "detail", function( form ){ |
---|
| 1133 | // |
---|
| 1134 | // // if( $.type( attObj ) !== "array" ){ |
---|
| 1135 | // // notArray = true; |
---|
| 1136 | // // attObj = [ attObj ]; |
---|
| 1137 | // // } |
---|
| 1138 | // |
---|
| 1139 | // var alarms = []; |
---|
| 1140 | // |
---|
| 1141 | // if( form.alarmType /*&& !form.*/ ) |
---|
| 1142 | // for( var i = 0; i < form.alarmType.length; i++ ) |
---|
| 1143 | // { |
---|
| 1144 | // if( form.alarmTime[i] === "" ) |
---|
| 1145 | // continue; |
---|
| 1146 | // |
---|
| 1147 | // alarms[i] = { type: form.alarmType[i], |
---|
| 1148 | // unit: form.alarmUnit[i], |
---|
| 1149 | // time: form.alarmTime[i] }; |
---|
| 1150 | // } |
---|
| 1151 | // |
---|
| 1152 | // return( alarms ); |
---|
| 1153 | // |
---|
| 1154 | // }); |
---|
| 1155 | |
---|