Commit e3d91b30 authored by Boris Kocherov's avatar Boris Kocherov

use html attribute data-origin-value for save original value parts of document

i need it for workaround `data side errors` in tests
parent 8116ef49
......@@ -617,6 +617,7 @@
error_message,
input,
first_path,
type_changed,
queue = RSVP.Queue();
if (json_field instanceof Array) {
......@@ -645,15 +646,11 @@
type = getDocumentType(default_value);
}
// XXX bad peace of code
// i do not sure that type can be computed so
// but our schema in slapos bad
if (!type) {
if (json_field.properties &&
json_field.required &&
json_field.required.length > 0) {
type = "object";
}
if (typeof type === "string") {
// it's only for simple types so we not use
// complex type detection
type_changed = default_value !== undefined &&
typeof default_value !== type;
}
div = document.createElement("div");
......@@ -708,6 +705,8 @@
if (json_field.enum !== undefined) {
input = render_enum(json_field, default_value);
// XXX take in account existing type with enum
type_changed = false;
}
if (type === "boolean") {
......@@ -721,10 +720,11 @@
input = document.createElement("input");
if (default_value !== undefined) {
if (typeof default_value === "object") {
default_value = JSON.stringify(default_value);
}
input.value = JSON.stringify(default_value);
} else {
input.value = default_value;
}
}
if (type === "integer" || type === "number") {
if (default_value === undefined && typeof json_field.default === "number") {
......@@ -732,8 +732,16 @@
}
input.type = "number";
input.setAttribute("data-json-type", type);
type_changed = default_value !== undefined &&
typeof default_value !== "number";
if (type === "integer") {
input.setAttribute("step", "1");
if (default_value !== undefined &&
parseInt(default_value, 10) !== default_value) {
// original json_document contain float schema
// limit integer we can save original document
type_changed = true;
}
}
if (type === "number") {
input.setAttribute("step", "any");
......@@ -786,6 +794,9 @@
gadget.props.inputs.push(input);
input.name = first_path;
input.required = options.required;
if (type_changed) {
input.setAttribute('data-origin-value', JSON.stringify(default_value));
}
// XXX for gui
//input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input);
......@@ -1291,6 +1302,9 @@
var json_dict = {},
k;
g.props.inputs.forEach(function (input) {
if (input.hasAttribute('data-origin-value')) {
json_dict[input.name] = JSON.parse(input.getAttribute('data-origin-value'));
} else {
if (input.required || input.value !== "") {
var type = input.getAttribute('data-json-type');
if (type === 'number') {
......@@ -1313,6 +1327,7 @@
json_dict[input.name] = input.value;
}
}
}
});
for (k in json_dict) {
if (json_dict.hasOwnProperty(k)) {
......@@ -1578,10 +1593,15 @@
var gadget = this,
field_list = this.props.inputs,
i,
input,
changed = false;
// on form data field
for (i = 0; i < field_list.length; i = i + 1) {
if (evt.target === field_list[i]) {
input = evt.target;
if (input.hasAttribute('data-origin-value')) {
input.removeAttribute('data-origin-value');
}
changed = true;
}
}
......
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