Commit 7885b2ba authored by Rafael Monnerat's avatar Rafael Monnerat

More stuff

parent 55ca9f4d
...@@ -31,6 +31,6 @@ apache2.conf ...@@ -31,6 +31,6 @@ apache2.conf
*~ *~
node_modules/ node_modules/
dev/ #dev/
tmp/ tmp/
.tern-port .tern-port
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
throw error}); throw error});
}; };
var validateJSON = function(json) { var validateJSONSchema = function(json) {
var promise = new RSVP.Promise(function(resolve, reject) { var promise = new RSVP.Promise(function(resolve, reject) {
return resolve(getMetaJSONSchema()); return resolve(getMetaJSONSchema());
...@@ -48,11 +48,23 @@ ...@@ -48,11 +48,23 @@
throw error}); throw error});
}; };
var validateJSON = function(json, generated_json) {
console.log(tv4.validate(generated_json, json));
return generated_json;
};
gk.declareMethod("loadJSONSchema", function(url) { gk.declareMethod("loadJSONSchema", function(url) {
return getJSON(url).then(function(json) { return getJSON(url).then(function(json) {
return validateJSON(json); return validateJSONSchema(json);
}, function(error) { }, function(error) {
throw error}); throw error});
})
.declareMethod("validateJSON", function(schema_url, generated_json) {
return getJSON(schema_url).then(function(json) {
return validateJSON(json, generated_json);
}, function(error) {
throw error});
}); });
}(window, rJS, RSVP, jQuery)); }(window, rJS, RSVP, jQuery));
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
</head> </head>
<body> <body>
<div> <div>
<fieldset id="top">
<label>Software Release URL</label>
<div class="software_release_url"></div>
</fieldset>
<fieldset id="main"> </fieldset> <fieldset id="main"> </fieldset>
<fieldset id="optional"> </fieldset> <fieldset id="optional"> </fieldset>
</div> </div>
......
...@@ -50,27 +50,38 @@ ...@@ -50,27 +50,38 @@
return input; return input;
}; };
gk.ready(function (g) { gk.declareMethod("getJSON", function() {
g.declareGadget(gadget_path_list.connection, {}) for (var key in document.getElementByTagName("input")) {
console.log(input.value);
}
})
.declareMethod('render', function(options) {
if (options.software_release_url === undefined) {
throw "undefined software_release_url";
}
var g = this;
return g.declareGadget(gadget_path_list.connection, {})
.push(function (gadget) { .push(function (gadget) {
return gadget.loadJSONSchema(json_url); return gadget.loadJSONSchema(json_url);
}) })
.push(function (json) { .push(function (json) {
var fieldset = g.__element.getElementsByTagName('fieldset')[0]; var fieldset = document.getElementsByTagName('fieldset')[1];
var fieldset_optional = g.__element.getElementsByTagName('fieldset')[1]; var fieldset_optional = document.getElementsByTagName('fieldset')[2];
for (var key in json.properties) { for (var key in json.properties) {
var div = document.createElement("div"); var div = document.createElement("div");
div.klass = "field"; div.setAttribute("class", "field");
div.title = json.properties[key].description; div.title = json.properties[key].description;
console.log(key); /* console.log(key); */
var label = document.createElement("label"); var label = document.createElement("label");
label.textContent = json.properties[key].title; label.textContent = json.properties[key].title;
div.appendChild(label); div.appendChild(label);
var div_input = document.createElement("div"); var div_input = document.createElement("div");
div.klass = "input"; div.setAttribute("class", "input");
var input = render_field(json.properties[key]); var input = render_field(json.properties[key]);
input.name = key; input.name = key;
input.setAttribute("class", "slapos-parameter");
div_input.appendChild(input); div_input.appendChild(input);
div.appendChild(div_input); div.appendChild(div_input);
...@@ -81,10 +92,6 @@ ...@@ -81,10 +92,6 @@
} }
} }
}); });
}).declareMethod("getCouscou", function() {
var sp = document.createElement("span");
sp.textContent = "couscous";
return sp
}); });
}(window, document, rJS)); }(window, document, rJS));
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../lib/rsvp.min.js" type="text/javascript"></script> <script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script> <script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js"></script>
<script src="slapos_request.js" type="text/javascript"></script> <script src="slapos_request.js" type="text/javascript"></script>
<link rel="stylesheet" href="./slapos_request.css" media="screen" ></link> <link rel="stylesheet" href="./slapos_request.css" media="screen" ></link>
<link rel="http://www.renderjs.org/rel/interface" <link rel="http://www.renderjs.org/rel/interface"
...@@ -15,9 +16,9 @@ ...@@ -15,9 +16,9 @@
data-gadget-url="../slapos_parameter/index.html" data-gadget-url="../slapos_parameter/index.html"
data-gadget-scope="parameter" > data-gadget-scope="parameter" >
</div> </div>
<div id="main"> <button class="update-button" > Update </button>
<textarea></textarea> <div class="debug"> </div>
</div>
</div> </div>
</body> </body>
</html> </html>
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global rJS */ /*global rJS */
(function (window, document, rJS) { (function (window, document, $, rJS) {
"use strict"; "use strict";
var gk = rJS(window); var gk = rJS(window);
var json_url = "../slapos_load_schema/schema.json";
var gadget_path_list = { var gadget_path_list = {
connection: "../slapos_parameter/index.html" parameter: "../slapos_parameter/index.html",
connection: "../slapos_load_schema/index.html"
}; };
gk.ready(function (g) { gk.declareMethod('render', function(options) {
if (options.software_release_url === undefined) {
throw "undefined software_release_url";
}
var g = this;
var gadget = g.declareGadget(gadget_path_list.parameter, {
software_release_url: options.software_instance_url,
json_url: json_url
})
.push(function(gadget) {
return gadget.render(options);
});
var connection_gadget = g.declareGadget(gadget_path_list.connection, {})
g.declareGadget(gadget_path_list.connection, {})
.push(function(gadget) { g.__element.querySelector("div.software_release_url").innerHTML = options.software_release_url;
return gadget.getCouscou();
}) $(this.__element).find(".update-button").click(function(e) {
.push(function (element) { var json_dict = {};
g.__element.querySelector("div#main").innerHTML = element.innerHTML; var input_list = document.getElementsByClassName("slapos-parameter");
}); for (var key in input_list) {
}); if (input_list[key].value !== "") {
json_dict[input_list[key].name] = input_list[key].value;
}
}
json = connection_gadget.validateJSON(json_url, json_dict);
$('div.debug')[0].innerHTML = JSON.stringify(json_dict);
});
});
}(window, document, rJS)); }(window, document, $, rJS));
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