Commit b7cd320d authored by Jérome Perrin's avatar Jérome Perrin

lots of cleanups

parent 2272f3e9
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
"use strict"; "use strict";
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
// TODO: save on parent gadget
function saveGraph(evt) { function saveGraph(evt) {
var gadget = this, var gadget = this;
graph_data;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
// Prevent double click // Prevent double click
...@@ -18,11 +18,10 @@ ...@@ -18,11 +18,10 @@
return graph_gadget.getContent(); return graph_gadget.getContent();
}) })
.push(function (body) { .push(function (body) {
console.log("saving", JSON.parse(body));
return gadget.aq_putAttachment({ return gadget.aq_putAttachment({
"_id": gadget.props.jio_key, "_id": gadget.props.jio_key,
"_attachment": "body.json", "_attachment": "body.json",
"_data": body, //JSON.stringify(data, null, 2), "_data": JSON.stringify(JSON.parse(body), null, 2),
"_mimetype": "application/json" "_mimetype": "application/json"
}); });
}) })
...@@ -44,6 +43,7 @@ ...@@ -44,6 +43,7 @@
gadget_klass gadget_klass
// TODO Mixin
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
}) })
......
...@@ -17,15 +17,17 @@ ...@@ -17,15 +17,17 @@
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass gadget_klass
.declareMethod("render", function (property_list, data, key) { .declareMethod("render", function (options, node_id) {
// XXX node_id is added like a property so that one can change the node
// id
var gadget = this, var gadget = this,
queue, queue,
value,
property; property;
gadget.key = key; // used for recursive fieldsets gadget.props.key = options.key; // used for recursive fieldsets
gadget.props.field_gadget_list = []; gadget.props.field_gadget_list = [];
function addField(property, value) {
function addField(property_id, property_definition, value) {
var sub_gadget; var sub_gadget;
queue queue
.push(function () { .push(function () {
...@@ -34,39 +36,29 @@ ...@@ -34,39 +36,29 @@
gadget.props.element.insertAdjacentHTML( gadget.props.element.insertAdjacentHTML(
'beforeend', 'beforeend',
label_template({ label_template({
"for": property.id, "for": property_id,
"name": (property.name || property.id) "name": (property_definition.name || property_id)
}) })
); );
if (property._class === "Dream.PropertyList") { if (property_definition.type === "object") {
// Create a recursive fieldset for this key. // Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html"); return gadget.declareGadget("../fieldset/index.html");
} }
if (property.type === "number") { if (property_definition.type === "number") {
return gadget.declareGadget("../number_field/index.html"); return gadget.declareGadget("../number_field/index.html");
} }
if (property.choice) { if (property_definition.enum) {
return gadget.declareGadget("../list_field/index.html"); return gadget.declareGadget("../list_field/index.html");
} }
return gadget.declareGadget("../string_field/index.html"); return gadget.declareGadget("../string_field/index.html");
}) })
.push(function (gg) { .push(function (gg) {
sub_gadget = gg; sub_gadget = gg;
var choice = property.choice || [], return sub_gadget.render({
default_opt = choice[0] ? [choice[0][1]] : [""]; key: property_id,
value = (data[property.id] === undefined ?
value : data[property.id]);
if (gg.__title === 'Fieldset') {
// XXX there must be a better way instead of using __title ?
return gg.render(property.property_list, value, property.id);
}
return sub_gadget.render({field_json: {
title: (property.description || ''),
key: property.id,
value: value, value: value,
items: choice, property_definition: property_definition
default: default_opt });
}});
}) })
.push(function () { .push(function () {
return sub_gadget.getElement(); return sub_gadget.getElement();
...@@ -79,13 +71,21 @@ ...@@ -79,13 +71,21 @@
queue = new RSVP.Queue() queue = new RSVP.Queue()
.push(function () { .push(function () {
Object.keys(property_list).forEach(function (i) { if (node_id) {
property = property_list[i]; addField('id', {'type': 'string'}, node_id);
value = property._default === undefined ? "" : property._default; }
addField(property, value); Object.keys(options.property_definition.properties
).forEach(function (property_name) {
var property_definition =
options.property_definition.properties[property_name],
value = (options.value || {})[property_name] === undefined
? property_definition._default : options.value[property_name];
// XXX some properties are not editable
if (property_name !== 'coordinate' && property_name !== '_class') {
addField(property_name, property_definition, value);
}
}); });
}); });
return queue; return queue;
}) })
...@@ -99,8 +99,8 @@ ...@@ -99,8 +99,8 @@
.push(function () { return RSVP.all(promise_list); }) .push(function () { return RSVP.all(promise_list); })
.push(function (result_list) { .push(function (result_list) {
var name, result = {}, content = result; var name, result = {}, content = result;
if (gadget.key) { if (gadget.props.key) {
content = result[gadget.key] = {}; content = result[gadget.props.key] = {};
} }
for (i = 0; i < result_list.length; i += 1) { for (i = 0; i < result_list.length; i += 1) {
for (name in result_list[i]) { for (name in result_list[i]) {
......
This diff is collapsed.
...@@ -28,18 +28,18 @@ ...@@ -28,18 +28,18 @@
var select = this.element.getElementsByTagName('select')[0], var select = this.element.getElementsByTagName('select')[0],
i, i,
template, template,
field_json = options.field_json,
tmp = ''; tmp = '';
select.setAttribute('name', field_json.key); select.setAttribute('name', options.key);
for (i = 0; i < field_json.items.length; i += 1) { for (i = 0; i < options.property_definition.enum.length; i += 1) {
if (field_json.items[i][1] === field_json.value) { if (options.property_definition.enum[i] === options.value) {
template = selected_option_template; template = selected_option_template;
} else { } else {
template = option_template; template = option_template;
} }
// XXX value and text are always same in json schema
tmp += template({ tmp += template({
value: field_json.items[i][1], value: options.property_definition.enum[i],
text: field_json.items[i][0] text: options.property_definition.enum[i]
}); });
} }
select.innerHTML += tmp; select.innerHTML += tmp;
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
}); });
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var input = this.element.querySelector('input'), var input = this.element.querySelector('input');
field_json = options.field_json || {}; input.setAttribute('value', options.value);
input.setAttribute('value', field_json.value); input.setAttribute('name', options.key);
input.setAttribute('name', field_json.key); input.setAttribute('title', options.title || options.key);
input.setAttribute('title', field_json.title);
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
}); });
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var input = this.element.querySelector('input'), var input = this.element.querySelector('input');
field_json = options.field_json || {}; input.setAttribute('value', options.value || "");
input.setAttribute('value', field_json.value || ""); input.setAttribute('name', options.key);
input.setAttribute('name', field_json.key); input.setAttribute('title', options.title || options.key);
input.setAttribute('title', field_json.title);
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
(function (window, document, RSVP, rJS, initGadgetMixin) { (function (window, document, RSVP, rJS, initGadgetMixin) {
"use strict"; "use strict";
// XXX use a renderjs utility function for that
/*jslint nomen: true*/ /*jslint nomen: true*/
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
function waitForDragstart(tool) { function waitForDragstart(tool) {
...@@ -19,7 +18,7 @@ ...@@ -19,7 +18,7 @@
callback = function (evt) { callback = function (evt) {
try { try {
evt.dataTransfer.setData('application/json', evt.dataTransfer.setData('application/json',
tool.dataset.class_definition); tool.dataset.class_name);
} catch (e) { } catch (e) {
reject(e); reject(e);
} }
...@@ -49,7 +48,7 @@ ...@@ -49,7 +48,7 @@
tool.className = "tool " + key; tool.className = "tool " + key;
tool.textContent = _class.name || key; tool.textContent = _class.name || key;
tool.draggable = true; tool.draggable = true;
tool.dataset.class_definition = JSON.stringify([key, _class]); tool.dataset.class_name = JSON.stringify(key);
Object.keys(_class.css || {}).forEach(function (k) { Object.keys(_class.css || {}).forEach(function (k) {
tool.style[k] = _class.css[k]; tool.style[k] = _class.css[k];
}); });
......
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