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, parent);
17 $('.xmlview-toolbar', this.element).bind('resize.xmlview', this.resized.bind(this));
19 this.parent.freeze('Ćadowanie edytora...');
20 this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
21 parserfile: 'parsexml.js',
22 path: "/static/js/lib/codemirror/",
23 stylesheet: "/static/css/xmlcolors.css",
24 parserConfig: {useHTMLKludges: false},
28 onChange: this.editorDataChanged.bind(this),
29 initCallback: this.editorDidLoad.bind(this)
33 resized: function(event) {
34 var height = this.element.height() - $('.xmlview-toolbar', this.element).outerHeight();
35 console.log('.xmlview height =', height);
36 $('.xmlview', this.element).height(height);
39 editorDidLoad: function(editor) {
40 $(editor.frame).css({width: '100%', height: '100%'});
42 .addObserver(this, 'data', this.modelDataChanged.bind(this))
43 .addObserver(this, 'synced', this.modelSyncChanged.bind(this));
45 this.parent.unfreeze();
47 this.editor.setCode(this.model.get('data'));
48 if (!this.model.get('synced')) {
49 this.parent.freeze('Niezsynchronizowany...');
54 // $.fbind(self, self.hotkeyPressed),
55 // $.fbind(self, self.isHotkey)
59 editorDataChanged: function() {
60 this.model.set('data', this.editor.getCode());
63 modelDataChanged: function(property, value) {
64 if (this.editor.getCode() != value) {
65 this.editor.setCode(value);
69 modelSyncChanged: function(property, value) {
71 this.parent.unfreeze();
73 this.parent.freeze('Niezsynchronizowany...');
78 this.model.removeObserver(this);
79 $(this.editor.frame).remove();
85 panels['xml'] = XMLView;