From a1e8540f5656e62db6a89f3af7829be6b259b7ed Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 8 May 2012 17:33:13 -0700 Subject: Adding SAVE for I/O Adding save functionality to new template. Need to implement user UI for prompts and also clean up... --- js/controllers/document-controller.js | 29 +++++--- js/document/models/base.js | 102 ++++++++++++++++++++++----- js/document/templates/montage-web/index.html | 17 +++-- js/document/views/design.js | 7 ++ js/io/templates/files/html.txt | 1 + js/mediators/io-mediator.js | 89 +++++++++++++---------- 6 files changed, 178 insertions(+), 67 deletions(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 6a25420a..ed4d33eb 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -166,23 +166,34 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, //////////////////////////////////////////////////////////////////// - //TODO: Check for appropiate structures + // handleExecuteSave: { value: function(event) { - if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ - //Text and HTML document classes should return the same save object for fileSave - this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); - } + // + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + // + this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) + } else { + //Error: + } } }, + testCallback: { + value: function (value) { + console.log(value); + } + }, //////////////////////////////////////////////////////////////////// //TODO: Check for appropiate structures handleExecuteSaveAll: { value: function(event) { - if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ - //Text and HTML document classes should return the same save object for fileSave - this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); - } + // + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + // + this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) + } else { + //Error: + } } }, //////////////////////////////////////////////////////////////////// diff --git a/js/document/models/base.js b/js/document/models/base.js index 5667fb24..2bbbe501 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -76,39 +76,104 @@ exports.BaseDocumentModel = Montage.create(Component, { //TODO: Add API to allow other browser support browserPreview: { value: function (browser) { - - //TODO: Add file save before previewing - - //Currently only supporting current browser (Chrome, obviously) - switch (browser) { - case 'chrome': - window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); - break; - default: - window.open(this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); - break; - } + //Generating URL for document + var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; + //TODO: Add logic to prompt user to save (all) before preview + this.saveAll(function (result) { + //Currently only supporting current browser (Chrome, obviously) + switch (this.browser) { + case 'chrome': + window.open(this.url); + break; + default: + window.open(this.url); + break; + } + }.bind({browser: browser, url: url})); } }, + //////////////////////////////////////////////////////////////////// + // + getStyleSheets: { + value: function () { + // + var styles = []; + // + for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { + if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { + if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { + styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); + } + } + } + // + return styles; + } + }, //////////////////////////////////////////////////////////////////// // save: { - value: function () { + value: function (callback) { // + if (this.currentView === this.views.design) { + // + this.application.ninja.ioMediator.fileSave({ + mode: 'html', + file: this.file, + webgl: this.webGlHelper.glData, + styles: this.getStyleSheets(), + document: this.views.design.iframe.contentWindow.document, + head: this.views.design.iframe.contentWindow.document.head, + body: this.views.design.iframe.contentWindow.document.body + }, callback.bind(this)); + } else { + //TODO: Add logic to save code view data + } + // + if (this.needsSave) { + //Save + } else { + //Ignore command + } } }, //////////////////////////////////////////////////////////////////// // - saveAs: { - value: function () { + saveAll: { + value: function (callback) { + // + if (this.currentView === this.views.design) { + // + this.application.ninja.ioMediator.fileSave({ + mode: 'html', + file: this.file, + webgl: this.webGlHelper.glData, + css: this.getStyleSheets(), + document: this.views.design.iframe.contentWindow.document, + head: this.views.design.iframe.contentWindow.document.head, + body: this.views.design.iframe.contentWindow.document.body + }, callback.bind(this)); + } else { + //TODO: Add logic to save code view data + } // + if (this.needsSave) { + //Save + } else { + //Ignore command + } } }, //////////////////////////////////////////////////////////////////// // - saveAll: { + saveAs: { value: function () { // + if (this.needsSave) { + //Save current file on memory + } else { + //Copy file from disk + } } }, //////////////////////////////////////////////////////////////////// @@ -116,6 +181,11 @@ exports.BaseDocumentModel = Montage.create(Component, { close: { value: function () { // + if (this.needsSave) { + //Prompt user to save of lose data + } else { + //Close file + } } } //////////////////////////////////////////////////////////////////// diff --git a/js/document/templates/montage-web/index.html b/js/document/templates/montage-web/index.html index 47964ae4..3d550768 100755 --- a/js/document/templates/montage-web/index.html +++ b/js/document/templates/montage-web/index.html @@ -5,13 +5,20 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. --> + + - Ninja Prototype + Ninja Prototype - - + - -