- this.element = $(element);
- this.model = $(model).get(0);
- console.log('XMLView#init model:', model);
- this.template = template || this.template;
- this.element.html(render_template(this.template, {}));
+ this._super(element, model, template);
this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
parserfile: 'parsexml.js',
path: "/static/js/lib/codemirror/",
stylesheet: "/static/css/xmlcolors.css",
parserConfig: {useHTMLKludges: false},
this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
parserfile: 'parsexml.js',
path: "/static/js/lib/codemirror/",
stylesheet: "/static/css/xmlcolors.css",
parserConfig: {useHTMLKludges: false},
- this.editor.setCode(this.model.xml);
- $(this.model).bind('modelxmlchanged.xmlview', this.codeChanged.bind(this));
- this.model.getXML();
+
+ this.model
+ .addObserver(this, 'data', this.modelDataChanged.bind(this))
+ .addObserver(this, 'synced', this.modelSyncChanged.bind(this));
+
+ if (!this.model.get('synced')) {
+ this.freeze('Niezsynchronizowany...');
+ this.model.load();
+ } else {
+ this.editor.setCode(this.model.get('data'));
+ }
+ this.unfreeze();
+
// editor.grabKeys(
// $.fbind(self, self.hotkeyPressed),
// $.fbind(self, self.isHotkey)
// );
},
// editor.grabKeys(
// $.fbind(self, self.hotkeyPressed),
// $.fbind(self, self.isHotkey)
// );
},
- codeChanged: function() {
- console.log('setCode:', this.editor, this.model);
- this.editor.setCode(this.model.xml);
+ editorDataChanged: function() {
+ this.model.set('data', this.editor.getCode());
+ modelDataChanged: function(property, value) {
+ if (this.editor.getCode() != value) {
+ this.editor.setCode(value);
+ }
+ },
+
+ modelSyncChanged: function(property, value) {
+ if (value) {
+ this.unfreeze();
+ } else {
+ this.freeze('Niezsynchronizowany...');
+ }
+ },
+