Commit 0028a25c authored by Boris Kocherov's avatar Boris Kocherov

rm jquery dependence, rm unused code, fix run validation event on change

parent 8f61be1d
......@@ -14,7 +14,7 @@
[gadget_json_generated_form.html](gadget_json_generated_form.html)
* **done** remove slapos specific code
* **partly done** remove jquery dependence
* **done** remove jquery dependence
* **partly done** full support of json schema
* **done** support in path [rfc6901](https://tools.ietf.org/html/rfc6901)
* using changeState and mutex
......
......@@ -8,7 +8,6 @@
<link href="gadget_erp5_page_slap_parameter_form.css" rel="stylesheet" type="text/css"/>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jquery.js" type="text/javascript"></script>
<script src="gadget_global.js"></script>
<script src="gadget_json_generated_form.js" type="text/javascript"></script>
</head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, window, document, RSVP, $, loopEventListener */
/*global window, document, rJS, RSVP, loopEventListener */
(function (window, document, rJS, $, loopEventListener) {
(function (window, document, rJS, RSVP, loopEventListener) {
"use strict";
function decodeJsonPointer(_str) {
......@@ -474,7 +474,7 @@
field_list[i],
'change',
false,
gadget.processValidation.bind(g, g.options.schema_url)
gadget.processValidation.bind(g, g.options.schema_url, undefined)
));
}
......@@ -548,38 +548,35 @@
return loadschema_gadget.validateJSON(schema_url, json_dict);
})
.push(function (validation) {
var error_index,
field_name,
var index,
div,
divm,
missing_index,
missing_field_name;
field_name;
$(g.element.querySelectorAll("span.error")).each(function (i, span) {
g.element.querySelectorAll("span.error").forEach(function (span) {
span.textContent = "";
});
$(g.element.querySelectorAll("div.error-input")).each(function (i, div) {
g.element.querySelectorAll("div.error-input").forEach(function (div) {
div.setAttribute("class", "");
});
if (validation.valid) {
return "VALID";
}
for (error_index in validation.errors) {
if (validation.errors.hasOwnProperty(error_index)) {
field_name = validation.errors[error_index].dataPath;
div = $(".slapos-parameter[name='" + field_name + "']")[0].parentNode;
for (index in validation.errors) {
if (validation.errors.hasOwnProperty(index)) {
field_name = validation.errors[index].dataPath;
div = g.element.querySelector(".slapos-parameter[name='" + field_name + "']").parentNode;
div.setAttribute("class", "slapos-parameter error-input");
div.querySelector("span.error").textContent = validation.errors[error_index].message;
div.querySelector("span.error").textContent = validation.errors[index].message;
}
}
for (missing_index in validation.missing) {
if (validation.missing.hasOwnProperty(missing_index)) {
missing_field_name = validation.missing[missing_index].dataPath;
divm = $('.slapos-parameter[name=' + missing_field_name + "']")[0].parentNode;
divm.setAttribute("class", "error-input");
divm.querySelector("span.error").textContent = validation.missing[missing_index].message;
for (index in validation.missing) {
if (validation.missing.hasOwnProperty(index)) {
field_name = validation.missing[index].dataPath;
div = g.element.querySelector('.slapos-parameter[name=' + field_name + "']").parentNode;
div.setAttribute("class", "error-input");
div.querySelector("span.error").textContent = validation.missing[index].message;
}
}
return "ERROR";
......@@ -614,78 +611,6 @@
});
})
.declareMethod('renderFailoverTextArea', function (content, error) {
var g = this,
div = document.createElement("div"),
div_error = document.createElement("div"),
span_error = document.createElement("span"),
textarea = document.createElement("textarea"),
fieldset = document.createElement("fieldset"),
fieldset_list = g.element.querySelectorAll('fieldset'),
button0 = g.element.querySelector("button.slapos-show-raw-parameter"),
button1 = g.element.querySelector("button.slapos-show-form");
if (button0 !== null) {
$(button0).addClass("hidden-button");
}
if (button1 !== null) {
$(button1).addClass("hidden-button");
}
div.setAttribute("class", "field");
textarea.setAttribute("rows", "10");
textarea.setAttribute("cols", "80");
textarea.setAttribute("name", "text_content");
textarea.textContent = content;
span_error.setAttribute("class", "error");
span_error.textContent = "Parameter form is not available, use the textarea above for edit the instance parameters.";
div_error.setAttribute("class", "error");
div.appendChild(textarea);
div_error.appendChild(span_error);
div.appendChild(textarea);
fieldset.appendChild(div);
fieldset.appendChild(div_error);
fieldset_list[0].innerHTML = '';
$(fieldset_list[1]).replaceWith(fieldset);
fieldset_list[2].innerHTML = '';
return fieldset;
})
.declareMethod('renderRawParameterTextArea', function (content) {
var g = this,
div = document.createElement("div"),
div_error = document.createElement("div"),
textarea = document.createElement("textarea"),
fieldset = document.createElement("fieldset"),
fieldset_list = g.element.querySelectorAll('fieldset');
div.setAttribute("class", "field");
textarea.setAttribute("rows", "10");
textarea.setAttribute("cols", "80");
textarea.setAttribute("name", "text_content");
textarea.textContent = content;
div.appendChild(textarea);
div.appendChild(textarea);
fieldset.appendChild(div);
fieldset.appendChild(div_error);
$(fieldset_list[1]).replaceWith(fieldset);
fieldset_list[2].innerHTML = '';
return fieldset;
})
.declareMethod('render', function (options) {
var g = this,
queue;
......@@ -731,21 +656,4 @@
// });
});
//.declareService(function () {
// var gadget = this;
//return gadget.processValidation(gadget.options.json_url)
// .fail(function (error) {
// var parameter_xml = '';
// console.log(error.stack);
// if (gadget.options.value.parameter.parameter_hash !== undefined) {
// parameter_xml = atob(gadget.options.value.parameter.parameter_hash);
// }
// return gadget.renderFailoverTextArea(parameter_xml, error.toString())
// .push(function () {
// error = undefined;
// return gadget;
// });
// });
//});
}(window, document, rJS, $, loopEventListener));
\ No newline at end of file
}(window, document, rJS, RSVP, loopEventListener));
\ 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