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);
20 $('.xmlview-toolbar', this.element).bind('resize.xmlview', this.resized.bind(this));
23 this.parent.freeze('Ładowanie edytora...');
24 this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
25 parserfile: 'parsexml.js',
26 path: "/static/js/lib/codemirror/",
27 stylesheet: "/static/css/xmlcolors.css",
34 onChange: this.editorDataChanged.bind(this),
35 initCallback: this.editorDidLoad.bind(this)
39 resized: function(event) {
40 var height = this.element.height() - $('.xmlview-toolbar', this.element).outerHeight();
41 $('.xmlview', this.element).height(height);
45 this.model.load(true);
48 editorDidLoad: function(editor) {
54 .addObserver(this, 'data', this.modelDataChanged.bind(this))
55 .addObserver(this, 'state', this.modelStateChanged.bind(this))
58 this.parent.unfreeze();
60 this.editor.setCode(this.model.get('data'));
61 this.modelStateChanged('state', this.model.get('state'));
64 this.hotkeyPressed.bind(this),
65 this.isHotkey.bind(this)
69 editorDataChanged: function() {
70 this.model.set('data', this.editor.getCode());
73 modelDataChanged: function(property, value) {
74 if (this.editor.getCode() != value) {
75 this.editor.setCode(value);
79 modelStateChanged: function(property, value) {
80 if (value == 'synced' || value == 'dirty') {
82 } else if (value == 'unsynced') {
83 this.freeze('Niezsynchronizowany...');
84 } else if (value == 'loading') {
85 this.freeze('Ładowanie...');
86 } else if (value == 'saving') {
87 this.freeze('Zapisywanie...');
88 } else if (value == 'error') {
89 this.freeze(this.model.get('error'));
94 this.model.removeObserver(this);
95 $(this.editor.frame).remove();
99 getHotkey: function(event) {
100 var code = event.keyCode;
101 var ch = String.fromCharCode(code & 0xff).toLowerCase();
102 var button = $('.buttontoolbarview-button[title='+ch+']', this.element)[0]
104 console.log(ch, '#', button);
107 if(event.altKey) mod |= 0x01;
108 if(event.ctrlKey) mod |= 0x02;
109 if(event.shiftKey) mod |= 0x04;
114 $(button).each(function() {
115 if( parseInt($(this).attr('ui:hotkey_mod')) == mod ) {
128 isHotkey: function() {
129 console.log(arguments);
131 if(this.getHotkey.apply(this, arguments))
137 hotkeyPressed: function() {
138 var button = this.getHotkey.apply(this, arguments);
139 this.buttonToolbar.buttonPressed({
146 function Hotkey(code) {
148 this.has_alt = ((code & 0x01 << 8) !== 0);
149 this.has_ctrl = ((code & 0x01 << 9) !== 0);
150 this.has_shift = ((code & 0x01 << 10) !== 0);
151 this.character = String.fromCharCode(code & 0xff);
154 Hotkey.prototype.toString = function() {
156 if(this.has_alt) mods.push('Alt');
157 if(this.has_ctrl) mods.push('Ctrl');
158 if(this.has_shift) mods.push('Shift');
159 mods.push('"'+this.character+'"');
160 return mods.join('+');
164 panels['xml'] = XMLView;