From afb35dd35a01caa8c7995adf5d101d9fbfc3200a Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Thu, 14 May 2015 12:22:24 +0200 Subject: [PATCH] feature #3748: Add image clone dialog --- .../app/tabs/images-tab/dialogs/clone.js | 40 ++++++++++++------- .../tabs/images-tab/dialogs/clone/html.hbs | 2 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/sunstone/public/app/tabs/images-tab/dialogs/clone.js b/src/sunstone/public/app/tabs/images-tab/dialogs/clone.js index 899758ceb7..7a33726522 100644 --- a/src/sunstone/public/app/tabs/images-tab/dialogs/clone.js +++ b/src/sunstone/public/app/tabs/images-tab/dialogs/clone.js @@ -6,12 +6,14 @@ define(function(require) { var BaseDialog = require('utils/dialogs/dialog'); var TemplateHTML = require('hbs!./clone/html'); var Sunstone = require('sunstone'); + var DatastoreTable = require('tabs/datastores-tab/datatable') /* CONSTANTS */ var DIALOG_ID = require('./clone/dialogId'); + var IMAGES_TAB_ID = require('tabs/images-tab/tabId') /* CONSTRUCTOR @@ -19,6 +21,14 @@ define(function(require) { function Dialog() { this.dialogId = DIALOG_ID; + + this.datastoreTable = new DatastoreTable('image_clone', { + 'select': true, + 'selectOptions': { + 'filter_fn': function(ds) { return ds.TYPE == 0; } + } + }); + BaseDialog.call(this); }; @@ -36,14 +46,16 @@ define(function(require) { */ function _html() { - return TemplateHTML({dialogId: this.dialogId}); + return TemplateHTML({ + 'dialogId': this.dialogId, + 'datastoreTableSelectHTML': this.datastoreTable.dataTableHTML + }); } function _setup(dialog) { + var that = this; // TODO: Show DS with the same ds mad only - setupDatastoreTableSelect(dialog, "image_clone", - {filter_fn: function(ds) { return ds.TYPE == 0; }} - ); + that.datastoreTable.initialize(); $('#image_clone_advanced_toggle', dialog).click(function() { $('#image_clone_advanced', dialog).toggle(); @@ -52,23 +64,23 @@ define(function(require) { $('#' + DIALOG_ID + 'Form', dialog).submit(function() { var name = $('input[name="image_clone_name"]', this).val(); - var sel_elems = imageElements(); + var sel_elems = Sunstone.getDataTable(IMAGES_TAB_ID).elements(); if (!name || !sel_elems.length) notifyError('A name or prefix is needed!'); var extra_info = {}; - if ($("#selected_resource_id_image_clone", dialog).val().length > 0) { - extra_info['target_ds'] = - $("#selected_resource_id_image_clone", dialog).val(); + var targeDS = that.datastoreTable.retrieveResourceTableSelect(); + if (targeDS) { + extra_info['target_ds'] = targeDS; } if (sel_elems.length > 1) { for (var i = 0; i < sel_elems.length; i++) { //If we are cloning several images we //use the name as prefix - extra_info['name'] = name + getImageName(sel_elems[i]); + extra_info['name'] = name // TODO + getImageName(sel_elems[i]); Sunstone.runAction('Image.clone', sel_elems[i], extra_info); } } else { @@ -76,8 +88,8 @@ define(function(require) { Sunstone.runAction('Image.clone', sel_elems[0], extra_info) } - Sunstone.hideDialog(DIALOG_ID); - Sunstone.resetDialog(DIALOG_ID); + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); setTimeout(function() { Sunstone.runAction('Image.refresh'); }, 1500); @@ -88,7 +100,7 @@ define(function(require) { } function _onShow(dialog) { - var sel_elems = imageElements(); + var sel_elems = Sunstone.getDataTable(IMAGES_TAB_ID).elements(); //show different text depending on how many elements are selected if (sel_elems.length > 1) { $('.clone_one', dialog).hide(); @@ -97,11 +109,11 @@ define(function(require) { } else { $('.clone_one', dialog).show(); $('.clone_several', dialog).hide(); - $('input[name="image_clone_name"]', dialog).val('Copy of ' + getImageName(sel_elems[0])); + $('input[name="image_clone_name"]', dialog).val('Copy of ' /* TODO + getImageName(sel_elems[0])*/); }; $('#image_clone_advanced', dialog).hide(); - resetResourceTableSelect(dialog, "image_clone"); + this.datastoreTable.resetResourceTableSelect(); $("input[name='image_clone_name']", dialog).focus(); diff --git a/src/sunstone/public/app/tabs/images-tab/dialogs/clone/html.hbs b/src/sunstone/public/app/tabs/images-tab/dialogs/clone/html.hbs index 1d5acbde7f..f91d6d5b15 100644 --- a/src/sunstone/public/app/tabs/images-tab/dialogs/clone/html.hbs +++ b/src/sunstone/public/app/tabs/images-tab/dialogs/clone/html.hbs @@ -26,7 +26,7 @@

- {{{datastoreTableSelect}}} + {{{datastoreTableSelectHTML}}}