diff --git a/src/sunstone/public/app/opennebula.js b/src/sunstone/public/app/opennebula.js index 0ae41e0e3e..9b7ae33c87 100644 --- a/src/sunstone/public/app/opennebula.js +++ b/src/sunstone/public/app/opennebula.js @@ -60,6 +60,7 @@ define(function(require) { 'Group': Group, 'Host': Host, 'Image': Image, + 'File': Image, 'Marketplace': Marketplace, 'Network': Network, 'Role': Role, diff --git a/src/sunstone/public/app/tabs/files-tab/datatable.js b/src/sunstone/public/app/tabs/files-tab/datatable.js index 5bdf5a60e2..66c6c2da2e 100644 --- a/src/sunstone/public/app/tabs/files-tab/datatable.js +++ b/src/sunstone/public/app/tabs/files-tab/datatable.js @@ -18,7 +18,8 @@ define(function(require) { var XML_ROOT = "IMAGE"; var TAB_NAME = require('./tabId'); var COLUMN_IDS = { - "DATASTORE": 5 + "DATASTORE": 5, + "TYPE": 7 }; /* diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js index 53e92c6e63..5d64285503 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js @@ -9,6 +9,7 @@ define(function(require) { var WizardFields = require('utils/wizard-fields'); var TemplateUtils = require('utils/template-utils'); var CustomTagsTable = require('utils/custom-tags-table'); + var FilesTable = require('tabs/files-tab/datatable') /* TEMPLATES @@ -36,9 +37,12 @@ define(function(require) { this.title = Locale.tr("Context"); this.classes = "hypervisor only_kvm only_vmware only_xen only_vcenter"; - /* TODO - this.contextFilesTable = new FilesTable(this.wizardTabId + 'ContextTable', {'select': true}); - */ + this.contextFilesTable = new FilesTable(this.wizardTabId + 'ContextTable', { + 'select': true, + 'selectOptions': { + 'multiple_choice': true, + "filter_fn": function(file) { return file.TYPE == 5; } // CONTEXT + }}); } WizardTab.prototype.constructor = WizardTab; @@ -47,6 +51,7 @@ define(function(require) { WizardTab.prototype.onShow = _onShow; WizardTab.prototype.retrieve = _retrieve; WizardTab.prototype.fill = _fill; + WizardTab.prototype.generateContextFiles = _generateContextFiles; return WizardTab; @@ -56,7 +61,8 @@ define(function(require) { function _html() { return TemplateHTML({ - 'customTagsTableHTML': CustomTagsTable.html() + 'customTagsTableHTML': CustomTagsTable.html(), + 'contextFilesTableHTML': this.contextFilesTable.dataTableHTML }); } @@ -64,32 +70,25 @@ define(function(require) { } function _setup(context) { + var that = this; Tips.setup(context); CustomTagsTable.setup(context); - /* TODO - that.context.initialize({ + var selectOptions = { 'selectOptions': { 'select_callback': function(aData, options) { - $('#KERNEL', context).text(aData[options.name_index]); - $('#KERNEL_DS', context).val("$FILE[IMAGE_ID="+ aData[options.id_index] +"]"); + that.generateContextFiles(context) + }, + 'unselect_callback': function(aData, options) { + that.generateContextFiles(context) } } - }); - that.context.refreshResourceTableSelect(); + } - var generate_context_files = function() { - var req_string = []; + that.contextFilesTable.initialize(selectOptions); + that.contextFilesTable.refreshResourceTableSelect(); - $.each($("span.image", $("#selected_files_spans")), function() { - req_string.push("$FILE[IMAGE_ID=" + $(this).attr("image_id") + "]"); - }); - - $('#FILES_DS', context).val(req_string.join(" ")); - }; - */ - context.on("click", ".add_service_custom_attr", function() { $(".service_custom_attrs tbody").append( '' + @@ -158,6 +157,7 @@ define(function(require) { } function _fill(context, templateJSON) { + var that = this; $("#ssh_context", context).removeAttr('checked'); $("#network_context", context).removeAttr('checked'); @@ -207,17 +207,15 @@ define(function(require) { $("input#INIT_SCRIPTS").val(TemplateUtils.htmlDecode(value)); } else if ("FILES_DS" == key) { $('#FILES_DS', context).val(TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode(contextJSON["FILES_DS"]))) - /* TODO var files = []; + var files = []; while (match = file_ds_regexp.exec(value)) { files.push(match[1]) } - var dataTable_context = $("#datatable_context").dataTable(); - - // TODO updateView should not be required. Currently the dataTable - // is filled twice. - update_datatable_template_files(dataTable_context, function() { - });*/ + var selectedResources = { + ids : files + } + that.contextFilesTable.selectResourceTableSelect(selectedResources); } else { customTagsJSON[key] = value; } @@ -228,4 +226,15 @@ define(function(require) { delete templateJSON['CONTEXT']; } } + + function _generateContextFiles(context) { + var req_string=[]; + var selected_files = this.contextFilesTable.retrieveResourceTableSelect(); + + $.each(selected_files, function(index, fileId) { + req_string.push("$FILE[IMAGE_ID="+ fileId +"]"); + }); + + $('#FILES_DS', context).val(req_string.join(" ")); + }; }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context/html.hbs index 781f85ddf1..aa39dbc5f9 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context/html.hbs @@ -56,7 +56,7 @@
- {{! TODO contextFilesTableSelectHTML}} + {{{contextFilesTableHTML}}}

- {{! TODO kernelFilesTableSelectHTML}} + {{{kernelFilesTableHTML}}}
@@ -157,7 +157,7 @@

- {{! TODO initrdFilesTableSelectHTML}} + {{{initrdFilesTableHTML}}}
diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js index 0fc3043c08..b4f9befa17 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js @@ -202,12 +202,12 @@ define(function(require) { var selected_hosts = this.hostsTable.retrieveResourceTableSelect(); var selected_clusters = this.clustersTable.retrieveResourceTableSelect(); - $.each(selected_hosts, function(key, value) { - req_string.push('ID=\\"'+key+'\\"'); + $.each(selected_hosts, function(index, hostId) { + req_string.push('ID=\\"'+hostId+'\\"'); }); - $.each(selected_clusters, function(key, value) { - req_string.push('CLUSTER_ID=\\"'+key+'\\"'); + $.each(selected_clusters, function(index, clusterId) { + req_string.push('CLUSTER_ID=\\"'+clusterId+'\\"'); }); $('#SCHED_REQUIREMENTS', context).val(req_string.join(" | "));