var checkme = null; silk.postings.resource = xb.core.object.extend( silk.resource, { ctor: function( config ) { var handlers = { "carousel": silk.postings.carousel.mount, "categories": silk.postings.categories.mount, "filters": silk.postings.filters.mount, "view": silk.postings.items.mount, "view-page": silk.postings.items.page.mount, "view-page-sections": silk.postings.items.page.mount }; if ( typeof( this.handlers ) !== "object" ) { this.handlers = {}; } for ( var i in handlers ) { if ( typeof( this.handlers[ i ] ) === "undefined" ) { this.handlers[ i ] = handlers[ i ]; } } this.selection = {}; silk.resource.prototype.ctor.call( this, config ); }, init: function() { this.initEditorSettings(); silk.postings.load( this ); }, getDataView: function( view, data ) { switch ( view ) { case "postings-items": return silk.data( data[ "postings-items" ], "posting-id" ); break; case "postings-categories": return silk.data( data[ "postings-categories" ], "category-id" ); break; case "postings-filters": return silk.postings.filters.data( data[ "postings-filters" ], "filter-id" ); break; } return silk.data.ptr( data[ "postings-items" ], data[ view ], "posting-id" ); }, initEditorSettings: function() { if ( typeof( editor ) !== "object" ) { return; } editor.loadToolbar( "/components/apps/postings/toolbar.postings.category.html" ); editor.loadToolbar( "/components/apps/postings/toolbar.postings.price.html" ); }, onRefresh: function( mount ) { console.warn( "refreshing", mount ); // this.mounts[ mount ].display(); }, select: function( selection ) { var selection = ( typeof( selection ) === "object" ) ? selection : { }; if ( typeof( selection.offset ) !== "number" ) { selection.offset = 0; } if ( typeof( selection.limit ) !== "number" ) { selection.limit = silk.postings.get( this, "offset-limit" ); if ( typeof( selection.limit ) !== "number" ) { selection.limit = 24; } } this.selection = selection; if ( typeof( selection.categories ) !== "object" ) { selection.categories = {}; } if ( ! ( selection.items instanceof Array ) ) { selection.items = []; } if ( this.mounts[ "view-page" ] instanceof silk.node.mount ) { this.mounts[ "view-page" ].select( selection ); this.mounts[ "view-page" ].display(); if ( this.mounts[ "view-page-sections" ] instanceof silk.node.mount ) { this.mounts[ "view-page-sections" ].select( selection ); this.mounts[ "view-page-sections" ].display(); } } if ( this.mounts.categories instanceof silk.node.mount ) { this.mounts.categories.select( selection ); this.mounts.categories.display(); } if ( this.mounts.filters instanceof silk.node.mount ) { this.mounts.filters.select( selection ); this.mounts.filters.display(); } if ( this.mounts.view instanceof silk.node.mount ) { this.mounts.view.select( selection ); this.mounts.view.display(); } for ( var name in this.mounts ) { if ( name.indexOf( "view/" ) === 0 ) { this.mounts[ name ].displayAll(); } } if ( this.mounts.carousel instanceof silk.node.mount ) { 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 ); this.putURL( silk.postings.get( this, "json" ), params, function( status, result ) { console.log( "saved", status, result ); } ); } } );