Changeset 5376 for trunk/prototype/app
- Timestamp:
- 01/13/12 09:10:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/app/datalayer.js
r5343 r5376 391 391 remove: function( concept, id, oneSide ){ 392 392 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 400 446 if( oneSide ) 401 this.commit( concept, id );447 this.commit( concept, ids ); 402 448 403 449 this.broadcast( concept, oneSide ? 'server' : bothSides ? 'serverclient' : 'client', false ); … … 411 457 current[ id ] = this.check( concept, id ) || {}; 412 458 413 this.store( ':current', concept, current [ id ]);459 this.store( ':current', concept, current ); 414 460 415 461 var diff = this.diff( current[ id ], data ); … … 640 686 641 687 }, 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 }, 644 706 645 707 merge: function( current, data ){ … … 752 814 } 753 815 754 var thisPass = this;755 756 816 // 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; 758 821 759 822 depth.depth--; … … 1111 1174 this.put( concept, newId, this.check( concept, oldId ), false ); 1112 1175 1113 this. del( concept, oldId);1176 this.remove( concept, oldId, false ); 1114 1177 }, 1115 1178 … … 1921 1984 result.push( deepCopy(source[i], result[i]) ); 1922 1985 } 1986 result = DataLayer.unique( result ) 1923 1987 return result; 1924 1988 } … … 1983 2047 } 1984 2048 } 2049 return result; 1985 2050 } 1986 2051 });
Note: See TracChangeset
for help on using the changeset viewer.