mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-19 06:50:07 +03:00
M #-: Allow update of sched actions (#4621)
* Fix datepickers * Update template edit * Update vm instantiated * Update sched instantiate Signed-off-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
parent
ff8dd585c9
commit
c0e17da69e
@ -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();
|
||||
|
@ -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"];
|
||||
}
|
||||
});
|
||||
|
@ -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 = [];
|
||||
|
@ -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 = "<div class=\"row\">\
|
||||
<div class=\"large-12 columns\">\
|
||||
<table id=\"scheduling_vms_actions_table\" class=\"info_table dataTable\">\
|
||||
var html = "<div class='row'>\
|
||||
<div class='large-12 columns'>\
|
||||
<table id='scheduling_vms_actions_table' class='info_table dataTable'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>" + Locale.tr("ID") + "</th>\
|
||||
@ -75,23 +75,24 @@ define(function(require) {
|
||||
<th>" + Locale.tr("End") + "</th>\
|
||||
<th>" + Locale.tr("Done") + "</th>\
|
||||
<th>" + Locale.tr("Message") + "</th>\
|
||||
<th colspan=\"\"> </th>\
|
||||
<th><button id=\"add_scheduling_vms_action\" class=\"button small success right radius\" >" + Locale.tr("Add action") + "</button></th>\
|
||||
<th colspan=''> </th>\
|
||||
<th><button id='add_scheduling_vms_action' class='button small success right radius' >" + Locale.tr("Add action") + "</button></th>\
|
||||
<th>" + Leases.html() + "</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id=\"sched_vms_actions_body\">"+
|
||||
<tbody id='sched_vms_actions_body' class='scheduling_place'>"+
|
||||
vmsfromJSONtoActionsTable(that.element.USER_TEMPLATE.SCHED_ACTION) +
|
||||
"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>";
|
||||
|
||||
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 = "<td class=\"done_row\">" + done_str + "</td>\
|
||||
<td class=\"message_row\">" + TemplateUtils.htmlEncode(message_str) + "</td>\
|
||||
<td>\
|
||||
<div>\
|
||||
<a id=\"minus_" + scheduling_action.ID + "\" class=\"remove_action_x\" href=\"#\"><i class=\"fas fa-trash-alt\"/></a>\
|
||||
</div>\
|
||||
var action_id = scheduling_action.ID || '';
|
||||
var update_sched = '';
|
||||
if(action_id){
|
||||
update_sched = "<button id='minus_"+scheduling_action.ID+ "' class='small button btn-warning edit_action_x' data_id='"+action_id+"'><i class='fas fa-edit'></i></button>";
|
||||
}
|
||||
var str = "<td class='done_row'>" + done_str + "</td>\
|
||||
<td class='message_row'>" + TemplateUtils.htmlEncode(message_str) + "</td>\
|
||||
<td colspan='3' style='text-align: right;'>\
|
||||
<div style='display: flex;justify-content: flex-end;'>\
|
||||
<div>\
|
||||
<button id='minus_" + scheduling_action.ID + "' class='small button btn-danger remove_action_x'><i class='fas fa-trash-alt'></i></button>\
|
||||
</div>\
|
||||
<div>"+update_sched+"</div>\
|
||||
</td>\
|
||||
</tr>";
|
||||
|
||||
|
@ -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;
|
||||
|
@ -48,12 +48,21 @@ define(function(require) {
|
||||
var time_str = Humanize.prettyTime(scheduling_action.TIME);
|
||||
|
||||
var str = "";
|
||||
str += "<tr class=\"tr_action\">\
|
||||
<td class=\"action_row\">" + TemplateUtils.htmlEncode(scheduling_action.ACTION) + "</td>\
|
||||
<td nowrap class=\"time_row\">" + time_str + "</td>\
|
||||
<td>\
|
||||
<div>\
|
||||
<a id=\"minus\" class=\"remove_action_x\" href=\"#\"><i class=\"fas fa-trash-alt\"/></a>\
|
||||
var action_id = scheduling_action.ID || '';
|
||||
var update_sched = '';
|
||||
if(action_id){
|
||||
update_sched = "<button id='minus' class='small button btn-warning edit_action_x' data_id='"+action_id+"'><i class='fas fa-edit'></i></button>";
|
||||
}
|
||||
|
||||
str += "<tr class='tr_action'>\
|
||||
<td class='action_row'>" + TemplateUtils.htmlEncode(scheduling_action.ACTION) + "</td>\
|
||||
<td nowrap class='time_row'>" + time_str + "</td>\
|
||||
<td colspan='3' style='text-align: right;'>\
|
||||
<div style='display: flex;justify-content: flex-end;'>\
|
||||
<div>\
|
||||
<button id='minus' class='small button btn-danger remove_action_x'><i class='fas fa-trash-alt'></i></button>\
|
||||
</div>\
|
||||
<div>"+update_sched+"</div>\
|
||||
</div>\
|
||||
</td>\
|
||||
</tr>";
|
||||
|
@ -93,7 +93,7 @@ define(function(require) {
|
||||
ACTION: schedAction
|
||||
};
|
||||
last = schedActionTime;
|
||||
$(idElementSchedActions).append(ScheduleActions.fromJSONtoActionsTable(newAction));
|
||||
$(idElementSchedActions).prepend(ScheduleActions.fromJSONtoActionsTable(newAction));
|
||||
pass = true;
|
||||
}
|
||||
});
|
||||
|
@ -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) {
|
||||
<td nowrap class='rep_row'>" + rep_str + "</td>\
|
||||
<td nowrap class='end_row'>" + end_str + "</td>";
|
||||
if (minus === undefined) {
|
||||
str += "<td>\
|
||||
var action_id = scheduling_action.ID || '';
|
||||
var update_sched = '';
|
||||
if(action_id){
|
||||
update_sched = "<button id='edit' class='small button btn-warning edit_action_x' data_id='"+action_id+"'><i class='fas fa-edit'></i></button>";
|
||||
}
|
||||
str += "<td colspan='3' style='text-align: right;'>\
|
||||
<div style='display: flex;justify-content: flex-end;'>\
|
||||
<div>\
|
||||
<a id='minus' class='remove_action_x' href='#'><i class='fas fa-trash-alt'/></a>\
|
||||
<button id='minus' class='small button btn-danger remove_action_x'><i class='fas fa-trash-alt'></i></button>\
|
||||
</div>\
|
||||
<div>\
|
||||
"+update_sched+"\
|
||||
</div>\
|
||||
</div>\
|
||||
</td>\
|
||||
</tr>";
|
||||
}
|
||||
@ -517,6 +786,8 @@ define(function (require) {
|
||||
"setup": _setup,
|
||||
"htmlTable": _html,
|
||||
"retrieveNewAction": _retrieveNewAction,
|
||||
"retrieve": _retrieve
|
||||
"retrieve": _retrieve,
|
||||
"fill": _fill,
|
||||
"reset": _reset
|
||||
};
|
||||
});
|
@ -21,19 +21,13 @@ the License for the specific language governing permissions and }} {{! limitatio
|
||||
<label for="relative_time">{{tr "Relative Time"}}</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="only_name_form" class="hide">
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="number" id="time_number" placeholder="{{tr 'Time'}}" style="width: 80%">
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="input_sched_action_form">
|
||||
<td></td>
|
||||
<td colspan="6">
|
||||
<div style="display: flex;">
|
||||
<input type="number" class="hide" id="diskid" placeholder="{{tr 'Disk Id'}}" style="width: 100%">
|
||||
<input type="number" class="hide" id="snapid" placeholder="{{tr 'Snap Id'}}" style="width: 100%">
|
||||
<input id="snapname" class="hide" placeholder="{{tr 'Snap Name'}}" style="width: 100%">
|
||||
<input type="string" id="snapname" class="hide" placeholder="{{tr 'Snap Name'}}" style="width: 100%">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -135,5 +129,6 @@ the License for the specific language governing permissions and }} {{! limitatio
|
||||
<tr class="create">
|
||||
<td>
|
||||
<button style="margin-top: 15px;" id="add_{{res}}_action_json" class="button small success secondary radius">{{tr "Add"}}</button>
|
||||
<button style="margin-top: 15px;" id="edit_{{res}}_action_json" class="button small warning radius">{{tr "Edit"}}</button>
|
||||
</td>
|
||||
</tr>
|
Loading…
x
Reference in New Issue
Block a user