aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-21 18:04:27 -0800
committerJose Antonio Marquez2012-02-21 18:04:27 -0800
commit25e6a03cf8af4bd0496a8b21c82332d76ddd9fff (patch)
tree9b4ef3a716139d5259261cae97e8603a1d33a91f /js/controllers/document-controller.js
parent20dc41e571ddec6b781653fac43e2ca34026937d (diff)
parent2f24dafec79583547fe663d5a387d8ef15aae3bf (diff)
downloadninja-25e6a03cf8af4bd0496a8b21c82332d76ddd9fff.tar.gz
Merge branch 'refs/heads/NinjaInternal' into Color
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js59
1 files changed, 44 insertions, 15 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index b1a22c1b..7491ef9f 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -14,7 +14,7 @@ var Montage = require("montage/core/core").Montage,
14 DocumentController; 14 DocumentController;
15//////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////
16// 16//
17DocumentController = exports.DocumentController = Montage.create(Component, { 17var DocumentController = exports.DocumentController = Montage.create(Component, {
18 hasTemplate: { 18 hasTemplate: {
19 value: false 19 value: false
20 }, 20 },
@@ -22,6 +22,10 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
22 _documents: { 22 _documents: {
23 value: [] 23 value: []
24 }, 24 },
25
26 _hackRootFlag: {
27 value: false
28 },
25 29
26 _activeDocument: { value: null }, 30 _activeDocument: { value: null },
27 _iframeCounter: { value: 1, enumerable: false }, 31 _iframeCounter: { value: 1, enumerable: false },
@@ -56,15 +60,43 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
56 this.eventManager.addEventListener("executeSave", this, false); 60 this.eventManager.addEventListener("executeSave", this, false);
57 61
58 this.eventManager.addEventListener("recordStyleChanged", this, false); 62 this.eventManager.addEventListener("recordStyleChanged", this, false);
63
59 } 64 }
60 }, 65 },
61 66
67
68
69
70
71
72
73 ////////////////////////////////////////////////////////////////////
74 //
75 handleWebRequest: {
76 value: function (request) {
77 if (this._hackRootFlag && request.url.indexOf('js/document/templates/montage-html') !== -1) {
78 //TODO: Optimize creating string
79 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]};
80 }
81 }
82 },
83 ////////////////////////////////////////////////////////////////////
84 //
62 handleAppLoaded: { 85 handleAppLoaded: {
63 value: function() { 86 value: function() {
64 // 87 //Adding an intercept to resources loaded to ensure user assets load from cloud simulator
88 chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]);
65 } 89 }
66 }, 90 },
91 ////////////////////////////////////////////////////////////////////
67 92
93
94
95
96
97
98
99
68 handleExecuteFileOpen: { 100 handleExecuteFileOpen: {
69 value: function(event) { 101 value: function(event) {
70 var pickerSettings = event._event.settings || {}; 102 var pickerSettings = event._event.settings || {};
@@ -88,28 +120,21 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
88 //TODO: Check for appropiate structures 120 //TODO: Check for appropiate structures
89 handleExecuteSave: { 121 handleExecuteSave: {
90 value: function(event) { 122 value: function(event) {
123 if(!!this.activeDocument){
91 //Text and HTML document classes should return the same save object for fileSave 124 //Text and HTML document classes should return the same save object for fileSave
92 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); 125 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
93 } 126 }
127 }
94 }, 128 },
95 //////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////
96 // 130 //
97 fileSaveResult: { 131 fileSaveResult: {
98 value: function (result) { 132 value: function (result) {
99 if(result.status === 204){ 133 if(result.status === 204){
100 this.clearDocumentDirtyFlag(); 134 this.activeDocument.needsSave = false;
101 } 135 }
102 } 136 }
103 }, 137 },
104 ////////////////////////////////////////////////////////////////////
105
106
107 clearDocumentDirtyFlag:{
108 value: function(){
109 this.activeDocument.dirtyFlag = false;
110 }
111 },
112
113 138
114 createNewFile:{ 139 createNewFile:{
115 value:function(newFileObj){ 140 value:function(newFileObj){
@@ -180,6 +205,9 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
180 // 205 //
181 openDocument: { 206 openDocument: {
182 value: function(doc) { 207 value: function(doc) {
208
209 //
210 this.documentHackReference = doc;
183 // 211 //
184 switch (doc.extension) { 212 switch (doc.extension) {
185 case 'html': case 'html': 213 case 'html': case 'html':
@@ -245,7 +273,7 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
245 273
246 closeDocument: { 274 closeDocument: {
247 value: function(id) { 275 value: function(id) {
248 if(this.activeDocument.dirtyFlag === true){ 276 if(this.activeDocument.needsSave === true){
249 //if file dirty then alert user to save 277 //if file dirty then alert user to save
250 } 278 }
251 279
@@ -268,6 +296,8 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
268 this._removeDocumentView(doc.container); 296 this._removeDocumentView(doc.container);
269 this.application.ninja.stage.stageView.hideRulers(); 297 this.application.ninja.stage.stageView.hideRulers();
270 document.getElementById("iframeContainer").style.display="block"; 298 document.getElementById("iframeContainer").style.display="block";
299
300 this.application.ninja.stage.hideCanvas(true);
271 } 301 }
272 } 302 }
273 }, 303 },
@@ -277,7 +307,6 @@ DocumentController = exports.DocumentController = Montage.create(Component, {
277 _onOpenDocument: { 307 _onOpenDocument: {
278 value: function(doc){ 308 value: function(doc){
279 //var data = DocumentManager.activeDocument; 309 //var data = DocumentManager.activeDocument;
280
281 this._hideCurrentDocument(); 310 this._hideCurrentDocument();
282 this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); 311 this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid);
283 312