Commit bce2a705 authored by Boxiang Sun's avatar Boxiang Sun

erp5_officejs: Reduce the number buttons in toolbar.

Add basic form ckeditor and move render code from `ready` to `onStateChange`.
parent 50b9ddf9
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CKEditor Gadget</title>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="gadget_ckeditor_basic.js" type="text/javascript"></script>
</head>
<body>
<div data-gadget-url="gadget_ckeditor.html"
data-gadget-scope="editor"
data-gadget-sandbox="public">
</div>
</body>
</html>
\ No newline at end of file
/*global window, rJS*/
/*jslint nomen: true, maxlen:80, indent:2*/
(function (rJS) {
"use strict";
rJS(window)
.declareMethod('render', function (options) {
return this.getDeclaredGadget('editor')
.push(function (editor) {
editor.render({
key: options.key || "text_content",
data: options.value || "",
configuration: {
toolbar: [
{
name: 'clipboard',
groups: [ 'clipboard', 'undo' ],
items: [
'PasteText', 'Undo', 'Redo'
]
},
{
name: 'basicstyles',
groups: [ 'basicstyles', 'cleanup' ],
items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript',
'Superscript', '-', 'RemoveFormat' ]
},
{
name: 'paragraph',
groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ],
items: [
'NumberedList', 'BulletedList'
]
},
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
{
name: 'insert',
items: [
'Image',
'Table',
'HorizontalRule',
'SpecialChar', 'PageBreak'
]
},
{
name: 'styles',
items: ['Styles', 'Format', 'Font', 'FontSize' ]
},
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{
name: 'tools',
items: [
'Maximize'
]
},
{ name: 'about', items: [ 'About' ] }
],
removePlugins: '',
disableNativeSpellChecker: false,
extraAllowedContent: "details section article"
}
});
});
});
}(rJS));
\ No newline at end of file
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>959.65360.8858.42939</string> </value> <value> <string>962.36988.16426.32853</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1497272689.07</float> <float>1507196869.4</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -4,8 +4,24 @@ ...@@ -4,8 +4,24 @@
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function () { .declareAcquiredMethod("submitContent", "triggerSubmit")
var gadget = this, .declareAcquiredMethod("notifyChange", 'notifyChange')
.declareMethod('render', function (options) {
return this.changeState({
key: options.key || "text_content",
data: options.value || "",
configuration: options.configuration || {}
});
})
.declareMethod('getContent', function () {
var result = {};
result[this.state.key] = this.state.ckeditor.getData();
return result;
})
.onStateChange(function (modification_dict) {
var gadget = this, editor_id, editor,
textarea = gadget.element.querySelector('textarea');
if (gadget.state.ckeditor === undefined) {
textarea = gadget.element.querySelector('textarea'); textarea = gadget.element.querySelector('textarea');
gadget.state.ckeditor = CKEDITOR.replace( gadget.state.ckeditor = CKEDITOR.replace(
textarea, textarea,
...@@ -33,24 +49,19 @@ ...@@ -33,24 +49,19 @@
event.editor.execCommand('maximize'); event.editor.execCommand('maximize');
}); });
gadget.state.ckeditor.on('change', gadget.notifyChange); gadget.state.ckeditor.on('change', gadget.notifyChange);
}) }
.declareAcquiredMethod("submitContent", "triggerSubmit") if (modification_dict.hasOwnProperty('configuration') !== {}) {
.declareAcquiredMethod("notifyChange", 'notifyChange') editor_id = gadget.state.ckeditor.name;
editor = CKEDITOR.instances[editor_id];
.declareMethod('render', function (options) { if (editor) { editor.destroy(true); }
return this.changeState({ gadget.state.ckeditor = CKEDITOR.replace(
key: options.key || "text_content", textarea,
data: options.value || "" modification_dict.configuration
);
gadget.state.ckeditor.on('instanceReady', function (event) {
event.editor.execCommand('maximize');
}); });
}) }
.declareMethod('getContent', function () {
var result = {};
result[this.state.key] = this.state.ckeditor.getData();
return result;
})
.onStateChange(function () {
var gadget = this;
return gadget.state.ckeditor.setData(gadget.state.data); return gadget.state.ckeditor.setData(gadget.state.data);
}); });
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.64612.15949.44475</string> </value> <value> <string>962.43020.35340.18090</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1501073715.33</float> <float>1507556458.53</float>
<string>UTC</string> <string>UTC</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