Skip to content

Instantly share code, notes, and snippets.

@diago
Created October 20, 2011 13:37
Show Gist options
  • Save diago/1301163 to your computer and use it in GitHub Desktop.
Save diago/1301163 to your computer and use it in GitHub Desktop.
dojo.provide( 'outland.store.JsonRestTreeModel' );
dojo.require( 'dojo.store.JsonRest' );
dojo.declare
( 'outland.store.JsonRestTreeModel'
, [ dojo.store.JsonRest ]
, { idProperty : 'id'
, rootQuery : { name: 'CONTAINER' }
, mayHaveChildren : function(obj) {
return obj.has_children;
} // mayHaveChildren
, getChildren : function( obj, onComplete, onError ) {
if( ! onComplete)
onComplete = dojo.hitch( this, function( children ){
this.onChildrenChange( obj, children );
} );
this.query( { parent_id: obj.id } ).then( onComplete, onError );
} // getChildren
, getRoot : function( onItem, onError ) {
this.query( this.rootQuery ).then( function( root ){
this.root = root[0];
onItem( this.root );
}, onError );
} // getRoot
, getLabel : function( obj ) {
return obj.name ;
} // getLabel
, pasteItem : function( item, from, to ) {
item.parent_id = to.id
this.put( item ).then( dojo.hitch( this, function() {
this.getChildren( from );
this.getChildren( to );
} ) );
} // pasteItem
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment