1 /*global View CodeMirror ButtonToolbarView render_template panels */
2 var XMLView = View.extend({
6 template: 'xml-view-template',
10 init: function(element, model, parent, template) {
11 this._super(element, model, template);
13 this.buttonToolbar = new ButtonToolbarView(
14 $('.xmlview-toolbar', this.element),
15 this.model.toolbarButtonsModel);
17 this.parent.freeze('Ćadowanie edytora...');
18 this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
19 parserfile: 'parsexml.js',
20 path: "/static/js/lib/codemirror/",
21 stylesheet: "/static/css/xmlcolors.css",
22 parserConfig: {useHTMLKludges: false},
26 onChange: this.editorDataChanged.bind(this),
27 initCallback: this.editorDidLoad.bind(this)
31 editorDidLoad: function(editor) {
32 $(editor.frame).css({width: '100%', height: '100%'});
34 .addObserver(this, 'data', this.modelDataChanged.bind(this))
35 .addObserver(this, 'synced', this.modelSyncChanged.bind(this));
37 this.parent.unfreeze();
39 this.editor.setCode(this.model.get('data'));
40 if (!this.model.get('synced')) {
41 this.parent.freeze('Niezsynchronizowany...');
46 // $.fbind(self, self.hotkeyPressed),
47 // $.fbind(self, self.isHotkey)
51 editorDataChanged: function() {
52 this.model.set('data', this.editor.getCode());
55 modelDataChanged: function(property, value) {
56 if (this.editor.getCode() != value) {
57 this.editor.setCode(value);
61 modelSyncChanged: function(property, value) {
63 this.parent.unfreeze();
65 this.parent.freeze('Niezsynchronizowany...');
70 this.model.removeObserver(this);
71 $(this.editor.frame).remove();
77 panels['xml'] = XMLView;