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/document/models/base.js | 102 ++++++++++++++++++++++----- js/document/templates/montage-web/index.html | 17 +++-- js/document/views/design.js | 7 ++ 3 files changed, 105 insertions(+), 21 deletions(-) (limited to 'js/document') 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 - - + - -