mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
feature #3748: Add image clone dialog
This commit is contained in:
1 parent
32409525eb
commit
afb35dd35a
2 files changed
+27
-15
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
{{{datastoreTableSelect}}}
|
||||
{{{datastoreTableSelectHTML}}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user