Commit 100bde26 authored by Sebastien Robin's avatar Sebastien Robin

officejs task app: implement saving of dates changes in the planning

parent 8cd4d1b3
...@@ -15,9 +15,15 @@ ...@@ -15,9 +15,15 @@
<body> <body>
<div class="planning-error-message"></div> <div class="planning-error-message"></div>
<div class='document-content'></div> <form class="view-web-page-form">
<div class='document-content'></div>
</div>
<button type="submit" data-i18n="Save" style="display:none;">Save</button>
</div>
</form>
</body> </body>
</html> </html>
/*globals window, RSVP, rJS, console*/ /*globals window, RSVP, rJS, loopEventListener, console*/
/*jslint indent: 2, nomen: true, maxlen: 80*/ /*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) { (function (window, RSVP, rJS) {
"use strict"; "use strict";
var PLANNING_WIDGET_GADGET_URL = "planning/"; var PLANNING_WIDGET_GADGET_URL = "planning/";
function saveContent(gadget, submit_event) {
console.log("Going to save the content of the planning");
return gadget.property_dict.planning_widget.saveContent();
}
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
g.props = {}; g.property_dict = {};
return g.getElement() return g.getElement()
.push(function (element) { .push(function (element) {
g.props.element = element; g.property_dict.element = element;
g.props.deferred = RSVP.defer(); g.property_dict.deferred = RSVP.defer();
}); });
}) })
.ready(function (g) { .ready(function (g) {
...@@ -24,7 +31,7 @@ ...@@ -24,7 +31,7 @@
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
g.props.translation_dict = { g.property_dict.translation_dict = {
"validated": result_list[0], "validated": result_list[0],
"invalidated": result_list[1], "invalidated": result_list[1],
"Not synced!": result_list[2], "Not synced!": result_list[2],
...@@ -47,10 +54,10 @@ ...@@ -47,10 +54,10 @@
// XXX jIO does not create UUID with module inside // XXX jIO does not create UUID with module inside
if (result.data.rows[i].id.indexOf("module") === -1) { if (result.data.rows[i].id.indexOf("module") === -1) {
result.data.rows[i].value.state = result.data.rows[i].value.state =
gadget.props.translation_dict["Not synced!"]; gadget.property_dict.translation_dict["Not synced!"];
} else { } else {
result.data.rows[i].value.state = result.data.rows[i].value.state =
gadget.props.translation_dict[ gadget.property_dict.translation_dict[
result.data.rows[i].value.local_state || result.data.rows[i].value.local_state ||
"Waiting for approval" "Waiting for approval"
]; ];
...@@ -59,6 +66,15 @@ ...@@ -59,6 +66,15 @@
return result; return result;
}); });
}) })
.allowPublicAcquisition('triggerSubmit', function () {
return this.property_dict.element.querySelector('button').click();
})
.declareMethod('triggerSubmit', function () {
return this.property_dict.element.querySelector('button').click();
})
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
...@@ -69,18 +85,18 @@ ...@@ -69,18 +85,18 @@
]); ]);
}) })
.push(function (answer_list) { .push(function (answer_list) {
gadget.props.portal_type = answer_list[0]; gadget.property_dict.portal_type = answer_list[0];
gadget.props.document_title_plural = answer_list[1]; gadget.property_dict.document_title_plural = answer_list[1];
return gadget.getUrlFor({page: "add_document"}); return gadget.getUrlFor({page: "add_document"});
}) })
.push(function (url) { .push(function (url) {
return gadget.updateHeader({ return gadget.updateHeader({
title: gadget.props.document_title_plural, title: gadget.property_dict.document_title_plural,
add_url: url save_action: true
}); });
}) })
.push(function () { .push(function () {
return gadget.props.deferred.resolve(); return gadget.property_dict.deferred.resolve();
}); });
}) })
...@@ -93,7 +109,7 @@ ...@@ -93,7 +109,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.props.deferred.promise; return gadget.property_dict.deferred.promise;
}) })
.push(function () { .push(function () {
return gadget.declareGadget( return gadget.declareGadget(
...@@ -101,18 +117,19 @@ ...@@ -101,18 +117,19 @@
{ {
scope: "planning", scope: "planning",
sandbox: "iframe", sandbox: "iframe",
element: gadget.props.element.querySelector(".document-content") element: gadget.property_dict.element.querySelector(".document-content")
} }
); );
}) })
.push(function (planning_gadget) { .push(function (planning_widget) {
var iframe = gadget.props.element.querySelector('iframe'); var iframe = gadget.property_dict.element.querySelector('iframe');
iframe.setAttribute( iframe.setAttribute(
'style', 'style',
'width:100%; border: 0 none; height: 600px' 'width:100%; border: 0 none; height: 600px'
); );
text_gadget = planning_gadget; text_gadget = planning_widget;
return planning_gadget.render({ gadget.property_dict.planning_widget = planning_widget;
return planning_widget.render({
search_page: 'planning', search_page: 'planning',
mapping: {title: 'title', mapping: {title: 'title',
start: 'start_date', start: 'start_date',
...@@ -137,7 +154,7 @@ ...@@ -137,7 +154,7 @@
title: 'Modification Date' title: 'Modification Date'
}], }],
query: { query: {
query: 'portal_type:("' + gadget.props.portal_type + '")', query: 'portal_type:("' + gadget.property_dict.portal_type + '")',
select_list: ['title', 'reference', 'start_date', select_list: ['title', 'reference', 'start_date',
'description', 'stop_date', 'modification_date'], 'description', 'stop_date', 'modification_date'],
limit: [0, 30] limit: [0, 30]
...@@ -150,9 +167,9 @@ ...@@ -150,9 +167,9 @@
.fail(function (error) { .fail(function (error) {
console.log("LOADing error, error", error); console.log("LOADing error, error", error);
var display_error_element; var display_error_element;
if (error.message.startsWith("Timeout") === true) { if ((error.message || '').startsWith("Timeout") === true) {
display_error_element = display_error_element =
gadget.props.element.querySelector( gadget.property_dict.element.querySelector(
".planning-error-message" ".planning-error-message"
); );
display_error_element.innerHTML = display_error_element.innerHTML =
...@@ -165,9 +182,27 @@ ...@@ -165,9 +182,27 @@
throw error; throw error;
} }
}); });
}); })
/////////////////////////////////////////
}(window, RSVP, rJS)); // Form submit
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.property_dict.deferred.promise;
})
.push(function () {
return loopEventListener(
gadget.property_dict.element.querySelector('form'),
'submit',
true,
function (event) {
return saveContent(gadget, event);
}
);
});
});
}(window, RSVP, rJS, loopEventListener));
\ No newline at end of file
...@@ -8,6 +8,20 @@ ...@@ -8,6 +8,20 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
function toDateString(date) {
var date_string = "" + date.getUTCFullYear() + "-",
month = date.getUTCMonth() + 1, day = date.getUTCDate();
if (month < 10) {
date_string += "0";
}
date_string += month + "-";
if (day < 10) {
date_string += "0";
}
date_string += day;
return date_string;
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// some methods // some methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -38,6 +52,7 @@ ...@@ -38,6 +52,7 @@
// acquired methods // acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("translate", "translate") .declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
...@@ -45,6 +60,21 @@ ...@@ -45,6 +60,21 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod('saveContent', function (option_dict) {
var gadget = this, id, promise_list = [], task, now = new Date().toISOString();
console.log("going to save from widget", gadget.property_dict.updated_task);
Object.getOwnPropertyNames(gadget.property_dict.updated_task).forEach(
function (value, index, array) {
task = gadget.property_dict.updated_task[value];
console.log("going to save document", value, task);
task.parent_relative_url = "task_module";
task.portal_type = "Task";
task.modification_date = now;
promise_list.push(
gadget.jio_put(value, gadget.property_dict.updated_task[value]));
});
return RSVP.all(promise_list);
})
.declareMethod('render', function (option_dict) { .declareMethod('render', function (option_dict) {
var gadget = this, var gadget = this,
content = '', content = '',
...@@ -80,6 +110,7 @@ ...@@ -80,6 +110,7 @@
cell_list, cell_list,
item_list = [], item_list = [],
item, item,
item_id,
task, task,
i_len, i_len,
i, i,
...@@ -87,15 +118,28 @@ ...@@ -87,15 +118,28 @@
j, j,
link, link,
container, container,
item_dict = {},
timeline, timeline,
task,
items = new vis.DataSet({ items = new vis.DataSet({
type: { start: 'ISODate', end: 'ISODate' } //type: { start: 'ISODate', end: 'ISODate' }
}); });
gadget.property_dict.updated_task = {};
// log changes to the console // log changes to the console
items.on('*', function (event, properties) { items.on('*', function (event, properties) {
console.log(event, properties.items); console.log(event, properties.items);
if (event === "update") {
console.log("we have an update event");
item = properties.data[0];
task = item_dict[item.id];
console.log("this task is updated", task);
task[option_dict.mapping.start] = toDateString(item.start);
task[option_dict.mapping.stop] = toDateString(item.end);
gadget.property_dict.updated_task[item.id] = task;
}
//task = {};
//return gadget.jio_put();
}); });
// planning-widget // planning-widget
...@@ -126,11 +170,13 @@ ...@@ -126,11 +170,13 @@
item = {}; item = {};
link = link_list[j]; link = link_list[j];
task = all_docs_result.data.rows[j].value; task = all_docs_result.data.rows[j].value;
item.id = j; item_id = all_docs_result.data.rows[j].id;
item.content = task.title; item.id = item_id;
item.start = task.start_date; item.content = task[option_dict.mapping.title];
item.end = task.stop_date; item.start = task[option_dict.mapping.start];
item.end = task[option_dict.mapping.stop];
item_list.push(item); item_list.push(item);
item_dict[item_id] = task;
} }
console.log("item_list", item_list); console.log("item_list", item_list);
......
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