aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/popup/confirm.reel/confirm.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /node_modules/montage/ui/popup/confirm.reel/confirm.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/popup/confirm.reel/confirm.js')
-rwxr-xr-xnode_modules/montage/ui/popup/confirm.reel/confirm.js186
1 files changed, 186 insertions, 0 deletions
diff --git a/node_modules/montage/ui/popup/confirm.reel/confirm.js b/node_modules/montage/ui/popup/confirm.reel/confirm.js
new file mode 100755
index 00000000..8e1660c5
--- /dev/null
+++ b/node_modules/montage/ui/popup/confirm.reel/confirm.js
@@ -0,0 +1,186 @@
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/confirm.reel"
9 @requires montage/core/core
10 @requires montage/ui/component
11 @requires "montage/ui/popup/popup.reel"
12*/
13
14var Montage = require("montage").Montage;
15var Component = require("ui/component").Component;
16var Popup = require("ui/popup/popup.reel").Popup;
17
18/**
19 @class module:"montage/ui/popup/confirm.reel".Confirm
20 @extends module:montage/ui/component.Component
21 */
22
23var Confirm = exports.Confirm = Montage.create(Component, /** @lends module:"montage/ui/popup/confirm.reel".Confirm# */ {
24 hasTemplate: {value: true},
25
26 title: {
27 value: 'Confirm'
28 },
29 /**
30 Text of message to display on the confirm popup
31 @type {Property}
32 @default {String} 'Are you sure?'
33 */
34 msg: {
35 value: 'Are you sure?'
36 },
37
38 /**
39 Text to display on the OK button
40 @type {Property}
41 @default {String} 'OK'
42 */
43 okLabel: {
44 value: 'OK'
45 },
46
47 /**
48 Text to display on the Cancel button
49 @type {Property}
50 @default {String} 'Cancel'
51 */
52 cancelLabel: {
53 value: 'Cancel'
54 },
55
56/**
57 Description TODO
58 @private
59*/
60 _popup: {
61 value: null
62 },
63/**
64 Description TODO
65 @type {Function}
66 @default null
67 */
68 popup: {
69 set: function(value) {
70 this._popup = value;
71 },
72 get: function() {
73 return this._popup;
74 }
75 },
76
77 okCallback: {value: null},
78 cancelCallback: {value: null},
79
80 prepareForDraw: {
81 value: function() {
82 this.element.addEventListener("keyup", this, false);
83 }
84 },
85/**
86 Description TODO
87 @function
88 */
89 draw: {
90 value: function() {
91 }
92 },
93/**
94 Description TODO
95 @function
96 @param {Event} evt The event keyCode.
97 */
98 handleKeyup: {
99 value: function(evt) {
100 if (evt.keyCode == 13 /*Enter*/) {
101 this.handleOkAction(evt);
102 } else if (evt.keyCode == 27 /*Escape*/) {
103 this.handleCancelAction(evt);
104 }
105 }
106 },
107/**
108 Description TODO
109 @function
110 @param {Event} evt The event keyCode.
111 */
112 handleOkAction: {
113 value: function(evt) {
114 if(this.okCallback) {
115 this.okCallback.call(this, evt);
116 }
117 var anEvent = document.createEvent("CustomEvent");
118 anEvent.initCustomEvent("montage_confirm_ok", true, true);
119 this.dispatchEvent(anEvent);
120
121 this.popup.hide();
122 }
123 },
124 /**
125 Description TODO
126 @function
127 @param {Event} evt The event keyCode.
128 */
129 handleCancelAction: {
130 value: function(evt) {
131 if(this.cancelCallback) {
132 this.cancelCallback.call(this, evt);
133 }
134 var anEvent = document.createEvent("CustomEvent");
135 anEvent.initCustomEvent("montage_confirm_cancel", true, true);
136 this.dispatchEvent(anEvent);
137
138 this.popup.hide();
139 }
140 },
141
142 // Static method to show a Confirmation dialog
143 /**
144 Displays a confirm dialog with OK and Cancel buttons.
145 @function
146 @param {String} msg A message to display in the dialog.
147 @param {Function} okCallback Function that's invoked when the user clicks OK
148 @param {Function} cancelCallback Function that's invoked if the user clicks Cancel.
149 @example
150 ...
151 */
152 show: {
153 value: function(options, okCallback, cancelCallback) {
154 var popup = this.application._confirmPopup, confirm;
155 if(!popup) {
156 popup = Popup.create();
157 this.popup = popup;
158
159 popup.type = 'confirm';
160 popup.title = 'Confirmation';
161 popup.modal = true;
162 this.application._confirmPopup = popup;
163
164 confirm = Confirm.create();
165 popup.content = confirm;
166 }
167
168 confirm = popup.content;
169
170 if (typeof(options) === "string") {
171 confirm.msg = options;
172 confirm.okLabel = "OK";
173 confirm.cancelLabel = "Cancel";
174 } else {
175 confirm.msg = options.message;
176 confirm.okLabel = options.okLabel || "OK";
177 confirm.cancelLabel = options.cancelLabel || "Cancel";
178 }
179
180 confirm.okCallback = okCallback || null;
181 confirm.cancelCallback = cancelCallback || null;
182
183 popup.show();
184 }
185 }
186});