Feature #3748: Refactor datatable tabId, xmlRoot and _list

This commit is contained in:
Carlos Martín committed 2015-05-18 17:56:12 +02:00
1 parent 07bcd78390
commit 1c8d43effb
6 files changed
+33 -23

No files matched your search

@@ -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,
@@ -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;
};
@@ -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
});
}
});
@@ -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,
+18 -5
View File
@@ -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
});
}
})
@@ -1,4 +1,5 @@
<div id="{{dataTableId}}Container">
{{! TODO: show also refresh and search box when {info: true} is used in panels}}
{{#if conf.select}}
<div class="row">
<div class="large-8 small-2 columns">