From fb7a3aa9ce0d9b99dca79cfb89951b5c51523250 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 10 May 2012 14:54:38 -0700 Subject: Adding partial close functionality --- js/controllers/document-controller.js | 7 +++++- js/document/document-html.js | 37 +++++++++++++++++++++++++++++- js/document/models/base.js | 43 ++++++++++++++++++++++++----------- js/document/views/design.js | 31 +++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 15 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 682bd6a6..58fa4de7 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -211,9 +211,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, //////////////////////////////////////////////////////////////////// handleExecuteFileClose:{ value: function(event) { - if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ + if (this.activeDocument) { + this.activeDocument.closeDocument(); + } + /* +if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ this.closeDocument(this.activeDocument.uuid); } +*/ } }, //////////////////////////////////////////////////////////////////// diff --git a/js/document/document-html.js b/js/document/document-html.js index 567e4455..e00333f0 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -70,10 +70,11 @@ exports.HtmlDocument = Montage.create(Component, { //Creating instance of HTML Document Model this.model = Montage.create(HtmlDocumentModel,{ file: {value: file}, + parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic }); //Initiliazing views and hiding - if (this.model.views.design.initialize(document.getElementById("iframeContainer"))) { + if (this.model.views.design.initialize(this.model.parentContainer)) { //Hiding iFrame, just initiliazing this.model.views.design.hide(); } else { @@ -123,6 +124,40 @@ exports.HtmlDocument = Montage.create(Component, { //Setting opacity to be viewable after load this.model.views.design.iframe.style.opacity = 1; } + }, + //////////////////////////////////////////////////////////////////// + // + closeDocument: { + value: function () { + // + this.model.close(null, this.handleCloseDocument.bind(this)); + } + }, + //////////////////////////////////////////////////////////////////// + // + handleCloseDocument: { + value: function (success) { + //TODO: Add logic for handling success or failure + // + this.application.ninja.documentController._documents.splice(this.uuid, 1); + // + NJevent("closeDocument", this.model.file.uri); + //TODO: Delete object here + } + }, + //////////////////////////////////////////////////////////////////// + // + saveAppState: { + value: function () { + //TODO: Import functionality + } + }, + //////////////////////////////////////////////////////////////////// + // + restoreAppState: { + value: function () { + //TODO: Import functionality + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/js/document/models/base.js b/js/document/models/base.js index 2bbbe501..ebfb73b8 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -60,6 +60,11 @@ exports.BaseDocumentModel = Montage.create(Component, { get: function() {return this._currentView;}, set: function(value) {this._currentView = value;} }, + //////////////////////////////////////////////////////////////////// + // + parentContainer: { + value: null + }, //////////////////////////////////////////////////////////////////// // views: { @@ -114,6 +119,12 @@ exports.BaseDocumentModel = Montage.create(Component, { // save: { value: function (callback) { + // + if (this.needsSave) { + //Save + } else { + //Ignore command + } // if (this.currentView === this.views.design) { // @@ -129,18 +140,18 @@ exports.BaseDocumentModel = Montage.create(Component, { } else { //TODO: Add logic to save code view data } - // - if (this.needsSave) { - //Save - } else { - //Ignore command - } } }, //////////////////////////////////////////////////////////////////// // saveAll: { value: function (callback) { + // + if (this.needsSave) { + //Save + } else { + //Ignore command + } // if (this.currentView === this.views.design) { // @@ -156,12 +167,7 @@ exports.BaseDocumentModel = Montage.create(Component, { } else { //TODO: Add logic to save code view data } - // - if (this.needsSave) { - //Save - } else { - //Ignore command - } + } }, //////////////////////////////////////////////////////////////////// @@ -179,13 +185,24 @@ exports.BaseDocumentModel = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // close: { - value: function () { + value: function (view, callback) { + //Outcome of close (pending on save logic) + var success; // if (this.needsSave) { //Prompt user to save of lose data } else { //Close file + success = true; + } + // + if (this.views.design && (!view || view === 'design')) { + // + this.parentContainer.removeChild(this.views.design.iframe); + this.views.design = null; } + // + if (callback) callback(success); } } //////////////////////////////////////////////////////////////////// diff --git a/js/document/views/design.js b/js/document/views/design.js index 765099e6..1a8f4986 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -289,6 +289,37 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { value: function(x, y) { return this.iframe.contentWindow.getElement(x,y); } + }, + //////////////////////////////////////////////////////////////////// + // + pauseVideos:{ + value:function(){ + var i, videos = this.document.getElementsByTagName("video"); + for(i = 0; i < videos.length; i++){ + if(!videos[i].paused) videos[i].pause(); + } + } + }, + //////////////////////////////////////////////////////////////////// + // + stopVideos:{ + value:function(){ + var i, videos = this.document.getElementsByTagName("video"); + for(i = 0; i < videos.length; i++){ + videos[i].src = ""; + } + } + }, + //////////////////////////////////////////////////////////////////// + // + pauseAndStopVideos:{ + value:function(){ + var i, videos = this.document.getElementsByTagName("video"); + for(i = 0; i < videos.length; i++){ + if(!videos[i].paused) videos[i].pause(); + videos[i].src = ""; + } + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3