Ignore:
Timestamp:
02/14/12 16:52:04 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Implementacao anexos, acls e delegacao de participantes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/js/calendar.codecs.js

    r5468 r5514  
    2929                this.preferenceIds = pref.ids; 
    3030    } 
     31} 
     32 
     33constantsParticipant = { 
     34        'o' : 'organization', 
     35        'w' : 'write', 
     36        'p' : 'participationRequired', 
     37        'i' : 'inviteGuests', 
     38        'r' : 'read' 
    3139} 
    3240 
     
    333341}); 
    334342 
     343DataLayer.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 
     375DataLayer.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 
    335395DataLayer.codec( "schedulable", "preview", { 
    336396 
     
    348408                                id: form.idEvent, 
    349409                                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                                }) 
    366458                        } 
    367459                }); 
    368                  
    369460                return notArray ? res[0] : res; 
    370461    }, 
     
    381472        statusLabels = [ '', 'accepted', 'tentative', 'cancelled', 'unanswered', 'delegated' ]; 
    382473         
     474        var delegateAttendee = {}; 
     475         
    383476        for( var i = 0; i < statusLabels.length; i++ ) 
    384477                statusParticipants[ statusLabels[i] ] = 0; 
    385  
    386         var isOrganizer = 1; 
    387478         
    388479        var res = $.map(evtObj, function( objEvent ){                    
    389480                     
    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                        }; 
    391490                                                 
    392491                    return { 
     
    406505                            endHour: dateCalendar.formatDate(Timezone.setDateTimezone(new Date(parseInt(objEvent.endTime)), objEvent.timezone, objEvent.calendar), User.preferences.hourFormat), 
    407506                            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                                }),                                              
    409513                            attendee: $.map(objEvent.participants || [], function( participant, i ){                                             
     514                                         
     515                                        if(delegateAttendee[participant]) 
     516                                                return(null); 
    410517                                         
    411518                                        var attend = DataLayer.get('participant', participant); 
     
    416523                                        if( attend.user.id ===  me.id ){ 
    417524                                            participantInfo.user = { 
     525                                                        id: attend.id, 
    418526                                                        status : attend.status, 
     527                                                        delegatedFrom: attend.delegatedFrom, 
     528                                                        acl: attend.acl, 
     529                                                        receiveNotification : attend.receiveNotification, 
    419530                                                        alarms : $.map(attend.alarms || [], function( alarm ){ 
    420531                                                                return DataLayer.get('alarm', alarm); 
     
    422533                                                }; 
    423534                                                me.id = attend.id; 
    424                                                 return(null); 
     535                                                return(null); 
    425536                                        }; 
    426537                                         
     
    429540                                                name: attend.user.name != 'false' ? attend.user.name : '', 
    430541                                                mail: attend.user.mail, 
    431                                                 isExternal: attend.isExternal 
     542                                                status : attend.status, 
     543                                                isExternal: attend.isExternal, 
     544                                                acl: attend.acl, 
     545                                                delegatedFrom: attend.delegatedFrom 
    432546                                        }; 
    433547                                         
     548                                        if(!!parseInt(attend.delegatedFrom)){ 
     549                                                delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person); 
     550                                                return(null); 
     551                                        } 
     552                                         
    434553                                        if( !!parseInt(attend.isOrganizer )){ 
    435                                                 isOrganizer = ((attend.user.id == User.me.id) || (!!!attend.user)) ? 1 : 0; 
    436554                                            participantInfo.organizer = DataLayer.copy(person); 
    437555                                                return(null); 
     
    441559                                }), 
    442560                            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, 
    447566                                statusParticipants: statusParticipants 
    448567                        }; 
    449                 }); 
    450  
     568                });      
    451569        return notArray ? res[0] : res; 
    452570    } 
     
    485603                              description: form.description, 
    486604                              timezone: tzId, 
     605                                  attachments: $.map(form.attachment || [], function( attachment, i ){ 
     606                                                return {attachment: attachment} 
     607                                  }), 
    487608                              participants: $.map( form.attendee || [], function( attendee, i ){ 
    488609 
     
    495616                                                if( participant.user === User.me.id ){ 
    496617                                                        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', ''), 
    498621                                                                alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ 
    499622                                                                                if( alarmTime === "" ) 
     
    502625                                                                                                                                        { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 
    503626                                                                        }), 
    504                                                                 status: form.status 
    505                                                         }, !!form.idEvent ? {id: attendee} : {user: participant.user});                                                  
     627                                                                status: !!form.status ? form.status : 3 
     628                                                                }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {});                                                  
    506629                                                }else{ 
    507                                                         return { 
     630                                                        return DataLayer.merge({ 
    508631                                                                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]} : {});  
    512637                                                }; 
    513638                                          }) 
     
    719844                        for(var i = 0; i < evt.participants.length; i++){ 
    720845                                attendee = DataLayer.get('participant', evt.participants[i]); 
    721                                 if(!!parseInt(attendee.isOrganizer)) 
    722846                                        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; 
    726848                        } 
    727849                } 
Note: See TracChangeset for help on using the changeset viewer.