Changeset 5376 for trunk/prototype/app


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}); 
Note: See TracChangeset for help on using the changeset viewer.