diff options
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 491 |
1 files changed, 240 insertions, 251 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index c6bf4c6b..d99fadbb 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -9,11 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component, | 10 | Component = require("montage/ui/component").Component, |
11 | Uuid = require("montage/core/uuid").Uuid, | 11 | Uuid = require("montage/core/uuid").Uuid, |
12 | HTMLDocument = require("js/document/html-document").HTMLDocument, | 12 | HTMLDocument = require("js/document/document-html").HtmlDocument, |
13 | TextDocument = require("js/document/text-document").TextDocument; | 13 | TextDocument = require("js/document/document-text").TextDocument; |
14 | |||
15 | // New Document Objects | ||
16 | var Document = require("js/document/document-html").HtmlDocument; | ||
17 | //////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////// |
18 | // | 15 | // |
19 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 16 | var DocumentController = exports.DocumentController = Montage.create(Component, { |
@@ -21,10 +18,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
21 | value: false | 18 | value: false |
22 | }, | 19 | }, |
23 | 20 | ||
24 | webTemplate: { | ||
25 | value: false | ||
26 | }, | ||
27 | |||
28 | _documents: { | 21 | _documents: { |
29 | value: [] | 22 | value: [] |
30 | }, | 23 | }, |
@@ -33,6 +26,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
33 | value: false | 26 | value: false |
34 | }, | 27 | }, |
35 | 28 | ||
29 | _hackInitialStyles: { | ||
30 | value: true | ||
31 | }, | ||
32 | |||
36 | _activeDocument: { value: null }, | 33 | _activeDocument: { value: null }, |
37 | _iframeCounter: { value: 1, enumerable: false }, | 34 | _iframeCounter: { value: 1, enumerable: false }, |
38 | _iframeHolder: { value: null, enumerable: false }, | 35 | _iframeHolder: { value: null, enumerable: false }, |
@@ -44,15 +41,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
44 | return this._activeDocument; | 41 | return this._activeDocument; |
45 | }, | 42 | }, |
46 | set: function(doc) { | 43 | set: function(doc) { |
47 | if(!!this._activeDocument){ this._activeDocument.isActive = false;} | 44 | // if(!!this._activeDocument){ this._activeDocument.isActive = false;} |
45 | |||
48 | this._activeDocument = doc; | 46 | this._activeDocument = doc; |
47 | |||
49 | if(!!this._activeDocument){ | 48 | if(!!this._activeDocument){ |
50 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | 49 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); |
51 | this._activeDocument.isActive = true; | 50 | this._activeDocument.isActive = true; |
52 | |||
53 | if(!!this._activeDocument.editor){ | ||
54 | this._activeDocument.editor.focus(); | ||
55 | } | ||
56 | } | 51 | } |
57 | } | 52 | } |
58 | }, | 53 | }, |
@@ -69,37 +64,25 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
69 | this.eventManager.addEventListener("executeFileCloseAll", this, false); | 64 | this.eventManager.addEventListener("executeFileCloseAll", this, false); |
70 | 65 | ||
71 | this.eventManager.addEventListener("styleSheetDirty", this, false); | 66 | this.eventManager.addEventListener("styleSheetDirty", this, false); |
72 | |||
73 | this.eventManager.addEventListener("addComponentFirstDraw", this, false); | ||
74 | |||
75 | // Temporary add listeners for the new stage templates | ||
76 | this.eventManager.addEventListener("executeWebpageOpen", this, false); | ||
77 | this.eventManager.addEventListener("executeNewWebpage", this, false); | ||
78 | } | 67 | } |
79 | }, | 68 | }, |
80 | 69 | ||
81 | handleAddComponentFirstDraw: { | ||
82 | value: function (e) { | ||
83 | //TODO: Add logic to reparse the document for dynamically added styles | ||
84 | //console.log(e); | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | |||
89 | |||
90 | |||
91 | 70 | ||
92 | //////////////////////////////////////////////////////////////////// | 71 | //TODO: Ensure these APIs are not needed |
72 | //////////////////////////////////////////////////////////////////// | ||
93 | // | 73 | // |
94 | handleWebRequest: { | 74 | handleWebRequest: { |
95 | value: function (request) { | 75 | value: function (request) { |
96 | //TODO: Check if frameId is proper | 76 | //TODO: Check if frameId is proper |
97 | if (this._hackRootFlag && request.parentFrameId !== -1) { | 77 | if (this._hackRootFlag && request.parentFrameId !== -1) { |
98 | //TODO: Optimize creating string | 78 | //Checking for proper URL redirect (from different directories) |
99 | //console.log(request); | 79 | if (request.url.indexOf('js/document/templates/banner') !== -1) { |
100 | //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); | 80 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; |
101 | //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; | 81 | } else if (request.url.indexOf('js/document/templates/html') !== -1) { |
102 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/montage-html/'))[1]}; | 82 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; |
83 | } else { | ||
84 | //Error, not a valid folder | ||
85 | } | ||
103 | } | 86 | } |
104 | } | 87 | } |
105 | }, | 88 | }, |
@@ -140,47 +123,47 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
140 | } | 123 | } |
141 | }, | 124 | }, |
142 | 125 | ||
143 | handleExecuteWebpageOpen: { | ||
144 | value: function(event) { | ||
145 | this.webTemplate = true; | ||
146 | this.handleExecuteFileOpen(event); | ||
147 | } | ||
148 | }, | ||
149 | |||
150 | handleExecuteNewWebpage: { | ||
151 | value: function(event) { | ||
152 | this.webTemplate = true; | ||
153 | this.handleExecuteNewFile(event); | ||
154 | } | ||
155 | }, | ||
156 | |||
157 | handleExecuteNewFile: { | 126 | handleExecuteNewFile: { |
158 | value: function(event) { | 127 | value: function(event) { |
159 | var newFileSettings = event._event.settings || {}; | 128 | var newFileSettings = event._event.settings || {}; |
160 | if (this.application.ninja.coreIoApi.cloudAvailable()) { | 129 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
161 | newFileSettings.callback = this.createNewFile.bind(this); | 130 | newFileSettings.callback = this.createNewFile.bind(this); |
162 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 131 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); |
163 | } | ||
164 | } | 132 | } |
133 | } | ||
165 | }, | 134 | }, |
166 | //////////////////////////////////////////////////////////////////// | 135 | //////////////////////////////////////////////////////////////////// |
167 | //TODO: Check for appropiate structures | 136 | // |
168 | handleExecuteSave: { | 137 | handleExecuteSave: { |
169 | value: function(event) { | 138 | value: function(event) { |
170 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 139 | // |
171 | //Text and HTML document classes should return the same save object for fileSave | 140 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
172 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 141 | //Currently we don't need a callback handler |
173 | } | 142 | //this.activeDocument.model.save(this.saveExecuted.bind(this)); |
143 | this.activeDocument.model.save(); | ||
144 | } else { | ||
145 | //Error: cloud not available and/or no active document | ||
146 | } | ||
174 | } | 147 | } |
175 | }, | 148 | }, |
176 | //////////////////////////////////////////////////////////////////// | 149 | //////////////////////////////////////////////////////////////////// |
150 | // | ||
151 | saveExecuted: { | ||
152 | value: function (value) { | ||
153 | //File saved, any callbacks or events should go here | ||
154 | } | ||
155 | }, | ||
156 | //////////////////////////////////////////////////////////////////// | ||
177 | //TODO: Check for appropiate structures | 157 | //TODO: Check for appropiate structures |
178 | handleExecuteSaveAll: { | 158 | handleExecuteSaveAll: { |
179 | value: function(event) { | 159 | value: function(event) { |
180 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 160 | // |
181 | //Text and HTML document classes should return the same save object for fileSave | 161 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
182 | this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); | 162 | // |
183 | } | 163 | this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) |
164 | } else { | ||
165 | //Error: | ||
166 | } | ||
184 | } | 167 | } |
185 | }, | 168 | }, |
186 | //////////////////////////////////////////////////////////////////// | 169 | //////////////////////////////////////////////////////////////////// |
@@ -188,8 +171,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
188 | value: function(event) { | 171 | value: function(event) { |
189 | var saveAsSettings = event._event.settings || {}; | 172 | var saveAsSettings = event._event.settings || {}; |
190 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 173 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
191 | saveAsSettings.fileName = this.activeDocument.name; | 174 | saveAsSettings.fileName = this.activeDocument.model.file.name; |
192 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); | 175 | saveAsSettings.folderUri = this.activeDocument.model.file.uri.substring(0, this.activeDocument.model.file.uri.lastIndexOf("/")); |
193 | saveAsSettings.callback = this.saveAsCallback.bind(this); | 176 | saveAsSettings.callback = this.saveAsCallback.bind(this); |
194 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); | 177 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); |
195 | } | 178 | } |
@@ -198,9 +181,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
198 | //////////////////////////////////////////////////////////////////// | 181 | //////////////////////////////////////////////////////////////////// |
199 | handleExecuteFileClose:{ | 182 | handleExecuteFileClose:{ |
200 | value: function(event) { | 183 | value: function(event) { |
201 |