silk.daghap = xb.core.object.extend( { ctor: function( resource ) { var self = this; this.resource = resource; var self = this; window.addEventListener( "hashchange", function( evt ) { if ( silk.inEditMode() ) { self.select(); } } ); this.load(); }, load: function() { var fields = { }; this.resource.select( {} ); }, select: function() { this.resource.select( {} ); } } ); var checkmedaghap = null; silk.daghap.resource = xb.core.object.extend( silk.resource, { ctor: function( config ) { this.handlers = { "view": silk.daghap.items.mount, "carousel": silk.daghap.carousel.mount }; this.app = null; this.selection = {}; silk.resource.prototype.ctor.call( this, config ); }, init: function() { this.initEditorSettings(); var self = this; this.data = []; console.log( "silk.daghap.resource::init" ); var params = {}; // this.loadURL( "/data/daghap.json", null, function( data ) { var items = silk.data( data[ "daghap-items" ], "daghap-id" ); data[ "daghap-items" ] = items; self.load( data ); checkmedaghap = self.data; self.app = new silk.daghap( self ); } ); }, initEditorSettings: function() { }, onRefresh: function( mount ) { console.warn( "refreshing", mount ); // this.mounts[ mount ].display(); }, select: function( selection ) { var selection = ( typeof( selection ) === "object" ) ? selection : {}; this.selection = selection; if ( this.mounts.view instanceof silk.node.mount ) { this.mounts.view.select( selection ); this.mounts.view.display(); } if ( this.mounts.carousel instanceof silk.node.mount ) { this.mounts.carousel.select( selection ); this.mounts.carousel.display(); } }, save: function() { var self = this; var data = {}; for ( var n in this.data ) { data[ n ] = this.data[ n ]; } for ( var n in this.mounts ) { data[ this.mounts[ n ].fieldName ] = this.mounts[ n ].save( this.data[ this.mounts[ n ].fieldName ] ); //.toJSON(); } for ( var n in data ) { if ( data[ n ] instanceof silk.data ) { data[ n ] = data[ n ].set; } } var params = JSON.stringify( data, null, "\t" ); //console.log( "saving string", params ); console.log( this.name, "saving data", data ); //return; this.putURL( "/data/daghap.json", params, function( status, result ) { console.log( "saved", status, result ); } ); } } );