Changeset 5376


Ignore:
Timestamp:
01/13/12 09:10:28 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Estabilizacao da nova api, correcoes de bug e melhorias na nova agenda

Location:
trunk/prototype
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/Sync.php

    r5341 r5376  
    144144                  unset( $data[$oldURI] ); 
    145145 
    146                   $return[ $oldURI ] = $tx['rollback'] ? 'ROLLBACK' : array( 'id' => $tx['id'] ); 
     146                  $return[ $oldURI ] = !$tx['rollback'] ? $dt ?  
     147                                       array( 'id' => $tx['id'] ) : false : 'ROLLBACK';; 
    147148          } 
    148149    } 
  • trunk/prototype/app/datalayer.js

    r5343 r5376  
    391391    remove: function( concept, id, oneSide ){ 
    392392       
    393         var bothSides = (typeof oneSide === "undefined"); 
    394  
    395         if( bothSides || !oneSide ) 
    396             this.del( concept, id ); 
    397  
    398         if( bothSides ) 
    399             this.report( concept, id, false ); 
     393        var bothSides = (typeof oneSide === "undefined"), 
     394 
     395        links = this.links( concept ), ids = [], 
     396 
     397        current = this.check( concept, id ); 
     398 
     399        if( !current ) return; 
     400         
     401        if( id ) 
     402            current.id = id; 
     403 
     404        if( notArray = ( $.type( current ) !== "array" ) ) 
     405            current = [ current ]; 
     406 
     407        for( var i = 0; i < current.length; i++ ) 
     408        { 
     409            var currentId = ids[ ids.length ] = current[i].id; 
     410 
     411            if( bothSides ) 
     412              this.report( concept, currentId, false ); 
     413 
     414            if( bothSides || !oneSide ) 
     415              this.del( concept, currentId ); 
     416 
     417            for( var link in links ) 
     418            { 
     419                if( !current[i][link] ) 
     420                    continue; 
     421 
     422                var nestedLinks = this.links( links[link], true ); 
     423 
     424                if( isConcept = this.isConcept( concept, link ) ) 
     425                    current[i][link] = [ current[i][link] ]; 
     426 
     427                $.each( current[i][link], function( ii, el ){ 
     428 
     429                        el = DataLayer.storage.cache[links[link]][el]; 
     430 
     431                        if( notArrayNested = ( $.type( el[ nestedLinks[concept] ] ) !== "array" ) ) 
     432                            el[ nestedLinks[concept] ] = [ el[nestedLinks[concept]] ]; 
     433 
     434                        el[ nestedLinks[concept] ] = $.grep( el[ nestedLinks[concept] ], function( nested, iii ){ 
     435                            return ( currentId !== nested ); 
     436                        }); 
     437 
     438                        if( notArrayNested ) 
     439                            el[ nestedLinks[concept] ] = el[ nestedLinks[concept] ][0] || false; 
     440                        if(!el[ nestedLinks[concept] ] || !el[ nestedLinks[concept] ].length) 
     441                                delete el[ nestedLinks[concept] ]; 
     442                }); 
     443            } 
     444        } 
     445 
    400446        if( oneSide ) 
    401             this.commit( concept, id ); 
     447            this.commit( concept, ids ); 
    402448 
    403449        this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false ); 
     
    411457            current[ id ] = this.check( concept, id ) || {}; 
    412458         
    413         this.store( ':current', concept, current[ id ] ); 
     459        this.store( ':current', concept, current ); 
    414460 
    415461        var diff = this.diff( current[ id ], data ); 
     
    640686             
    641687    }, 
    642  
    643      
     688     
     689    unique: function( origArr ){  
     690 
     691        var newArr = []; 
     692       
     693        for ( var x = 0; x < origArr.length; x++ ) 
     694        { 
     695                var found = false; 
     696            for ( var y = 0; !found && y < newArr.length; y++ )  
     697                if ( origArr[x] === newArr[y] )   
     698                  found = true; 
     699 
     700            if ( !found )  
     701                newArr[ newArr.length ] = origArr[x]; 
     702        } 
     703 
     704        return newArr; 
     705    }, 
    644706 
    645707    merge: function( current, data ){ 
     
    752814                            } 
    753815 
    754                             var thisPass = this; 
    755  
    756816                            // It's now safe to let the comparator recursively deep copy its properties. 
    757                             comparator.populate( function(source, result) { return thisPass.copy(source, result, depth); }, source, result ); 
     817                            var returned = comparator.populate( function(source, result) { return DataLayer.copy(source, result, depth); }, source, result ); 
     818         
     819                                if(returned) 
     820                                        result = returned; 
    758821 
    759822                            depth.depth--; 
     
    11111174        this.put( concept, newId, this.check( concept, oldId ), false ); 
    11121175 
    1113         this.del( concept, oldId ); 
     1176        this.remove( concept, oldId, false ); 
    11141177    }, 
    11151178     
     
    19211984                        result.push( deepCopy(source[i], result[i]) ); 
    19221985                } 
     1986                result =  DataLayer.unique( result ) 
    19231987                return result; 
    19241988        } 
     
    19832047                      } 
    19842048              } 
     2049                return result; 
    19852050      } 
    19862051}); 
  • trunk/prototype/config/alarm.ini

    r5341 r5376  
    1111[after.find] 
    1212decodeFindConcept = modules/calendar/interceptors/DBMapping.php 
     13decodeSignatureAlarmType = modules/calendar/interceptors/DBMapping.php 
    1314 
    1415[before.create] 
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r5366 r5376  
    372372                     
    373373                        if($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
    374                             $participantLog = $vv['id'];  
     374                           $participants[$ii]['alarms'] = Controller::find( array( 'concept' => 'alarm' ) , null , array('filter' => array('AND' , array('=', 'participant' ,$vv['id'] ) ,array('=' , 'schedulable', $v['id'])) ) );  
    375375                    }        
    376376                    $result[$i]['participants'] = $participants; 
    377                 } 
    378                  
    379                 if(isset($participantLog)) 
    380                     $result[$i]['alarms'] = Controller::find( array( 'concept' => 'alarm' ) , null , array('filter' => array('AND' , array('=', 'participant' ,$participantLog ) ,array('=' , 'schedulable', $v['id'])) ) ); 
     377                }                
    381378                 
    382379           } 
     
    401398                           $participants[$ii]['user'] = Controller::read( array( 'concept' => 'user' , 'id' => $vv['user'] )); 
    402399 
    403                          if($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
    404                             $participantLog = $vv['id'];  
    405                      
     400                        if($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
     401                           $participants[$ii]['alarms'] = Controller::find( array( 'concept' => 'alarm' ) , null , array('filter' => array('AND' , array('=', 'participant' ,$vv['id'] ) ,array('=' , 'schedulable', $result['id'])) ) );  
     402                
    406403 
    407404                $result['participants'] = $participants; 
    408                 if(isset($participantLog)) 
    409                     $result['alarms'] = Controller::find( array( 'concept' => 'alarm' ) , null , array('filter' => array('AND' , array('=', 'user' , $participantLog ) ,array('=' , 'schedulable', $result['id'])) ) ); 
    410             } 
     405                } 
    411406       } 
    412407 
  • trunk/prototype/modules/calendar/js/calendar.codecs.js

    r5365 r5376  
    109109          for( var i = 0; i < this.signatures.length; i++ ) 
    110110          { 
    111               this.signatureOf[ this.calendarIds[i] = this.signatures[i].calendar.id ] = this.signatures[i]; 
    112               //this.signatureOf[ this.calendarIds[i] = this.signatures[i].calendar ] = this.signatures[i]; 
     111              this.signatureOf[ this.calendarIds[i] = ( this.calendars[ this.calendars.length ] = this.signatures[i].calendar ).id ] = this.signatures[i]; 
    113112          } 
    114  
    115           this.calendars = DataLayer.get( "calendar", {filter: ["IN", "id", this.calendarIds], criteria: {order: 'name'}} ); 
    116  
    117113          delete Calendar.currentViewKey; 
    118114      } 
     
    179175Calendar.load(); 
    180176 
    181 DataLayer.poll( "schedulable" ); 
     177//DataLayer.poll( "schedulable" ); 
    182178 
    183179DataLayer.listen( "schedulable", function( status ){ 
     
    320316         
    321317        encoder: function (evtObjt){ 
     318         
     319                        if(notArray = typeof(evtObjt) == 'array' ) 
     320                                evtObjt = [evtObjt]; 
     321                         
    322322                        var res = $.map(evtObjt, function( objEvent ){   
    323323                                var timezone = User.timezones[objEvent.schedulable.timezone]; 
     
    377377 
    378378                var res = $.map(evtObj, function( form ){ 
    379                         var event = {}; 
    380                         event.id = form.idEvent; 
    381                         event.calendar = form.calendar;  
    382                         var isCurrentParticipant = function(user, event){ 
    383                                 var participant =  DataLayer.get('participant', ['AND',['=', 'user', user],['=', 'schedulable', event]]); 
    384                                 if(participant != '') 
    385                                         return participant[0].id; 
    386                                 else 
    387                                         return false; 
    388                         };   
    389                          
    390                         event.participants = []; 
    391                         var participant = {}; 
    392                         participant.user = User.me.id, 
    393                         participant.status = form.status; 
    394                         if((form.idEvent) && (id = isCurrentParticipant(participant.user, form.idEvent))) 
    395                                 participant.id = id; 
    396                          
    397                         if(typeof(form.alarmTime) != 'undefined'){ 
    398                                 participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){ 
    399  
    400                                         if( alarmTime === "" ) 
    401                                                 return( null ); 
    402  
    403                                         if(form.alarmId[i] === "") 
    404                                                 return { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 
    405                                         else 
    406                                                 return { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] }; 
    407                                 });      
     379                         
     380                        return { 
     381                                id: form.idEvent, 
     382                                calendar: form.calendar, 
     383                                participants : [{ 
     384                                        user: User.me.id, 
     385                                        status: form.status, 
     386                                        id: form.attendee_organizer[0], 
     387                                        isOrganizer: 0, 
     388                                        alarms: typeof(form.alarmTime) != 'undefined' ?  
     389                                                $.map( form.alarmTime || [], function( alarmTime, i ){ 
     390 
     391                                                        if( alarmTime === "" ) 
     392                                                                return( null ); 
     393 
     394                                                        if(form.alarmId[i] === "") 
     395                                                                return { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] }; 
     396                                                        else 
     397                                                                return { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] }; 
     398                                                }) : [] 
     399                                        }] 
    408400                        } 
    409                          
    410                         event.participants[0] = participant; 
    411                          
    412                         return event; 
    413401                }); 
    414         return notArray ? res[0] : res; 
     402                 
     403                return notArray ? res[0] : res; 
    415404    }, 
    416405 
     
    460449                                data.setTime(time); 
    461450                                return dateFormat(setDateTimezone(data, timezone, existsTimezone, idCalendar), User.preferences.hourFormat.replace(/m/g,'M'))                    
    462                         }        
    463                         var temp = []; 
    464                         var tempAlarm = []; 
    465                                          
    466                         var typeAlarm = function(obj){ 
    467                                 var alarm = []; 
    468                                 for(var i = 0; i < obj.length; i++){ 
    469                                         if(tempAlarm[obj[i].id])  
    470                                                 continue;  
    471                                         tempAlarm[obj[i].id] = true; 
    472                                          
    473                                         if(obj[i].type == "1"){ 
    474                                                 obj[i].type = 'alert'; 
    475                                         }else if(obj[i].type == "2"){ 
    476                                                 obj[i].type = 'mail'; 
    477                                         }else{ 
    478                                                 obj[i].type = 'sms'; 
    479                                         } 
    480                                         alarm.push(obj[i]); 
     451                        }                                                
     452                        var alarmParticipant = function(obj){ 
     453                                var alarms = []; 
     454                                for(var i = 0; i < obj.length; i++){  
     455                                        alarms.push(DataLayer.get('alarm', obj[i])); 
    481456                                } 
    482                                 return alarm; 
     457                                return alarms; 
    483458                        } 
    484459                    return { 
     
    499474                              allDay: !!parseInt( objEvent.allDay ), 
    500475          //                            attachments: this.decode( "attachment:detail", form ), 
    501                               attendee: $.map(objEvent.participants || [], function( participant, i ){ 
    502                                                 if(participant.indexOf('java') >= 0)  
    503                                                         return (null);  
    504                                                 if(temp[participant])  
    505                                                         return (null);  
    506                                                 temp[participant] = true; 
    507                                                  
     476                              attendee: $.map(objEvent.participants || [], function( participant, i ){                                           
     477                                         
    508478                                        var attend = DataLayer.get('participant', participant); 
    509479                                        attend.user = DataLayer.get('user', attend.user) 
     
    520490                                          { 
    521491                                              participantInfo.status = attend.status; 
    522                                               participantInfo.alarms = typeAlarm(objEvent.alarms); 
     492                                              participantInfo.alarms = alarmParticipant(attend.alarms); 
     493                                                  me.uid = attend.id; 
    523494                                          } 
    524495                                          if( parseInt( attend.isOrganizer ) ) 
  • trunk/prototype/modules/calendar/js/helpers.js

    r5364 r5376  
    267267            }); 
    268268                 
    269                 UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { 
     269                UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el){ 
     270                        var id; 
     271                        if( id = $(this).parent().find('input[name="alarmId[]"]').val()) 
     272                                DataLayer.remove('alarm', id); 
    270273                        if( $(this).parent().remove().find('li').is(':empty') ) { 
    271274                                //alert('nao tem'); 
     
    303306                                        var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); 
    304307                                                jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { 
     308                                                        var id; 
     309                                                        if( id = $(this).parent().find('input[name="alarmId[]"]').val()) 
     310                                                                DataLayer.remove('alarm', id); 
    305311                                                        if( $(this).parent().remove().find('li').is(':empty') ) { 
    306312                                                                //alert('nao tem'); 
     
    608614                                        if (user){ 
    609615                                                if (!skipAddNewLine) { 
     616                                                        user[0].id =  DataLayer.put('participant', {user: user[0].id, isExternal: 1}); 
    610617                                                        blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( 
    611618                                                                DataLayer.render('templates/participants_add_itemlist.ejs', user) 
     
    860867 
    861868                                form_content.find('.button-add-alarms').click(function(){ 
    862                                         DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ 
     869                                        DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){                                                 
    863870                                                jQuery('.preferences-alarms-list').append(template) 
    864871                                                .find('li:last label:eq(0)').remove().end() 
  • trunk/prototype/modules/calendar/templates/alarms_add_itemlist.ejs

    r5341 r5376  
    1111                        <select name="alarmUnit[]"> 
    1212                                <option value="d" <%= data.alarm.defaultAlarms[i].unit=='d' ? 'selected="selected"':'' %>>Dias</option> 
    13                                 <option value="h" <%= data.alarm.defaultAlarms[i].unit=='H' ? 'selected="selected"':'' %>>Horas</option> 
     13                                <option value="h" <%= data.alarm.defaultAlarms[i].unit=='h' ? 'selected="selected"':'' %>>Horas</option> 
    1414                                <option value="m" <%= data.alarm.defaultAlarms[i].unit=='m' ? 'selected="selected"':'' %>>Minutos</option> 
    1515                        </select> 
     
    3131                <select name="alarmUnit[]"> 
    3232                        <option value="d">Dias</option> 
    33                         <option value="H">Horas</option> 
     33                        <option value="h">Horas</option> 
    3434                        <option value="m">Minutos</option> 
    3535                </select> 
  • trunk/prototype/modules/calendar/templates/event_add.ejs

    r5345 r5376  
    127127                                <select name="alarmUnit[]"> 
    128128                                        <option value="d" <%= data.event.alarms[i].unit=='d' ? 'selected="selected"':'' %>>Dias</option> 
    129                                         <option value="h" <%= data.event.alarms[i].unit=='H' ? 'selected="selected"':'' %>>Horas</option> 
     129                                        <option value="h" <%= data.event.alarms[i].unit=='h' ? 'selected="selected"':'' %>>Horas</option> 
    130130                                        <option value="m" <%= data.event.alarms[i].unit=='m' ? 'selected="selected"':'' %>>Minutos</option> 
    131131                                </select> 
Note: See TracChangeset for help on using the changeset viewer.