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 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>959.65360.8858.42939</string> </value>
<value> <string>962.36988.16426.32853</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -195,7 +195,7 @@
</tuple>
<state>
<tuple>
<float>1497272689.07</float>
<float>1507196869.4</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,53 +4,64 @@
"use strict";
rJS(window)
.ready(function () {
var gadget = this,
textarea = gadget.element.querySelector('textarea');
gadget.state.ckeditor = CKEDITOR.replace(
textarea,
{
removeButtons: 'NewPage,Preview,Cut,Paste,Copy,PasteText,' +
'PasteFromWord,Flash,Iframe,Form,Checkbox,Radio,TextField,' +
'Textarea,Select,Button,ImageButton,HiddenField,Maximize',
removePlugins: '',
disableNativeSpellChecker: false,
extraAllowedContent: "details section article"
}
);
gadget.state.ckeditor.addCommand('saveRJS', {
readOnly: 1,
exec: function () {
return gadget.submitContent();
}
});
gadget.state.ckeditor.ui.addButton('Save', {
label: "Save",
command: 'saveRJS',
toolbar: 'document,1'
});
gadget.state.ckeditor.on('instanceReady', function (event) {
event.editor.execCommand('maximize');
});
gadget.state.ckeditor.on('change', gadget.notifyChange);
})
.declareAcquiredMethod("submitContent", "triggerSubmit")
.declareAcquiredMethod("notifyChange", 'notifyChange')
.declareMethod('render', function (options) {
return this.changeState({
key: options.key || "text_content",
data: options.value || ""
data: options.value || "",
configuration: options.configuration || {}
});
})
.declareMethod('getContent', function () {
var result = {};
result[this.state.key] = this.state.ckeditor.getData();
return result;
})
.onStateChange(function () {
var gadget = this;
.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');
gadget.state.ckeditor = CKEDITOR.replace(
textarea,
{
removeButtons: 'NewPage,Preview,Cut,Paste,Copy,PasteText,' +
'PasteFromWord,Flash,Iframe,Form,Checkbox,Radio,TextField,' +
'Textarea,Select,Button,ImageButton,HiddenField,Maximize',
removePlugins: '',
disableNativeSpellChecker: false,
extraAllowedContent: "details section article"
}
);
gadget.state.ckeditor.addCommand('saveRJS', {
readOnly: 1,
exec: function () {
return gadget.submitContent();
}
});
gadget.state.ckeditor.ui.addButton('Save', {
label: "Save",
command: 'saveRJS',
toolbar: 'document,1'
});
gadget.state.ckeditor.on('instanceReady', function (event) {
event.editor.execCommand('maximize');
});
gadget.state.ckeditor.on('change', gadget.notifyChange);
}
if (modification_dict.hasOwnProperty('configuration') !== {}) {
editor_id = gadget.state.ckeditor.name;
editor = CKEDITOR.instances[editor_id];
if (editor) { editor.destroy(true); }
gadget.state.ckeditor = CKEDITOR.replace(
textarea,
modification_dict.configuration
);
gadget.state.ckeditor.on('instanceReady', function (event) {
event.editor.execCommand('maximize');
});
}
return gadget.state.ckeditor.setData(gadget.state.data);
});
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.64612.15949.44475</string> </value>
<value> <string>962.43020.35340.18090</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1501073715.33</float>
<float>1507556458.53</float>
<string>UTC</string>
</tuple>
</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