diff options
author | Jose Antonio Marquez | 2012-06-11 15:44:15 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-11 15:44:15 -0700 |
commit | 19c77d87df72a85345e527d790878fc65eca189a (patch) | |
tree | 3cca8b3d2583f754f1c8de02adb7596d98a8e89d | |
parent | c629361d7182d5f4727caeab7c2b0822f33187c7 (diff) | |
download | ninja-19c77d87df72a85345e527d790878fc65eca189a.tar.gz |
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.
-rw-r--r-- | js/components/prompt.reel/prompt.js | 73 | ||||
-rwxr-xr-x | js/document/document-html.js | 6 | ||||
-rwxr-xr-x | js/document/models/base.js | 66 |
3 files changed, 123 insertions, 22 deletions
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 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component; | ||
11 | //////////////////////////////////////////////////////////////////////// | ||
12 | // | ||
13 | exports.NinjaPrompt = Montage.create(Component, { | ||
14 | //////////////////////////////////////////////////////////////////// | ||
15 | //TODO: This should have an UI template eventually | ||
16 | hasTemplate: { | ||
17 | value: false | ||
18 | }, | ||
19 | //////////////////////////////////////////////////////////////////// | ||
20 | //Type of prompt window (should be confirm, prompt, alert, or input) | ||
21 | _type: { | ||
22 | value: null | ||
23 | }, | ||
24 | //////////////////////////////////////////////////////////////////// | ||
25 | // | ||
26 | _params: { | ||
27 | value: null | ||
28 | }, | ||
29 | //////////////////////////////////////////////////////////////////// | ||
30 | // | ||
31 | _callback: { | ||
32 | value: null | ||
33 | }, | ||
34 | //////////////////////////////////////////////////////////////////// | ||
35 | // | ||
36 | initialize: { | ||
37 | value: function (type, params, callback) { | ||
38 | // | ||
39 | this._type = type.toLowerCase(); | ||
40 | this._params = params; | ||
41 | this._callback = callback; | ||
42 | } | ||
43 | }, | ||
44 | //////////////////////////////////////////////////////////////////// | ||
45 | // | ||
46 | show: { | ||
47 | value: function () { | ||
48 | // | ||
49 | var input; | ||
50 | // | ||
51 | switch (this._type) { | ||
52 | case 'confirm': | ||
53 | input = confirm(this._params.message); | ||
54 | if (this._callback) this._callback(input); | ||
55 | break; | ||
56 | default: | ||
57 | //TODO: Add support for other standard box types | ||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | }, | ||
62 | //////////////////////////////////////////////////////////////////// | ||
63 | //This is for later, need to hide if need (overwrite) | ||
64 | hide: { | ||
65 | value: function () { | ||
66 | //TODO: Add support as real UI component | ||
67 | } | ||
68 | } | ||
69 | //////////////////////////////////////////////////////////////////// | ||
70 | //////////////////////////////////////////////////////////////////// | ||
71 | }); | ||
72 | //////////////////////////////////////////////////////////////////////// | ||
73 | //////////////////////////////////////////////////////////////////////// \ 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, { | |||
115 | // | 115 | // |
116 | closeDocument: { | 116 | closeDocument: { |
117 | value: function (context, callback) { | 117 | value: function (context, callback) { |
118 | //Closing document and getting outcome | 118 | //Closing document (sending null to close all views) |
119 | var closed = this.model.close(null); | 119 | this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this)); |
120 | //Making callback if specified | ||
121 | if (callback) callback.call(context, this); | ||
122 | } | 120 | } |
123 | }, | 121 | }, |
124 | //////////////////////////////////////////////////////////////////// | 122 | //////////////////////////////////////////////////////////////////// |
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 | |||
6 | 6 | ||
7 | //////////////////////////////////////////////////////////////////////// | 7 | //////////////////////////////////////////////////////////////////////// |
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component; | 10 | Component = require("montage/ui/component").Component, |
11 | NinjaPrompt = require("js/components/prompt.reel").NinjaPrompt; | ||
11 | //////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////// |
12 | // | 13 | // |
13 | exports.BaseDocumentModel = Montage.create(Component, { | 14 | exports.BaseDocumentModel = Montage.create(Component, { |
@@ -264,30 +265,59 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
264 | if (this.callback) this.callback(result); | 265 | if (this.callback) this.callback(result); |
265 | } | 266 | } |
266 | }, | 267 | }, |
268 | //////////////////////////////////////////////////////////////////// | ||
269 | // | ||
270 | handleSavePrompt: { | ||
271 | value: function (continueToClose, callback) { | ||
272 | //TODO: Perhaps add logic to save the file is the user wants | ||
273 | if (continueToClose) { | ||
274 | if (callback) callback(); | ||
275 | } else { | ||
276 | //User canceled | ||
277 | //this.saveAll(null, callback); | ||
278 | } | ||
279 | } | ||
280 | }, | ||
267 | //////////////////////////////////////////////////////////////////// | 281 | //////////////////////////////////////////////////////////////////// |
268 | //TODO: Implement better logic to include different views on single document | 282 | //TODO: Implement better logic to include different views on single document |
269 | close: { | 283 | close: { |
270 | value: function (view, callback) { | 284 | value: function (view, callback) { |
271 | //Outcome of close (pending on save logic) | 285 | //Checking if files needs to be saved to avoid losing data |
272 | var success; | ||
273 | // | ||
274 | if (this.needsSave) { | 286 | if (this.needsSave) { |
275 | //TODO: Prompt user to save or lose data | 287 | //Creating prompt to ask user to save the file |
288 | var prompt = NinjaPrompt.create(); | ||
289 | 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)); | ||
290 | //Showing the prompt, it will make callback with user input | ||
291 | prompt.show(); | ||
276 | } else { | 292 | } else { |
277 | //Close file | 293 | //TODO: Add support for other views |
278 | success = true; | 294 | if (!view || view === 'design') { |
279 | } | 295 | this.closeView('design'); |
280 | //Checking for view mode to close | 296 | } |
281 | if (this.views.design && (!view || view === 'design')) { | 297 | //Making callback |
282 | //TODO: Create a destroy method, this is messy | 298 | if (callback) callback(); |
283 | this.views.design.pauseAndStopVideos(); | ||
284 | this.parentContainer.removeChild(this.views.design.iframe); | ||
285 | this.views.design = null; | ||
286 | } | 299 | } |
287 | //Returning result of operation | 300 | |
288 | return success; | ||
289 | } | 301 | } |
290 | } | 302 | }, |
303 | //////////////////////////////////////////////////////////////////// | ||
304 | // | ||
305 | closeView: { | ||
306 | value: function (view) { | ||
307 | //Checking for view mode to close | ||
308 | switch (view.toLowerCase()) { | ||
309 | case 'design': | ||
310 | //TODO: Make into clean method in the design view | ||
311 | this.views.design.pauseAndStopVideos(); | ||
312 | this.parentContainer.removeChild(this.views.design.iframe); | ||
313 | this.views.design = null; | ||
314 | break; | ||
315 | default: | ||
316 | //TODO: Error? | ||
317 | break; | ||
318 | } | ||
319 | } | ||
320 | } | ||
291 | //////////////////////////////////////////////////////////////////// | 321 | //////////////////////////////////////////////////////////////////// |
292 | //////////////////////////////////////////////////////////////////// | 322 | //////////////////////////////////////////////////////////////////// |
293 | }); | 323 | }); |