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.js407
1 files changed, 74 insertions, 333 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 2c34eedf..a3ebac24 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 }
@@ -152,9 +174,9 @@ exports.DocumentController = Montage.create(Component, {
152 handleExecuteSaveAll: { 174 handleExecuteSaveAll: {
153 value: function(event) { 175 value: function(event) {
154 // 176 //
155 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 177 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
156 // 178 //
157 this.activeDocument.model.saveAll(); 179 this.currentDocument.model.saveAll();
158 } else { 180 } else {
159 //TODO: Add error handling 181 //TODO: Add error handling
160 } 182 }
@@ -164,9 +186,9 @@ exports.DocumentController = Montage.create(Component, {
164 handleExecuteSaveAs: { 186 handleExecuteSaveAs: {
165 value: function(event) { 187 value: function(event) {
166 var saveAsSettings = event._event.settings || {}; 188 var saveAsSettings = event._event.settings || {};
167 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 189 if((typeof this.currentDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
168 saveAsSettings.fileName = this.activeDocument.model.file.name; 190 saveAsSettings.fileName = this.currentDocument.model.file.name;
169 saveAsSettings.folderUri = this.activeDocument.model.file.uri.substring(0, this.activeDocument.model.file.uri.lastIndexOf("/")); 191 saveAsSettings.folderUri = this.currentDocument.model.file.uri.substring(0, this.currentDocument.model.file.uri.lastIndexOf("/"));
170 saveAsSettings.callback = this.saveAsCallback.bind(this); 192 saveAsSettings.callback = this.saveAsCallback.bind(this);
171 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); 193 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
172 } 194 }
@@ -175,19 +197,16 @@ 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?? 207 if(this.currentDocument && this.application.ninja.coreIoApi.cloudAvailable()){
188 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 208 while(this.currentDocument.length > 0){
189 while(this._documents.length > 0){ 209 this.closeDocument(this.currentDocument[this.currentDocument.length -1].uuid);
190 this.closeDocument(this._documents[this._documents.length -1].uuid);
191 } 210 }
192 } 211 }
193 } 212 }
@@ -272,19 +291,19 @@ exports.DocumentController = Montage.create(Component, {
272 value:function(saveAsDetails){