X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/0ac983162763199b07270a9a675e22672d4462ce..be81f64e2a76d6023ad1a10083e079ae18d51691:/project/static/js/models.js?ds=inline diff --git a/project/static/js/models.js b/project/static/js/models.js index 9ccefcaa..96cab868 100644 --- a/project/static/js/models.js +++ b/project/static/js/models.js @@ -8,11 +8,40 @@ Editor.Model = Editor.Object.extend({ }); +Editor.ToolbarButtonsModel = Editor.Model.extend({ + _className: 'Editor.ToolbarButtonsModel', + serverURL: '/api/toolbar/buttons', + buttons: {}, + + init: function() { + this._super(); + }, + + load: function() { + if (!this.get('buttons').length) { + $.ajax({ + url: this.serverURL, + dataType: 'json', + success: this.loadSucceeded.bind(this) + }); + } + }, + + loadSucceeded: function(data) { + this.set('buttons', data); + } +}); + + Editor.XMLModel = Editor.Model.extend({ + _className: 'Editor.XMLModel', serverURL: null, + data: '', init: function(serverURL) { + this._super(); this.serverURL = serverURL; + this.toolbarButtonsModel = new Editor.ToolbarButtonsModel(); }, getData: function() { @@ -22,11 +51,6 @@ Editor.XMLModel = Editor.Model.extend({ return this.data; }, - setData: function(data) { - this.data = data; - this.dataChanged(); - }, - load: function() { if (!this.get('synced')) { $.ajax({ @@ -45,9 +69,12 @@ Editor.XMLModel = Editor.Model.extend({ Editor.HTMLModel = Editor.Model.extend({ + _className: 'Editor.HTMLModel', serverURL: null, + data: '', init: function(serverURL) { + this._super(); this.serverURL = serverURL; }, @@ -69,10 +96,12 @@ Editor.HTMLModel = Editor.Model.extend({ Editor.DocumentModel = Editor.Model.extend({ + _className: 'Editor.DocumentModel', data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size contentModels: {}, init: function() { + this._super(); this.load(); }, @@ -93,6 +122,19 @@ Editor.DocumentModel = Editor.Model.extend({ 'xml': new Editor.XMLModel(data.text_url), 'html': new Editor.HTMLModel(data.html_url) }; + for (var key in this.contentModels) { + this.contentModels[key].addObserver(this, 'data', this.contentModelDataChanged.bind(this)); + } + }, + + contentModelDataChanged: function(property, value, contentModel) { + console.log('data of', contentModel.description(), 'changed!'); + for (var key in this.contentModels) { + if (this.contentModels[key].guid() != contentModel.guid()) { + console.log(this.contentModels[key].description(), 'frozen'); + this.contentModels[key].set('synced', false); + } + } } });