//////////////////////////////////////////////////////////////////////////////////////////////
Mesan.Rules.SourcePanel = function(config){
config = config || {};
Ext.applyIf(config, {
id: config.prefix+'rule-source-panel',
title: _('Source Code'),
iconCls: 'rule-code',
tbar: this.createToolbar()
});
Mesan.Rules.SourcePanel.superclass.constructor.call(this, config);
var that = this;
this.on('render', function(){
this.createEditor(function(editor){
if (that.readOnly) that.body.mask();
});
}, this);
this.on('show', function(){
this.updateToolbar();
}, this);
};
Ext.extend(Mesan.Rules.SourcePanel, Ext.Panel, {
//----------------------------------------------------------------------------------------
createEditor: function(fn){
this.editor = new CodeMirror(this.body.dom, {
path: 'libjs/codemirror/js/',
parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
stylesheet: "libjs/codemirror/css/jscolors.css",
height: '100%',
width: '100%',
readOnly: this.readOnly,
initCallback: fn
});
},
//----------------------------------------------------------------------------------------
createToolbar: function(){
this.undoButton = new Ext.Toolbar.Button({
text: _('Undo'),
tooltip: {title:_('Undo'), text:_('Undoes last action')},
iconCls: 'rule-undo',
disabled: true,
scope: this,
handler: this.undoAction
}
);
this.redoButton = new Ext.Toolbar.Button({
text: _('Redo'),
tooltip: {title:_('Redo'), text:_('Redoes last action')},
iconCls: 'rule-redo',
disabled: true,
scope: this,
handler: this.redoAction
}
);
this.indentButton = new Ext.Toolbar.Button({
text: _('Indent'),
tooltip: {title:_('Indent document'), text:_('Applies indentation to the whole document')},
iconCls: 'rule-indent',
disabled: true,
scope: this,
handler: this.indentAction
}
);
var res = [this.undoButton, this.redoButton, this.indentButton];
if (Mesan.PRODUCTION_MODE) return res;
this.tokenizeButton = new Ext.Toolbar.Button({
text: 'Tokenize',
iconCls: 'rule-warning',
scope: this,
handler: this.tokenizeAction
}
);
res.push(this.tokenizeButton);
return res;
},
//----------------------------------------------------------------------------------------
updateToolbar: function(){
if (this.editor && !this.readOnly)
{
this.undoButton.enable();
this.redoButton.enable();
this.indentButton.enable();
}
else
{
this.undoButton.disable();
this.redoButton.disable();
this.indentButton.disable();
}
},
//----------------------------------------------------------------------------------------
setCode: function(code){
this.currentCode = code||'';
if (!this.editor) { return; }
if (!this.editor.editor) // velmi divne chovani na FF - vnitrni editor jeste nemusi byt pripraveny
{
this.setCode.defer(100, this, [code]);
return;
}
this.editor.setCode(this.currentCode);
this.updateToolbar();
},
//----------------------------------------------------------------------------------------
getCode: function(){
if (!this.editor) return this.currentCode||'';
this.currentCode = this.editor.getCode();
return this.currentCode;
},
//----------------------------------------------------------------------------------------
undoAction: function(){
if (this.editor) this.editor.editor.history.undo();
},
//----------------------------------------------------------------------------------------
redoAction: function(){
if (this.editor) this.editor.editor.history.redo();
},
//----------------------------------------------------------------------------------------
indentAction: function(){
if (this.editor) this.editor.reindent();
},
//----------------------------------------------------------------------------------------
tokenizeAction: function(){
var code = this.getCode();
this.form.editor.parseSource(code, true);
},
//----------------------------------------------------------------------------------------
loadItem: function(item){
this.setCode(item.code);
},
//----------------------------------------------------------------------------------------
saveItem: function(item){
item.code = this.getCode();
}
});