diff options
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 160 |
1 files changed, 86 insertions, 74 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index f6b850b2..26c3ebaa 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -13,7 +13,8 @@ var Montage = require("montage/core/core").Montage, | |||
13 | TextDocument = require("js/document/text-document").TextDocument; | 13 | TextDocument = require("js/document/text-document").TextDocument; |
14 | 14 | ||
15 | // New Document Objects | 15 | // New Document Objects |
16 | var Document = require("js/document/document-html").HtmlDocument; | 16 | var Document_HTML = require("js/document/document-html").HtmlDocument; |
17 | var Document_Text = require("js/document/document-text").TextDocument; | ||
17 | //////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////// |
18 | // | 19 | // |
19 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 20 | var DocumentController = exports.DocumentController = Montage.create(Component, { |
@@ -51,10 +52,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
51 | if(!!this._activeDocument){ | 52 | if(!!this._activeDocument){ |
52 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | 53 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); |
53 | this._activeDocument.isActive = true; | 54 | this._activeDocument.isActive = true; |
54 | |||
55 | if(!!this._activeDocument.editor){ | ||
56 | this._activeDocument.editor.focus(); | ||
57 | } | ||
58 | } | 55 | } |
59 | } | 56 | } |
60 | }, | 57 | }, |
@@ -311,42 +308,39 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
311 | this.activeDocument.uri = fileUri; | 308 | this.activeDocument.uri = fileUri; |
312 | //save a new file | 309 | //save a new file |
313 | //use the ioMediator.fileSaveAll when implemented | 310 | //use the ioMediator.fileSaveAll when implemented |
314 | this.activeDocument._userDocument.name=filename; | 311 | this.activeDocument.model.file.name=filename; |
315 | this.activeDocument._userDocument.root=destination; | 312 | this.activeDocument.model.file.uri=fileUri; |
316 | this.activeDocument._userDocument.uri=fileUri; | 313 | this.activeDocument.model.save(); |
317 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | ||
318 | // | 314 | // |
319 | } | 315 | } |
320 | }, | 316 | }, |
321 | 317 | ||
322 | //////////////////////////////////////////////////////////////////// | 318 | //////////////////////////////////////////////////////////////////// |
323 | openDocument: { | 319 | openDocument: { |
324 | value: function(doc) { | 320 | value: function(file) { |
325 | var template, dimensions; | 321 | var template, dimensions; |
326 | if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { | 322 | |
327 | dimensions = (doc.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x'); | ||
328 | dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])}; | ||
329 | template = {type: 'banner', size: dimensions}; | ||
330 | } | ||
331 | // TODO: HACKS to remove | 323 | // TODO: HACKS to remove |
332 | this.documentHackReference = doc; | 324 | this.documentHackReference = file; |
333 | document.getElementById("iframeContainer").style.overflow = "hidden"; | 325 | document.getElementById("iframeContainer").style.overflow = "hidden"; |
334 | // | 326 | // |
335 | switch (doc.extension) { | 327 | switch (file.extension) { |
336 | case 'html': | 328 | case 'html': |
329 | |||
330 | if (file.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { | ||
331 | dimensions = (file.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x'); | ||
332 | dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])}; | ||
333 | template = {type: 'banner', size: dimensions}; | ||
334 | } | ||
335 | |||
337 | //Open in designer view | 336 | //Open in designer view |
338 | this._hackRootFlag = false; | 337 | this._hackRootFlag = false; |
339 | Montage.create(Document).init(doc, this, this._onOpenDocument, 'design', template); | 338 | Montage.create(Document_HTML).init(file, this, this._onOpenDocument, 'design', template); |
340 | break; | 339 | break; |
341 | default: | 340 | default: |
342 | //Open in code view | 341 | //Open in code view |
343 | var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; | 342 | Montage.create(Document_Text).init(file, this, this._onOpenTextDocument, 'code'); |
344 | textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); | 343 | break; |
345 | code.initialize(doc, docuuid, textArea, textArea.parentNode); | ||
346 | //code.init(doc.name, doc.uri, doc.extension, null, docuuid); | ||
347 | code.textArea.value = doc.content; | ||
348 | this.application.ninja.stage.stageView.createTextView(code); | ||
349 | break; | ||
350 | } | 344 | } |
351 | } | 345 | } |
352 | }, | 346 | }, |
@@ -357,7 +351,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
357 | console.log("URI is: ", uri); | 351 | console.log("URI is: ", uri); |
358 | } | 352 | } |
359 | }, | 353 | }, |
360 | 354 | ||
355 | //todo: remove this funciton as it is not used | ||
361 | textDocumentOpened: { | 356 | textDocumentOpened: { |
362 | value: function(doc) { | 357 | value: function(doc) { |
363 | 358 | ||
@@ -408,12 +403,17 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
408 | 403 | ||
409 | this._activeDocument = null; | 404 | this._activeDocument = null; |
410 | 405 | ||
411 | this.application.ninja.stage.stageView.hideRulers(); | 406 | this.application.ninja.stage.hideRulers(); |
412 | 407 | ||
413 | // document.getElementById("iframeContainer").style.display="block"; | 408 | // document.getElementById("iframeContainer").style.display="block"; |
414 | 409 | ||
415 | this.application.ninja.stage.hideCanvas(true); | 410 | this.application.ninja.stage.hideCanvas(true); |
416 | 411 | ||
412 | if(this._documents.length === 0){ | ||
413 | document.getElementById("iframeContainer").style.display="block"; | ||
414 | document.getElementById("codeViewContainer").style.display="block"; | ||
415 | } | ||
416 | |||
417 | 417 | ||
418 | NJevent("closeDocument", doc.model.file.uri); | 418 | NJevent("closeDocument", doc.model.file.uri); |
419 | //TODO: Delete object here | 419 | //TODO: Delete object here |
@@ -466,7 +466,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
466 | 466 | ||
467 | // Show the rulers | 467 | // Show the rulers |
468 | // TODO: Move this indo design view | 468 | // TODO: Move this indo design view |
469 | this.application.ninja.stage.stageView.showRulers(); | 469 | this.application.ninja.stage.showRulers(); |
470 | 470 | ||
471 | // Show the canvas | 471 | // Show the canvas |
472 | this.application.ninja.stage.hideCanvas(false); | 472 | this.application.ninja.stage.hideCanvas(false); |
@@ -484,69 +484,81 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
484 | } | 484 | } |
485 | }, | 485 | }, |
486 | 486 | ||
487 | |||
488 | _onOpenTextDocument: { | ||
489 | value: function(doc) { | ||
490 | var currentDocument=null; | ||
491 | if(this.activeDocument) { | ||
492 | // There is a document currently opened | ||
493 | currentDocument = this.activeDocument; | ||
494 | } | ||
495 | |||
496 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | ||
497 | this.activeDocument = doc; | ||
498 | document.getElementById("iframeContainer").style.display = "none"; | ||
499 | this.application.ninja.codeEditorController.applySettings(); | ||
500 | this.switchDocuments(currentDocument, doc, true); | ||
501 | } | ||
502 | }, | ||
503 | |||
487 | switchDocuments: { | 504 | switchDocuments: { |
488 | value: function(currentDocument, newDocument, didCreate) { | 505 | value: function(currentDocument, newDocument, didCreate) { |
489 | 506 | ||
490 | if(currentDocument) { | 507 | if(currentDocument && currentDocument.currentView === "design") { |
491 | currentDocument.serializeDocument(); | 508 | currentDocument.serializeDocument(); |
492 | |||
493 | this.application.ninja.selectionController._selectionContainer = null; | 509 | this.application.ninja.selectionController._selectionContainer = null; |
494 | currentDocument.model.views.design.propertiesPanel.clear(); | 510 | currentDocument.model.views.design.propertiesPanel.clear(); |
495 | currentDocument.model.views.design.hide(); | ||
496 | } | 511 | } |
497 | 512 | ||
498 | this.application.ninja.stage.clearAllCanvas(); | 513 | if(currentDocument) { |
499 | 514 | currentDocument.model.currentView.hide(); | |
500 | if(didCreate) { | 515 | currentDocument.model.isActive = false; |
501 | newDocument.model.views.design.iframe.style.opacity = 1; | 516 | } |
502 | NJevent("onOpenDocument", newDocument); | 517 | if(currentDocument && newDocument && (currentDocument.model.parentContainer !== newDocument.model.parentContainer)){ |
503 | } else { | 518 | currentDocument.model.parentContainer.style["display"] = "none"; |
504 | this.activeDocument = newDocument; | ||
505 | newDocument.model.views.design.show(); | ||
506 | newDocument.deserializeDocument(); | ||
507 | NJevent("onSwitchDocument"); | ||
508 | } | 519 | } |
509 | } | ||
510 | }, | ||
511 | 520 | ||
521 | if(newDocument && newDocument.currentView === "code"){ | ||
522 | this.application.ninja.stage.showCodeViewBar(true); | ||
523 | this.application.ninja.stage.collapseAllPanels(); | ||
524 | this.application.ninja.stage.hideCanvas(true); | ||
525 | this.application.ninja.stage.hideRulers(); | ||
512 | 526 | ||
513 | _onOpenTextDocument: { | 527 | newDocument.model.views.code.editor.focus(); |
514 | value: function(doc) { | ||
515 | if(this.activeDocument) { | ||
516 | if(this.activeDocument.currentView === "design"){ | ||
517 | this.activeDocument.saveAppState(); | ||
518 | this.activeDocument.container.parentNode.style["display"] = "none"; | ||
519 | this.application.ninja.stage.hideCanvas(true); | ||
520 | this.application.ninja.stage.stageView.hideRulers(); | ||
521 | } | ||
522 | 528 | ||
523 | this.activeDocument.container.style["display"] = "none"; | 529 | }else if(currentDocument && newDocument && newDocument.currentView === "design"){ |
530 | this.application.ninja.stage.showCodeViewBar(false); | ||
531 | this.application.ninja.stage.restoreAllPanels(); | ||