Commit f2431d1b authored by Boris Kocherov's avatar Boris Kocherov

remove slapos related code

parent 46c17273
...@@ -7,40 +7,12 @@ ...@@ -7,40 +7,12 @@
<link rel="shortcut icon" href="favicon.ico"> <link rel="shortcut icon" href="favicon.ico">
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="URI.js" type="text/javascript"></script>
<script src="jquery.js" type="text/javascript"></script> <script src="jquery.js" type="text/javascript"></script>
<script src="vkbeautify.js" type="text/javascript"></script> <script src="gadget_global.js"></script>
<script src="gadget_erp5_page_slap_parameter_form.js" type="text/javascript"></script> <script src="gadget_json_generated_form.js" type="text/javascript"></script>
<link href="gadget_erp5_page_slap_parameter_form.css" rel="stylesheet" type="text/css"/>
</head> </head>
<body> <body>
<div> <div>
<fieldset id="software-type">
<div class="field" title="software_type">
<label> Software Type </label>
<div class="input">
<select size="1" name="software_type" class="slapos-software-type">
</select>
</div>
</div>
<div class="field" title="serialisation_type">
<div class="input">
<input type=hidden name="serialisation_type" class="slapos-serialisation-type"/>
</div>
</div>
<div class="field" title="hide_show_button">
<div class="input">
<button type="button" class="slapos-show-form hidden-button"> Show Parameter Form </button>
<button type="button" class="slapos-show-raw-parameter"> Show Parameter XML</button>
</div>
</div>
</fieldset>
<fieldset id="parameter-main"> </fieldset>
<fieldset id="parameter-optional"> </fieldset>
<fieldset id="parameter-xml">
<input type=hidden name="parameter_hash" class="parameter_hash_output"/>
<input type=hidden name="shared" class="parameter_shared"/>
</fieldset>
</div> </div>
<div class="loadschema" <div class="loadschema"
data-gadget-url="gadget_erp5_page_slap_load_schema.html" data-gadget-url="gadget_erp5_page_slap_load_schema.html"
......
/*jslint nomen: true, maxlen: 200, indent: 2*/ /*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, btoa, atob, $, XMLSerializer, jQuery, URI, vkbeautify */ /*global rJS, console, window, document, RSVP, btoa, atob, $ */
(function (window, document, rJS, $, XMLSerializer, jQuery, vkbeautify) { (function (window, document, rJS, $, loopEventListener) {
"use strict"; "use strict";
var gk = rJS(window);
function jsonDictToParameterXML(json) {
var parameter_id,
xml_output = $($.parseXML('<?xml version="1.0" encoding="utf-8" ?><instance />'));
// Used by serialisation XML
for (parameter_id in json) {
if (json.hasOwnProperty(parameter_id)) {
$('instance', xml_output).append(
$('<parameter />', xml_output)
.text(json[parameter_id])
.attr({id: parameter_id})
);
}
}
return vkbeautify.xml(
(new XMLSerializer()).serializeToString(xml_output.context)
);
}
function jsonDictToParameterJSONInXML(json) {
var xml_output = $($.parseXML('<?xml version="1.0" encoding="utf-8" ?><instance />'));
// Used by serialisation XML
$('instance', xml_output).append(
$('<parameter />', xml_output)
.text(vkbeautify.json(JSON.stringify(json)))
.attr({id: "_"})
);
return vkbeautify.xml(
(new XMLSerializer()).serializeToString(xml_output.context)
);
}
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) { function render_selection(json_field, default_value) {
var input = document.createElement("select"), var input = document.createElement("select"),
option = document.createElement("option"), option = document.createElement("option"),
...@@ -453,7 +360,8 @@ ...@@ -453,7 +360,8 @@
return ""; return "";
} }
gk.declareMethod("loadJSONSchema", function (url) { rJS(window)
.declareMethod("loadJSONSchema", function (url) {
return this.getDeclaredGadget('loadschema') return this.getDeclaredGadget('loadschema')
.push(function (gadget) { .push(function (gadget) {
return gadget.loadJSONSchema(url); return gadget.loadJSONSchema(url);
...@@ -535,18 +443,15 @@ ...@@ -535,18 +443,15 @@
}); });
}) })
.declareMethod('renderParameterForm', function (json_url, default_dict) { .declareMethod('renderParameterForm', function (schema, default_dict) {
var g = this; var g = this;
return g.loadJSONSchema(json_url) var parent_element = document.createDocumentFragment();
.push(function (json) { render_subform(schema, default_dict, parent_element);
var fieldset_list = g.element.querySelectorAll('fieldset'), while (g.element.firstChild) {
fieldset = document.createElement("fieldset"); g.element.removeChild(g.element.firstChild);
}
fieldset = render_subform(json, default_dict, fieldset); g.element.appendChild(parent_element);
$(fieldset_list[1]).replaceWith(fieldset); return g.element;
return fieldset_list;
});
}) })
.declareMethod('renderFailoverTextArea', function (content, error) { .declareMethod('renderFailoverTextArea', function (content, error) {
...@@ -623,156 +528,20 @@ ...@@ -623,156 +528,20 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this, var gadget = this,
to_hide = gadget.element.querySelector("button.slapos-show-form"), queue;
to_show = gadget.element.querySelector("button.slapos-show-raw-parameter"),
softwaretype,
json_url = options.value.parameter.json_url;
gadget.options = options; gadget.options = options;
if (options.schema) {
if (options.value.parameter.parameter_hash !== undefined) { queue = RSVP.Queue()
// A JSON where provided via gadgetfield .push(function () {
options.value.parameter.parameter_xml = atob(options.value.parameter.parameter_hash); return options.schema;
} });
} else {
if (json_url === undefined) { queue = gadget.loadJSONSchema(options.schema_url);
throw new Error("undefined json_url");
}
if (to_hide !== null) {
$(to_hide).addClass("hidden-button");
}
if (to_show !== null) {
$(to_show).removeClass("hidden-button");
} }
return queue
.push(function (schema) {
return gadget.loadSoftwareJSON(json_url) console.log(schema);
.push(function (json) { return gadget.renderParameterForm(schema, {});
var option_index,
option,
option_selected = options.value.parameter.softwaretypeindex,
restricted_softwaretype = options.value.parameter.restricted_softwaretype,
input = gadget.element.querySelector('select.slapos-software-type'),
parameter_shared = gadget.element.querySelector('input.parameter_shared'),
s_input = gadget.element.querySelector('input.slapos-serialisation-type');
if (option_selected === undefined) {
option_selected = options.value.parameter.softwaretype;
}
if (input.children.length === 0) {
for (option_index in json['software-type']) {
if (json['software-type'].hasOwnProperty(option_index)) {
option = document.createElement("option");
if (json['software-type'][option_index]['software-type'] !== undefined) {
option.value = json['software-type'][option_index]['software-type'];
} else {
option.value = option_index;
}
option['data-id'] = option_index;
option.textContent = json['software-type'][option_index].title;
// option.index = json['software-type'][option_index].index;
if (options.value.parameter.shared === undefined) {
options.value.parameter.shared = false;
}
if (option_selected === undefined) {
option_selected = option_index;
if (json['software-type'][option_index].shared === true) {
parameter_shared.value = true;
} else {
parameter_shared.value = false;
}
}
if (softwaretype === undefined) {
softwaretype = option_selected;
}
if (json['software-type'][option_index].shared === undefined) {
json['software-type'][option_index].shared = false;
}
option['data-shared'] = json['software-type'][option_index].shared;
if ((option_index === option_selected) &&
(options.value.parameter.shared === json['software-type'][option_index].shared)) {
option.selected = "selected";
if (json['software-type'][option_index].shared === true) {
parameter_shared.value = true;
} else {
parameter_shared.value = false;
}
}
if (restricted_softwaretype === true) {
if (option.value === options.value.parameter.softwaretype) {
if (options.value.parameter.shared === json['software-type'][option_index].shared) {
input.appendChild(option);
}
}
} else {
input.appendChild(option);
}
}
}
}
if (softwaretype === undefined) {
softwaretype = option_selected;
}
if (input.children.length === 0) {
if (options.value.parameter.shared) {
throw new Error("The software type is not part of the json (" + softwaretype + " as slave)");
}
throw new Error("The software type is not part of the json (" + softwaretype + ")");
}
if (json['software-type'][softwaretype] === undefined) {
throw new Error("The sotware type is not part of the json (" + softwaretype + ")");
}
if (json['software-type'][softwaretype].serialisation !== undefined) {
s_input.value = json['software-type'][softwaretype].serialisation;
options.serialisation = json['software-type'][softwaretype].serialisation;
} else {
s_input.value = json.serialisation;
options.serialisation = json.serialisation;
}
return json['software-type'][softwaretype].request;
})
.push(function (parameter_json_schema_url) {
var parameter_dict = {}, json_url_uri, prefix, parameter_entry;
if (options.value.parameter.parameter_xml !== undefined) {
if (options.serialisation === "json-in-xml") {
parameter_entry = jQuery.parseXML(
options.value.parameter.parameter_xml
).querySelector("parameter[id='_']");
if (parameter_entry !== null) {
parameter_dict = JSON.parse(parameter_entry.textContent);
}
} else {
$(jQuery.parseXML(options.value.parameter.parameter_xml)
.querySelectorAll("parameter"))
.each(function (key, p) {
parameter_dict[p.id] = p.textContent;
});
}
}
if (URI(parameter_json_schema_url).protocol() === "") {
// URL is relative, turn into absolute
json_url_uri = URI(options.value.parameter.json_url);
prefix = json_url_uri.path().split("/");
prefix.pop();
prefix = options.value.parameter.json_url.split(json_url_uri.path())[0] + prefix.join("/");
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;
}
return gadget.renderParameterForm(parameter_json_schema_url, parameter_dict);
}) })
.push(function () { .push(function () {
var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'), var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'),
...@@ -792,122 +561,9 @@ ...@@ -792,122 +561,9 @@
.push(function () { .push(function () {
console.log("FINISHED TO RENDER, RETURNING THE GADGET"); console.log("FINISHED TO RENDER, RETURNING THE GADGET");
return gadget; return gadget;
})
.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;
});
}); });
}) })
.declareService(function () {
var g = this,
element = g.element.getElementsByTagName('select')[0];
if (element === undefined) {
return true;
}
function updateParameterForm(evt) {
var e = g.element.getElementsByTagName('select')[0],
parameter_shared = g.element.querySelector('input.parameter_shared');
if (e === undefined) {
throw new Error("Select not found.");
}
g.options.value.parameter.softwaretype = e.value;
g.options.value.parameter.softwaretypeindex = e.selectedOptions[0]["data-id"];
parameter_shared.value = e.selectedOptions[0]["data-shared"];
return g.render(g.options)
.push(function () {
return loadEventList(g);
});
}
return loopEventListener(
element,
'change',
false,
updateParameterForm.bind(g)
);
})
.declareService(function () {
var g = this,
element = g.element.querySelector("button.slapos-show-raw-parameter");
if (element === undefined) {
return true;
}
function showRawParameter(evt) {
var e = g.element.querySelector("button.slapos-show-raw-parameter"),
to_show = g.element.querySelector("button.slapos-show-form"),
parameter_xml;
if (g.options.value.parameter.parameter_hash !== undefined) {
parameter_xml = atob(g.options.value.parameter.parameter_hash);
}
$(e).addClass("hidden-button");
$(to_show).removeClass("hidden-button");
return g.renderRawParameterTextArea(parameter_xml)
.push(function () {
return loadEventList(g);
});
}
return loopEventListener(
element,
'click',
false,
showRawParameter.bind(g)
);
})
.declareService(function () {
var g = this,
element = g.element.querySelector("button.slapos-show-form");
function showParameterForm(evt) {
var e = g.element.getElementsByTagName('select')[0],
to_hide = g.element.querySelector("button.slapos-show-form"),
to_show = g.element.querySelector("button.slapos-show-raw-parameter");
if (e === undefined) {
throw new Error("Select not found.");
}
$(to_hide).addClass("hidden-button");
$(to_show).removeClass("hidden-button");
g.options.value.parameter.softwaretype = e.value;
g.options.value.parameter.softwaretypeindex = e.selectedOptions[0]["data-id"];
return g.render(g.options)
.push(function () {
return loadEventList(g);
});
}
return loopEventListener(
element,
'click',
false,
showParameterForm.bind(g)
);
})
.declareService(function () { .declareService(function () {
return loadEventList(this); return loadEventList(this);
}) })
...@@ -951,4 +607,4 @@ ...@@ -951,4 +607,4 @@
// }); // });
//}); //});
}(window, document, rJS, $, XMLSerializer, jQuery, vkbeautify)); }(window, document, rJS, $));
\ No newline at end of file \ 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