Commit c113c5ef authored by Rafael Monnerat's avatar Rafael Monnerat

Support schemas more accurately based on serialisation

See merge request nexedi/slapos.core!375
parents 2d374bc9 e837fd71
......@@ -196,7 +196,7 @@ url_list = [
"gadget_slapos_network_status.js",
"gadget_slapos_panel.html",
"gadget_slapos_panel.js",
"gadget_slapos_panel.png?format=",
"gadget_slapos_panel.png?format=png",
"gadget_slapos_invoice_logo.png?format=",
"gadget_slapos_payment_result.js",
"gadget_slapos_project_status.html",
......@@ -210,6 +210,11 @@ url_list = [
"leaflet.js",
"tv4.min.js",
"vkbeautify.js",
"jquery.js",
"URI.js",
"slapos_load_software_schema.json",
"slapos_load_meta_schema_xml.json",
"slapos_load_meta_schema_json_in_xml.json",
"gadget_erp5_page_slap_language_view.js",
"gadget_erp5_page_slap_language_view.html"
]
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $, btoa */
(function (window, rJS, $, RSVP, btoa) {
(function (window, rJS, $, RSVP, btoa, URI, tv4) {
"use strict";
var gk = rJS(window);
......@@ -57,12 +57,12 @@
}
if (ref.substr(0, 1) === "#") {
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
return resolveLocalReference(ref, schema);
});
}
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
if (URI(ref).protocol() === "") {
if (base_url !== undefined) {
ref = base_url + "/" + ref;
......@@ -91,7 +91,7 @@
expanded_json_schema.properties = {};
}
return RSVP.Queue().push(function () {
return new RSVP.Queue().push(function () {
if (json_schema.$ref) {
return resolveReference(
json_schema,
......@@ -113,7 +113,7 @@
return true;
}).push(function () {
var property, queue = RSVP.Queue();
var property, queue = new RSVP.Queue();
function wrapperResolveReference(p) {
return resolveReference(
......@@ -149,7 +149,7 @@
})
.push(function () {
var zqueue = RSVP.Queue();
var zqueue = new RSVP.Queue();
function wrapperExpandSchema(p) {
return expandSchema(
......@@ -187,12 +187,18 @@
});
}
function getMetaJSONSchema() {
function getMetaJSONSchema(serialisation) {
if (serialisation === "xml") {
return getJSON("slapos_load_meta_schema_xml.json");
}
if (serialisation === "json-in-xml") {
return getJSON("slapos_load_meta_schema_json_in_xml.json");
}
return getJSON("slapos_load_meta_schema.json");
}
function validateJSONSchema(json, base_url) {
return getMetaJSONSchema()
function validateJSONSchema(json, base_url, serialisation) {
return getMetaJSONSchema(serialisation)
.push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
......@@ -204,8 +210,17 @@
});
}
gk
function validateSoftwareJSONSchema(json) {
return getJSON("slapos_load_software_schema.json")
.push(function (schema) {
if (!tv4.validate(json, schema)) {
throw new Error("Non valid JSON for software.cfg.json:" + json);
}
return JSON.parse(json);
});
}
gk
.declareMethod("getBaseUrl", function (url) {
var base_url, url_uri = URI(url);
base_url = url_uri.path().split("/");
......@@ -213,13 +228,13 @@
base_url = url.split(url_uri.path())[0] + base_url.join("/");
return base_url;
})
.declareMethod("loadJSONSchema", function (url) {
.declareMethod("loadJSONSchema", function (url, serialisation) {
var gadget = this;
return getJSON(url)
.push(function (json) {
return gadget.getBaseUrl(url)
.push(function (base_url) {
return validateJSONSchema(json, base_url);
return validateJSONSchema(json, base_url, serialisation);
});
});
})
......@@ -227,7 +242,7 @@
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.push(function (json) {
return JSON.parse(json);
return validateSoftwareJSONSchema(json);
});
})
......@@ -249,4 +264,4 @@
});
});
});
}(window, rJS, $, RSVP, btoa));
}(window, rJS, $, RSVP, btoa, URI, tv4));
......@@ -150,11 +150,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -198,17 +200,20 @@
</item>
</dictionary>
</list>
<none/>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -231,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.28125.59086.62805</string> </value>
<value> <string>999.31669.11148.21196</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -249,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1583836689.5</float>
<float>1649728041.67</float>
<string>UTC</string>
</tuple>
</state>
......@@ -258,17 +263,20 @@
</item>
</dictionary>
</list>
<none/>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -316,8 +324,9 @@
</item>
</dictionary>
</list>
<none/>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -553,10 +553,10 @@
return "";
}
gk.declareMethod("loadJSONSchema", function (url) {
gk.declareMethod("loadJSONSchema", function (url, serialisation) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.loadJSONSchema(url);
return gadget.loadJSONSchema(url, serialisation);
});
})
......@@ -648,10 +648,10 @@
});
})
.declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter) {
.declareMethod('renderParameterForm', function (json_url, default_dict, restricted_parameter, serialisation) {
var g = this;
return g.loadJSONSchema(json_url)
return g.loadJSONSchema(json_url, serialisation)
.push(function (json) {
var fieldset_list = g.element.querySelectorAll('fieldset'),
fieldset = document.createElement("fieldset");
......@@ -944,7 +944,8 @@
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;
}
return gadget.renderParameterForm(parameter_json_schema_url,
parameter_dict, restricted_parameter);
parameter_dict, restricted_parameter,
options.serialisation);
})
.push(function () {
var i, div_list = gadget.element.querySelectorAll('.slapos-parameter-dict-key > div'),
......
......@@ -280,7 +280,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>999.21924.60509.42444</string> </value>
<value> <string>999.23324.48841.24558</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -298,7 +298,7 @@
</tuple>
<state>
<tuple>
<float>1649185724.55</float>
<float>1649686520.32</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -79,9 +79,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
<value> <string>Generic Core schema meta-schema Draft4</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......@@ -156,11 +154,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -204,16 +204,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -236,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.7498.47076.23671</string> </value>
<value> <string>999.27453.45440.44629</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +258,7 @@
</tuple>
<state>
<tuple>
<float>1420558741.68</float>
<float>1649434525.63</float>
<string>UTC</string>
</tuple>
</state>
......@@ -263,16 +267,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -320,7 +328,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
\ No newline at end of file
......@@ -16,7 +16,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -59,7 +58,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -71,19 +69,19 @@
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
<value> <string>text/plain</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_slapos_load_schema.html</string> </value>
<value> <string>slapos_load_meta_schema_json_in_xml.json</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Parameter</string> </value>
<value> <string>Meta schema for validate the json-in-xml serialisation</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_slapos_load_schema_html</string> </value>
<value> <string>rjs_slapos_load_meta_schema_xml_in_json_json</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -101,7 +99,9 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget for Load JSON Schema</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -152,11 +152,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -187,7 +189,7 @@
</tuple>
<state>
<tuple>
<float>1420555575.29</float>
<float>1649442421.11</float>
<string>UTC</string>
</tuple>
</state>
......@@ -200,16 +202,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -232,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.28812.63809.3840</string> </value>
<value> <string>999.27603.1231.41864</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1460381638.62</float>
<float>1649442481.77</float>
<string>UTC</string>
</tuple>
</state>
......@@ -259,16 +265,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -307,7 +317,7 @@
</tuple>
<state>
<tuple>
<float>1420551335.83</float>
<float>1649442044.14</float>
<string>UTC</string>
</tuple>
</state>
......@@ -316,7 +326,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Meta-schema for XML serialisaton schemas",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
},
"customProperties": {
"definitions": {
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "string" ]
}
},
"type": "object",
"properties": {
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/customProperties/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/customProperties/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#/definitions/customProperties" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -16,7 +16,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -59,35 +58,30 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/plain</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>slapos_parameter_form.js</string> </value>
<value> <string>slapos_load_meta_schema_xml.json</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
<value> <string>Meta schema for XML serialisation schemas.</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_slapos_parameter_form_js</string> </value>
<value> <string>rjs_slapos_load_meta_schema_xml_json</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -95,7 +89,7 @@
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
......@@ -105,7 +99,9 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>slapos_parameter_form.js</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -156,11 +152,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -191,7 +189,7 @@
</tuple>
<state>
<tuple>
<float>1420555875.95</float>
<float>1649434615.38</float>
<string>UTC</string>
</tuple>
</state>
......@@ -204,16 +202,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -236,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.11326.56915.27153</string> </value>
<value> <string>999.27474.41330.28689</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1474892353.46</float>
<float>1649440822.18</float>
<string>UTC</string>
</tuple>
</state>
......@@ -263,16 +265,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -311,7 +317,7 @@
</tuple>
<state>
<tuple>
<float>1420555828.84</float>
<float>1649434537.05</float>
<string>UTC</string>
</tuple>
</state>
......@@ -320,7 +326,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Slapos Software Release instantiation descriptor",
"additionalProperties": false,
"required": [
"software-type"
],
"properties": {
"name": {
"description": "A short human-friendly name for the sofware release",
"default": "",
"type": "string"
},
"description": {
"description": "A short description of the sofware release",
"default": "",
"type": "string"
},
"serialisation": {
"description": "How the parameters and results are serialised",
"enum": [
"xml",
"json-in-xml"
],
"type": "string"
},
"software-type": {
"description": "Existing software types",
"patternProperties": {
".*": {
"description": "Software type declaration",
"additionalProperties": false,
"required": [
"request",
"response"
],
"properties": {
"title": {
"description": "A human-friendly title of the software type",
"default": "",
"type": "string"
},
"description": {
"description": "A human-friendly description of the software type",
"default": "",
"type": "string"
},
"serialisation": {
"description": "How the parameters and results are serialised, if different from global setting, required if global setting is not provided",
"enum": [
"xml",
"json-in-xml"
],
"type": "string"
},
"request": {
"description": "URL, relative to Software Release base path, of a json schema for values expected by instance of current software type",
"type": "string"
},
"response": {
"description": "URL, relative to Software Release base path, of a json schema for values published by instance of current software type",
"type": "string"
},
"software-type": {
"description": "Value to be used as software type instead of the software type id (in order to use multiple diferent forms for the same software type).",
"type": "string"
},
"shared": {
"description": "Define if the request will request a Slave or Software Instance.",
"default": "false",
"type": "boolean"
},
"index": {
"description": "Value to use instead of software type id to sort them (in order to display most relevant software types earlier in a list, for example)",
"default": 0,
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -16,7 +16,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -59,7 +58,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -69,19 +67,22 @@
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/plain</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>slapos_request_form.js</string> </value>
<value> <string>slapos_load_software_schema.json</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
<value> <string>Json schema for the validation of the software.cfg.json\n
https://lab.nexedi.com/nexedi/slapos/raw/master/schema.json#</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_slapos_request_form_js</string> </value>
<value> <string>rjs_slapos_load_software_schema_json</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -89,7 +90,7 @@
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
......@@ -99,7 +100,9 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>slapos_request_form.js</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -150,11 +153,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -185,7 +190,7 @@
</tuple>
<state>
<tuple>
<float>1420557834.51</float>
<float>1649721303.44</float>
<string>UTC</string>
</tuple>
</state>
......@@ -198,16 +203,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -230,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.63528.40790.54084</string> </value>
<value> <string>999.32250.5458.58606</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1462378412.41</float>
<float>1649721266.53</float>
<string>UTC</string>
</tuple>
</state>
......@@ -257,16 +266,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -305,7 +318,7 @@
</tuple>
<state>
<tuple>
<float>1420557463.67</float>
<float>1649721038.85</float>
<string>UTC</string>
</tuple>
</state>
......@@ -314,7 +327,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -209,6 +209,10 @@ web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_gadget_slapos_utils_js
web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_slapos_load_software_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs
......
......@@ -211,6 +211,10 @@ web_page_module/rjs_gadget_trial_panel_html
web_page_module/rjs_gadget_trial_panel_js
web_page_module/rjs_leaflet_css
web_page_module/rjs_leaflet_js
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_meta_schema_xml_in_json_json
web_page_module/rjs_slapos_load_meta_schema_xml_json
web_page_module/rjs_slapos_load_software_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
web_site_module/hostingjs
......
<!DOCTYPE html>
<html manifest="gadget_erp5.appcache">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ERP5</title>
<link rel="shortcut icon" href="favicon.ico">
<script src="rsvp.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="tv4.min.js" type="text/javascript"></script>
<script src="URI.js" type="text/javascript"></script>
<script src="jio.js" type="text/javascript"></script>
<script src="slapos_load_schema.js" type="text/javascript"></script>
</head>
<body>
<div />
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $ */
(function (window, rJS, $, RSVP) {
"use strict";
var gk = rJS(window);
function getJSON(url) {
var protocol = URI(url).protocol();
if ( protocol === "http" || protocol === "https" ) {
if (URI(window.location).protocol() !== protocol) {
throw new Error("You cannot mixed http and https calls");
}
}
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
})
.then(function (evt) {
return evt.target.responseText;
});
});
}
function resolveLocalReference(ref, schema) {
// 2 here is for #/
var i, ref_path = ref.substr(2, ref.length),
parts = ref_path.split("/");
if (parts.length === 1 && parts[0] === "") {
// It was uses #/ to reference the entire json so just return it.
return schema;
}
for (i = 0; i < parts.length; i += 1) {
schema = schema[parts[i]];
}
return schema;
}
function resolveReference(partial_schema, schema, base_url) {
var parts,
external_schema,
ref = partial_schema.$ref;
if (ref === undefined) {
return RSVP.Queue().push(function () {
return partial_schema;
});
}
if (ref.substr(0, 1) === "#") {
return RSVP.Queue().push(function () {
return resolveLocalReference(ref, schema);
});
}
return RSVP.Queue().push(function () {
if (URI(ref).protocol() === "") {
if (base_url !== undefined) {
ref = base_url + "/" + ref;
}
}
return getJSON(ref);
})
.push(function (json) {
external_schema = JSON.parse(json);
parts = ref.split("#");
ref = "#" + parts[1];
return resolveLocalReference(ref, external_schema);
});
}
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
// Inspired from https://github.com/nexedi/dream/blob/master/dream/platform/src/jsplumb/jsplumb.js#L398
function expandSchema(json_schema, full_schema, base_url) {
var i,
expanded_json_schema = clone(json_schema) || {};
if (!expanded_json_schema.properties) {
expanded_json_schema.properties = {};
}
return RSVP.Queue().push(function () {
if (json_schema.$ref) {
return resolveReference(
json_schema,
full_schema,
base_url
)
.push(function (remote_schema) {
return expandSchema(
remote_schema,
full_schema,
base_url
);
}).push(function (referencedx) {
$.extend(expanded_json_schema, referencedx);
delete expanded_json_schema.$ref;
return true;
});
}
return true;
}).push(function () {
var property, queue = RSVP.Queue();
function wrapperResolveReference(p) {
return resolveReference(
json_schema.properties[p],
full_schema,
base_url
).push(function (external_schema) {
// console.log(p);
return expandSchema(
external_schema,
full_schema,
base_url
)
.push(function (referencedx) {
$.extend(expanded_json_schema.properties[p], referencedx);
if (json_schema.properties[p].$ref) {
delete expanded_json_schema.properties[p].$ref;
}
return referencedx;
});
});
}
// expand ref in properties
for (property in json_schema.properties) {
if (json_schema.properties.hasOwnProperty(property)) {
queue.push(
wrapperResolveReference.bind(this, property)
);
}
}
return queue;
})
.push(function () {
var zqueue = RSVP.Queue();
function wrapperExpandSchema(p) {
return expandSchema(
json_schema.allOf[p],
full_schema,
base_url
).push(function (referencedx) {
if (referencedx.properties) {
$.extend(
expanded_json_schema.properties,
referencedx.properties
);
delete referencedx.properties;
}
$.extend(expanded_json_schema, referencedx);
});
}
if (json_schema.allOf) {
for (i = 0; i < json_schema.allOf.length; i += 1) {
zqueue.push(wrapperExpandSchema.bind(this, i));
}
}
return zqueue;
})
.push(function () {
if (expanded_json_schema.allOf) {
delete expanded_json_schema.allOf;
}
if (expanded_json_schema.$ref) {
delete expanded_json_schema.$ref;
}
// console.log(expanded_json_schema);
return clone(expanded_json_schema);
});
}
function getMetaJSONSchema() {
return getJSON("../../renderjs/slapos_load_meta_schema.json");
}
function validateJSONSchema(json, base_url) {
return getMetaJSONSchema()
.push(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
}
return JSON.parse(json);
})
.push(function (schema) {
return expandSchema(schema, schema, base_url);
});
}
gk
.declareMethod("loadJSONSchema", function (url) {
return getJSON(url)
.push(function (json) {
var base_url, url_uri;
url_uri = URI(url);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = url.split(url_uri.path())[0] + base_url.join("/");
return validateJSONSchema(json, base_url);
});
})
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.push(function (json) {
return JSON.parse(json);
});
})
.declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) {
return getJSON(schema_url)
.push(function (json) {
return JSON.parse(json);
})
.push(function (json_object) {
var parameter_schema_url,
st,
base_url,
url_uri = URI(schema_url);
for (st in json_object["software-type"]) {
if (json_object["software-type"].hasOwnProperty(st)) {
if (st === software_type) {
parameter_schema_url = json_object["software-type"][st].request;
}
}
}
if (URI(parameter_schema_url).protocol() === "") {
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
if (base_url !== undefined) {
parameter_schema_url = base_url + "/" + parameter_schema_url;
}
}
return getJSON(parameter_schema_url)
.push(function (json) {
var schema = JSON.parse(json);
return expandSchema(schema, schema, base_url)
.push(function (loaded_json) {
return tv4.validateMultiple(generated_json, loaded_json);
});
});
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.push(function (json) {
var base_url,
url_uri = URI(schema_url),
schema = JSON.parse(json);
base_url = url_uri.path().split("/");
base_url.pop();
base_url = schema_url.split(url_uri.path())[0] + base_url.join("/");
return expandSchema(schema, schema, base_url)
.push(function (loaded_schema) {
return tv4.validateMultiple(generated_json, loaded_schema);
});
});
});
}(window, rJS, $, RSVP));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>slapos_load_schema.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_slapos_load_schema_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>slapos_load_schema.js</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>002</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1425591032.03</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>941.48697.33489.29337</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1426706745.9</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1425591012.56</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, jQuery, jIO, tv4, JSON */
(function (window, rJS) {
"use strict";
var gk = rJS(window);
function getJSON(url) {
return jIO.util.ajax({
url: url
})
.then(function (evt) {
return evt.target.responseText;
});
}
function getMetaJSONSchema() {
return getJSON("slapos_load_meta_schema.json");
}
function validateJSONSchema(json) {
return getMetaJSONSchema()
.then(function (meta_schema) {
if (!tv4.validate(json, meta_schema)) {
throw new Error("Non valid JSON schema " + json);
}
return JSON.parse(json);
});
}
gk
.declareMethod("loadJSONSchema", function (url) {
return getJSON(url)
.then(function (json) {
return validateJSONSchema(json);
});
})
.declareMethod("loadSoftwareJSON", function (url) {
return getJSON(url)
.then(function (json) {
return JSON.parse(json);
});
})
.declareMethod("validateJSON", function (schema_url, generated_json) {
return getJSON(schema_url)
.then(function (json) {
return tv4.validateMultiple(generated_json, json);
});
});
}(window, rJS, jQuery));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>slapos_load_schema.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_slapos_load_schema_js_backup</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>slapos_load_schema.js</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>archive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1425591032.04</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>archived</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>941.28525.1724.13670</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1425493494.84</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1420554890.96</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, btoa, atob, $, XMLSerializer, jQuery, URI, vkbeautify */
(function (window, document, rJS, $, XMLSerializer, jQuery, vkbeautify) {
"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) {
var input = document.createElement("select"),
option = document.createElement("option"),
option_index,
optionz;
input.size = 1;
option.value = "";
if (default_value === undefined) {
option.selected = "selected";
}
input.appendChild(option);
for (option_index in json_field['enum']) {
if (json_field['enum'].hasOwnProperty(option_index)) {
optionz = document.createElement("option");
optionz.value = json_field['enum'][option_index];
optionz.textContent = json_field['enum'][option_index];
if (json_field['enum'][option_index] === default_value) {
optionz.selected = "selected";
}
input.appendChild(optionz);
}
}
return input;
}
function render_textarea(json_field, default_value, data_format) {
var input = document.createElement("textarea");
if (default_value !== undefined) {
if (default_value instanceof Array) {
input.value = default_value.join("\n");
} else {
input.value = default_value;
}
}
input["data-format"] = data_format;
return input;
}
function render_field(json_field, default_value) {
if (json_field['enum'] !== undefined) {
return render_selection(json_field, default_value);
}
if (json_field.type === "boolean") {
json_field['enum'] = [true, false];
if (default_value === "true") {
default_value = true;
}
if (default_value === "false") {
default_value = false;
}
return render_selection(json_field, default_value);
}
if (json_field.type === "array") {
return render_textarea(json_field, default_value, "array");
}
if (json_field.type === "string" && json_field.textarea === true) {
return render_textarea(json_field, default_value, "string");
}
var input = document.createElement("input");
if (default_value !== undefined) {
input.value = default_value;
}
if (json_field.type === "integer") {
input.type = "number";
} else {
input.type = "text";
}
return input;
}
function render_subform(json_field, default_dict, root, path) {
var div_input,
key,
div,
label,
input,
default_value,
default_used_list = [],
default_div,
span_error,
span_info;
if (default_dict === undefined) {
default_dict = {};
}
if (path === undefined) {
path = "/";
}
if (json_field.patternProperties !== undefined) {
if (json_field.patternProperties['.*'] !== undefined) {
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = json_field.description;
/* console.log(key); */
div_input = document.createElement("div");
div_input = document.createElement("div");
div_input.setAttribute("class", "input");
input = document.createElement("input");
input.type = "text";
div_input.appendChild(input);
input = document.createElement("button");
input.value = btoa(JSON.stringify(json_field.patternProperties['.*']));
input.setAttribute("class", "add-sub-form");
input.type = "button";
input.name = path;
input.textContent = "Add";
div_input.appendChild(input);
div.appendChild(div_input);
for (default_value in default_dict) {
if (default_dict.hasOwnProperty(default_value)) {
default_div = document.createElement("div");
default_div.setAttribute("class", "slapos-parameter-dict-key");
label = document.createElement("label");
label.textContent = default_value;
label.setAttribute("class", "slapos-parameter-dict-key");
default_div.appendChild(label);
default_div = render_subform(
json_field.patternProperties['.*'],
default_dict[default_value],
default_div,
path + "/" + default_value);
div.appendChild(default_div);
}
}
root.appendChild(div);
return div;
}
}
for (key in json_field.properties) {
if (json_field.properties.hasOwnProperty(key)) {
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = json_field.properties[key].description;
/* console.log(key); */
label = document.createElement("label");
label.textContent = json_field.properties[key].title;
div.appendChild(label);
div_input = document.createElement("div");
div_input.setAttribute("class", "input");
if (json_field.properties[key].type === 'object') {
div_input = render_subform(json_field.properties[key],
default_dict[key],
div_input,
path + "/" + key);
} else {
input = render_field(json_field.properties[key], default_dict[key]);
input.name = path + "/" + key;
input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input);
}
default_used_list.push(key);
if (json_field.properties[key]['default'] !== undefined) {
span_info = document.createElement("span");
span_info.textContent = '(default = ' + json_field.properties[key]['default'] + ')';
div_input.appendChild(span_info);
}
span_error = document.createElement("span");
span_error.setAttribute("class", "error");
div_input.appendChild(span_error);
div.appendChild(div_input);
root.appendChild(div);
}
}
for (key in default_dict) {
if (default_dict.hasOwnProperty(key)) {
if (default_used_list.indexOf(key) < 0 ) {
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = key;
label = document.createElement("label");
label.textContent = key;
div.appendChild(label);
div_input = document.createElement("div");
div_input.setAttribute("class", "input");
input = render_field({"type": "string", "textarea": true}, default_dict[key]);
input.name = path + "/" + key;
input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input);
default_used_list.push(key);
span_info = document.createElement("span");
span_info.textContent = '(Not part of the schema)';
div_input.appendChild(span_info);
span_error = document.createElement("span");
span_error.setAttribute("class", "error");
div_input.appendChild(span_error);
div.appendChild(div_input);
root.appendChild(div);
}
}
}
return root;
}
function getFormValuesAsJSONDict(element) {
var json_dict = {},
entry,
multi_level_dict = {};
$(element.querySelectorAll(".slapos-parameter")).each(function (key, input) {
if (input.value !== "") {
if (input.type === 'number') {
json_dict[input.name] = parseInt(input.value, 10);
} else if (input.value === "true") {
json_dict[input.name] = true;
} else if (input.value === "false") {
json_dict[input.name] = false;
} else if (input.tagName === "TEXTAREA") {
if (input["data-format"] === "string") {
json_dict[input.name] = input.value;
} else {
json_dict[input.name] = input.value.split('\n');
}
} else {
json_dict[input.name] = input.value;
}
}
});
function convertOnMultiLevel(key, value, d) {
var i,
kk,
key_list = key.split("/");
for (i = 2; i < key_list.length; i += 1) {
kk = key_list[i];
if (i === key_list.length - 1) {
d[kk] = value;
} else {
if (!d.hasOwnProperty(kk)) {
d[kk] = {};
}
d = d[kk];
}
}
}
for (entry in json_dict) {
if (json_dict.hasOwnProperty(entry)) {
convertOnMultiLevel(entry, json_dict[entry], multi_level_dict);
}
}
return multi_level_dict;
}
function validateForm(gadget, 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) {
var subform_json = JSON.parse(atob(element.value)),
input_text = element.parentNode.querySelector("input[type='text']"),
div = document.createElement("div"),
label;
if (input_text.value === "") {
return false;
}
div.setAttribute("class", "slapos-parameter-dict-key");
label = document.createElement("label");
label.textContent = input_text.value;
label.setAttribute("class", "slapos-parameter-dict-key");
div.appendChild(label);
div = render_subform(subform_json, {}, div, element.name + "/" + input_text.value);
element.parentNode.parentNode.insertBefore(div, element.parentNode.parentNode.children[1]);
// element.parentNode.parentNode.appendChild(div);
return div;
}
function loadEventList(gadget) {
var g = gadget,
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'),
i,
promise_list = [];
for (i = 0; i < field_list.length; i = i + 1) {
promise_list.push(loopEventListener(
field_list[i],
'change',
false,
validateForm.bind(g, g, g.options.json_url)
));
}
for (i = 0; i < button_list.length; i = i + 1) {
promise_list.push(loopEventListener(
button_list[i],
'click',
false,
addSubForm.bind(g, button_list[i])
));
}
for (i = 0; i < label_list.length; i = i + 1) {
promise_list.push(loopEventListener(
label_list[i],
'click',
false,
collapseParameter.bind(g, label_list[i])
));
}
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 "";
}
gk.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareMethod("loadJSONSchema", function (url) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.loadJSONSchema(url);
});
})
.declareMethod("validateJSONForSoftwareType", function (schema_url, softwaretype, generated_json) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.validateJSONForSoftwareType(schema_url, softwaretype, generated_json);
});
})
.declareMethod("loadSoftwareJSON", function (url) {
return this.getDeclaredGadget('loadschema')
.push(function (gadget) {
return gadget.loadSoftwareJSON(url);
});
})
.declareAcquiredMethod('pleaseRedirectMyHash', 'pleaseRedirectMyHash')
.declareMethod('processValidation', function (json_url) {
var g = this,
software_type = getSoftwareTypeFromForm(g.props.element),
json_dict = getFormValuesAsJSONDict(g.props.element),
serialisation_type = getSerialisationTypeFromForm(g.props.element);
if (software_type === "") {
if (g.options.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) {
var error_index,
parameter_hash_input = g.props.element.querySelectorAll('.parameter_hash_output')[0],
field_name,
div,
divm,
missing_index,
missing_field_name,
xml_output;
$(g.props.element.querySelectorAll("span.error")).each(function (i, span) {
span.textContent = "";
});
$(g.props.element.querySelectorAll("div.error-input")).each(function (i, div) {
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) {
return xml_output;
}
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;
div.setAttribute("class", "slapos-parameter error-input");
div.querySelector("span.error").textContent = validation.errors[error_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;
}
}
return "ERROR";
});
})
.declareMethod('renderParameterForm', function (json_url, default_dict) {
var g = this;
return g.loadJSONSchema(json_url)
.push(function (json) {
var fieldset_list = g.props.element.querySelectorAll('fieldset'),
fieldset = document.createElement("fieldset");
fieldset = render_subform(json, default_dict, fieldset);
$(fieldset_list[1]).replaceWith(fieldset);
return fieldset_list;
});
})
.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.props.element.querySelectorAll('fieldset'),
button0 = g.props.element.querySelector("button.slapos-show-raw-parameter"),
button1 = g.props.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", "field_your_instance_xml");
textarea.textContent = content;
span_error.setAttribute("class", "error");
span_error.textContent = "You got one error when loading json schema, so the form is not going to be rendered: " + error;
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.props.element.querySelectorAll('fieldset');
div.setAttribute("class", "field");
textarea.setAttribute("rows", "10");
textarea.setAttribute("cols", "80");
textarea.setAttribute("name", "field_your_instance_xml");
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) {
if (options.json_url === undefined) {
throw new Error("undefined json_url");
}
var g = this,
to_hide = g.props.element.querySelector("button.slapos-show-form"),
to_show = g.props.element.querySelector("button.slapos-show-raw-parameter"),
softwaretype;
if (to_hide !== null) {
$(to_hide).addClass("hidden-button");
}
if (to_show !== null) {
$(to_show).removeClass("hidden-button");
}
this.options = options;
return g.loadSoftwareJSON(g.options.json_url).push(function (json) {
var option_index,
option,
option_selected = options.parameter.softwaretypeindex,
restricted_softwaretype = options.parameter.restricted_softwaretype,
input = g.props.element.querySelector('select.slapos-software-type'),
parameter_shared = g.props.element.querySelector('input.parameter_shared'),
s_input = g.props.element.querySelector('input.slapos-serialisation-type');
if (options.parameter.softwaretypeindex === undefined) {
option_selected = options.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.parameter.shared === undefined) {
options.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.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.parameter.softwaretype) {
if (options.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.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.parameter.parameter_xml !== undefined) {
if (options.serialisation === "json-in-xml") {
parameter_entry = jQuery.parseXML(
options.parameter.parameter_xml
).querySelector("parameter[id='_']");
if (parameter_entry !== null) {
parameter_dict = JSON.parse(parameter_entry.textContent);
}
} else {
$(jQuery.parseXML(options.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.json_url);
prefix = json_url_uri.path().split("/");
prefix.pop();
prefix = options.json_url.split(json_url_uri.path())[0] + prefix.join("/");
parameter_json_schema_url = prefix + "/" + parameter_json_schema_url;
}
return g.renderParameterForm(parameter_json_schema_url, parameter_dict);
})
.push(function () {
var i, div_list = g.props.element.querySelectorAll('.slapos-parameter-dict-key > div'),
label_list = g.props.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 g;
})
.push(function () {
console.log("FINISHED TO RENDER, RETURNING THE GADGET");
return g;
})
.fail(function (error) {
var parameter_xml = '';
console.log(error.stack);
if (g.options.parameter.parameter_hash !== undefined) {
parameter_xml = atob(g.options.parameter.parameter_hash);
}
return g.renderFailoverTextArea(parameter_xml, error.toString())
.push(function () {
error = undefined;
return g;
});
});
})
.declareService(function () {
var g = this,
element = g.props.element.getElementsByTagName('select')[0];
if (element === undefined) {
return true;
}
function updateParameterForm(evt) {
var e = g.props.element.getElementsByTagName('select')[0],
parameter_shared = g.props.element.querySelector('input.parameter_shared');
if (e === undefined) {
throw new Error("Select not found.");
}
g.options.parameter.softwaretype = e.value;
g.options.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.props.element.querySelector("button.slapos-show-raw-parameter");
if (element === undefined) {
return true;
}
function showRawParameter(evt) {
var e = g.props.element.querySelector("button.slapos-show-raw-parameter"),
to_show = g.props.element.querySelector("button.slapos-show-form"),
parameter_xml;
if (g.options.parameter.parameter_hash !== undefined) {
parameter_xml = atob(g.options.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.props.element.querySelector("button.slapos-show-form");
function showParameterForm(evt) {
var e = g.props.element.getElementsByTagName('select')[0],
to_hide = g.props.element.querySelector("button.slapos-show-form"),
to_show = g.props.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.parameter.softwaretype = e.value;
g.options.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 () {
return loadEventList(this);
})
.declareService(function () {
var g = this;
return g.processValidation(g.options.json_url)
.fail(function (error) {
var parameter_xml = '';
console.log(error.stack);
if (g.options.parameter.parameter_hash !== undefined) {
parameter_xml = atob(g.options.parameter.parameter_hash);
}
return g.renderFailoverTextArea(parameter_xml, error.toString())
.push(function () {
error = undefined;
return g;
});
});
});
}(window, document, rJS, $, XMLSerializer, jQuery, vkbeautify));
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS , $ , console */
(function (window, rJS, $) {
"use strict";
var gk = rJS(window),
json_url = "sample_schema.json",
parameter_gadget_url = "gadget_slapos_parameter_form.html";
gk.declareMethod('getContent', function () {
var g = this;
return g.getDeclaredGadget("parameter")
.push(function(gadget) {
var field_your_instance_xml = gadget.__element.querySelector('textarea[name=field_your_instance_xml]');
if (field_your_instance_xml !== null) {
return "SKIP";
}
return gadget.processValidation(g.options.json_url);
})
.push(function (xml_result) {
if (xml_result === "SKIP") {
/* The raw parameters are already on the request */
return {};
}
return {"field_your_instance_xml": xml_result};
})
.fail(function (e) {
return {};
});
});
gk.declareMethod('render', function (options) {
var g = this;
options.json_url = "../../renderjs/slapos_load_schema_software_type.json";
options.parameter = {};
g.options = options;
if (options.value !== undefined) {
// A JSON where provided via gadgetfield
$.extend(options, JSON.parse(options.value));
delete options.value;
}
if (options.parameter.parameter_hash !== undefined) {
// A JSON where provided via gadgetfield
options.parameter.parameter_xml = atob(options.parameter.parameter_hash);
}
if (options.parameter.json_url !== undefined) {
// A JSON where provided via gadgetfield
options.json_url = options.parameter.json_url;
}
return g.declareGadget(parameter_gadget_url, {'scope': 'parameter'})
.push(function (gadget) {
return gadget.render(options);
}).push(function (gadget) {
var div = g.__element.querySelector(".parameter");
$(div).replaceWith(gadget.__element);
return gadget;
});
});
}(window, rJS, $));
\ No newline at end of file
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_slapos_sample_schema_json
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_slapos_sample_schema_with_remote_json
web_page_module/rjs_gadget_slapos_request_form_html
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_schema_js
web_page_module/rjs_slapos_load_schema_js_backup
web_page_module/rjs_slapos_parameter_form_js
web_page_module/rjs_slapos_request_form_js
web_page_module/slapos-free-trial-*
image_module/vifib.cloud
image_module/vifib.rack
......
......@@ -2,6 +2,7 @@ portal_caches/facebook_server_auth_token_cache_factory
portal_caches/facebook_server_auth_token_cache_factory/persistent_cache_plugin
portal_caches/google_server_auth_token_cache_factory
portal_caches/google_server_auth_token_cache_factory/persistent_cache_plugin
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_tv4_min_js
web_page_module/rjs_vkbeautify_js
portal_types/Certificate Authority Tool
......
image_module/vifib.cloud
image_module/vifib.kvm
image_module/vifib.rack
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_load_schema_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_parameter_form_html
web_page_module/rjs_gadget_slapos_request_form_html
web_page_module/rjs_slapos_load_meta_schema_json
web_page_module/rjs_slapos_load_schema_js
web_page_module/rjs_slapos_load_schema_js_backup
web_page_module/rjs_slapos_parameter_form_js
web_page_module/rjs_slapos_request_form_js
web_page_module/rjs_slapos_sample_schema_json
web_page_module/rjs_slapos_sample_schema_with_remote_json
web_page_module/slapos-free-trial-*
\ 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