Commit 007d8fc1 authored by Jérome Perrin's avatar Jérome Perrin

Implement getContent on fieldset gadget and use it

parent 86024186
...@@ -4,39 +4,13 @@ ...@@ -4,39 +4,13 @@
"use strict"; "use strict";
function saveForm(gadget) { function saveForm(gadget) {
var general = {}, var general;
field_gadget_list;
return gadget.getDeclaredGadget('fieldset') return gadget.getDeclaredGadget('fieldset')
.push(function (fieldset_gadget) { .push(function (fieldset_gadget) {
return fieldset_gadget.getFieldGadgetList(); return fieldset_gadget.getContent();
}) })
.push(function (field_gadgets) { .push(function (content) {
field_gadget_list = field_gadgets; general = content;
})
.push(function () {
var i,
promise_list = [];
for (i = 0; i < field_gadget_list.length; i += 1) {
promise_list.push(field_gadget_list[i].getContent());
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
result,
key;
for (i = 0; i < result_list.length; i += 1) {
result = result_list[i];
for (key in result) {
if (result.hasOwnProperty(key)) {
// Drop empty
if (result[key]) {
general[key] = result[key];
}
}
}
}
// Always get a fresh version, to prevent deleting spreadsheet & co // Always get a fresh version, to prevent deleting spreadsheet & co
return gadget.aq_getAttachment({ return gadget.aq_getAttachment({
"_id": gadget.props.jio_key, "_id": gadget.props.jio_key,
......
...@@ -79,8 +79,25 @@ ...@@ -79,8 +79,25 @@
return queue; return queue;
}) })
.declareMethod("getFieldGadgetList", function () { // getContent of all subfields
return this.props.field_gadget_list; .declareMethod("getContent", function () {
var i, promise_list = [];
for (i = 0; i < this.props.field_gadget_list.length; i += 1) {
promise_list.push(this.props.field_gadget_list[i].getContent());
}
return RSVP.Queue()
.push(function () { return RSVP.all(promise_list); })
.push(function (result_list) {
var name, result = {};
for (i = 0; i < result_list.length; i += 1) {
for (name in result_list[i]) {
if (result_list[i].hasOwnProperty(name)) {
result[name] = result_list[i][name];
}
}
}
return result;
});
}); });
......
...@@ -405,10 +405,10 @@ ...@@ -405,10 +405,10 @@
function updateElementData(gadget, node_id, data) { function updateElementData(gadget, node_id, data) {
var element_id = gadget.props.node_container[node_id].element_id, var element_id = gadget.props.node_container[node_id].element_id,
new_id = data.id; new_id = data.id;
if (data.name) { if (data.data.name) {
$(gadget.props.element).find("#" + element_id).text(data.name) $(gadget.props.element).find("#" + element_id).text(data.data.name)
.append('<div class="ep"></div></div>'); .append('<div class="ep"></div></div>');
gadget.props.node_container[node_id].name = data.name; gadget.props.node_container[node_id].name = data.data.name;
} }
delete data.id; delete data.id;
$.extend(gadget.props.node_container[node_id], data.data); $.extend(gadget.props.node_container[node_id], data.data);
...@@ -485,19 +485,6 @@ ...@@ -485,19 +485,6 @@
// onDataChange(); // onDataChange();
// } // }
function saveNode(evt, gadget, node_id) {
var i,
data = {
"id": $(evt.target[1]).val(),
"name": $(evt.target[2]).val()
};
data.data = {};
for (i = 3; i < evt.target.length - 1; i += 1) {
data.data[evt.target[i].name] = $(evt.target[i]).val();
}
updateElementData(gadget, node_id, data);
}
function openNodeDialog(gadget, element, config_dict) { function openNodeDialog(gadget, element, config_dict) {
var node_id = getNodeId(gadget.props.node_container, element.id), var node_id = getNodeId(gadget.props.node_container, element.id),
node_data = gadget.props.node_container[node_id], node_data = gadget.props.node_container[node_id],
...@@ -505,7 +492,6 @@ ...@@ -505,7 +492,6 @@
property_list = config_dict[element_type].property_list || [], property_list = config_dict[element_type].property_list || [],
node_edit_popup = $(gadget.props.element).find('#popup-edit-template'), node_edit_popup = $(gadget.props.element).find('#popup-edit-template'),
fieldset_element, fieldset_element,
save_promise,
delete_promise; delete_promise;
if (node_edit_popup.length !== 0) { if (node_edit_popup.length !== 0) {
...@@ -521,6 +507,7 @@ ...@@ -521,6 +507,7 @@
node_data.id = node_id; node_data.id = node_id;
if (property_list.length === 0 || property_list[0].id !== "id") { if (property_list.length === 0 || property_list[0].id !== "id") {
// XXX name & id should not be handled differently in form.
property_list.unshift({ property_list.unshift({
"_class": "Dream.Property", "_class": "Dream.Property",
"id": "name", "id": "name",
...@@ -536,17 +523,27 @@ ...@@ -536,17 +523,27 @@
}); });
} }
save_promise = new RSVP.Queue() function save_promise(fieldset_gadget, node_id) {
.push(function () { return RSVP.Queue()
return promiseEventListener( .push(function () {
node_edit_popup.find("form")[0], return promiseEventListener(
'submit', node_edit_popup.find("form")[0],
false 'submit',
); false
}) );
.push(function (evt) { })
return saveNode(evt, gadget, node_id); .push(function (evt) {
}); var data = {
// XXX id should not be handled differently ...
"id": $(evt.target[1]).val(),
"data": {}
};
return fieldset_gadget.getContent().then(function (r) {
$.extend(data.data, r);
updateElementData(gadget, node_id, data);
});
});
}
delete_promise = new RSVP.Queue() delete_promise = new RSVP.Queue()
.push(function () { .push(function () {
...@@ -565,15 +562,17 @@ ...@@ -565,15 +562,17 @@
scope: 'fieldset' scope: 'fieldset'
}) })
.push(function (fieldset_gadget) { .push(function (fieldset_gadget) {
return fieldset_gadget.render(property_list, node_data); return RSVP.all([fieldset_gadget,
fieldset_gadget.render(property_list, node_data)]);
}) })
.push(function () { .push(function (fieldset_gadget) {
node_edit_popup.enhanceWithin(); node_edit_popup.enhanceWithin();
node_edit_popup.popup('open'); node_edit_popup.popup('open');
return fieldset_gadget[0];
}) })
.push(function () { .push(function (fieldset_gadget) {
return RSVP.any([ return RSVP.any([
save_promise, save_promise(fieldset_gadget, node_id),
delete_promise delete_promise
]); ]);
}) })
......
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