aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js327
1 files changed, 59 insertions, 268 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 2c34eedf..f85e2f97 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -8,37 +8,58 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
8// 8//
9var Montage = require("montage/core/core").Montage, 9var 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,
12 HTMLDocument = require("js/document/document-html").HtmlDocument, 11 HTMLDocument = require("js/document/document-html").HtmlDocument,
13 TextDocument = require("js/document/document-text").TextDocument; 12 TextDocument = require("js/document/document-text").TextDocument;
14//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
15// 14//
16exports.DocumentController = Montage.create(Component, { 15exports.DocumentController = Montage.create(Component, {
17 // 16 //
18 hasTemplate: {value: false}, 17 hasTemplate: {
19 _documents: {value: []}, 18 value: false
20 //TODO: what is this?!?! 19 },
21 _hackInitialStyles: {value: true}, 20
22 _activeDocument: { value: null }, 21 iframeContainer: {
23 //TODO: Are any of these needed? 22 value: null
24 _iframeCounter: { value: 1, enumerable: false }, 23 },
25 _iframeHolder: { value: null, enumerable: false }, 24
26 _textHolder: { value: null, enumerable: false }, 25 codeContainer: {
27 _codeMirrorCounter: {value: 1, enumerable: false}, 26 value: null
28 27 },
29 activeDocument: { 28
30 get: function() { 29 documents: {
31 return this._activeDocument; 30 value: []
31 },
32
33 _currentDocument: {
34 value : null
35 },
36
37 currentDocument : {
38 get : function() {
39 return this._currentDocument;
32 }, 40 },
33 set: function(doc) { 41 set : function(value) {
34 //if(!!this._activeDocument){ this._activeDocument.isActive = false;} 42 if (value === this._currentDocument) {
43 return;
44 }
35 45
36 this._activeDocument = doc; 46 if(this._currentDocument) {
47 this._currentDocument.model.currentView.hide();
48 }
49
50 this._currentDocument = value;
37 51
38 if(!!this._activeDocument){ 52 if(!value) {
39 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 53 document.getElementById("iframeContainer").style.display = "block";
40 this._activeDocument.isActive = true; 54 document.getElementById("codeViewContainer").style.display = "block";
55 } else if(this._currentDocument.currentView === "design") {
56 this._currentDocument.model.currentView.show();
57 this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*');
58 } else {
59 document.getElementById("iframeContainer").style.display = "none";
60 this._currentDocument.model.currentView.show();
41 } 61 }
62
42 } 63 }
43 }, 64 },
44 65
@@ -52,11 +73,15 @@ exports.DocumentController = Montage.create(Component, {
52 this.eventManager.addEventListener("executeSaveAll", this, false); 73 this.eventManager.addEventListener("executeSaveAll", this, false);
53 this.eventManager.addEventListener("executeFileClose", this, false); 74 this.eventManager.addEventListener("executeFileClose", this, false);
54 this.eventManager.addEventListener("executeFileCloseAll", this, false); 75 this.eventManager.addEventListener("executeFileCloseAll", this, false);
76 }
77 },
55 78
56 this.eventManager.addEventListener("styleSheetDirty", this, false); 79 didCreate: {
80 value: function() {
81 this.iframeContainer = document.getElementById("iframeContainer");
82 this.codeContainer = document.getElementById("codeViewContainer");
57 } 83 }
58 }, 84 },
59
60 85
61 //TODO: Ensure these APIs are not needed 86 //TODO: Ensure these APIs are not needed
62 redirectRequests: { 87 redirectRequests: {
@@ -70,11 +95,11 @@ exports.DocumentController = Montage.create(Component, {
70 if (this.redirectRequests && request.parentFrameId !== -1) { 95 if (this.redirectRequests && request.parentFrameId !== -1) {
71 //Checking for proper URL redirect (from different directories) 96 //Checking for proper URL redirect (from different directories)
72 if (request.url.indexOf('js/document/templates/banner') !== -1) { 97 if (request.url.indexOf('js/document/templates/banner') !== -1) {
73 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]}; 98 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]};
74 } else if (request.url.indexOf('js/document/templates/html') !== -1) { 99 } else if (request.url.indexOf('js/document/templates/html') !== -1) {
75 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]}; 100 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]};
76 } else if (request.url.indexOf('js/document/templates/app') !== -1) { 101 } else if (request.url.indexOf('js/document/templates/app') !== -1) {
77 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/app/'))[1]}; 102 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]};
78 } else { 103 } else {
79 //Error, not a valid folder 104 //Error, not a valid folder
80 } 105 }
@@ -98,13 +123,7 @@ exports.DocumentController = Montage.create(Component, {
98 }, 123 },
99 //////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////
100 125
101 126
102
103
104
105
106
107
108 handleExecuteFileOpen: { 127 handleExecuteFileOpen: {
109 value: function(event) { 128 value: function(event) {
110 var pickerSettings = event._event.settings || {}; 129 var pickerSettings = event._event.settings || {};
@@ -131,10 +150,10 @@ exports.DocumentController = Montage.create(Component, {
131 handleExecuteSave: { 150 handleExecuteSave: {
132 value: function(event) { 151 value: function(event) {
133 // 152 //
134 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 153 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
135 //Currently we don't need a callback handler 154 //Currently we don't need a callback handler
136 //this.activeDocument.model.save(this.saveExecuted.bind(this)); 155 //this.activeDocument.model.save(this.saveExecuted.bind(this));
137 this.activeDocument.model.save(); 156 this.currentDocument.model.save();
138 } else { 157 } else {
139 //Error: cloud not available and/or no active document 158 //Error: cloud not available and/or no active document
140 } 159 }
@@ -175,16 +194,13 @@ exports.DocumentController = Montage.create(Component, {
175 //////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////
176 handleExecuteFileClose:{ 195 handleExecuteFileClose:{
177 value: function(event) { 196 value: function(event) {
178 if (this.activeDocument) { 197 this.closeFile(this.currentDocument);
179 this.closeFile(this.activeDocument);
180 }
181 } 198 }
182 }, 199 },
183 //////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////
184 //TODO: Is this used, should be cleaned up 201 //TODO: Is this used, should be cleaned up
185 handleExecuteFileCloseAll:{ 202 handleExecuteFileCloseAll:{
186 value: function(event) { 203 value: function(event) {
187 var i=0;//TODO: who is using this??
188 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 204 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
189 while(this._documents.length > 0){ 205 while(this._documents.length > 0){
190 this.closeDocument(this._documents[this._documents.length -1].uuid); 206 this.closeDocument(this._documents[this._documents.length -1].uuid);
@@ -308,11 +324,11 @@ exports.DocumentController = Montage.create(Component, {
308 324
309 //Open in designer view 325 //Open in designer view
310 this.redirectRequests = false; 326 this.redirectRequests = false;
311 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template); 327 Montage.create(HTMLDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'design', template);
312 break; 328 break;
313 default: 329 default:
314 //Open in code view 330 //Open in code view
315 Montage.create(TextDocument).init(file, this, this._onOpenTextDocument, 'code'); 331 Montage.create(TextDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'code');
316 break; 332 break;
317 } 333 }
318 } 334 }
@@ -325,156 +341,9 @@ exports.DocumentController = Montage.create(Component, {
325 } 341 }
326 }, 342 },
327 343
328 //todo: remove this funciton as it is not used
329 textDocumentOpened: {
330 value: function(doc) {
331
332
333
334 this.application.ninja.stage.stageView.createTextView(doc);
335
336 /*
337 DocumentManager._hideCurrentDocument();
338 stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
339 DocumentManager.activeDocument = doc;
340
341 var type;
342
343 switch(doc.documentType) {
344 case "css" :
345 type = "css";