Commit 840cf299 authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: comply with jslint and renderjs conventions

 * format code as jslint expects it
 * use RSVP.Queue instead of Promise
parent d05f146b
...@@ -72,19 +72,19 @@ ...@@ -72,19 +72,19 @@
// render the erp5 form // render the erp5 form
return this.getDeclaredGadget("erp5_form") return this.getDeclaredGadget("erp5_form")
.push(function(erp5_form) { .push(function (erp5_form) {
return gadget.getDeclaredGadget("editor") return gadget.getDeclaredGadget("editor")
.push(function(editor) { .push(function (editor) {
return [editor, erp5_form]; return [editor, erp5_form];
});
}) })
})
.push(function (gadgets) { .push(function (gadgets) {
var form_options = gadget.state.erp5_form, var form_options = gadget.state.erp5_form,
rendered_form = gadget.state.erp5_document._embedded._view, rendered_form = gadget.state.erp5_document._embedded._view,
rendered_field, rendered_field,
key, key,
editor=gadgets[0], editor = gadgets[0],
erp5_form=gadgets[1]; erp5_form = gadgets[1];
// Remove all empty fields, and mark all others as non editable // Remove all empty fields, and mark all others as non editable
for (key in rendered_form) { for (key in rendered_form) {
if (rendered_form.hasOwnProperty(key) && (key[0] !== "_")) { if (rendered_form.hasOwnProperty(key) && (key[0] !== "_")) {
...@@ -102,32 +102,36 @@ ...@@ -102,32 +102,36 @@
form_options.form_definition = gadget.state.form_definition; form_options.form_definition = gadget.state.form_definition;
form_options.view = gadget.state.view; form_options.view = gadget.state.view;
return gadget.jio_getAttachment( return gadget.jio_getAttachment(
'post_module', 'post_module',
gadget.hateoas_url + gadget.options.jio_key + "/Base_getEditorFieldPreferredTextEditor", gadget.hateoas_url + gadget.options.jio_key + "/Base_getEditorFieldPreferredTextEditor",
{format: "text"} {format: "text"}
).push(function(preferred_editor) { ).push(function (preferred_editor) {
return Promise.all([ return new RSVP.Queue()
erp5_form.render(form_options), .push(
editor.render({ function () {
value: "", return RSVP.all([
key: "comment", erp5_form.render(form_options),
portal_type: "HTML Post", editor.render({
editable: true, value: "",
editor: preferred_editor key: "comment",
})]).then(function (){ portal_type: "HTML Post",
editable: true,
editor: preferred_editor
})]);
}
).push(function () {
// make our submit button editable // make our submit button editable
var element = /** @type {HTMLInputElement} */(gadget.element.querySelector('input[type="submit"]')); var element = gadget.element.querySelector('input[type="submit"]');
element.removeAttribute('disabled'); element.removeAttribute('disabled');
element.classList.remove('ui-disabled'); element.classList.remove('ui-disabled');
}); });
}) });
}) })
// render the header // render the header
.push(function () { .push(function () {
return Promise.all([ return RSVP.all([
gadget.getUrlFor({command: 'change', options: {editable: true}}), gadget.getUrlFor({command: 'change', options: {editable: true}}),
gadget.getUrlFor({command: 'change', options: {page: "action"}}), gadget.getUrlFor({command: 'change', options: {page: "action"}}),
gadget.getUrlFor({command: 'history_previous'}), gadget.getUrlFor({command: 'history_previous'}),
...@@ -157,10 +161,10 @@ ...@@ -157,10 +161,10 @@
return gadget.jio_getAttachment( return gadget.jio_getAttachment(
'post_module', 'post_module',
gadget.hateoas_url + "/Localizer/get_selected_language", gadget.hateoas_url + "/Localizer/get_selected_language",
{format:'text'} {format: 'text'}
).push(function(lang){ ).push(function (lang) {
moment.locale(lang); moment.locale(lang);
}) });
}) })
.push(function () { .push(function () {
return gadget.jio_getAttachment( return gadget.jio_getAttachment(
...@@ -169,9 +173,9 @@ ...@@ -169,9 +173,9 @@
); );
}) })
.push(function (post_list) { .push(function (post_list) {
var queue_list = []; var queue_list = [], i = 0;
if (post_list.length) { if (post_list.length) {
for (var i = 0; i < post_list.length; i += 1) { for (i = 0; i < post_list.length; i += 1) {
if (post_list[i].attachment_link !== null && post_list[i].attachment_link.indexOf("image_module") !== -1) { if (post_list[i].attachment_link !== null && post_list[i].attachment_link.indexOf("image_module") !== -1) {
queue_list.push(gadget.getImageUrl(post_list[i].attachment_link)); queue_list.push(gadget.getImageUrl(post_list[i].attachment_link));
} else if (post_list[i].attachment_link !== null && post_list[i].attachment_link.indexOf("document_module") !== -1) { } else if (post_list[i].attachment_link !== null && post_list[i].attachment_link.indexOf("document_module") !== -1) {
...@@ -224,58 +228,58 @@ ...@@ -224,58 +228,58 @@
var gadget = this, var gadget = this,
submitButton = null, submitButton = null,
queue = null, queue = null,
editor = null; editor = null;
return gadget.getDeclaredGadget("editor") return gadget.getDeclaredGadget("editor")
.then(function(e) { .push(function (e) {
editor = e; editor = e;
return e.getContent(); }) return e.getContent();
.then(function (content) {
if (content.comment === '') {
return gadget.notifySubmitted({message: "Post content can not be empty!"});
}
submitButton = gadget.element.querySelector("input[type=submit]");
submitButton.disabled = true;
function enableSubmitButton() {
submitButton.disabled = false;
}
queue = gadget.notifySubmitted({message: "Posting comment"})
.push(function () {
var choose_file_html_element = gadget.element.querySelector('#attachment'),
file_blob = choose_file_html_element.files[0],
url = gadget.hateoas_url + "post_module/PostModule_createHTMLPostForSupportRequest",
data = new FormData();
data.append("follow_up", gadget.options.jio_key);
data.append("predecessor", '');
data.append("data", content.comment);
data.append("file", file_blob);
// XXX: Hack, call jIO.util.ajax directly to pass the file blob
// Because the jio_putAttachment will call readBlobAsText, which
// will broke the binary file. Call the jIO.util.ajax directly
// will not touch the blob
return jIO.util.ajax({
"type": "POST",
"url": url,
"data": data,
"xhrFields": {
withCredentials: true
}
});
}) })
.push(function () { .push(function (content) {
return gadget.notifySubmitted({message: "Comment added", status: "success"}); if (content.comment === '') {
}) return gadget.notifySubmitted({message: "Post content can not be empty!"});
.push(function () { }
editor.changeState({value: ''})
.push(function (){ submitButton = gadget.element.querySelector("input[type=submit]");
return gadget.redirect({command: 'reload'}); submitButton.disabled = true;
}) function enableSubmitButton() {
submitButton.disabled = false;
}
queue = gadget.notifySubmitted({message: "Posting comment"})
.push(function () {
var choose_file_html_element = gadget.element.querySelector('#attachment'),
file_blob = choose_file_html_element.files[0],
url = gadget.hateoas_url + "post_module/PostModule_createHTMLPostForSupportRequest",
data = new FormData();
data.append("follow_up", gadget.options.jio_key);
data.append("predecessor", '');
data.append("data", content.comment);
data.append("file", file_blob);
// XXX: Hack, call jIO.util.ajax directly to pass the file blob
// Because the jio_putAttachment will call readBlobAsText, which
// will broke the binary file. Call the jIO.util.ajax directly
// will not touch the blob
return jIO.util.ajax({
"type": "POST",
"url": url,
"data": data,
"xhrFields": {
withCredentials: true
}
});
})
.push(function () {
return gadget.notifySubmitted({message: "Comment added", status: "success"});
})
.push(function () {
editor.changeState({value: ''})
.push(function () {
return gadget.redirect({command: 'reload'});
});
});
queue.push(enableSubmitButton, enableSubmitButton);
return queue;
}); });
queue.then(enableSubmitButton, enableSubmitButton);
return queue;
}) })
}
)
.onEvent('submit', function () { .onEvent('submit', function () {
this.submitPostComment(); this.submitPostComment();
}); });
......
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1539065902.53</float> <float>1539132486.97</float>
<string>GMT+9</string> <string>GMT+9</string>
</tuple> </tuple>
</state> </state>
......
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