diff options
Diffstat (limited to 'node_modules/montage-user/ui/popup/alert.reel/alert.js')
-rwxr-xr-x | node_modules/montage-user/ui/popup/alert.reel/alert.js | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/node_modules/montage-user/ui/popup/alert.reel/alert.js b/node_modules/montage-user/ui/popup/alert.reel/alert.js new file mode 100755 index 00000000..54b854a4 --- /dev/null +++ b/node_modules/montage-user/ui/popup/alert.reel/alert.js | |||
@@ -0,0 +1,134 @@ | |||
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 | @module "montage/ui/popup/alert.reel" | ||
9 | @requires montage/core/core | ||
10 | @requires montage/ui/component | ||
11 | @requires "montage/ui/popup/popup.reel" | ||
12 | */ | ||
13 | |||
14 | var Montage = require("montage").Montage; | ||
15 | var Component = require("ui/component").Component; | ||
16 | var Popup = require("ui/popup/popup.reel").Popup; | ||
17 | |||
18 | /** | ||
19 | @class module:"montage/ui/popup/alert.reel".Alert | ||
20 | @extends module:montage/ui/component.Component | ||
21 | */ | ||
22 | |||
23 | var Alert = exports.Alert = Montage.create(Component, { | ||
24 | title: { | ||
25 | value: 'Alert' | ||
26 | }, | ||
27 | /** | ||
28 | Description TODO | ||
29 | @type {Property} | ||
30 | @default {String} '' | ||
31 | */ | ||
32 | msg: { | ||
33 | value: '' | ||
34 | }, | ||
35 | /** | ||
36 | Description TODO | ||
37 | @type {Property} | ||
38 | @default {String} '' | ||
39 | */ | ||
40 | details: { | ||
41 | value: '' | ||
42 | }, | ||
43 | /** | ||
44 | Description TODO | ||
45 | @private | ||
46 | */ | ||
47 | _popup: { | ||
48 | value: null | ||
49 | }, | ||
50 | /** | ||
51 | Description TODO | ||
52 | @type {Function} | ||
53 | @default null | ||
54 | */ | ||
55 | popup: { | ||
56 | set: function(value) { | ||
57 | this._popup = value; | ||
58 | }, | ||
59 | get: function() { | ||
60 | return this._popup; | ||
61 | } | ||
62 | }, | ||
63 | |||
64 | okCallback: {value: null}, | ||
65 | |||
66 | prepareForDraw: { | ||
67 | value: function() { | ||
68 | this.element.addEventListener("keyup", this, false); | ||
69 | } | ||
70 | }, | ||
71 | /** | ||
72 | Description TODO | ||
73 | @function | ||
74 | @param {Event} evt The event keyCode. | ||
75 | */ | ||
76 | handleKeyup: { | ||
77 | value: function(evt) { | ||
78 | if (evt.keyCode == 13 /*Enter*/ || | ||
79 | evt.keyCode == 27 /*Escape*/) { | ||
80 | |||
81 | this.handleOkAction(evt); | ||
82 | } | ||
83 | } | ||
84 | }, | ||
85 | /** | ||
86 | Description TODO | ||
87 | @function | ||
88 | @param {Event} evt The event keyCode. | ||
89 | */ | ||
90 | handleOkAction: { | ||
91 | value: function(evt) { | ||
92 | if(this.okCallback) { | ||
93 | this.okCallback.call(this, evt); | ||
94 | } | ||
95 | var anEvent = document.createEvent("CustomEvent"); | ||
96 | anEvent.initCustomEvent("montage_alert_ok", true, true, null); | ||
97 | |||
98 | this.dispatchEvent(anEvent); | ||
99 | this.popup.hide(); | ||
100 | } | ||
101 | }, | ||
102 | |||
103 | // Static method to show an Alert dialog | ||
104 | /** | ||
105 | Displays an Alert dialog with a OK button. | ||
106 | @function | ||
107 | @param {String} msg A message to display in the dialog. | ||
108 | @param {Function} okCallback Function that's invoked when the user clicks OK | ||
109 | @example | ||
110 | ... | ||
111 | */ | ||
112 | show: { | ||
113 | value: function(msg, okCallback) { | ||
114 | var popup = this.application._alertPopup, alert; | ||
115 | if(!popup) { | ||
116 | popup = Popup.create(); | ||
117 | this.popup = popup; | ||
118 | |||
119 | popup.type = 'alert'; | ||
120 | popup.title = 'Message'; | ||
121 | popup.modal = true; | ||
122 | this.application._alertPopup = popup; | ||
123 | |||
124 | alert = Alert.create(); | ||
125 | popup.content = alert; | ||
126 | } | ||
127 | alert = popup.content; | ||
128 | alert.msg = msg; | ||
129 | alert.okCallback = okCallback || null; | ||
130 | popup.show(); | ||
131 | } | ||
132 | } | ||
133 | }); | ||
134 | |||