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 /js/document | |
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.
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/document-html.js | 6 | ||||
-rwxr-xr-x | js/document/models/base.js | 66 |
2 files changed, 50 insertions, 22 deletions
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 | }); |