From c629361d7182d5f4727caeab7c2b0822f33187c7 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 11 Jun 2012 15:43:31 -0700 Subject: Adding close Ninja prompt Adding a prompt to the user to ensure all data is saved prior to closing the application. This will not let me check for documents to need saving, so it must be general and will appear at all times. --- js/ninja.reel/ninja.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js') diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 38f5efcf..f0f8b46d 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -184,6 +184,10 @@ exports.Ninja = Montage.create(Component, { this.setupGlobalHelpers(); window.addEventListener("resize", this, false); + //Prompting the user to make sure data was saved before closing Ninja + window.onbeforeunload = function () { + return 'Are you sure you want to close Ninja? Any unsaved data will be lost.'; + }; this.eventManager.addEventListener("selectTool", this, false); this.eventManager.addEventListener("selectSubTool", this, false); -- cgit v1.2.3 From 19c77d87df72a85345e527d790878fc65eca189a Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 11 Jun 2012 15:44:15 -0700 Subject: Adding temp prompt UI component Added a temp prompt component and added on before close logic to ensure user does not lose data if the file needs saving when they close. --- js/components/prompt.reel/prompt.js | 73 +++++++++++++++++++++++++++++++++++++ js/document/document-html.js | 6 +-- js/document/models/base.js | 66 ++++++++++++++++++++++++--------- 3 files changed, 123 insertions(+), 22 deletions(-) create mode 100644 js/components/prompt.reel/prompt.js (limited to 'js') diff --git a/js/components/prompt.reel/prompt.js b/js/components/prompt.reel/prompt.js new file mode 100644 index 00000000..652d7b7e --- /dev/null +++ b/js/components/prompt.reel/prompt.js @@ -0,0 +1,73 @@ +/* +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.NinjaPrompt = Montage.create(Component, { + //////////////////////////////////////////////////////////////////// + //TODO: This should have an UI template eventually + hasTemplate: { + value: false + }, + //////////////////////////////////////////////////////////////////// + //Type of prompt window (should be confirm, prompt, alert, or input) + _type: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + _params: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + _callback: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + initialize: { + value: function (type, params, callback) { + // + this._type = type.toLowerCase(); + this._params = params; + this._callback = callback; + } + }, + //////////////////////////////////////////////////////////////////// + // + show: { + value: function () { + // + var input; + // + switch (this._type) { + case 'confirm': + input = confirm(this._params.message); + if (this._callback) this._callback(input); + break; + default: + //TODO: Add support for other standard box types + break; + } + } + }, + //////////////////////////////////////////////////////////////////// + //This is for later, need to hide if need (overwrite) + hide: { + value: function () { + //TODO: Add support as real UI component + } + } + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// +}); +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/js/document/document-html.js b/js/document/document-html.js index 04565753..8874c34b 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -115,10 +115,8 @@ exports.HtmlDocument = Montage.create(Component, { // closeDocument: { value: function (context, callback) { - //Closing document and getting outcome - var closed = this.model.close(null); - //Making callback if specified - if (callback) callback.call(context, this); + //Closing document (sending null to close all views) + this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this)); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/document/models/base.js b/js/document/models/base.js index 5fa06259..0fd609c3 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -6,8 +6,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + NinjaPrompt = require("js/components/prompt.reel").NinjaPrompt; //////////////////////////////////////////////////////////////////////// // exports.BaseDocumentModel = Montage.create(Component, { @@ -264,30 +265,59 @@ exports.BaseDocumentModel = Montage.create(Component, { if (this.callback) this.callback(result); } }, + //////////////////////////////////////////////////////////////////// + // + handleSavePrompt: { + value: function (continueToClose, callback) { + //TODO: Perhaps add logic to save the file is the user wants + if (continueToClose) { + if (callback) callback(); + } else { + //User canceled + //this.saveAll(null, callback); + } + } + }, //////////////////////////////////////////////////////////////////// //TODO: Implement better logic to include different views on single document close: { value: function (view, callback) { - //Outcome of close (pending on save logic) - var success; - // + //Checking if files needs to be saved to avoid losing data if (this.needsSave) { - //TODO: Prompt user to save or lose data + //Creating prompt to ask user to save the file + var prompt = NinjaPrompt.create(); + prompt.initialize('confirm', {message: 'Do you want to save the changes you made in the document '+this.file.name+'?\n\nYour changes will be lost if you do not save them.'}, function (result){this.handleSavePrompt(result, callback);}.bind(this)); + //Showing the prompt, it will make callback with user input + prompt.show(); } else { - //Close file - success = true; - } - //Checking for view mode to close - if (this.views.design && (!view || view === 'design')) { - //TODO: Create a destroy method, this is messy - this.views.design.pauseAndStopVideos(); - this.parentContainer.removeChild(this.views.design.iframe); - this.views.design = null; + //TODO: Add support for other views + if (!view || view === 'design') { + this.closeView('design'); + } + //Making callback + if (callback) callback(); } - //Returning result of operation - return success; + } - } + }, + //////////////////////////////////////////////////////////////////// + // + closeView: { + value: function (view) { + //Checking for view mode to close + switch (view.toLowerCase()) { + case 'design': + //TODO: Make into clean method in the design view + this.views.design.pauseAndStopVideos(); + this.parentContainer.removeChild(this.views.design.iframe); + this.views.design = null; + break; + default: + //TODO: Error? + break; + } + } + } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); -- cgit v1.2.3