Commit 3e3b4441 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_web: Minor fixes and update parameter gadget for new version of renderjs.

Yes, I copied loopEventListener locally instead reimplement onEvent(), so this must be reworked in future.
parent 0df6e7d0
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, loopEventListener, btoa, atob, $, XMLSerializer, jQuery, URI, vkbeautify */
/*global rJS, console, window, document, RSVP, btoa, atob, $, XMLSerializer, jQuery, URI, vkbeautify */
(function (window, document, rJS, loopEventListener, $, XMLSerializer, jQuery, vkbeautify) {
(function (window, document, rJS, $, XMLSerializer, jQuery, vkbeautify) {
"use strict";
var gk = rJS(window);
......@@ -37,6 +37,66 @@
);
}
function loopEventListener(target, type, useCapture, callback,
prevent_default) {
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
//////////////////////////
var handle_event_callback,
callback_promise;
if (prevent_default === undefined) {
prevent_default = true;
}
function cancelResolver() {
if ((callback_promise !== undefined) &&
(typeof callback_promise.cancel === "function")) {
callback_promise.cancel();
}
}
function canceller() {
if (handle_event_callback !== undefined) {
target.removeEventListener(type, handle_event_callback, useCapture);
}
cancelResolver();
}
function itsANonResolvableTrap(resolve, reject) {
var result;
handle_event_callback = function (evt) {
if (prevent_default) {
evt.stopPropagation();
evt.preventDefault();
}
cancelResolver();
try {
result = callback(evt);
} catch (e) {
result = RSVP.reject(e);
}
callback_promise = result;
new RSVP.Queue()
.push(function () {
return result;
})
.push(undefined, function (error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
}
function render_selection(json_field, default_value) {
var input = document.createElement("select"),
option = document.createElement("option"),
......@@ -120,7 +180,6 @@
key,
div,
label,
close_span,
input,
default_value,
default_used_list = [],
......@@ -171,11 +230,6 @@
label = document.createElement("label");
label.textContent = default_value;
label.setAttribute("class", "slapos-parameter-dict-key");
close_span = document.createElement("span");
close_span.textContent = "×";
close_span.setAttribute("class", "bt_close");
close_span.setAttribute("title", "Remove this parameter section.");
label.appendChild(close_span);
default_div.appendChild(label);
default_div = render_subform(
json_field.patternProperties['.*'],
......@@ -321,11 +375,6 @@
return element;
}
function removeSubParameter(element) {
$(element).parent().parent().remove();
return false;
}
function addSubForm(element) {
var subform_json = JSON.parse(atob(element.value)),
input_text = element.parentNode.querySelector("input[type='text']"),
......@@ -355,7 +404,6 @@
field_list = g.props.element.querySelectorAll(".slapos-parameter"),
button_list = g.props.element.querySelectorAll('button.add-sub-form'),
label_list = g.props.element.querySelectorAll('label.slapos-parameter-dict-key'),
close_list = g.props.element.querySelectorAll(".bt_close"),
i,
promise_list = [];
......@@ -386,15 +434,6 @@
));
}
for (i = 0; i < close_list.length; i = i + 1) {
promise_list.push(loopEventListener(
close_list[i],
'click',
false,
removeSubParameter.bind(g, close_list [i])
));
}
return RSVP.all(promise_list);
}
......@@ -890,4 +929,4 @@
});
});
}(window, document, rJS, loopEventListener, $, XMLSerializer, jQuery, vkbeautify));
\ No newline at end of file
}(window, document, rJS, $, XMLSerializer, jQuery, vkbeautify));
\ No newline at end of file
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS , $ , console, loopEventListener*/
(function (window, rJS, $, loopEventListener) {
/*global window, rJS , $ , console */
(function (window, rJS, $) {
"use strict";
var gk = rJS(window),
......@@ -65,4 +65,4 @@
});
});
}(window, rJS, $, loopEventListener));
\ No newline at end of file
}(window, rJS, $));
\ No newline at end of file
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