Changeset 5514 for trunk/prototype/modules/calendar/js/calendar.codecs.js
- Timestamp:
- 02/14/12 16:52:04 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/modules/calendar/js/calendar.codecs.js
r5468 r5514 29 29 this.preferenceIds = pref.ids; 30 30 } 31 } 32 33 constantsParticipant = { 34 'o' : 'organization', 35 'w' : 'write', 36 'p' : 'participationRequired', 37 'i' : 'inviteGuests', 38 'r' : 'read' 31 39 } 32 40 … … 333 341 }); 334 342 343 DataLayer.codec( "suggestion", "duration", { 344 345 decoder: function( evtObj ){ 346 if( notArray = $.type(evtObj) !== "array" ) 347 evtObj = [ evtObj ]; 348 349 350 351 var meAttendee = function(attendees){ 352 for(var i = 0; i < attendees.length; i++) 353 if(DataLayer.get('participant', attendees[i]).user == User.me.id) 354 return attendee; 355 }; 356 357 var res = $.map(evtObj, function( form ){ 358 return { 359 participant : meAttendee(form.attendee), 360 startTime: Timezone.getDateUTC(Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ), tzId).getTime(), 361 endTime: parseInt(Timezone.getDateUTC(Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ), tzId).getTime()) + (!!form.allDay ? 86400000 : 0) , 362 allDay: ( !!form.allDay ? 1 : 0 ), 363 schedulable: form.idEvent 364 } 365 }); 366 367 368 return notArray ? res[0] : res; 369 }, 370 371 encoder: function( evtObj ){} 372 373 }); 374 375 DataLayer.codec( "attachment", "detail", { 376 377 decoder: function(evtObj){ 378 379 if( notArray = $.type(evtObj) !== "array" ) 380 evtObj = [ evtObj ]; 381 382 var res = $.map(evtObj, function( form){ 383 return [$.map(form.files , function( files){ 384 return { source: files }; 385 })]; 386 }); 387 return notArray ? res[0] : res; 388 }, 389 390 encoder: function(){} 391 392 393 }); 394 335 395 DataLayer.codec( "schedulable", "preview", { 336 396 … … 348 408 id: form.idEvent, 349 409 calendar: form.calendar, 350 participants : [{ 351 user: User.me.id, 352 status: form.status, 353 id: form.meId, 354 isOrganizer: 0, 355 alarms: typeof(form.alarmTime) != 'undefined' ? 356 $.map( form.alarmTime || [], function( alarmTime, i ){ 357 358 if( alarmTime === "" ) 359 return( null ); 360 361 return !!form.alarmId[i] ? 362 { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] } : 363 { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 364 }) : [] 365 }] 410 participants : $.map(form.attendee, function( attendee, i ){ 411 if(isNaN(attendee)){ 412 return{ 413 id: attendee, 414 acl: form.attendeeAcl[i], 415 delegatedFrom: !!form.delegatedFrom[i] ? form.delegatedFrom[i] : 0, 416 isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), 417 isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, 418 acl: form.attendeeAcl[i].replace('o', '') 419 }; 420 }else{ 421 if(DataLayer.get('participant', attendee).user == User.me.id){ 422 var me = { 423 user: User.me.id, 424 status: form.status, 425 id: attendee, 426 isOrganizer: 0, 427 receiveNotification : (!!form.receiveNotification ? 1 : 0), 428 alarms: typeof(form.alarmTime) != 'undefined' ? 429 $.map( form.alarmTime || [], function( alarmTime, i ){ 430 431 if( alarmTime === "" ) 432 return( null ); 433 434 return !!form.alarmId[i] ? 435 { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] } : 436 { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 437 }) : [] 438 }; 439 440 if(form.startDate){ 441 var tzId = DataLayer.get('schedulable', form.idEvent).timezone || User.preferences.timezone, 442 formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? pref.dateFormat+" HH:mm" : pref.dateFormat + " " + pref.hourFormat; 443 444 DataLayer.put('notification', { 445 participant: me.id, 446 type: 'suggestion', 447 startTime: Timezone.getDateUTC(Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ), tzId).getTime(), 448 endTime: parseInt(Timezone.getDateUTC(Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ), tzId).getTime()) + (!!form.allDay ? 86400000 : 0) , 449 allDay: ( !!form.allDay ? 1 : 0 ), 450 schedulable: form.idEvent 451 }); 452 453 } 454 return me; 455 }else return(null); 456 }; 457 }) 366 458 } 367 459 }); 368 369 460 return notArray ? res[0] : res; 370 461 }, … … 381 472 statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ]; 382 473 474 var delegateAttendee = {}; 475 383 476 for( var i = 0; i < statusLabels.length; i++ ) 384 477 statusParticipants[ statusLabels[i] ] = 0; 385 386 var isOrganizer = 1;387 478 388 479 var res = $.map(evtObj, function( objEvent ){ 389 480 390 var participantInfo = {}, me = DataLayer.copy(User.me); 481 var participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy(User.me); 482 483 var constantAcl = function(acl){ 484 var returns = {}; 485 for (var i in constantsParticipant){ 486 returns[constantsParticipant[i]] = acl.indexOf(i) >= 0 ? true : false 487 } 488 return returns; 489 }; 391 490 392 491 return { … … 406 505 endHour: dateCalendar.formatDate(Timezone.setDateTimezone(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar), User.preferences.hourFormat), 407 506 allDay: !!parseInt( objEvent.allDay ), 408 // attachments: this.decode( "attachment:detail", form ), 507 attachments: $.map(objEvent.attachments || [], function( attachment, i ){ 508 var attach = DataLayer.get('schedulableToAttachment', attachment, false); 509 attach.name = attach.name.length < 10 ? attach.name : ( attach.name.substr(0, 6) + attach.name.substr( attach.name.length-4, attach.name.length)); 510 511 return attach; 512 }), 409 513 attendee: $.map(objEvent.participants || [], function( participant, i ){ 514 515 if(delegateAttendee[participant]) 516 return(null); 410 517 411 518 var attend = DataLayer.get('participant', participant); … … 416 523 if( attend.user.id === me.id ){ 417 524 participantInfo.user = { 525 id: attend.id, 418 526 status : attend.status, 527 delegatedFrom: attend.delegatedFrom, 528 acl: attend.acl, 529 receiveNotification : attend.receiveNotification, 419 530 alarms : $.map(attend.alarms || [], function( alarm ){ 420 531 return DataLayer.get('alarm', alarm); … … 422 533 }; 423 534 me.id = attend.id; 424 535 return(null); 425 536 }; 426 537 … … 429 540 name: attend.user.name != 'false' ? attend.user.name : '', 430 541 mail: attend.user.mail, 431 isExternal: attend.isExternal 542 status : attend.status, 543 isExternal: attend.isExternal, 544 acl: attend.acl, 545 delegatedFrom: attend.delegatedFrom 432 546 }; 433 547 548 if(!!parseInt(attend.delegatedFrom)){ 549 delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); 550 return(null); 551 } 552 434 553 if( !!parseInt(attend.isOrganizer )){ 435 isOrganizer = ((attend.user.id == User.me.id) || (!!!attend.user)) ? 1 : 0;436 554 participantInfo.organizer = DataLayer.copy(person); 437 555 return(null); … … 441 559 }), 442 560 organizer: participantInfo.organizer || me, 443 alarms: !!participantInfo.user ? participantInfo.user.alarms : [], 444 status: !!participantInfo.user ? participantInfo.user.status : 1, 445 me: me, 446 isOrganizer: isOrganizer, 561 alarms: !!participantInfo.user ? participantInfo.user.alarms : [], 562 status: !!participantInfo.user ? participantInfo.user.status : 1, 563 acl: !!participantInfo.user ? constantAcl(participantInfo.user.acl) : constantAcl('rowi'), 564 me: !!participantInfo.user ? DataLayer.merge(participantInfo.user, me) : DataLayer.merge(me, {acl: 'rowi', delegatedFrom: 0, receiveNotification: 1}), 565 delegatedFrom: delegatedFrom, 447 566 statusParticipants: statusParticipants 448 567 }; 449 }); 450 568 }); 451 569 return notArray ? res[0] : res; 452 570 } … … 485 603 description: form.description, 486 604 timezone: tzId, 605 attachments: $.map(form.attachment || [], function( attachment, i ){ 606 return {attachment: attachment} 607 }), 487 608 participants: $.map( form.attendee || [], function( attendee, i ){ 488 609 … … 495 616 if( participant.user === User.me.id ){ 496 617 return DataLayer.merge({ 497 isOrganizer: ( !i ? 1 : 0 ), 618 id: attendee, 619 isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), 620 acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''), 498 621 alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ 499 622 if( alarmTime === "" ) … … 502 625 { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 503 626 }), 504 status: form.status505 }, !!form.idEvent ? {id: attendee} : {user: participant.user});627 status: !!form.status ? form.status : 3 628 }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {}); 506 629 }else{ 507 return {630 return DataLayer.merge({ 508 631 id: attendee, 509 isOrganizer: ( !i ? 1 : 0 ), 510 isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0 511 }; 632 acl: form.attendeeAcl[i], 633 isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), 634 isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, 635 acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '') 636 }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {}); 512 637 }; 513 638 }) … … 719 844 for(var i = 0; i < evt.participants.length; i++){ 720 845 attendee = DataLayer.get('participant', evt.participants[i]); 721 if(!!parseInt(attendee.isOrganizer))722 846 if(attendee.user == User.me.id) 723 return true; 724 else 725 return false; 847 return (attendee.acl.indexOf('w') >= 0 || attendee.acl.indexOf('o') >= 0 ) ? true : false; 726 848 } 727 849 }
Note: See TracChangeset
for help on using the changeset viewer.