Skip to content
Snippets Groups Projects
Commit bf349596 authored by legac's avatar legac
Browse files

Redesign the App.form.field.AceEditor using the Ext.form.FieldContainer.

parent 0bd56533
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
* [ACE editor](http://http://ace.c9.io/#nav=about) * [ACE editor](http://http://ace.c9.io/#nav=about)
* It can be embedded in Ext.form.Panel. * It can be embedded in Ext.form.Panel.
* *
* @experimental
* @since 0.4.15.0 * @since 0.4.15.0
* *
*/ */
Ext.define('App.form.field.AceEditor', { Ext.define('App.form.field.AceEditor', {
extend: 'Ext.form.field.Base', extend: 'Ext.form.FieldContainer',
mixins: {
field: 'Ext.form.field.Field'
},
alias: 'widget.xaceeditorfield', alias: 'widget.xaceeditorfield',
/** /**
...@@ -37,94 +39,78 @@ Ext.define('App.form.field.AceEditor', { ...@@ -37,94 +39,78 @@ Ext.define('App.form.field.AceEditor', {
// private property // private property
editor: null, editor: null,
panel: null,
valueBeforeRender: undefined, valueBeforeRender: undefined,
// private method requests by the component model of ExtJS // private method requests by the component model of ExtJS
initComponent: function (config) { initComponent: function (config) {
// Hack to get the size of the editor render properly var me = this;
// The width is to small when it is not specified.
this.minWidth = this.minWidth || 258;
this.callParent(arguments); me.items = [{
}, frame: true,
height: me.editorHeight,
xtype: 'panel'
}];
// private method requests by the component model of ExtJS me.callParent(arguments);
beforeDestroy: function () { me.panel = me.child('panel');
Ext.destroyMembers(this, 'editor'); me.panel.on('afterrender', me.addEditor, me);
this.callParent(arguments); me.initField();
}, },
/** // private method requests by the component model of ExtJS
* Return the value of this field. beforeDestroy: function () {
*
* @return {String}
*
*/
getValue: function () {
"use strict"; var me = this;
if (this.editor) { me.panel.un('afterrender', me.addEditor, me);
return this.editor.getValue();
}
return undefined; me.editor.destroy();
}, Ext.destroyMembers(me, 'editor');
/** me.callParent(arguments);
* Render the editor field. },
*
* @param {Ext.Element} ct The container to render to.
* @param {Object} position The position in the container to render to.
*
*/
onRender: function (ct, position) {
this.callParent(arguments);
// wrap an element around the input field // private to embed the ace editor inside the panel
this.resizeEl = this.positionEl = this.wrap = this.bodyEl.wrap(); addEditor: function () {
// the editor require that the width an height are defined "use strict";
this.wrap.setWidth(this.wrap.getWidth()); var me = this;
this.wrap.setHeight(this.editorHeight);
// instantiate the editor // instantiate the editor
this.editor = ace.edit(this.wrap.id); me.editor = ace.edit(me.panel.getId());
this.editor.getSession().setMode('ace/mode/' + this.language); me.editor.getSession().setMode('ace/mode/' + me.language);
this.editor.setFontSize(this.fontSize); me.editor.setFontSize(me.fontSize);
if (this.theme) { if (me.theme) {
this.editor.setTheme('ace/theme/' + this.theme); me.editor.setTheme('ace/theme/' + me.theme);
} }
// load the value // load the value
this.editor.setValue(this.valueBeforeRender); me.editor.setValue(me.valueBeforeRender);
this.editor.clearSelection(); me.editor.clearSelection();
this.editor.moveCursorTo(0, 0); me.editor.moveCursorTo(0, 0);
// hide the default input field
this.bodyEl.setVisibilityMode(Ext.dom.Element.DISPLAY).hide();
}, },
/** /**
* Resize the component * Return the value of this field.
* *
* @param {Number} w * @return {String}
* @param {Number} h
* *
*/ */
onResize: function (w, h) { getValue: function () {
"use strict";
var me = this;
this.wrap.setSize(w - this.getLabelWidth(), h); if (me.editor) {
if (this.editor) { return me.editor.getValue();
this.editor.resize();
} }
this.callParent(arguments); return undefined;
}, },
/** /**
...@@ -135,19 +121,24 @@ Ext.define('App.form.field.AceEditor', { ...@@ -135,19 +121,24 @@ Ext.define('App.form.field.AceEditor', {
*/ */
setValue: function (value) { setValue: function (value) {
this.callParent(arguments); "use strict";
var me = this;
if (this.editor) { if (me.editor) {
this.editor.setValue(value); me.editor.setValue(value);
this.editor.clearSelection(); me.editor.clearSelection();
this.editor.moveCursorTo(0, 0); me.editor.moveCursorTo(0, 0);
this.valueBeforeRender = undefined; me.valueBeforeRender = undefined;
// Keep track of the value. // Keep track of the value.
// It will be used at the first rendering of the editor // It will be used at the first rendering of the editor
} else { } else {
this.valueBeforeRender = value; me.valueBeforeRender = value;
} }
// the standard way to set the value for a field
// extract from Ext.form.field.Base
return me.mixins.field.setValue.call(me, value);
} }
}); });
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment