Commit a949f63f authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: post comments as HTML with editor

parent 578c1a32
...@@ -28,11 +28,15 @@ ...@@ -28,11 +28,15 @@
<p style="background-color:#0E81C2;color:white;margin:1em 0;padding:0.5em">Comments:</p> <p style="background-color:#0E81C2;color:white;margin:1em 0;padding:0.5em">Comments:</p>
<ol id="post_list"></ol> <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> <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>
<textarea id="comment" name="comment" placeholder="Enter your comment here..."></textarea> <div data-gadget-url="gadget_editor.html"
data-gadget-scope="editor"
data-gadget-sandbox="">
</div>
<div id="file_upload_div"> <div id="file_upload_div">
<input value="" name="attachment" id="attachment" type="file" title="Upload"> <input value="" name="attachment" id="attachment" type="file" title="Upload">
</div> </div>
<input data-theme="b" data-inline="true" type="submit" data-i18n="[value]Post Comment" value="Post Comment" data-icon="check" /> <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> </form>
</div> </div>
</body> </body>
......
...@@ -252,8 +252,8 @@ ...@@ -252,8 +252,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1506616673.69</float> <float>1538885951.97</float>
<string>UTC</string> <string>GMT+9</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -67,16 +67,24 @@ ...@@ -67,16 +67,24 @@
}); });
}) })
.onStateChange(function () { .onStateChange(function () {
/** @type {GadgetInstance} */
var gadget = this; var gadget = this;
// 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")
.push(function(editor) {
return [editor, erp5_form];
})
})
.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],
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] !== "_")) {
...@@ -94,12 +102,32 @@ ...@@ -94,12 +102,32 @@
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 erp5_form.render(form_options);
}) return gadget.jio_getAttachment(
'post_module',
gadget.hateoas_url + gadget.options.jio_key + "/Base_getEditorFieldPreferredTextEditor",
{format: "text"}
).push(function(preferred_editor) {
return Promise.all([
erp5_form.render(form_options),
editor.render({
value: "",
key: "comment",
portal_type: "HTML Post",
editable: true,
editor: preferred_editor
})]).then(function (){
// make our submit button editable
var element = /** @type {HTMLInputElement} */(gadget.element.querySelector('input[type="submit"]'));
element.removeAttribute('disabled');
element.classList.remove('ui-disabled');
});
})
})
// render the header // render the header
.push(function () { .push(function () {
return RSVP.all([ return Promise.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'}),
...@@ -131,10 +159,9 @@ ...@@ -131,10 +159,9 @@
); );
}) })
.push(function (post_list) { .push(function (post_list) {
var i, // XXX abbreviation var queue_list = [];
queue_list = [];
if (post_list.length) { if (post_list.length) {
for (i = 0; i < post_list.length; i += 1) { for (var i = 0; i < post_list.length; i += 1) {
if (post_list[i][3] !== null && post_list[i][3].indexOf("image_module") !== -1) { if (post_list[i][3] !== null && post_list[i][3].indexOf("image_module") !== -1) {
queue_list.push(gadget.getImageUrl(post_list[i][3])); queue_list.push(gadget.getImageUrl(post_list[i][3]));
} else if (post_list[i][3] !== null && post_list[i][3].indexOf("document_module") !== -1) { } else if (post_list[i][3] !== null && post_list[i][3].indexOf("document_module") !== -1) {
...@@ -187,9 +214,13 @@ ...@@ -187,9 +214,13 @@
var gadget = this, var gadget = this,
submitButton = null, submitButton = null,
queue = null, queue = null,
editor = gadget.element.querySelector('#comment'); editor = null;
return gadget.getDeclaredGadget("editor")
if (editor.value === '') { .then(function(e) {
editor = e;
return e.getContent(); })
.then(function (content) {
if (content.comment === '') {
return gadget.notifySubmitted({message: "Post content can not be empty!"}); return gadget.notifySubmitted({message: "Post content can not be empty!"});
} }
...@@ -206,7 +237,7 @@ ...@@ -206,7 +237,7 @@
data = new FormData(); data = new FormData();
data.append("follow_up", gadget.options.jio_key); data.append("follow_up", gadget.options.jio_key);
data.append("predecessor", ''); data.append("predecessor", '');
data.append("data", editor.value); data.append("data", content.comment);
data.append("file", file_blob); data.append("file", file_blob);
// XXX: Hack, call jIO.util.ajax directly to pass the file blob // XXX: Hack, call jIO.util.ajax directly to pass the file blob
// Because the jio_putAttachment will call readBlobAsText, which // Because the jio_putAttachment will call readBlobAsText, which
...@@ -225,12 +256,16 @@ ...@@ -225,12 +256,16 @@
return gadget.notifySubmitted({message: "Comment added", status: "success"}); return gadget.notifySubmitted({message: "Comment added", status: "success"});
}) })
.push(function () { .push(function () {
editor.value = ''; editor.changeState({value: ''})
return gadget.redirect({command: 'reload'}); .push(function (){
return gadget.redirect({command: 'reload'});
})
}); });
queue.then(enableSubmitButton, enableSubmitButton); queue.then(enableSubmitButton, enableSubmitButton);
return queue; return queue;
}) })
}
)
.onEvent('submit', function () { .onEvent('submit', function () {
this.submitPostComment(); this.submitPostComment();
}); });
......
...@@ -252,8 +252,8 @@ ...@@ -252,8 +252,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1507898069.5</float> <float>1538886067.22</float>
<string>UTC</string> <string>GMT+9</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
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