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.js247
1 files changed, 131 insertions, 116 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index cf46e73e..3e15511d 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -9,11 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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, 11 Uuid = require("montage/core/uuid").Uuid,
12 HTMLDocument = require("js/document/html-document").HTMLDocument, 12 HTMLDocument = require("js/document/document-html").HtmlDocument,
13 TextDocument = require("js/document/text-document").TextDocument; 13 TextDocument = require("js/document/document-text").TextDocument;
14
15 // New Document Objects
16var Document = require("js/document/document-html").HtmlDocument;
17//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
18// 15//
19var DocumentController = exports.DocumentController = Montage.create(Component, { 16var DocumentController = exports.DocumentController = Montage.create(Component, {
@@ -51,10 +48,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
51 if(!!this._activeDocument){ 48 if(!!this._activeDocument){
52 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 49 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
53 this._activeDocument.isActive = true; 50 this._activeDocument.isActive = true;
54
55 if(!!this._activeDocument.editor){
56 this._activeDocument.editor.focus();
57 }
58 } 51 }
59 } 52 }
60 }, 53 },
@@ -145,18 +138,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
145 value: function(event) { 138 value: function(event) {
146 // 139 //
147 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 140 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
148 // 141 //Currently we don't need a callback handler
149 this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) 142 //this.activeDocument.model.save(this.saveExecuted.bind(this));
143 this.activeDocument.model.save();
150 } else { 144 } else {
151 //Error: 145 //Error: cloud not available and/or no active document
152 } 146 }
153 } 147 }
154 }, 148 },
155 testCallback: { 149 ////////////////////////////////////////////////////////////////////
150 //
151 saveExecuted: {
156 value: function (value) { 152 value: function (value) {
157 console.log(value); 153 //File saved, any callbacks or events should go here
158 //TODO: Move this to the model.save()
159 this.activeDocument.model.needsSave = false;
160 } 154 }
161 }, 155 },
162 //////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////
@@ -177,8 +171,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
177 value: function(event) { 171 value: function(event) {
178 var saveAsSettings = event._event.settings || {}; 172 var saveAsSettings = event._event.settings || {};
179 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 173 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
180 saveAsSettings.fileName = this.activeDocument.name; 174 saveAsSettings.fileName = this.activeDocument.model.file.name;
181 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); 175 saveAsSettings.folderUri = this.activeDocument.model.file.uri.substring(0, this.activeDocument.model.file.uri.lastIndexOf("/"));
182 saveAsSettings.callback = this.saveAsCallback.bind(this); 176 saveAsSettings.callback = this.saveAsCallback.bind(this);
183 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); 177 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
184 } 178 }
@@ -310,42 +304,38 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
310 this.activeDocument.uri = fileUri; 304 this.activeDocument.uri = fileUri;
311 //save a new file 305 //save a new file
312 //use the ioMediator.fileSaveAll when implemented 306 //use the ioMediator.fileSaveAll when implemented
313 this.activeDocument._userDocument.name=filename; 307 this.activeDocument.model.file.name = filename;
314 this.activeDocument._userDocument.root=destination; 308 this.activeDocument.model.file.uri = fileUri;
315 this.activeDocument._userDocument.uri=fileUri; 309 this.activeDocument.model.save();
316 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
317 //
318 } 310 }
319 }, 311 },
320 312
321 //////////////////////////////////////////////////////////////////// 313 ////////////////////////////////////////////////////////////////////
322 openDocument: { 314 openDocument: {
323 value: function(doc) { 315 value: function(file) {
324 var template, dimensions; 316 var template, dimensions;
325 if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { 317
326 dimensions = (doc.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
327 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
328 template = {type: 'banner', size: dimensions};
329 }
330 // TODO: HACKS to remove 318 // TODO: HACKS to remove
331 this.documentHackReference = doc; 319 this.documentHackReference = file;
332 document.getElementById("iframeContainer").style.overflow = "hidden"; 320 document.getElementById("iframeContainer").style.overflow = "hidden";
333 // 321 //
334 switch (doc.extension) { 322 switch (file.extension) {
335 case 'html': 323 case 'html':
324
325 if (file.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) {
326 dimensions = (file.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x');
327 dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])};
328 template = {type: 'banner', size: dimensions};
329 }
330
336 //Open in designer view 331 //Open in designer view
337 this._hackRootFlag = false; 332 this._hackRootFlag = false;
338 Montage.create(Document).init(doc, this, this._onOpenDocument, 'design', template); 333 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template);
339 break; 334 break;
340 default: 335 default:
341 //Open in code view 336 //Open in code view
342 var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; 337 Montage.create(TextDocument).init(file, this, this._onOpenTextDocument, 'code');
343 textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); 338 break;
344 code.initialize(doc, docuuid, textArea, textArea.parentNode);
345 //code.init(doc.name, doc.uri, doc.extension, null, docuuid);
346 code.textArea.value = doc.content;
347 this.application.ninja.stage.stageView.createTextView(code);
348 break;
349 } 339 }
350 } 340 }
351 }, 341 },
@@ -356,7 +346,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
356 console.log("URI is: ", uri); 346 console.log("URI is: ", uri);
357 } 347 }
358 }, 348 },
359 349
350 //todo: remove this funciton as it is not used
360 textDocumentOpened: { 351 textDocumentOpened: {
361 value: function(doc) { 352 value: function(doc) {
362 353
@@ -402,19 +393,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
402 393
403 onCloseFile: { 394 onCloseFile: {
404 value: function(doc) { 395 value: function(doc) {
396 var previousFocusedDocument;
405 397
406 this._documents.splice(this._documents.indexOf(doc), 1); 398 this._documents.splice(this._documents.indexOf(doc), 1);
407
408 this._activeDocument = null;
409
410 this.application.ninja.stage.stageView.hideRulers();
411 399
412// document.getElementById("iframeContainer").style.display="block"; 400 if(this._documents.length > 0) {
401 previousFocusedDocument = this._documents[this._documents.length - 1];
402 this._activeDocument = previousFocusedDocument;
403 this.switchDocuments(this.activeDocument, previousFocusedDocument, true);
404 } else {
405 this._activeDocument = null;
406 this.application.ninja.stage.hideRulers();
413 407
414 this.application.ninja.stage.hideCanvas(true); 408 this.application.ninja.stage.hideCanvas(true);
409 }
415 410
411 //TODO: Use references for those instead of calling getElementById
412 if(this._documents.length === 0){
413 document.getElementById("iframeContainer").style.display="block";
414 document.getElementById("codeViewContainer").style.display="block";
415 }
416 416
417 NJevent("closeDocument", doc.model.file.uri); 417 NJevent("closeDocument", doc.model.file.uri);
418
418 //TODO: Delete object here 419 //TODO: Delete object here
419 } 420 }
420 }, 421 },
@@ -454,100 +455,114 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
454 // Open document callback 455 // Open document callback
455 _onOpenDocument: { 456 _onOpenDocument: {
456 value: function(doc){ 457 value: function(doc){
457 458 var currentDocument;
458 if(this.activeDocument) { 459 if(this.activeDocument) {
459 // There is a document currently opened 460 // There is a document currently opened
460 461 currentDocument = this.activeDocument;
461
462
463 //this.application.ninja.stage.stageView.showCodeViewBar(false);
464 //this.application.ninja.stage.stageView.restoreAllPanels();
465
466 //
467 /*
468 if(this.activeDocument.currentView === "design"){
469 this.activeDocument.saveAppState();
470 this.activeDocument.container.parentNode.style["display"] = "none";
471 this.application.ninja.stage.hideCanvas(true);
472 this.application.ninja.stage.stageView.hideRulers();
473 }