- Timestamp:
- 07/25/12 17:05:36 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js
r6797 r6876 596 596 }); 597 597 598 DataLayer.codec( "schedulable", "task", { 599 600 decoder: function( evtObj ){ 601 Encoder.EncodeType = "entity"; 602 603 if( notArray = $.type(evtObj) !== "array" ) 604 evtObj = [ evtObj ]; 605 606 var pref = User.preferences; 607 608 var res = $.map(evtObj, function( form ){ 609 610 var tzId = form.timezone || Calendar.signatureOf[form.group].calendar.timezone || User.preferences.timezone, 611 612 formatString = pref.dateFormat + " " + pref.hourFormat; 613 614 return DataLayer.merge({ 615 "class": form["class"], 616 startTime: Date.parseExact(form.startDate + " "+$.trim(form.startHour) , formatString ).toString(!!form.allDay ? 'yyyy-MM-dd 00:00:00' : 'yyyy-MM-dd HH:mm:00'), 617 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) , 618 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'), 619 allDay: ( !!form.allDay ? 1 : 0 ), 620 status: form.taskStatus, 621 id: form.idTask, 622 location: form.location, 623 type: 2, 624 percentage: form.percentage, 625 priority: form.priority, 626 category: form.category, 627 summary: form.summary, 628 description: form.description, 629 timezone: tzId, 630 attachments: $.map(form.attachment || [], function( attachment, i ){ 631 return { 632 attachment: attachment 633 } 634 }), 635 participants: $.map( form.attendee || [], function( attendee, i ){ 636 637 if( !attendee || attendee === "" ) 638 return( null ); 639 640 var participant = {}; 641 participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ; 642 643 if( participant.user === User.me.id ){ 644 return DataLayer.merge({ 645 id: attendee, 646 isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), 647 alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ 648 if( alarmTime === "" ) 649 return( null ); 650 return !!form.alarmId[i] ? { 651 type: form.alarmType[i], 652 unit: form.alarmUnit[i], 653 time: form.alarmTime[i], 654 id: form.alarmId[i] 655 }: 656 657 { 658 type: form.alarmType[i], 659 unit: form.alarmUnit[i], 660 time: form.alarmTime[i] 661 }; 662 }), 663 status: !!form.status ? form.status : 3 664 }, (form.delegatedFrom[i] != '0' && form.delegatedFrom[i] != '') ? { 665 delegatedFrom: form.delegatedFrom[i] 666 } : {}); 667 }else{ 668 return { 669 id: attendee, 670 isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ), 671 isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0, 672 }; 673 }; 674 }) 675 }, form.lastGroup ? (( form.lastGroup == form.group ) ? {} : {calendar: form.group, lastGroup: form.lastGroup}) : {calendar: form.group}); 676 }); 677 678 return notArray ? res[0] : res; 679 }, 680 681 encoder: function( evtObj ){ 682 683 var notArray = false; 684 685 if( notArray = $.type(evtObj) !== "array" ) 686 evtObj = [ evtObj ]; 687 688 var statusParticipants = {}, isAttendee = false, 689 690 statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ], 691 692 participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy( User.me ); 693 694 var delegateAttendee = {}; 695 696 for( var i = 0; i < statusLabels.length; i++ ) 697 statusParticipants[ statusLabels[i] ] = 0; 698 699 var res = $.map(evtObj, function( objEvent ){ 700 701 if(!(typeof(objEvent) == 'object')) 702 return (null); 703 704 var limitAttendee = false; 705 706 return { 707 "class": objEvent["class"], 708 id: objEvent.id, 709 location: objEvent.location, 710 category: objEvent.category, 711 taskStatus: objEvent.status, 712 groups: Calendar.groups, 713 group: objEvent.group, 714 summary: objEvent.summary, 715 description: objEvent.description, 716 timezone: objEvent.timezone, 717 timezones: Timezone.timezones, 718 percentage: (objEvent.percentage) ? objEvent.percentage : '0', 719 priority: objEvent.priority, 720 startDate: new Date( parseInt(objEvent.startTime) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), 721 startHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date( parseInt(objEvent.startTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'startTime'), User.preferences.hourFormat), 722 endDate: new Date( parseInt(objEvent.endTime) - (!!parseInt(objEvent.allDay) ? 86400000 : 0) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), 723 endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat), 724 dueDate: (!objEvent.due || objEvent.due == '' || objEvent.due == '0') ? '' : new Date( parseInt(objEvent.due) ).setTimezoneOffset( Timezone.timezone( objEvent.timezone ) ).toString( User.preferences.dateFormat ), 725 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), 726 allDay: !!parseInt( objEvent.allDay ), 727 historic: [], 728 attachments: $.map(objEvent.attachments || [], function( attachment, i ){ 729 var attach = DataLayer.get('schedulableToAttachment', attachment, false); 730 //TODO - Verificar na API retorno de id sobre os conceitos em que s?o utilizados tabelas de liga??o 731 if(!attach.name) return(null); 732 733 var ext = attach.name.split('.'); 734 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])); 735 attach.size = formatBytes(attach.size); 736 return attach; 737 }), 738 attendee: $.map(objEvent.participants || [], function( participant, i ){ 739 740 if(delegateAttendee[participant]) 741 return(null); 742 743 var attend = DataLayer.get('participant', (participant.id || participant)); 744 attend.user = DataLayer.get('user', attend.user); 745 746 statusParticipants[ statusLabels[attend.status] ]++; 747 748 if(attend.user.mail == User.me.mail) 749 isAttendee = true; 750 751 if( attend.user.id === me.id ){ 752 participantInfo.user = { 753 id: attend.id, 754 status : attend.status, 755 delegatedFrom: attend.delegatedFrom || '0', 756 acl: attend.acl, 757 receiveNotification : attend.receiveNotification, 758 alarms : $.map(attend.alarms || [], function( alarm ){ 759 var alarm = DataLayer.get('alarm', alarm); 760 return (alarm == "" ? (null) : alarm); 761 }) 762 }; 763 me = attend; 764 return(null); 765 }; 766 767 var person = { 768 id: attend.id, 769 name: attend.user.name != 'false' ? attend.user.name : '', 770 mail: attend.user.mail, 771 status : attend.status, 772 isExternal: attend.isExternal, 773 acl: attend.acl, 774 delegatedFrom: attend.delegatedFrom 775 }; 776 777 if(!!parseInt(attend.delegatedFrom)){ 778 delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); 779 return(null); 780 } 781 782 if( !!parseInt(attend.isOrganizer)){ 783 participantInfo.organizer = DataLayer.copy(person); 784 return(null); 785 }; 786 787 return (person); 788 }), 789 organizer: participantInfo.organizer || me, 790 alarms: !!participantInfo.user ? participantInfo.user.alarms : [], 791 status: !!participantInfo.user ? participantInfo.user.status : 1, 792 isAttendee: isAttendee, 793 me: me, 794 delegatedFrom: delegatedFrom, 795 statusParticipants: (objEvent.sizeAttendees != "") ? objEvent.statusAttendees : statusParticipants, 796 sizeAttendeeLimit: (objEvent.sizeAttendees != "") ? objEvent.sizeAttendees : false 797 }; 798 }); 799 console.log(res[0]); 800 return (notArray ? res[0] : res); 801 } 802 }); 598 803 599 804 function decodeOwnerCalendar(calendar){ … … 1055 1260 ] 1056 1261 ], 1057 ['IN', 'calendar', Calendar.calendarIds]1262 ['IN', 'calendar', $.merge( Calendar.calendarIds, Calendar.groupIds )] 1058 1263 ], 1059 1264 criteria: {
Note: See TracChangeset
for help on using the changeset viewer.