1 /*globals Editor fileId SplitView PanelContainerView*/
2 var documentsUrl = '/api/documents/';
5 Editor.Model = Editor.Object.extend({
11 Editor.ToolbarButtonsModel = Editor.Model.extend({
12 _className: 'Editor.ToolbarButtonsModel',
13 serverURL: '/api/toolbar/buttons',
21 if (!this.get('buttons').length) {
25 success: this.loadSucceeded.bind(this)
30 loadSucceeded: function(data) {
31 this.set('buttons', data);
36 Editor.XMLModel = Editor.Model.extend({
37 _className: 'Editor.XMLModel',
41 init: function(serverURL) {
43 this.serverURL = serverURL;
44 this.toolbarButtonsModel = new Editor.ToolbarButtonsModel();
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.HTMLModel = Editor.Model.extend({
72 _className: 'Editor.HTMLModel',
76 init: function(serverURL) {
78 this.serverURL = serverURL;
82 if (!this.get('synced')) {
86 success: this.reloadSucceeded.bind(this)
91 reloadSucceeded: function(data) {
92 this.set('data', data);
93 this.set('synced', true);
98 Editor.DocumentModel = Editor.Model.extend({
99 _className: 'Editor.DocumentModel',
100 data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
109 console.log('DocumentModel#load');
112 url: documentsUrl + fileId,
114 success: this.successfulLoad.bind(this)
118 successfulLoad: function(data) {
119 console.log('DocumentModel#successfulLoad:', data);
120 this.set('data', data);
121 this.contentModels = {
122 'xml': new Editor.XMLModel(data.text_url),
123 'html': new Editor.HTMLModel(data.html_url)
125 for (var key in this.contentModels) {
126 this.contentModels[key].addObserver(this, 'data', this.contentModelDataChanged.bind(this));
130 contentModelDataChanged: function(property, value, contentModel) {
131 console.log('data of', contentModel.description(), 'changed!');
132 for (var key in this.contentModels) {
133 if (this.contentModels[key].guid() != contentModel.guid()) {
134 console.log(this.contentModels[key].description(), 'frozen');
135 this.contentModels[key].set('synced', false);
142 var leftPanelView, rightPanelContainer, doc;
145 doc = new Editor.DocumentModel();
146 var editor = new EditorView('body', doc);
147 var splitView = new SplitView('#splitview', doc);
148 leftPanelView = new PanelContainerView('#left-panel-container', doc);
149 rightPanelContainer = new PanelContainerView('#right-panel-container', doc);