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 @@
<body>
<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>
</html>
/*globals window, RSVP, rJS, console*/
/*globals window, RSVP, rJS, loopEventListener, console*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) {
"use strict";
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)
.ready(function (g) {
g.props = {};
g.property_dict = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.deferred = RSVP.defer();
g.property_dict.element = element;
g.property_dict.deferred = RSVP.defer();
});
})
.ready(function (g) {
......@@ -24,7 +31,7 @@
]);
})
.push(function (result_list) {
g.props.translation_dict = {
g.property_dict.translation_dict = {
"validated": result_list[0],
"invalidated": result_list[1],
"Not synced!": result_list[2],
......@@ -47,10 +54,10 @@
// XXX jIO does not create UUID with module inside
if (result.data.rows[i].id.indexOf("module") === -1) {
result.data.rows[i].value.state =
gadget.props.translation_dict["Not synced!"];
gadget.property_dict.translation_dict["Not synced!"];
} else {
result.data.rows[i].value.state =
gadget.props.translation_dict[
gadget.property_dict.translation_dict[
result.data.rows[i].value.local_state ||
"Waiting for approval"
];
......@@ -59,6 +66,15 @@
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) {
var gadget = this;
return new RSVP.Queue()
......@@ -69,18 +85,18 @@
]);
})
.push(function (answer_list) {
gadget.props.portal_type = answer_list[0];
gadget.props.document_title_plural = answer_list[1];
gadget.property_dict.portal_type = answer_list[0];
gadget.property_dict.document_title_plural = answer_list[1];
return gadget.getUrlFor({page: "add_document"});
})
.push(function (url) {
return gadget.updateHeader({
title: gadget.props.document_title_plural,
add_url: url
title: gadget.property_dict.document_title_plural,
save_action: true
});
})
.push(function () {
return gadget.props.deferred.resolve();
return gadget.property_dict.deferred.resolve();
});
})
......@@ -93,7 +109,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
return gadget.property_dict.deferred.promise;
})
.push(function () {
return gadget.declareGadget(
......@@ -101,18 +117,19 @@
{
scope: "planning",
sandbox: "iframe",
element: gadget.props.element.querySelector(".document-content")
element: gadget.property_dict.element.querySelector(".document-content")
}
);
})
.push(function (planning_gadget) {
var iframe = gadget.props.element.querySelector('iframe');
.push(function (planning_widget) {
var iframe = gadget.property_dict.element.querySelector('iframe');
iframe.setAttribute(
'style',
'width:100%; border: 0 none; height: 600px'
);
text_gadget = planning_gadget;
return planning_gadget.render({
text_gadget = planning_widget;
gadget.property_dict.planning_widget = planning_widget;
return planning_widget.render({
search_page: 'planning',
mapping: {title: 'title',
start: 'start_date',
......@@ -137,7 +154,7 @@
title: 'Modification Date'
}],
query: {
query: 'portal_type:("' + gadget.props.portal_type + '")',
query: 'portal_type:("' + gadget.property_dict.portal_type + '")',
select_list: ['title', 'reference', 'start_date',
'description', 'stop_date', 'modification_date'],
limit: [0, 30]
......@@ -150,9 +167,9 @@
.fail(function (error) {
console.log("LOADing error, error", error);
var display_error_element;
if (error.message.startsWith("Timeout") === true) {
if ((error.message || '').startsWith("Timeout") === true) {
display_error_element =
gadget.props.element.querySelector(
gadget.property_dict.element.querySelector(
".planning-error-message"
);
display_error_element.innerHTML =
......@@ -165,9 +182,27 @@
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 @@
/////////////////////////////////////////////////////////////////
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
/////////////////////////////////////////////////////////////////
......@@ -38,6 +52,7 @@
// acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("redirect", "redirect")
......@@ -45,6 +60,21 @@
/////////////////////////////////////////////////////////////////
// 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) {
var gadget = this,
content = '',
......@@ -80,6 +110,7 @@
cell_list,
item_list = [],
item,
item_id,
task,
i_len,
i,
......@@ -87,15 +118,28 @@
j,
link,
container,
item_dict = {},
timeline,
task,
items = new vis.DataSet({
type: { start: 'ISODate', end: 'ISODate' }
//type: { start: 'ISODate', end: 'ISODate' }
});
gadget.property_dict.updated_task = {};
// log changes to the console
items.on('*', function (event, properties) {
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
......@@ -126,11 +170,13 @@
item = {};
link = link_list[j];
task = all_docs_result.data.rows[j].value;
item.id = j;
item.content = task.title;
item.start = task.start_date;
item.end = task.stop_date;
item_id = all_docs_result.data.rows[j].id;
item.id = item_id;
item.content = task[option_dict.mapping.title];
item.start = task[option_dict.mapping.start];
item.end = task[option_dict.mapping.stop];
item_list.push(item);
item_dict[item_id] = task;
}
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