+
+
+var HTMLModel = Model.extend({
+ parent: null,
+ data: '',
+ serverURL: null,
+ needsReload: false,
+
+ init: function(parent, serverURL) {
+ this.parent = parent;
+ this.serverURL = serverURL;
+ },
+
+ getData: function() {
+ if (!this.data) {
+ this.reload();
+ }
+ return this.data;
+ },
+
+ setData: function(data) {
+ console.log('setData');
+ if (this.data != data) {
+ this.data = data;
+ this.dataChanged();
+ }
+ },
+
+ 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');
+ }
+})
+
+