aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-24 11:43:51 -0700
committerNivesh Rajbhandari2012-04-24 11:43:51 -0700
commit915d92707dd07bf5ddcaca7039114649dab61467 (patch)
tree9de810bfa45ebdb21005358e5b58414792b40bdf /js/controllers
parenta0daa3668883c8c35ce277b60509a3a3dcf303b2 (diff)
parent55e6d621b9555abac06ab4adff44dfe29a78ec4e (diff)
downloadninja-915d92707dd07bf5ddcaca7039114649dab61467.tar.gz
Merge branch 'refs/heads/ninja-internal' into AllFixes
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js73
1 files changed, 64 insertions, 9 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index ddaeb061..4be0767a 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -10,8 +10,10 @@ 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/html-document").HTMLDocument,
13 TextDocument = require("js/document/text-document").TextDocument, 13 TextDocument = require("js/document/text-document").TextDocument;
14 DocumentController; 14
15 // New Document Objects
16var Document = require("js/document/document-html").HtmlDocument;
15//////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////
16// 18//
17var DocumentController = exports.DocumentController = Montage.create(Component, { 19var DocumentController = exports.DocumentController = Montage.create(Component, {
@@ -19,6 +21,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
19 value: false 21 value: false
20 }, 22 },
21 23
24 webTemplate: {
25 value: false
26 },
27
22 _documents: { 28 _documents: {
23 value: [] 29 value: []
24 }, 30 },
@@ -65,6 +71,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
65 this.eventManager.addEventListener("styleSheetDirty", this, false); 71 this.eventManager.addEventListener("styleSheetDirty", this, false);
66 72
67 this.eventManager.addEventListener("addComponentFirstDraw", this, false); 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);
68 } 78 }
69 }, 79 },
70 80
@@ -130,6 +140,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
130 } 140 }
131 }, 141 },
132 142
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
133 handleExecuteNewFile: { 157 handleExecuteNewFile: {
134 value: function(event) { 158 value: function(event) {
135 var newFileSettings = event._event.settings || {}; 159 var newFileSettings = event._event.settings || {};
@@ -235,7 +259,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
235 this.creatingNewFile = true;//flag for timeline to identify new file flow 259 this.creatingNewFile = true;//flag for timeline to identify new file flow
236 260
237 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); 261 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this));
238 }else if(!!response && !response.success){ 262 } else if(!!response && !response.success){
239 //Todo: restrict directory path to the sandbox, in the dialog itself 263 //Todo: restrict directory path to the sandbox, in the dialog itself
240 alert("Unable to create file.\n [Error: Forbidden directory]"); 264 alert("Unable to create file.\n [Error: Forbidden directory]");
241 } 265 }
@@ -268,7 +292,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
268 this.isNewFilePath = false;//reset path identifier flag 292 this.isNewFilePath = false;//reset path identifier flag
269 293
270 //Sending full response object 294 //Sending full response object
271 this.openDocument(response); 295 // TODO: Unify those 2 methods. Using if/else for the new template
296 if(this.webTemplate) {
297 this.openWebDocument(response);
298 } else {
299 this.openDocument(response);
300 }
272 } else if (!!response && (response.status === 404)){ 301 } else if (!!response && (response.status === 404)){
273 alert("Unable to open file.\n [Error: File does not exist]"); 302 alert("Unable to open file.\n [Error: File does not exist]");
274 } else if (!!response && (response.status === 500)){ 303 } else if (!!response && (response.status === 500)){
@@ -311,7 +340,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
311 this.documentHackReference = doc; 340 this.documentHackReference = doc;
312 // 341 //
313 switch (doc.extension) { 342 switch (doc.extension) {
314 case 'html': case 'html': 343 case 'html':
315 //Open in designer view 344 //Open in designer view
316 Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this)); 345 Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this));
317 break; 346 break;
@@ -327,6 +356,30 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
327 } 356 }
328 } 357 }
329 }, 358 },
359 openWebDocument: {
360 value: function(doc) {
361 // TODO: HACKS to remove
362 this.documentHackReference = doc;
363 document.getElementById("iframeContainer").style.overflow = "hidden";
364 //
365 switch (doc.extension) {
366 case 'html':
367 //Open in designer view
368 this._hackRootFlag = false;
369 Montage.create(Document).init(doc, this, this._onOpenDocument);
370 break;
371 default:
372 //Open in code view
373 var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea;
374 textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid);
375 code.initialize(doc, docuuid, textArea, textArea.parentNode);
376 //code.init(doc.name, doc.uri, doc.extension, null, docuuid);
377 code.textArea.value = doc.content;
378 this.application.ninja.stage.stageView.createTextView(code);
379 break;
380 }
381 }
382 },
330 //////////////////////////////////////////////////////////////////// 383 ////////////////////////////////////////////////////////////////////
331 384
332 openProjectWithURI: { 385 openProjectWithURI: {
@@ -428,11 +481,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
428 481
429 this.activeDocument = doc; 482 this.activeDocument = doc;
430 483
431 this._showCurrentDocument(); 484 if(!this.webTemplate) {
485 this._showCurrentDocument();
486 }
487
488 this.webTemplate = false;
432 489
433 NJevent("onOpenDocument", doc); 490 NJevent("onOpenDocument", doc);
434// appDelegateModule.MyAppDelegate.onSetActiveDocument();
435
436 } 491 }
437 }, 492 },
438 493
@@ -526,7 +581,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
526 this.application.ninja.stage.stageView.showRulers(); 581 this.application.ninja.stage.stageView.showRulers();
527 }else{ 582 }else{
528 //hide the iframe when switching to code view 583 //hide the iframe when switching to code view
529 document.getElementById("iframeContainer").style.display="none"; 584 document.getElementById("iframeContainer").style.display = "none";
530 } 585 }
531 } 586 }
532 } 587 }