});
+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() {
return this.data;
},
- setData: function(data) {
- this.data = data;
- this.dataChanged();
- },
-
load: function() {
if (!this.get('synced')) {
$.ajax({
Editor.HTMLModel = Editor.Model.extend({
+ _className: 'Editor.HTMLModel',
serverURL: null,
+ data: '',
init: function(serverURL) {
+ this._super();
this.serverURL = serverURL;
},
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();
},
'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);
+ }
+ }
}
});