Commit fca49e31 authored by Roque's avatar Roque

erp5_messenger: get rid of code in gadget field

- code removed: post comment; render form; editor
parent d551b9c3
......@@ -37,25 +37,9 @@
</head>
<body>
<div class="ui-body-c">
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="erp5_form"
data-gadget-sandbox="public">
</div>
<form>
<p style="background-color:#0E81C2;color:white;margin:1em 0;padding:0.5em">Comments:</p>
<ol id="post_list"></ol>
<h3 class="ui-content-title ui-body-c ui-icon ui-icon-custom ui-icon-random" id="comment-title" name="comment-title">&nbsp;Post a comment</h3>
<div data-gadget-url="gadget_editor.html"
data-gadget-scope="editor"
data-gadget-sandbox="">
</div>
<div id="file_upload_div">
<input value="" name="attachment" id="attachment" type="file" title="Upload">
</div>
<input data-theme="b" data-inline="true" type="submit" data-i18n="[value]Post Comment" value="Post Comment" data-icon="check" disabled class="ui-disabled"/>
</form>
</div>
</body>
......
/*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, document,moment, FormData, jIO, Handlebars*/
(function (window, rJS, RSVP, document, moment, FormData, jIO, Handlebars) {
/*global window, rJS, RSVP, document,moment, jIO, Handlebars*/
(function (window, rJS, RSVP, document, moment, jIO, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
comment_list_template = Handlebars.compile(
......@@ -10,11 +10,8 @@
rJS(window)
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("redirect", "redirect")
.declareMethod('render', function (options) {
var gadget = this;
......@@ -36,57 +33,10 @@
.onStateChange(function () {
var gadget = this;
// render the erp5 form
return gadget.getDeclaredGadget("erp5_form")
.push(function (erp5_form) {
return gadget.getDeclaredGadget("editor")
.push(function (editor) {
return [editor, erp5_form];
});
})
.push(function (gadgets) {
var form_options = gadget.state.erp5_form,
rendered_field,
key,
editor = gadgets[0],
erp5_form = gadgets[1];
return new RSVP.Queue()
/* TODO: I get an error with this
// I think that this rendering is the key to refresh the comment list including the new element
// some times, after a "post comment" the list is refreshed but the new post doens't appear
.push(
function () {
return RSVP.all([
erp5_form.render(form_options),
editor.render({
value: "",
key: "comment",
portal_type: "HTML Post",
editable: true,
editor: gadget.state.preferred_editor,
maximize: true
})
]);
}
)
*/
.push(function () {
// make our submit button editable
var element = gadget.element.querySelector('input[type="submit"]');
element.removeAttribute('disabled');
element.classList.remove('ui-disabled');
});
})
.push(function () {
return gadget.jio_getAttachment(
'post_module',
gadget.hateoas_url + gadget.options.jio_key + "/MessengerThread_getCommentPostListAsJson"
);
})
)
.push(function (post_list) {
function getPostWithLinkAndLocalDate(post) {
......@@ -126,60 +76,6 @@
})
.declareJob('submitPostComment', function () {
var gadget = this,
submitButton = null,
queue = null;
submitButton = gadget.element.querySelector("input[type=submit]");
submitButton.disabled = true;
submitButton.classList.add("ui-disabled");
function enableSubmitButton() {
submitButton.disabled = false;
submitButton.classList.remove("ui-disabled");
}
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 + gadget.options.jio_key + "/MessengerThread_createNewMessengerPost",
data = new FormData();
data.append("title", "hardcoded title!"); //TODO
data.append("follow_up", gadget.options.jio_key);
data.append("predecessor", '');
data.append("text_content", "this is a hardcoded comment!"); //TODO
data.append("file", file_blob); //TODO
// reset the file upload, otherwise next comment would upload same file again
choose_file_html_element.value = "";
// 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 new RSVP.Queue().push(function () {
gadget.notifySubmitted({message: "Comment added", status: "success"});
}).push(function () {
return gadget.redirect({command: 'reload'});
});
}, function (e) {
enableSubmitButton();
return gadget.notifySubmitted({message: "Error:" + e, status: "error"});
});
return queue;
})
.onLoop(function () {
// update relative time
var elements = this.element.querySelectorAll("li>time");
......@@ -188,8 +84,8 @@
});
}, 5000)
.onEvent('submit', function () {
/*.onEvent('submit', function () {
return this.submitPostComment();
});
})*/;
}(window, rJS, RSVP, document, moment, FormData, jIO, Handlebars));
\ No newline at end of file
}(window, rJS, RSVP, document, moment, jIO, Handlebars));
\ No newline at end of file
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