diff --git a/src/sunstone/public/app/tabs/datastores-tab/datatable.js b/src/sunstone/public/app/tabs/datastores-tab/datatable.js index 7d84cfd150..f6a0749e7e 100644 --- a/src/sunstone/public/app/tabs/datastores-tab/datatable.js +++ b/src/sunstone/public/app/tabs/datastores-tab/datatable.js @@ -13,7 +13,8 @@ define(function(require) { CONSTANTS */ - var RESOURCE = "Datastore" + var RESOURCE = "Datastore"; + var XML_ROOT = "DATASTORE"; var TAB_NAME = require('./tabId'); /* @@ -36,8 +37,10 @@ define(function(require) { */ function Table(dataTableId, conf) { this.conf = conf || {}; + this.tabId = TAB_NAME; this.dataTableId = dataTableId; this.resource = RESOURCE; + this.xmlRoot = XML_ROOT; this.dataTableOptions = { "bAutoWidth": false, diff --git a/src/sunstone/public/app/tabs/datastores-tab/panels/images.js b/src/sunstone/public/app/tabs/datastores-tab/panels/images.js index 5c0c58ac6d..604c7ac92e 100644 --- a/src/sunstone/public/app/tabs/datastores-tab/panels/images.js +++ b/src/sunstone/public/app/tabs/datastores-tab/panels/images.js @@ -9,8 +9,7 @@ define(function(require){ /* CONSTANTS */ - - var IAMGES_TAB_ID = require('tabs/images-tab/tabId'); + var PANEL_ID = require('./images/panelId'); var IMAGES_TABLE_ID = PANEL_ID + "ImagesTable" var RESOURCE = "Datastore" @@ -24,7 +23,7 @@ define(function(require){ this.icon = "fa-upload"; this.element = info[RESOURCE.toUpperCase()]; - this.imagesDataTable = new ImagesTable(IMAGES_TABLE_ID, {info: true}, IAMGES_TAB_ID); + this.imagesDataTable = new ImagesTable(IMAGES_TABLE_ID, {info: true}); return this; }; diff --git a/src/sunstone/public/app/tabs/images-tab/datatable.js b/src/sunstone/public/app/tabs/images-tab/datatable.js index ccdca90fbc..736351811b 100644 --- a/src/sunstone/public/app/tabs/images-tab/datatable.js +++ b/src/sunstone/public/app/tabs/images-tab/datatable.js @@ -15,6 +15,7 @@ define(function(require) { */ var RESOURCE = "Image" + var XML_ROOT = "Image" var TAB_NAME = require('./tabId'); var COLUMN_IDS = { "DATASTORE": 5 @@ -23,11 +24,12 @@ define(function(require) { CONSTRUCTOR */ - function Table(dataTableId, conf, tabId) { + function Table(dataTableId, conf) { this.conf = conf || {}; - this.tabId = tabId; + this.tabId = TAB_NAME; this.dataTableId = dataTableId; this.resource = RESOURCE; + this.xmlRoot = XML_ROOT; this.dataTableOptions = { "bAutoWidth": false, @@ -71,7 +73,6 @@ define(function(require) { Table.prototype = Object.create(TabDataTable.prototype); Table.prototype.constructor = Table; Table.prototype.elementArray = _elementArray; - Table.prototype.list = _list; Table.COLUMN_IDS = COLUMN_IDS; return Table; @@ -136,14 +137,4 @@ define(function(require) { element.TEMPLATE.TARGET ? element.TEMPLATE.TARGET : '--' ]; } - - function _list() { - var that = this; - OpenNebulaImage.list({ - success: function(req, resp) { - that.updateView(req, resp); - }, - error: Notifier.onError - }); - } }); diff --git a/src/sunstone/public/app/tabs/zones-tab/datatable.js b/src/sunstone/public/app/tabs/zones-tab/datatable.js index a1f84944d9..d457ee31de 100644 --- a/src/sunstone/public/app/tabs/zones-tab/datatable.js +++ b/src/sunstone/public/app/tabs/zones-tab/datatable.js @@ -11,7 +11,8 @@ define(function(require) { CONSTANTS */ - var RESOURCE = "Zone" + var RESOURCE = "Zone"; + var XML_ROOT = "ZONE"; var TAB_NAME = require('./tabId'); /* @@ -20,8 +21,10 @@ define(function(require) { function Table(dataTableId, conf) { this.conf = conf || {}; + this.tabId = TAB_NAME; this.dataTableId = dataTableId; this.resource = RESOURCE; + this.xmlRoot = XML_ROOT; this.dataTableOptions = { "bAutoWidth": false, diff --git a/src/sunstone/public/app/utils/tab-datatable.js b/src/sunstone/public/app/utils/tab-datatable.js index d21624b779..9a4385c147 100644 --- a/src/sunstone/public/app/utils/tab-datatable.js +++ b/src/sunstone/public/app/utils/tab-datatable.js @@ -124,7 +124,8 @@ define(function(require) { 'initSelectResourceTableSelect': _initSelectResourceTableSelect, 'retrieveResourceTableSelect': _retrieveResourceTableSelect, 'updateFn': _updateFn, - 'getName': _getName + 'getName': _getName, + 'list': _list } return TabDatatable; @@ -518,7 +519,7 @@ define(function(require) { $('#refresh_button_' + that.dataTableId, section).off("click"); section.on('click', '#refresh_button_' + that.dataTableId, function() { - that.updateFn($('table[id=datatable_' + that.dataTableId + ']', section).dataTable()); + that.updateFn(); return false; }); @@ -823,17 +824,17 @@ define(function(require) { var add = true; if (that.selectOptions.filter_fn) { - add = that.selectOptions.filter_fn(this.DATASTORE); + add = that.selectOptions.filter_fn(this[that.xmlRoot]); } if (that.selectOptions.fixed_ids != undefined) { - add = (add && fixed_ids_map[this.DATASTORE.ID]); + add = (add && fixed_ids_map[this[that.xmlRoot].ID]); } if (add) { list_array.push(that.elementArray(this)); - delete fixed_ids_map[this.DATASTORE.ID]; + delete fixed_ids_map[this[that.xmlRoot].ID]; } }); @@ -894,4 +895,16 @@ define(function(require) { }); return name; }; + + // Used by panels that contain tables from other resources. + // TODO: This is probably duplicated somewhere + function _list() { + var that = this; + OpenNebula[that.resource].list({ + success: function(req, resp) { + that.updateView(req, resp); + }, + error: Notifier.onError + }); + } }) diff --git a/src/sunstone/public/app/utils/tab-datatable/table.hbs b/src/sunstone/public/app/utils/tab-datatable/table.hbs index d22a3c5541..6c77bb3a80 100644 --- a/src/sunstone/public/app/utils/tab-datatable/table.hbs +++ b/src/sunstone/public/app/utils/tab-datatable/table.hbs @@ -1,4 +1,5 @@