Commit 801f592b authored by Romain Courteaud's avatar Romain Courteaud

Lint gadget_erp5_page_slap_load_schema.js

parent dc2fdc3d
/*jslint nomen: true, maxlen: 200, indent: 2*/ /*jslint nomen: true, maxlen: 80, indent: 2*/
/*global window, rJS, console, RSVP, jIO, tv4, URI, JSON*/ /*global window, rJS, RSVP, jIO, tv4, URI*/
(function (window, rJS, RSVP, URI, jIO, tv4) { (function (window, rJS, RSVP, URI, jIO, tv4) {
"use strict"; "use strict";
function extend(obj, obj1) { function extend(obj, obj1) {
for (var i in obj1) { var key;
if (obj1.hasOwnProperty(i)) { for (key in obj1) {
obj[i] = obj1[i]; if (obj1.hasOwnProperty(key)) {
obj[key] = obj1[key];
} }
} }
} }
...@@ -89,7 +90,9 @@ ...@@ -89,7 +90,9 @@
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
// Inspired from https://github.com/nexedi/dream/blob/master/dream/platform/src/jsplumb/jsplumb.js#L398 // Inspired from
// https://github.com/nexedi/dream/blob/master/dream/platform/
// src/jsplumb/jsplumb.js#L398
function expandSchema(json_schema, full_schema, base_url) { function expandSchema(json_schema, full_schema, base_url) {
var i, var i,
expanded_json_schema = clone(json_schema) || {}; expanded_json_schema = clone(json_schema) || {};
...@@ -98,7 +101,8 @@ ...@@ -98,7 +101,8 @@
expanded_json_schema.properties = {}; expanded_json_schema.properties = {};
} }
return RSVP.Queue().push(function () { return RSVP.Queue()
.push(function () {
if (json_schema.$ref) { if (json_schema.$ref) {
return resolveReference( return resolveReference(
json_schema, json_schema,
...@@ -121,21 +125,23 @@ ...@@ -121,21 +125,23 @@
return true; return true;
}) })
.push(function () { .push(function () {
var property,
var property, queue = RSVP.Queue(); queue = RSVP.Queue();
function wrapperResolveReference(p) { function wrapperResolveReference(p) {
return resolveReference( return resolveReference(
json_schema.properties[p], json_schema.properties[p],
full_schema, full_schema,
base_url base_url
).push(function (external_schema) { )
.push(function (external_schema) {
// console.log(p); // console.log(p);
return expandSchema( return expandSchema(
external_schema, external_schema,
full_schema, full_schema,
base_url base_url
) );
})
.push(function (referencedx) { .push(function (referencedx) {
extend(expanded_json_schema.properties[p], referencedx); extend(expanded_json_schema.properties[p], referencedx);
if (json_schema.properties[p].$ref) { if (json_schema.properties[p].$ref) {
...@@ -143,7 +149,6 @@ ...@@ -143,7 +149,6 @@
} }
return referencedx; return referencedx;
}); });
});
} }
// expand ref in properties // expand ref in properties
...@@ -196,6 +201,7 @@ ...@@ -196,6 +201,7 @@
}); });
} }
/*
function getMetaJSONSchema() { function getMetaJSONSchema() {
return getJSON("slapos_load_meta_schema.json"); return getJSON("slapos_load_meta_schema.json");
} }
...@@ -209,6 +215,7 @@ ...@@ -209,6 +215,7 @@
return expandSchema(schema, schema, base_url); return expandSchema(schema, schema, base_url);
}); });
} }
*/
rJS(window) rJS(window)
.declareMethod("loadJSONSchema", function (url) { .declareMethod("loadJSONSchema", function (url) {
...@@ -224,7 +231,9 @@ ...@@ -224,7 +231,9 @@
return getJSON(url); return getJSON(url);
}) })
.declareMethod("validateJSONForSoftwareType", function (schema_url, software_type, generated_json) { .declareMethod("validateJSONForSoftwareType", function (schema_url,
software_type,
generated_json) {
var base_url = getBaseUrl(schema_url); var base_url = getBaseUrl(schema_url);
return getJSON(schema_url) return getJSON(schema_url)
.push(function (json_object) { .push(function (json_object) {
......
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