1 /*globals Editor fileId SplitView PanelContainerView*/
2 var documentsUrl = '/api/documents/';
5 Editor.Model = Editor.Object.extend({
11 Editor.XMLModel = Editor.Model.extend({
12 _className: 'Editor.XMLModel',
16 init: function(serverURL) {
18 this.serverURL = serverURL;
29 if (!this.get('synced')) {
33 success: this.reloadSucceeded.bind(this)
38 reloadSucceeded: function(data) {
39 this.set('data', data);
40 this.set('synced', true);
45 Editor.HTMLModel = Editor.Model.extend({
46 _className: 'Editor.HTMLModel',
50 init: function(serverURL) {
52 this.serverURL = serverURL;
56 if (!this.get('synced')) {
60 success: this.reloadSucceeded.bind(this)
65 reloadSucceeded: function(data) {
66 this.set('data', data);
67 this.set('synced', true);
72 Editor.DocumentModel = Editor.Model.extend({
73 _className: 'Editor.DocumentModel',
74 data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
83 console.log('DocumentModel#load');
86 url: documentsUrl + fileId,
88 success: this.successfulLoad.bind(this)
92 successfulLoad: function(data) {
93 console.log('DocumentModel#successfulLoad:', data);
94 this.set('data', data);
95 this.contentModels = {
96 'xml': new Editor.XMLModel(data.text_url),
97 'html': new Editor.HTMLModel(data.html_url)
99 for (var key in this.contentModels) {
100 this.contentModels[key].addObserver(this, 'data', this.contentModelDataChanged.bind(this));
104 contentModelDataChanged: function(property, value, contentModel) {
105 console.log('data of', contentModel.description(), 'changed!');
106 for (var key in this.contentModels) {
107 if (this.contentModels[key].guid() != contentModel.guid()) {
108 console.log(this.contentModels[key].description(), 'frozen');
109 this.contentModels[key].set('synced', false);
116 var leftPanelView, rightPanelContainer, doc;
119 doc = new Editor.DocumentModel();
120 var splitView = new SplitView('#splitview', doc);
121 leftPanelView = new PanelContainerView('#left-panel-container', doc);
122 rightPanelContainer = new PanelContainerView('#right-panel-container', doc);