Commit 47f0cb25 authored by Boris Kocherov's avatar Boris Kocherov

remove slapos code

parent 363830cf
...@@ -270,16 +270,6 @@ ...@@ -270,16 +270,6 @@
return gadget.processValidation(json_url); return gadget.processValidation(json_url);
} }
function collapseParameter(element) {
$(element).parent().children("div").toggle(300);
if ($(element).hasClass("slapos-parameter-dict-key-colapse")) {
$(element).removeClass("slapos-parameter-dict-key-colapse");
} else {
$(element).addClass("slapos-parameter-dict-key-colapse");
}
return element;
}
function addSubForm(element) { function addSubForm(element) {
var subform_json = JSON.parse(atob(element.value)), var subform_json = JSON.parse(atob(element.value)),
input_text = element.parentNode.querySelector("input[type='text']"), input_text = element.parentNode.querySelector("input[type='text']"),
...@@ -342,24 +332,6 @@ ...@@ -342,24 +332,6 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
} }
function getSoftwareTypeFromForm(element) {
var input = element.querySelector(".slapos-software-type");
if (input !== undefined && input !== null) {
return input.value;
}
return "";
}
function getSerialisationTypeFromForm(element) {
var input = element.querySelector(".slapos-serialisation-type");
if (input !== undefined && input !== null) {
return input.value;
}
return "";
}
rJS(window) rJS(window)
.declareMethod("loadJSONSchema", function (url) { .declareMethod("loadJSONSchema", function (url) {
return this.getDeclaredGadget('loadschema') return this.getDeclaredGadget('loadschema')
...@@ -368,42 +340,19 @@ ...@@ -368,42 +340,19 @@
}); });
}) })
.declareMethod("validateJSONForSoftwareType", function (schema_url, softwaretype, generated_json) { .declareMethod('processValidation', function (schema_url, json_dict) {
return this.getDeclaredGadget('loadschema') var g = this;
.push(function (gadget) {
return gadget.validateJSONForSoftwareType(schema_url, softwaretype, generated_json);
});
})
.declareMethod("loadSoftwareJSON", function (url) {
return this.getDeclaredGadget('loadschema') return this.getDeclaredGadget('loadschema')
.push(function (gadget) { .push(function (gadget) {
return gadget.loadSoftwareJSON(url); return gadget.validateJSON(schema_url, json_dict);
}); })
})
.declareMethod('processValidation', function (json_url) {
var g = this,
software_type = getSoftwareTypeFromForm(g.element),
json_dict = getFormValuesAsJSONDict(g.element),
serialisation_type = getSerialisationTypeFromForm(g.element);
if (software_type === "") {
if (g.options.value.parameter.shared) {
throw new Error("The software type is not part of the json (" + software_type + " as slave)");
}
throw new Error("The software type is not part of the json (" + software_type + ")");
}
return g.validateJSONForSoftwareType(json_url, software_type, json_dict)
.push(function (validation) { .push(function (validation) {
var error_index, var error_index,
parameter_hash_input = g.element.querySelectorAll('.parameter_hash_output')[0],
field_name, field_name,
div, div,
divm, divm,
missing_index, missing_index,
missing_field_name, missing_field_name;
xml_output;
$(g.element.querySelectorAll("span.error")).each(function (i, span) { $(g.element.querySelectorAll("span.error")).each(function (i, span) {
span.textContent = ""; span.textContent = "";
...@@ -412,15 +361,8 @@ ...@@ -412,15 +361,8 @@
$(g.element.querySelectorAll("div.error-input")).each(function (i, div) { $(g.element.querySelectorAll("div.error-input")).each(function (i, div) {
div.setAttribute("class", ""); div.setAttribute("class", "");
}); });
if (serialisation_type === "json-in-xml") {
xml_output = jsonDictToParameterJSONInXML(json_dict);
} else {
xml_output = jsonDictToParameterXML(json_dict);
}
parameter_hash_input.value = btoa(xml_output);
// console.log(parameter_hash_input.value);
if (validation.valid) { if (validation.valid) {
return xml_output; return "VALID";
} }
for (error_index in validation.errors) { for (error_index in validation.errors) {
if (validation.errors.hasOwnProperty(error_index)) { if (validation.errors.hasOwnProperty(error_index)) {
...@@ -527,40 +469,28 @@ ...@@ -527,40 +469,28 @@
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this, var g = this,
queue; queue;
gadget.options = options; g.options = options;
if (!options.value) {
options.value = {};
}
if (options.schema) { if (options.schema) {
queue = RSVP.Queue() queue = RSVP.Queue()
.push(function () { .push(function () {
return options.schema; return options.schema;
}); });
} else { } else {
queue = gadget.loadJSONSchema(options.schema_url); queue = g.loadJSONSchema(options.schema_url);
} }
return queue return queue
.push(function (schema) { .push(function (schema) {
console.log(schema); g.options.schema = schema;
return gadget.renderParameterForm(schema, {}); return g.renderParameterForm(schema, options.value);
})
.push(function () {
var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'),
label_list = gadget.element.querySelectorAll('label.slapos-parameter-dict-key');
console.log("Collapse paramaters");
for (i = 0; i < div_list.length; i = i + 1) {
$(div_list[i]).hide();
}
for (i = 0; i < label_list.length; i = i + 1) {
$(label_list[i]).addClass("slapos-parameter-dict-key-colapse");
}
return gadget;
}) })
.push(function () { .push(function () {
console.log("FINISHED TO RENDER, RETURNING THE GADGET"); console.log("FINISHED TO RENDER, RETURNING THE GADGET");
return gadget; return g;
}); });
}) })
...@@ -569,24 +499,14 @@ ...@@ -569,24 +499,14 @@
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
var gadget = this; var g = this,
return gadget.getElement() json_dict = getFormValuesAsJSONDict(g.element);
.push(function (element) { return g.processValidation(g.options.schema_url, json_dict)
var text_content = element.querySelector('textarea[name=text_content]'); .push(function (status) {
if (text_content !== null) { return {
return "SKIP"; value: json_dict,
} status: status
return gadget.processValidation(gadget.options.value.parameter.json_url); };
})
.push(function (xml_result) {
if (xml_result === "SKIP") {
/* The raw parameters are already on the request */
return {};
}
return {"text_content": xml_result};
})
.fail(function (e) {
return {};
}); });
}); });
......
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