aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js198
-rwxr-xr-xjs/controllers/elements/body-controller.js30
-rwxr-xr-xjs/controllers/elements/component-controller.js4
-rwxr-xr-xjs/controllers/elements/shapes-controller.js4
-rwxr-xr-xjs/controllers/selection-controller.js29
-rwxr-xr-xjs/controllers/styles-controller.js13
6 files changed, 187 insertions, 91 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index c6bf4c6b..1e894f02 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -33,6 +33,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
33 value: false 33 value: false
34 }, 34 },
35 35
36 _hackInitialStyles: {
37 value: true
38 },
39
36 _activeDocument: { value: null }, 40 _activeDocument: { value: null },
37 _iframeCounter: { value: 1, enumerable: false }, 41 _iframeCounter: { value: 1, enumerable: false },
38 _iframeHolder: { value: null, enumerable: false }, 42 _iframeHolder: { value: null, enumerable: false },
@@ -44,8 +48,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
44 return this._activeDocument; 48 return this._activeDocument;
45 }, 49 },
46 set: function(doc) { 50 set: function(doc) {
47 if(!!this._activeDocument){ this._activeDocument.isActive = false;} 51// if(!!this._activeDocument){ this._activeDocument.isActive = false;}
52
48 this._activeDocument = doc; 53 this._activeDocument = doc;
54
49 if(!!this._activeDocument){ 55 if(!!this._activeDocument){
50 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 56 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
51 this._activeDocument.isActive = true; 57 this._activeDocument.isActive = true;
@@ -70,36 +76,28 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
70 76
71 this.eventManager.addEventListener("styleSheetDirty", this, false); 77 this.eventManager.addEventListener("styleSheetDirty", this, false);
72 78
73 this.eventManager.addEventListener("addComponentFirstDraw", this, false);
74
75 // Temporary add listeners for the new stage templates 79 // Temporary add listeners for the new stage templates
76 this.eventManager.addEventListener("executeWebpageOpen", this, false); 80 this.eventManager.addEventListener("executeWebpageOpen", this, false);
77 this.eventManager.addEventListener("executeNewWebpage", this, false); 81 this.eventManager.addEventListener("executeNewWebpage", this, false);
78 } 82 }
79 }, 83 },
80 84
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 85
92//////////////////////////////////////////////////////////////////// 86 //TODO: Ensure these APIs are not needed
87 ////////////////////////////////////////////////////////////////////
93 // 88 //
94 handleWebRequest: { 89 handleWebRequest: {
95 value: function (request) { 90 value: function (request) {
96 //TODO: Check if frameId is proper 91 //TODO: Check if frameId is proper
97 if (this._hackRootFlag && request.parentFrameId !== -1) { 92 if (this._hackRootFlag && request.parentFrameId !== -1) {
98 //TODO: Optimize creating string 93 //Checking for proper URL redirect (from different directories)
99 //console.log(request); 94 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); 95 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]}; 96 } 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]}; 97 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]};
98 } else {
99 //Error, not a valid folder
100 }
103 } 101 }
104 } 102 }
105 }, 103 },
@@ -155,32 +153,43 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
155 }, 153 },
156 154
157 handleExecuteNewFile: { 155 handleExecuteNewFile: {
158 value: function(event) { 156 value: function(event) {
159 var newFileSettings = event._event.settings || {}; 157 var newFileSettings = event._event.settings || {};
160 if (this.application.ninja.coreIoApi.cloudAvailable()) { 158 if (this.application.ninja.coreIoApi.cloudAvailable()) {
161 newFileSettings.callback = this.createNewFile.bind(this); 159 newFileSettings.callback = this.createNewFile.bind(this);
162 this.application.ninja.newFileController.showNewFileDialog(newFileSettings); 160 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
163 }
164 } 161 }
162 }
165 }, 163 },
166 //////////////////////////////////////////////////////////////////// 164 ////////////////////////////////////////////////////////////////////
167 //TODO: Check for appropiate structures 165 //
168 handleExecuteSave: { 166 handleExecuteSave: {
169 value: function(event) { 167 value: function(event) {
170 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 168 //
171 //Text and HTML document classes should return the same save object for fileSave 169 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
172 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); 170 //
173 } 171 this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this)
172 } else {
173 //Error:
174 }
174 } 175 }
175 }, 176 },
177 testCallback: {
178 value: function (value) {
179 console.log(value);
180 }
181 },
176 //////////////////////////////////////////////////////////////////// 182 ////////////////////////////////////////////////////////////////////
177 //TODO: Check for appropiate structures 183 //TODO: Check for appropiate structures
178 handleExecuteSaveAll: { 184 handleExecuteSaveAll: {
179 value: function(event) { 185 value: function(event) {
180 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 186 //
181 //Text and HTML document classes should return the same save object for fileSave 187 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
182 this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); 188 //
183 } 189 this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this)
190 } else {
191 //Error:
192 }
184 } 193 }
185 }, 194 },
186 //////////////////////////////////////////////////////////////////// 195 ////////////////////////////////////////////////////////////////////
@@ -198,9 +207,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
198 //////////////////////////////////////////////////////////////////// 207 ////////////////////////////////////////////////////////////////////
199 handleExecuteFileClose:{ 208 handleExecuteFileClose:{
200 value: function(event) { 209 value: function(event) {
201 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 210 if (this.activeDocument) {
202 this.closeDocument(this.activeDocument.uuid); 211// this.activeDocument.closeDocument();
203 } 212 this.closeFile(this.activeDocument);
213 }
204 } 214 }
205 }, 215 },
206 //////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////
@@ -219,7 +229,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
219 fileSaveResult: { 229 fileSaveResult: {
220 value: function (result) { 230 value: function (result) {
221 if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved 231 if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved
222 this.activeDocument.needsSave = false; 232 this.activeDocument.model.needsSave = false;
223 if(this.application.ninja.currentDocument !== null){ 233 if(this.application.ninja.currentDocument !== null){
224 //clear Dirty StyleSheets for the saved document 234 //clear Dirty StyleSheets for the saved document
225 this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); 235 this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument);
@@ -228,20 +238,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
228 } 238 }
229 }, 239 },
230 240
241
242
243 ////////////////////////////////////////////////////////////////////
244 //
231 createNewFile:{ 245 createNewFile:{
232 value:function(newFileObj){ 246 value:function(newFileObj){
233 //console.log(newFileObj);//contains the template uri and the new file uri 247 //
234 if(!newFileObj) return; 248 if(!newFileObj) return;
235 this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this)); 249 //
236 250 this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this), newFileObj.template);
237 if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view
238
239 } else {
240 //open design view
241 }
242 } 251 }
243 }, 252 },
244 253 ////////////////////////////////////////////////////////////////////
254
245 /** 255 /**
246 * Public method 256 * Public method
247 * doc contains: 257 * doc contains:
@@ -358,6 +368,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
358 }, 368 },
359 openWebDocument: { 369 openWebDocument: {
360 value: function(doc) {