+ reload: function() {
+ $.ajax({
+ url: this.serverURL,
+ dataType: 'text',
+ success: this.reloadSucceeded.bind(this)
+ });
+ },
+
+ reloadSucceeded: function(data) {
+ this.data = data;
+ this.signal('reloaded');
+ },
+
+ dataChanged: function() {
+ this.parent.modelChanged('html');
+ },
+
+ needsReload: function() {
+ this.needsReload = true;
+ this.signal('needsReload');
+ }
+})
+
+
+var DocumentModel = Model.extend({
+ data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
+ xml: null,
+ html: null,
+ contentModels: {},
+
+ init: function() {
+ this.getData();
+ },
+
+ getData: function() {
+ console.log('DocumentModel#getData');
+ $.ajax({
+ cache: false,
+ url: documentsUrl + fileId,
+ dataType: 'json',
+ success: this.successfulGetData.bind(this)
+ });
+ },
+
+ successfulGetData: function(data) {
+ console.log('DocumentModel#successfulGetData:', data);
+ this.data = data;
+ this.contentModels = {
+ 'xml': new XMLModel(this, data.text_url)
+ };
+ },
+
+ modelChanged: function(contentModelName) {
+ for (modelName in this.contentModels) {
+ if (!(modelName == contentModelName)) {
+ this.contentModels[modelName].needsReload();
+ }
+ }