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',
15 init: function(serverURL) {
17 this.serverURL = serverURL;
28 if (!this.get('synced')) {
32 success: this.reloadSucceeded.bind(this)
37 reloadSucceeded: function(data) {
38 this.set('data', data);
39 this.set('synced', true);
44 Editor.HTMLModel = Editor.Model.extend({
45 _className: 'Editor.HTMLModel',
49 init: function(serverURL) {
51 this.serverURL = serverURL;
55 if (!this.get('synced')) {
59 success: this.reloadSucceeded.bind(this)
64 reloadSucceeded: function(data) {
65 this.set('data', data);
66 this.set('synced', true);
71 Editor.DocumentModel = Editor.Model.extend({
72 _className: 'Editor.DocumentModel',
73 data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
82 console.log('DocumentModel#load');
85 url: documentsUrl + fileId,
87 success: this.successfulLoad.bind(this)
91 successfulLoad: function(data) {
92 console.log('DocumentModel#successfulLoad:', data);
93 this.set('data', data);
94 this.contentModels = {
95 'xml': new Editor.XMLModel(data.text_url),
96 'html': new Editor.HTMLModel(data.html_url)
98 for (var key in this.contentModels) {
99 this.contentModels[key].addObserver(this, 'data', this.contentModelDataChanged.bind(this));
103 contentModelDataChanged: function(property, value, contentModel) {
104 console.log('data of', contentModel.description(), 'changed!');
105 for (var key in this.contentModels) {
106 if (this.contentModels[key].guid() != contentModel.guid()) {
107 console.log(this.contentModels[key].description(), 'frozen');
108 this.contentModels[key].set('synced', false);
115 var leftPanelView, rightPanelContainer, doc;
118 doc = new Editor.DocumentModel();
119 var splitView = new SplitView('#splitview', doc);
120 leftPanelView = new PanelContainerView('#left-panel-container', doc);
121 rightPanelContainer = new PanelContainerView('#right-panel-container', doc);