From a6a4f91317a695011e17b6d2b22c189f02631ff9 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Fri, 12 Dec 2014 00:18:11 -0800 Subject: [PATCH] refresh and add buttons working --- .../core/xoslib/static/js/xoslib/xosHelper.js | 94 ++++++++++++------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index 5e4b1cc..2a1e94f 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -702,47 +702,44 @@ XOSListView = FilteredCompositeView.extend({ }, }); -XOSDataTableViewOld = Marionette.View.extend( { - //tagName: "table", - el: "
", - - initialize: function() { - //$(this.el).html('

scott was here

' ); - }, +XOSDataTableView = Marionette.View.extend( { + el: '
' + + '

' + + '
' + + '
' + + '' + + '
', - render: function() { - //this.el = "
"; - console.log(this.el); - console.log(this.$el); - console.log("render!"); - actualEntries = []; - actualEntries.push(["foo", "bar", "1", "2"]); - actualEntries.push(["zoo", "zar", "0", "9"]); + filter: undefined, - oTable = $(this.el).find("table").dataTable( { - "bJQueryUI": true, - "aaData": actualEntries, - "bStateSave": true, - "aoColumns": [ - { "sTitle": "Slice" }, - { "sTitle": "Privilege" , sClass: "alignCenter"}, - { "sTitle": "Number of Slivers" , sClass: "alignCenter"}, - { "sTitle": "Number of Sites" , sClass: "alignCenter"}, - ] - } ); - dtcounter = dtcounter + 1; + events: {"click button.btn-xos-add": "addClicked", + "click button.btn-xos-refresh": "refreshClicked", + }, - return this; - }, + _fetchStateChange: function() { + if (this.collection.fetching) { + $("#xos-list-title-spinner").show(); + } else { + $("#xos-list-title-spinner").hide(); + } + }, -}); + addClicked: function(e) { + e.preventDefault(); + this.app.Router.navigate("add" + firstCharUpper(this.collection.modelName), {trigger: true}); + }, -XOSDataTableView = Marionette.View.extend( { - el: '
', + refreshClicked: function(e) { + e.preventDefault(); + this.collection.refresh(refreshRelated=true); + }, - filter: undefined, initialize: function() { + $(this.el).find(".footer_placeholder").html( xosListFooterTemplate({addChildHash: this.getAddChildHash()}) ); + $(this.el).find(".header_placeholder").html( xosListHeaderTemplate() ); + + this.listenTo(this.collection, 'fetchStateChange', this._fetchStateChange); }, render: function() { @@ -766,6 +763,10 @@ XOSDataTableView = Marionette.View.extend( { view.columnsByFieldName[fieldName] = thisColumn; }); + deleteColumn = {sTitle: "delete", mRender: function(x,y,z) { return xosDeleteButtonTemplate({modelName: view.collection.modelName, id: z.id}); }, mData: function() { return "delete"; }}; + view.columnsByIndex.push(deleteColumn); + view.columnsByFieldName["delete"] = deleteColumn; + oTable = $(this.el).find("table").dataTable( { "bJQueryUI": true, "bStateSave": true, @@ -799,12 +800,14 @@ XOSDataTableView = Marionette.View.extend( { return false; }; - console.log(aoData); + //console.log(aoData); // function used to populate the DataTable with the current // content of the collection var populateTable = function() { + console.log("populatetable!"); + // clear out old row views rows = []; @@ -869,12 +872,35 @@ XOSDataTableView = Marionette.View.extend( { aoData.shift(); // ignore sEcho populateTable(); + + view.listenTo(view.collection, 'change', populateTable); + view.listenTo(view.collection, 'add', populateTable); + view.listenTo(view.collection, 'remove', populateTable); }, } ); return this; }, + getAddChildHash: function() { + if (this.parentModel) { + parentFieldName = this.parentModel.relatedCollections[this.collection.collectionName]; + parentFieldName = parentFieldName || "unknown"; + + /*parentFieldName = "unknown"; + + for (fieldName in this.collection.foreignFields) { + cname = this.collection.foreignFields[fieldName]; + if (cname = this.collection.collectionName) { + parentFieldName = fieldName; + } + }*/ + return "#addChild" + firstCharUpper(this.collection.modelName) + "/" + this.parentModel.modelName + "/" + parentFieldName + "/" + this.parentModel.id; // modelName, fieldName, id + } else { + return null; + } + }, + }); idToName = function(id, collectionName, fieldName) { -- 2.43.0