Commit 48d8ce80 authored by Sven Franck's avatar Sven Franck

added action menu handlers to start/stop instance

parent 48e917dc
......@@ -130,7 +130,7 @@
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href
})
.then(function(answer){
.then(function (answer) {
if (pass.config.initial_query === undefined) {
pass.config.initial_query = {};
}
......@@ -167,6 +167,44 @@
**/
map.actions = {
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"start_instance": function (obj) {
var element = obj.element;
util.loader("", "status_dict.starting", "signal");
jIO.util.ajax({
"url": element.href,
"type": element.getAttribute("data-method")
})
.then(function (response) {
util.loader("", "status_dict.success", "check");
})
.fail(util.error);
},
/**
* Stop a software instance
* @method stop_instance
* @param {object} obj Action Object
**/
"stop_instance": function (obj) {
var element = obj.element;
util.loader("", "status_dict.stopping", "ban-circle");
jIO.util.ajax({
"url": element.href,
"type": element.getAttribute("data-method")
})
.then(function (response) {
util.loader("", "status_dict.success", "check");
})
.fail(util.error);
},
/**
* Look up single value from dict
* @method translateLookup
......@@ -1765,7 +1803,57 @@
/* ********************************************************************** */
factory.util = {};
/** Generate a seach bar (controlbar)
/**
* Generate an action menu (controlgroup)
* @actionMenu
* @param {object} spec Menu configuration
* @param {object} finished element
**/
factory.util.actionMenu = function (spec) {
var k, button, config, dict, attribute;
config = {
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": []
};
// can be single action or a button group!
for (k = 0; k < spec.length; k += 1) {
dict = {};
button = spec[k];
for (attribute in button) {
if (button.hasOwnProperty(attribute)) {
if (attribute.substring(0, 5) === "data-") {
dict[attribute] = button[attribute]
}
}
}
dict["data-action"] = button.action;
config.children.push({
"type": "a",
"direct": {
"href": button.href || "#",
"className": button.class_list +
(button.text_i18n ? " translate" : " ") + "ui-btn " +
"ui-btn-icon-" + (button.iconpos || "notext") +
" ui-shadow ui-corner-all ui-icon-" + button.icon + " action"
},
"attributes": dict,
"logic": {
"data-i18n": button.text_i18n || null,
"text": button.text
}
});
}
return config;
};
/**
* Generate a seach bar (controlbar)
* @method searchBar
* @param {object} spec Pagination configuration
* @return {object} finished config object
......@@ -2569,9 +2657,10 @@
// TODO: crap to use both layout and children!
// NOTE: securing ? http://nedbatchelder.com/text/stopbots.html
factory.form = function (spec) {
var i, j, k, l, segment, element, container, area, field, overrides,
var i, j, k, l, m, n, segment, element, container, area, field, overrides,
position, doc, config, value, stamp, sauce, encode, secure,
safety_box, fragment, wrap, item_id, input_config, setter, setter_list;
safety_box, fragment, wrap, item_id, input_config, setter, setter_list,
button;
spec.set_id = "form_" + util.uuid();
fragment = factory.util.wrapInForm(spec);
......@@ -2685,7 +2774,7 @@
// TODO: can we also generate a field from another portal_type here?
if (field.type) {
input_config = field;
setter = input_config.logic.setValue;
setter = input_config.logic ? input_config.logic.setValue : undefined;
// make sure value is set correctly
if (input_config.logic && setter) {
......@@ -2704,6 +2793,8 @@
config = spec.fields[field.field];
overrides = field.overrides;
doc = spec.data || undefined;
// try to set a value
if (doc && field.custom) {
setter = field.setValue || undefined;
} else {
......@@ -2711,15 +2802,30 @@
}
value = doc ? (doc[setter]) : undefined;
// map config to what we need
input_config = map.utils.mapFormField(
spec.set_id,
config,
overrides,
value
);
}
// action menu
if (field.action_list && field.action_list.length) {
for (m = 0; m < field.action_list.length; m += 1) {
button = field.action_list[m];
if (button.setters.length) {
for (n = 0; n < button.setters.length; n += 1) {
field.action_list[m][button.setters[n]] =
util.fetchByArray(doc, button.setValues[n]);
}
}
}
input_config = factory.util.actionMenu(field.action_list);
// links and/or sorting
} else {
// map config to what we need
input_config = map.utils.mapFormField(
spec.set_id,
config,
overrides,
value
);
}
}
switch (j) {
case 0:
......@@ -2736,15 +2842,21 @@
break;
}
if (input_config.logic && input_config.logic.skip) {
// widget
if (input_config.generate) {
container.appendChild(app.setContent(input_config));
// html element
} else if (input_config.logic && input_config.logic.skip) {
container.appendChild(factory.element(
input_config.type,
input_config.direct,
input_config.attributes || {},
input_config.logic || {}
));
// form element
} else {
// generate and append
container.appendChild(factory.formElement(
input_config,
true,
......@@ -3606,7 +3718,7 @@
// TODO: merge check/radio on table and listview!
factory.tableRow = function (spec, body) {
var i, j, k, field, link, attributes, property, title, action, cell, set,
column_list, temp, container, row, group, button, input_type,
column_list, temp, container, row, group, input_type,
global_check, skip, input_dict, snippet, logic;
// checkbox row
......@@ -3708,33 +3820,10 @@
snippet;
// cell action buttons
// TODO: need help here once fully converting to promises
if ((field.action_list && field.action_list.length)) {
group = {
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"children": []
};
// can be single action or a button group!
for (k = 0; k < field.action_list.length; k += 1) {
button = field.action_list[k];
group.children.push({
"type": "a",
"direct": {
"href": button.href || "#",
"className": button.class_list +
(button.text_i18n ? " translate" : " ") + "ui-btn " +
"ui-btn-icon-notext ui-shadow ui-corner-all" +
" ui-icon-" + button.icon + " action"
},
"attributes": {"data-action": button.action},
"logic": {
"data-i18n": button.text_i18n || null,
"text": button.text
}
});
}
group = factory.util.actionMenu(field.action_list);
// TODO: need help because this will make a promise!
// hijack link variable
link = app.setContent(group);
......@@ -6604,6 +6693,10 @@
raw_url = window.location.href;
}
if (data && data.options.reverse) {
raw_url = window.decodeURIComponent(raw_url);
}
if (typeof raw_url === "string") {
config = app.generateLinkObject(raw_url);
......@@ -6846,6 +6939,22 @@
*/
util.storage_dict = {};
/**
* Fetch a value from an object based on an array path
* @method fetchByArray
* @param {object} obj Object containing a value
* @param {array} arr Path leading to a value
* @return {string} value
**/
util.fetchByArray = function(obj, arr) {
var n, key;
for (n = 0; n < arr.length; n += 1) {
key = obj[arr[n]] || key[arr[n]];
}
return key;
};
/**
* Generate a UUID ticket for a transaction
* @method uuid
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment