diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js index 257b15c732..ca64154448 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js @@ -104,7 +104,6 @@ define(function(require) { $(".drivers", context).hide(); $("#host_type_mad", context).on("change", function() { - console.log("-->", this.value); $("#vmm_mad", context).val(this.value).change(); $("#im_mad", context).val(this.value).change(); $(".vcenter_credentials", context).hide(); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions.js index 22dc17372d..9b4274c9ad 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/actions.js @@ -17,7 +17,7 @@ define(function(require) { /* DEPENDENCIES - */ + */ var Config = require("sunstone-config"); var ScheduleActions = require("utils/schedule_action"); @@ -29,13 +29,16 @@ define(function(require) { var TemplateUtils = require("utils/template-utils"); var Actions = require("utils/actions"); var Leases = require("utils/leases"); - var TemplateHTML = require("hbs!./actions/html"); + /* CONSTANTS - */ + */ var WIZARD_TAB_ID = require("./actions/wizardTabId"); + var RESOURCE = "temp"; + var CREATE = true; + var contextRow; /* CONSTRUCTOR @@ -62,7 +65,7 @@ define(function(require) { function _html() { return TemplateHTML({ - "table_sched_actions": ScheduleActions.htmlTable("temp", Leases.html()), + "table_sched_actions": ScheduleActions.htmlTable(RESOURCE, Leases.html()), }); } @@ -71,8 +74,11 @@ define(function(require) { } function _setup(context) { + if(!CREATE){ + CREATE = true; + } var that = this; - var actions = [ + var actions = [ "terminate", "terminate-hard", "hold", @@ -93,12 +99,21 @@ define(function(require) { "disk-snapshot-delete", "disk-snapshot-revert" ]; - context.off("click", "#add_scheduling_temp_action"); - context.on("click", "#add_scheduling_temp_action", function() { - $("#add_scheduling_temp_action", context).attr("disabled", "disabled"); - ScheduleActions.htmlNewAction(actions, context, "temp"); - ScheduleActions.setup(context); + function renderCreateForm() { + if(CREATE){ + ScheduleActions.htmlNewAction(actions, context, "temp"); + ScheduleActions.setup(context); + CREATE = false; + } return false; + } + context.off("click", "#add_scheduling_temp_action"); + context.on("click", "#add_scheduling_temp_action", function(e){ + renderCreateForm(); + e.preventDefault(); + ScheduleActions.reset(); + $("#edit_"+RESOURCE+"_action_json").hide(); + $("#add_"+RESOURCE+"_action_json").show(); }); context.off("click", "#add_temp_action_json"); @@ -106,7 +121,26 @@ define(function(require) { $(".wickedpicker").hide(); var sched_action = ScheduleActions.retrieveNewAction(context); if (sched_action != false) { - $("#sched_temp_actions_body").append(ScheduleActions.fromJSONtoActionsTable(sched_action)); + $("#sched_temp_actions_body").prepend(ScheduleActions.fromJSONtoActionsTable(sched_action)); + } + $("#input_sched_action_form").remove(); + clear(); + return false; + }); + + context.off("click" , "#edit_temp_action_json").on("click" , "#edit_temp_action_json", function(e){ + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length && contextRow){ + $(".wickedpicker").hide(); + var sched_action = ScheduleActions.retrieveNewAction(context); + if (sched_action != false) { + sched_action.ID = id; + contextRow.replaceWith(ScheduleActions.fromJSONtoActionsTable(sched_action)); + contextRow = undefined; + $("#input_sched_action_form").remove(); + } + clear(); } return false; }); @@ -116,6 +150,18 @@ define(function(require) { $(this).parents("tr").remove(); }); + context.off("click", ".edit_action_x"); + context.on("click", ".edit_action_x", function (e) { + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length){ + contextRow = $(this).closest("tr.tr_action"); + renderCreateForm(); + $("#edit_"+RESOURCE+"_action_json").show().attr("data_id", id); + $("#add_"+RESOURCE+"_action_json").hide(); + ScheduleActions.fill($(this),context); + } + }); } function _retrieve(context) { @@ -124,9 +170,13 @@ define(function(require) { return templateJSON; } + function clear(){ + CREATE = true; + } + function _fill(context, templateJSON) { var actions = ScheduleActions.fromJSONtoActionsTable(templateJSON.SCHED_ACTION); - $("#sched_temp_actions_body").append(actions); + $("#sched_temp_actions_body").prepend(actions); delete templateJSON["SCHED_ACTION"]; } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 2ab13af7f8..0be3f37128 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -51,6 +51,9 @@ define(function(require) { var FORM_PANEL_ID = require("./instantiate/formPanelId"); var TAB_ID = require("../tabId"); + var RESOURCE = 'inst'; + var CREATE = true; + var contextRow; /* CONSTRUCTOR @@ -95,6 +98,30 @@ define(function(require) { } function _setup(context) { + if(!CREATE){ + CREATE = true; + } + var actions = [ + "terminate", + "terminate-hard", + "hold", + "release", + "stop", + "suspend", + "resume", + "reboot", + "reboot-hard", + "poweroff", + "poweroff-hard", + "undeploy", + "undeploy-hard", + "snapshot-create", + "snapshot-delete", + "snapshot-revert", + "disk-snapshot-create", + "disk-snapshot-delete", + "disk-snapshot-revert" + ]; var that = this; var objLeases = $.extend(true, {}, that); objLeases.resource = "template"; @@ -126,51 +153,73 @@ define(function(require) { $("#vm_n_times", context).show(); } + function renderCreateForm() { + if(CREATE){ + ScheduleActions.htmlNewAction(actions, context, RESOURCE); + ScheduleActions.setup(context); + CREATE=false; + } + } + context.off("click", "#add_scheduling_inst_action"); - context.on("click", "#add_scheduling_inst_action", function() { - var actions = [ - "terminate", - "terminate-hard", - "hold", - "release", - "stop", - "suspend", - "resume", - "reboot", - "reboot-hard", - "poweroff", - "poweroff-hard", - "undeploy", - "undeploy-hard", - "snapshot-create", - "snapshot-delete", - "snapshot-revert", - "disk-snapshot-create", - "disk-snapshot-delete", - "disk-snapshot-revert" - ]; - $("#add_scheduling_inst_action", context).attr("disabled", "disabled"); - ScheduleActions.htmlNewAction(actions, context, "inst"); - ScheduleActions.setup(context); - return false; + context.on("click", "#add_scheduling_inst_action", function(e){ + e.preventDefault(); + renderCreateForm(); + $("#edit_"+RESOURCE+"_action_json").hide(); + $("#add_"+RESOURCE+"_action_json").show(); }); + context.off("click", "#add_inst_action_json"); context.on("click", "#add_inst_action_json", function(){ var sched_action = ScheduleActions.retrieveNewAction(context); if (sched_action != false) { - $("#sched_inst_actions_body").append(ScheduleActions.fromJSONtoActionsTable(sched_action)); + $("#no_actions_tr", context).remove(); + $("#sched_inst_actions_body").prepend(ScheduleActions.fromJSONtoActionsTable(sched_action)); } - + $("#input_sched_action_form").remove(); + clear(); return false; }); + context.on("focusout" , "#time_input", function(){ $("#time_input").removeAttr("data-invalid"); $("#time_input").removeAttr("class"); }); + + context.off("click" , "#edit_inst_action_json").on("click" , "#edit_inst_action_json", function(e){ + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length && contextRow){ + $(".wickedpicker").hide(); + var sched_action = ScheduleActions.retrieveNewAction(context); + if (sched_action != false) { + sched_action.ID = id; + contextRow.replaceWith(ScheduleActions.fromJSONtoActionsTable(sched_action)); + contextRow = undefined; + $("#input_sched_action_form").remove(); + } + clear(); + } + return false; + }); + context.off("click", ".remove_action_x"); context.on("click", ".remove_action_x", function(){ $(this).parents("tr").remove(); }); + + context.off("click", ".edit_action_x"); + context.on("click", ".edit_action_x", function(e){ + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length){ + contextRow = $(this).closest("tr.tr_action"); + renderCreateForm(); + $("#edit_"+RESOURCE+"_action_json").show().attr("data_id", id); + $("#add_"+RESOURCE+"_action_json").hide(); + ScheduleActions.fill($(this),context); + } + }); } function _calculateCost(){ @@ -433,7 +482,7 @@ define(function(require) { dsDatatable: that.datastoresTable.dataTableHTML, usersDatatable: that.usersTable.dataTableHTML, groupDatatable: that.groupTable.dataTableHTML, - table_sched_actions: ScheduleActions.htmlTable("inst", Leases.html()) + table_sched_actions: ScheduleActions.htmlTable(RESOURCE, Leases.html()) }) ); $(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable", that.hostsTable); @@ -442,7 +491,7 @@ define(function(require) { $(".provision_gid_selector" + template_json.VMTEMPLATE.ID, context).data("groupTable", that.groupTable); var actions = ScheduleActions.fromJSONtoActionsTable(template_json.VMTEMPLATE.TEMPLATE.SCHED_ACTION); - $("#sched_inst_actions_body").append(actions); + $("#sched_inst_actions_body").prepend(actions); var selectOptions = { "selectOptions": { @@ -618,12 +667,20 @@ define(function(require) { function _onShow(context) { Sunstone.disableFormPanelSubmit(this.tabId); - $("input.instantiate_pers", context).change(); - Tips.setup(context); - + if(context){ + $("input.instantiate_pers", context).change(); + Tips.setup(context); + var form = context.find("#sched_inst_actions_body"); + form.find("tr.create,tr#schedule_base,tr#input_sched_action_form,tr#relative_time_form,tr#no_relative_time_form").remove(); + } + clear(); return false; } + function clear(){ + CREATE = true; + } + function generateRequirements(hosts_table, ds_table, context, id) { var req_string = []; var req_ds_string = []; diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/actions.js b/src/sunstone/public/app/tabs/vms-tab/panels/actions.js index 44e45ebebf..851c855bc1 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/actions.js @@ -35,8 +35,8 @@ define(function(require) { var TAB_ID = require("../tabId"); var PANEL_ID = require("./actions/panelId"); var RESOURCE = "VM"; + var RESOURCE_SCHED_ACTIONS = 'vms' var XML_ROOT = "VM"; - /* CONSTRUCTOR */ @@ -63,9 +63,9 @@ define(function(require) { function _html() { var that = this; - var html = "
\ -
\ - \ + var html = "
\ +
\ +
\ \ \ \ @@ -75,23 +75,24 @@ define(function(require) { \ \ \ - \ - \ + \ + \ \ \ \ - "+ + "+ vmsfromJSONtoActionsTable(that.element.USER_TEMPLATE.SCHED_ACTION) + "\
" + Locale.tr("ID") + "" + Locale.tr("End") + "" + Locale.tr("Done") + "" + Locale.tr("Message") + " " + Leases.html() + "
\
\
"; - ScheduleActions.htmlTable("vms"); //only charge the resource attribute + ScheduleActions.htmlTable(RESOURCE_SCHED_ACTIONS); //only charge the resource attribute return html; } function _setup(context) { + var CREATE = true; var that = this; that.formContext = context; Leases.actions(that,'vm','update'); @@ -116,12 +117,22 @@ define(function(require) { "disk-snapshot-delete", "disk-snapshot-revert" ]; - context.off("click", "#add_scheduling_vms_action"); - context.on("click" , "#add_scheduling_vms_action", function(){ - $(this).attr("disabled", "disabled"); - ScheduleActions.htmlNewAction(actions, context, "vms"); - ScheduleActions.setup(context); + + function renderCreateForm(){ + if(CREATE){ + ScheduleActions.htmlNewAction(actions, context, "vms"); + ScheduleActions.setup(context); + CREATE = false; + } return false; + }; + + context.off("click", "#add_scheduling_vms_action"); + context.on("click" , "#add_scheduling_vms_action", function(e){ + e.preventDefault(); + renderCreateForm(); + $("#edit_"+RESOURCE_SCHED_ACTIONS+"_action_json").hide(); + $("#add_"+RESOURCE_SCHED_ACTIONS+"_action_json").show(); }); context.off("click", "#add_vms_action_json"); @@ -129,18 +140,41 @@ define(function(require) { var sched_action = ScheduleActions.retrieveNewAction(context); if (sched_action != false) { $("#no_actions_tr", context).remove(); - $("#sched_vms_actions_body").append(ScheduleActions.fromJSONtoActionsTable(sched_action)); + $("#sched_vms_actions_body").prepend(ScheduleActions.fromJSONtoActionsTable(sched_action)); } else { return false; } - that.element.USER_TEMPLATE.SCHED_ACTION = ScheduleActions.retrieve(context); - // Let OpenNebula know var template_str = TemplateUtils.templateToString(that.element.USER_TEMPLATE); Sunstone.runAction("VM.update_template", that.element.ID, template_str); + return false; + }); - $("#add_scheduling_vms_action", context).removeAttr("disabled"); + context.off("click" , "#edit_vms_action_json").on("click" , "#edit_vms_action_json", function(e){ + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length){ + $(".wickedpicker").hide(); + var sched_action = ScheduleActions.retrieveNewAction(context); + if (sched_action != false) { + sched_action.ID = id; + var sched_actions = ScheduleActions.retrieve(context); + if(Array.isArray(sched_actions)){ + sched_actions = sched_actions.map(function(action){ + if(action && action.ID && action.ID===id){ + return sched_action; + }else{ + return action; + } + }) + } + that.element.USER_TEMPLATE.SCHED_ACTION = sched_actions; + var template_str = TemplateUtils.templateToString(that.element.USER_TEMPLATE); + Sunstone.runAction("VM.update_template", that.element.ID, template_str); + } + clear(); + } return false; }); @@ -161,6 +195,17 @@ define(function(require) { // Let OpenNebula know Sunstone.runAction("VM.update_template", that.element.ID, template_str); }); + context.off("click", ".edit_action_x"); + context.on("click", ".edit_action_x", function(e) { + e.preventDefault(); + var id = $(this).attr("data_id"); + if(id && id.length){ + renderCreateForm(); + $("#edit_"+RESOURCE_SCHED_ACTIONS+"_action_json").show().attr("data_id", id); + $("#add_"+RESOURCE_SCHED_ACTIONS+"_action_json").hide(); + ScheduleActions.fill($(this),context); + } + }); } // Returns an HTML string with the json keys and values @@ -196,17 +241,27 @@ define(function(require) { return str; } + function clear(){ + CREATE = true; + } + // Helper for fromJSONtoHTMLTable function function vmsfromJSONtoActionRow(scheduling_action) { var done_str = scheduling_action.DONE ? (Humanize.prettyTime(scheduling_action.DONE)) : ""; var message_str = scheduling_action.MESSAGE ? scheduling_action.MESSAGE : ""; - - var str = "" + done_str + "\ - " + TemplateUtils.htmlEncode(message_str) + "\ - \ -
\ - \ -
\ + var action_id = scheduling_action.ID || ''; + var update_sched = ''; + if(action_id){ + update_sched = ""; + } + var str = "" + done_str + "\ + " + TemplateUtils.htmlEncode(message_str) + "\ + \ +
\ +
\ + \ +
\ +
"+update_sched+"
\ \ "; diff --git a/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js b/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js index 8e0485e5dd..3d5f5e5d36 100644 --- a/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js +++ b/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js @@ -55,8 +55,8 @@ define(function(require) { var rtn = false; if(startTime && addedEndTime){ var regexNumber = new RegExp('[0-9]*$','gm'); - var date = parseInt(startTime); - var added = parseInt(addedEndTime.match(regexNumber)[0]); + var date = parseInt(startTime,10); + var added = parseInt(addedEndTime.match(regexNumber)[0],10); if(!isNaN(date) && !isNaN(added)){ var operator = addedEndTime.replace(regexNumber, ""); var finalTime = date; diff --git a/src/sunstone/public/app/utils/actions.js b/src/sunstone/public/app/utils/actions.js index de7aacf9b1..9c078142d5 100644 --- a/src/sunstone/public/app/utils/actions.js +++ b/src/sunstone/public/app/utils/actions.js @@ -48,12 +48,21 @@ define(function(require) { var time_str = Humanize.prettyTime(scheduling_action.TIME); var str = ""; - str += "\ - " + TemplateUtils.htmlEncode(scheduling_action.ACTION) + "\ - " + time_str + "\ - \ -
\ - \ + var action_id = scheduling_action.ID || ''; + var update_sched = ''; + if(action_id){ + update_sched = ""; + } + + str += "\ + " + TemplateUtils.htmlEncode(scheduling_action.ACTION) + "\ + " + time_str + "\ + \ +
\ +
\ + \ +
\ +
"+update_sched+"
\
\ \ "; diff --git a/src/sunstone/public/app/utils/leases.js b/src/sunstone/public/app/utils/leases.js index 6815de98ec..b64356f2f9 100644 --- a/src/sunstone/public/app/utils/leases.js +++ b/src/sunstone/public/app/utils/leases.js @@ -93,7 +93,7 @@ define(function(require) { ACTION: schedAction }; last = schedActionTime; - $(idElementSchedActions).append(ScheduleActions.fromJSONtoActionsTable(newAction)); + $(idElementSchedActions).prepend(ScheduleActions.fromJSONtoActionsTable(newAction)); pass = true; } }); diff --git a/src/sunstone/public/app/utils/schedule_action.js b/src/sunstone/public/app/utils/schedule_action.js index 2774ac938f..1b4e1732ce 100644 --- a/src/sunstone/public/app/utils/schedule_action.js +++ b/src/sunstone/public/app/utils/schedule_action.js @@ -26,6 +26,15 @@ define(function (require) { var TemplateTableHTML = require("hbs!./schedule_action/table"); var selector = ''; + var defaultHour = "12:30"; + var actionsWithARGS = [ + 'snapshot-create', + 'snapshot-revert', + 'snapshot-delete', + 'disk-snapshot-create', + 'disk-snapshot-revert', + 'disk-snapshot-delete' + ]; function _html(resource, leases = null) { this.res = resource; @@ -35,26 +44,98 @@ define(function (require) { }); } + function formatDate( date, type = 'full') { + var d = date? new Date(date): new Date(); + var month = '' + (d.getMonth() + 1); + var day = '' + d.getDate(); + var year = d.getFullYear(); + var hour = d.getHours(); + var minutes = d.getMinutes(); + if (hour.length < 2) + hour = '0' + hour; + if (minutes.length < 2) + minutes = '0' + minutes; + if (month.length < 2) + month = '0' + month; + if (day.length < 2) + day = '0' + day; + var date = []; + switch (type) { + case 'hour': + date = [hour+":"+minutes]; + break; + case 'date': + date = [year, month, day]; + break; + default: + date = [year, month, day, hour+":"+minutes]; + break; + } + return date.join('-'); + } + + var clearEmpySpaces = function(e){ + var value = e.val().replace(/\s/g, ""); + e.val(value); + }; + + var options_date_picker={ + dateFormat: "yy-mm-dd", + minDate: new Date(), + showOptions: { direction: "down" } + }; + var options_hour_picker = { + title: Locale.tr("Hour"), + twentyFour: "true", + timeSeparator: ":", + beforeShow: clearEmpySpaces, + now: defaultHour + }; + + function addPickers(schedule,context){ + if(schedule && context){ + //input periodic scheduled date + $("#end_value_date").datepicker("disable"); + schedule.find("#end_value_date",context).off("click").on("click",function(e){ + e.stopPropagation(); + $(".wickedpicker").hide(); + }).on("keypress",function(e){ + e.preventDefault(); + return false; + }).datepicker(options_date_picker); + + //input date scheduled + $("#date_input").datepicker("disable"); + schedule.find("#date_input",context).off("click").on("click",function(e){ + e.stopPropagation(); + $(".wickedpicker").hide(); + }).on("keypress",function(e){ + e.preventDefault(); return false; + }).datepicker(options_date_picker); + + //input hour picker + schedule.find("#time_input",context).off("click").on("click",function(e){ + e.stopPropagation(); + }).wickedpicker(options_hour_picker); + + schedule.find("#relative_time", context).off("click").on("click", function (e) { + $("#schedule_type", context).prop("checked", false); + if ($(this).is(":checked")) { + $("#no_relative_time_form, .periodic", context).addClass("hide"); + $("#schedule_time", context).prop("", false); + $("#relative_time_form", context).removeClass("hide"); + } else { + $("#relative_time_form", context).addClass("hide"); + $("#no_relative_time_form", context).removeClass("hide"); + } + }); + } + } + function _htmlNewAction(actions, context, res) { + $("tr.periodic.create, tr#no_relative_time_form").remove(); this.res = res var options = ""; - var clearEmpySpaces = function(e){ - var value = e.val().replace(/\s/g, ""); - e.val(value); - }; - - var options_date_picker={ - dateFormat: "yy-mm-dd", - minDate: new Date(), - showOptions: { direction: "down" } - }; - var options_hour_picker = { - title: Locale.tr("Hour"), - twentyFour: "true", - timeSeparator: ":", - beforeShow: clearEmpySpaces, - now: "12:30" - }; var that = this; $.each(actions, function (key, action) { var actionAux = action.replace(/\-/g, "_"); @@ -66,29 +147,10 @@ define(function (require) { "actions": options, "res": this.res })); - - //input periodic scheduled date - schedule.find("#end_value_date",context).on("click",function(e){e.stopPropagation();$(".wickedpicker").hide();}).on("keypress",function(e){e.preventDefault(); return false;}).datepicker(options_date_picker); - - //input date scheduled - schedule.find("#date_input",context).on("click",function(e){e.stopPropagation();$(".wickedpicker").hide();}).on("keypress",function(e){e.preventDefault(); return false;}).datepicker(options_date_picker); - - schedule.find("#time_input",context).on("click",function(e){e.stopPropagation();}).wickedpicker(options_hour_picker); - - schedule.find("#relative_time", context).on("click", function (e) { - $("#schedule_type", context).prop("checked", false); - if ($(this).is(":checked")) { - $("#no_relative_time_form, .periodic", context).addClass("hide"); - $("#schedule_time", context).prop("", false); - $("#relative_time_form", context).removeClass("hide"); - } else { - $("#relative_time_form", context).addClass("hide"); - $("#no_relative_time_form", context).removeClass("hide"); - } - }); + addPickers(schedule,context); if (this.res === "vms") { - $("#title", context).prop("colspan", "2"); - $("#td_days", context).prop("colspan", "5"); + $("#title", context).prop("colspan", "10"); + $("#td_days", context).prop("colspan", "8"); } } @@ -104,12 +166,12 @@ define(function (require) { mm = "0" + mm; } $("#date_input", context).attr("value", yyyy + "-" + mm + "-" + dd); - $(".periodic", context).hide(); - this.selector = $("select#select_new_action"); + $(".periodic", context).addClass("hide"); + this.selector = $("select#select_new_action", context); $("select#select_new_action").on("change",function(){ - var snap_name = $("#snapname"); - var snap_id = $("#snapid"); - var disk_id = $("#diskid"); + var snap_name = $("#snapname",context); + var snap_id = $("#snapid",context); + var disk_id = $("#diskid",context); switch ($(this).val()) { case "snapshot-create": @@ -151,13 +213,12 @@ define(function (require) { }); $("input#schedule_type", context).on("change", function () { var periodic = $(this).prop("checked"); - if (periodic) { - $(".periodic", context).show(); - $(".non-periodic", context).hide(); + $(".periodic", context).removeClass("hide"); + $(".non-periodic", context).addClass("hide"); } else { - $(".periodic", context).hide(); - $(".non-periodic", context).show(); + $(".periodic", context).addClass("hide"); + $(".non-periodic", context).removeClass("hide"); } }); var that = this; @@ -234,32 +295,223 @@ define(function (require) { } + function _fill(element, context){ + _reset(); + if(element && element.closest && element.closest("tr") && element.closest("tr").attr && element.closest("tr").attr("data") && context){ + var data = element.closest("tr").attr("data"); + var dataJSON = JSON.parse(data); + if(dataJSON){ + var relative = true; + + Object.keys(dataJSON).forEach(function(key){ + valuesForRelative = ['ACTION','ID','TIME']; + if(key!=='ARGS' && !valuesForRelative.includes(key)){ + relative = false; + } + }) + + if(dataJSON.ACTION){ + $("#select_new_action").val(dataJSON.ACTION).change(); + if(dataJSON.ARGS){ + var args = dataJSON.ARGS.split(","); + var disk_id = $("#diskid",context); + var snap_id = $("#snapid",context); + var snap_name = $("#snapname",context); + if(args && Array.isArray(args)){ + switch (dataJSON.ACTION) { + case "snapshot-create": + disk_id.val(""); + snap_id.val(""); + snap_name.val(args[0]||""); + break; + case "snapshot-revert": + disk_id.val(""); + snap_id.val(args[0]||""); + snap_name.val(""); + break; + case "snapshot-delete": + disk_id.val(""); + snap_id.val(args[0]||""); + snap_name.val(""); + break; + case "disk-snapshot-create": + disk_id.val(args[0]||""); + snap_id.val(""); + snap_name.val(args[1]||""); + break; + case "disk-snapshot-revert": + disk_id.val(args[0]||""); + snap_id.val(args[1]||""); + snap_name.val(""); + break; + case "disk-snapshot-delete": + disk_id.val(args[0]||""); + snap_id.val(args[1]||""); + snap_name.val(""); + break; + default: + snap_name.val(""); + snap_id.val(""); + disk_id.val(""); + break; + } + }else{ + snap_name.val(""); + snap_id.val(""); + disk_id.val(""); + } + } + } + //relative check + if(relative){ + $('#relative_time').prop('checked', true); + $("#relative_time_form").removeClass("hide"); + $("#no_relative_time_form").addClass("hide"); + if(dataJSON.TIME){ + var relativeTime = _time(parseInt(dataJSON.TIME,10)); + if(relativeTime && relativeTime.split && relativeTime.split(" ")){ + relativeDate = relativeTime.trim().split(" "); + if(relativeDate[0]){ + $("#time_number").val(relativeDate[0]); + } + if(relativeDate[1]){ + $('#time_unit').val(relativeDate[1].toLowerCase()); + } + } + } + }else{ + $('#relative_time').prop('checked', false); + $("#relative_time_form").addClass("hide"); + $("#no_relative_time_form").removeClass("hide"); + //periodic check + if(dataJSON.DAYS || dataJSON.REPEAT){ + $('#schedule_type').click().attr('checked', true); + } + if(dataJSON.TIME && dataJSON.TIME > 1){ + var end_value = parseInt(dataJSON.TIME,10) * 1000; + $("#date_input").val( + formatDate(end_value,'date') + ); + $("#time_input").val( + formatDate(end_value, 'hour') + ); + }else{ + _resetInputs(); + } + if(dataJSON.REPEAT && dataJSON.REPEAT.length){ + _resetRepeatValues(); + switch (dataJSON.REPEAT) { + case '0': + $("#repeat").val('week').change(); + if(dataJSON.DAYS && dataJSON.DAYS.length){ + var days = $("#days_week_value input[name=days]"); + var dataDays = dataJSON.DAYS.split(","); + dataDays.forEach(function(dataValue){ + if(days[dataValue]){ + $(days[dataValue]).prop("checked", true); + } + }) + } + break; + case '1': + $("#repeat").val('month').change(); + if(dataJSON.DAYS && dataJSON.DAYS.length){ + $("#days_month_value").val(dataJSON.DAYS); + } + break; + case '2': + $("#repeat").val('year').change(); + if(dataJSON.DAYS && dataJSON.DAYS.length){ + $("#days_year_value").val(dataJSON.DAYS); + } + break; + case '3': + $("#repeat").val('hour').change(); + if(dataJSON.DAYS && dataJSON.DAYS.length){ + $("#days_hour_value").val(dataJSON.DAYS); + } + break; + default: + break; + } + }else{ + _resetRepeat(); + } + if(dataJSON.END_TYPE && dataJSON.END_TYPE.length){ + switch (dataJSON.END_TYPE) { + case "0": + $("#end_type_ever").prop("checked",true).click(); + break; + case "1": + $("#end_type_n_rep[value=n_rep]").click(); + if(dataJSON.END_VALUE && dataJSON.END_VALUE.length){ + $("#end_value_n_rep").val(dataJSON.END_VALUE); + } + break; + case "2": + $("#end_type_n_rep[value=date]").click(); + if(dataJSON.END_VALUE && dataJSON.END_VALUE.length){ + var end_value = parseInt(dataJSON.END_VALUE,10) * 1000; + $("#end_value_date").val( + formatDate(end_value,'date') + ); + } + break; + default: + break; + } + } + } + } + } + } + + function _reset(){ + $("#relative_time").prop("checked",false); + $("#schedule_type").prop("checked",false); + $("#time_number").val(""); + $("#end_value_date").val("").prop("disabled", true); + $("#end_value_n_rep").val("").prop("disabled", true); + $("#end_type_ever").click(); + _resetInputs(); + _resetRepeat(); + _resetRepeatValues(); + $(".periodic").addClass("hide"); + $(".non-periodic").removeClass("hide"); + $("#relative_time_form").addClass("hide"); + $("#no_relative_time_form").removeClass("hide"); + + } + + function _resetRepeatValues(){ + $("#days_week_value input[name=days]").prop("checked", false); + $("#days_month_value").val(""); + $("#days_year_value").val(""); + $("#days_hour_value").val(""); + } + + function _resetRepeat(){ + $("#repeat").val('week').change(); + } + + function _resetInputs(){ + $("#date_input").val( + formatDate(false, 'date') + ); + $("#time_input").val(defaultHour); + } + function _retrieve(context) { $("#scheduling_" + this.res + "_actions_table .create", context).remove(); var actionsJSON = []; var that = this; $("#scheduling_" + this.res + "_actions_table tbody tr").each(function (index) { var first = $(this).children("td")[0]; - if (!$("select", first).html()) { + if (!$("select", first).html()) { //table header var actionJSON = {}; if ($(this).attr("data")) { actionJSON = JSON.parse($(this).attr("data")); actionJSON.ID = String(index); - var actions = [ - 'snapshot-create', - 'snapshot-revert', - 'snapshot-delete', - 'disk-snapshot-create', - 'disk-snapshot-revert', - 'disk-snapshot-delete' - ]; - if(that.selector && that.selector.val && actions.includes(that.selector.val())){ - var snap_name = $("#snapname").val(); - var snap_id = $("#snapid").val(); - var disk_id = $("#diskid").val(); - var rawData = [disk_id,snap_id,snap_name]; - actionJSON.ARGS = rawData.filter(function (e) {return e;}).join(); - } } } if (!$.isEmptyObject(actionJSON)) { actionsJSON.push(actionJSON); }; @@ -323,7 +575,7 @@ define(function (require) { end_type = 2; var timeCal = date_input_value + " " + time_input_value; epochStr = new Date(timeCal); - var time = parseInt(epochStr.getTime()) / 1000; + var time = parseInt(epochStr.getTime(),10) / 1000; sched_action.END_TYPE = end_type; sched_action.END_VALUE = time; sched_action.TIME = time; @@ -377,6 +629,13 @@ define(function (require) { sched_action.END_TYPE = String(end_type); } sched_action.ACTION = String(new_action); + if(sched_action.ACTION && actionsWithARGS.includes(sched_action.ACTION)){ + var snap_name = $("#snapname",context).val(); + var snap_id = $("#snapid",context).val(); + var disk_id = $("#diskid",context).val(); + var rawData = [disk_id,snap_id,snap_name]; + sched_action.ARGS = rawData.filter(function (e) {return e;}).join(); + } $("#scheduling_" + this.res + "_actions_table .create", context).remove(); $("#scheduling_" + this.res + "_actions_table #relative_time_form", context).remove(); $("#scheduling_" + this.res + "_actions_table #no_relative_time_form", context).remove(); @@ -494,10 +753,20 @@ define(function (require) { " + rep_str + "\ " + end_str + ""; if (minus === undefined) { - str += "\ + var action_id = scheduling_action.ID || ''; + var update_sched = ''; + if(action_id){ + update_sched = ""; + } + str += "\ +
\
\ - \ + \
\ +
\ + "+update_sched+"\ +
\ +
\ \ "; } @@ -517,6 +786,8 @@ define(function (require) { "setup": _setup, "htmlTable": _html, "retrieveNewAction": _retrieveNewAction, - "retrieve": _retrieve + "retrieve": _retrieve, + "fill": _fill, + "reset": _reset }; }); \ No newline at end of file diff --git a/src/sunstone/public/app/utils/schedule_action/html.hbs b/src/sunstone/public/app/utils/schedule_action/html.hbs index a701db79ef..cddb65d10c 100644 --- a/src/sunstone/public/app/utils/schedule_action/html.hbs +++ b/src/sunstone/public/app/utils/schedule_action/html.hbs @@ -21,19 +21,13 @@ the License for the specific language governing permissions and }} {{! limitatio - - - - - -
- +
@@ -135,5 +129,6 @@ the License for the specific language governing permissions and }} {{! limitatio + \ No newline at end of file