aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-06-04 10:37:29 -0700
committerPushkar Joshi2012-06-04 10:37:29 -0700
commitf1d75e5b29661abc4e173adc1f9de2e0cd91df83 (patch)
tree796931014054ad6b0647854183f632ffd72ed9ee /js/controllers/document-controller.js
parent06b609df1ff7833592faddbd8d7abb5b9f15a74d (diff)
parentc1ec69879028220b0c3f11ad6e24035bf527802c (diff)
downloadninja-f1d75e5b29661abc4e173adc1f9de2e0cd91df83.tar.gz
Merge branch 'master' into pentool
Conflicts: js/tools/PenTool.js
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js381
1 files changed, 61 insertions, 320 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 2c34eedf..a90375af 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -8,37 +8,61 @@ 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 }
45
46 if(this._currentDocument) {
47 this._currentDocument.model.currentView.hide();
48 }
35 49
36 this._activeDocument = doc; 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 document.getElementById("codeViewContainer").style.display = "none";
57 document.getElementById("iframeContainer").style.display = "block";
58 this._currentDocument.model.currentView.show();
59 this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*');
60 } else {
61 document.getElementById("iframeContainer").style.display = "none";
62 this._currentDocument.model.parentContainer.style["display"] = "block";
63 this._currentDocument.model.currentView.show();
41 } 64 }
65
42 } 66 }
43 }, 67 },
44 68
@@ -52,11 +76,15 @@ exports.DocumentController = Montage.create(Component, {
52 this.eventManager.addEventListener("executeSaveAll", this, false); 76 this.eventManager.addEventListener("executeSaveAll", this, false);
53 this.eventManager.addEventListener("executeFileClose", this, false); 77 this.eventManager.addEventListener("executeFileClose", this, false);
54 this.eventManager.addEventListener("executeFileCloseAll", this, false); 78 this.eventManager.addEventListener("executeFileCloseAll", this, false);
79 }
80 },
55 81
56 this.eventManager.addEventListener("styleSheetDirty", this, false); 82 didCreate: {
83 value: function() {
84 this.iframeContainer = document.getElementById("iframeContainer");
85 this.codeContainer = document.getElementById("codeViewContainer");
57 } 86 }
58 }, 87 },
59
60 88
61 //TODO: Ensure these APIs are not needed 89 //TODO: Ensure these APIs are not needed
62 redirectRequests: { 90 redirectRequests: {
@@ -70,11 +98,11 @@ exports.DocumentController = Montage.create(Component, {
70 if (this.redirectRequests && request.parentFrameId !== -1) { 98 if (this.redirectRequests && request.parentFrameId !== -1) {
71 //Checking for proper URL redirect (from different directories) 99 //Checking for proper URL redirect (from different directories)
72 if (request.url.indexOf('js/document/templates/banner') !== -1) { 100 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]}; 101 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) { 102 } 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]}; 103 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) { 104 } 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]}; 105 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 { 106 } else {
79 //Error, not a valid folder 107 //Error, not a valid folder
80 } 108 }
@@ -98,13 +126,7 @@ exports.DocumentController = Montage.create(Component, {
98 }, 126 },
99 //////////////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////
100 128
101 129
102
103
104
105
106
107
108 handleExecuteFileOpen: { 130 handleExecuteFileOpen: {
109 value: function(event) { 131 value: function(event) {
110 var pickerSettings = event._event.settings || {}; 132 var pickerSettings = event._event.settings || {};
@@ -131,10 +153,10 @@ exports.DocumentController = Montage.create(Component, {
131 handleExecuteSave: { 153 handleExecuteSave: {
132 value: function(event) { 154 value: function(event) {
133 // 155 //
134 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 156 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
135 //Currently we don't need a callback handler 157 //Currently we don't need a callback handler
136 //this.activeDocument.model.save(this.saveExecuted.bind(this)); 158 //this.activeDocument.model.save(this.saveExecuted.bind(this));
137 this.activeDocument.model.save(); 159 this.currentDocument.model.save();
138 } else { 160 } else {
139 //Error: cloud not available and/or no active document 161 //Error: cloud not available and/or no active document
140 } 162 }
@@ -175,16 +197,13 @@ exports.DocumentController = Montage.create(Component, {
175 //////////////////////////////////////////////////////////////////// 197 ////////////////////////////////////////////////////////////////////
176 handleExecuteFileClose:{ 198 handleExecuteFileClose:{
177 value: function(event) { 199 value: function(event) {
178 if (this.activeDocument) { 200 this.closeFile(this.currentDocument);
179 this.closeFile(this.activeDocument);
180 }
181 } 201 }
182 }, 202 },
183 //////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////
184 //TODO: Is this used, should be cleaned up 204 //TODO: Is this used, should be cleaned up
185 handleExecuteFileCloseAll:{ 205 handleExecuteFileCloseAll:{
186 value: function(event) { 206 value: function(event) {
187 var i=0;//TODO: who is using this??
188 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 207 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
189 while(this._documents.length > 0){ 208 while(this._documents.length > 0){
190 this.closeDocument(this._documents[this._documents.length -1].uuid); 209 this.closeDocument(this._documents[this._documents.length -1].uuid);
@@ -308,11 +327,11 @@ exports.DocumentController = Montage.create(Component, {
308 327
309 //Open in designer view 328 //Open in designer view
310 this.redirectRequests = false; 329 this.redirectRequests = false;
311 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template); 330 Montage.create(HTMLDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'design', template);
312 break; 331 break;
313 default: 332 default:
314 //Open in code view 333 //Open in code view
315 Montage.create(TextDocument).init(file, this, this._onOpenTextDocument, 'code'); 334 Montage.create(TextDocument).init(file, this.application.ninja, this.application.ninja.openDocument, 'code');
316 break; 335 break;
317 } 336 }
318 } 337 }
@@ -325,287 +344,9 @@ exports.DocumentController = Montage.create(Component, {
325 } 344 }
326 }, 345 },
327 346
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 /*