/* This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/ //////////////////////////////////////////////////////////////////////// // var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; //////////////////////////////////////////////////////////////////////// // exports.BaseDocumentModel = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // hasTemplate: { value: false }, //////////////////////////////////////////////////////////////////// // _file: { value: null }, //////////////////////////////////////////////////////////////////// // file: { get: function() {return this._file;}, set: function(value) {this._file = value;} }, //////////////////////////////////////////////////////////////////// // _isActive: { value: null }, //////////////////////////////////////////////////////////////////// // isActive: { get: function() {return this._isActive;}, set: function(value) {this._isActive = value;} }, //////////////////////////////////////////////////////////////////// // _needsSave: { value: null }, //////////////////////////////////////////////////////////////////// // needsSave: { get: function() {return this._needsSave;}, set: function(value) {this._needsSave = value;} }, //////////////////////////////////////////////////////////////////// // _currentView: { value: null }, //////////////////////////////////////////////////////////////////// // currentView: { get: function() {return this._currentView;}, set: function(value) {this._currentView = value;} }, //////////////////////////////////////////////////////////////////// // views: { value: null }, //////////////////////////////////////////////////////////////////// // switchViewTo: { value: function (view) { // } }, //////////////////////////////////////////////////////////////////// //TODO: Add API to allow other browser support browserPreview: { value: function (browser) { //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 (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 } } }, //////////////////////////////////////////////////////////////////// // 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 } } }, //////////////////////////////////////////////////////////////////// // saveAs: { value: function () { // if (this.needsSave) { //Save current file on memory } else { //Copy file from disk } } }, //////////////////////////////////////////////////////////////////// // close: { value: function () { // if (this.needsSave) { //Prompt user to save of lose data } else { //Close file } } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////