Skip to content

Commit d4563b4

Browse files
committed
new MessageBox widget
1 parent 5048c6f commit d4563b4

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

widgets/MessageBox.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
define([
2+
'dojo/_base/declare',
3+
'dijit/_WidgetBase',
4+
5+
'dojo/_base/lang',
6+
'dojo/_base/array',
7+
'dojo/dom-class',
8+
'dojo/Deferred',
9+
'dojo/aspect',
10+
11+
'dijit/ConfirmDialog',
12+
13+
'xstyle/css!./MessageBox/css/MessageBox.css'
14+
15+
], function (
16+
declare,
17+
_WidgetBase,
18+
19+
lang,
20+
array,
21+
domClass,
22+
Deferred,
23+
aspect,
24+
25+
ConfirmDialog
26+
) {
27+
28+
return declare([_WidgetBase], {
29+
30+
nameSpace: null,
31+
okMessage: 'MessageBox.OK',
32+
cancelMessage: 'MessageBox.Cancel',
33+
34+
startup: function () {
35+
36+
// create the namespace if it doesn't exist
37+
if (this.nameSpace && (typeof(this.nameSpace) === 'string')) {
38+
this.nameSpace = this._createNamespace(this.nameSpace);
39+
}
40+
var ns = this.nameSpace || window;
41+
42+
// only create it once
43+
if (!ns.MessageBox) {
44+
ns.MessageBox = {
45+
okMessage: this.okMessage,
46+
cancelMessage: this.cancelMessage,
47+
48+
confirm: lang.hitch(this, function (opts) {
49+
opts = lang.mixin(opts, {
50+
'class': 'cmvMessageBox cmvConfirmDialog'
51+
});
52+
return this._createDialog(opts);
53+
}),
54+
55+
alert: lang.hitch(this, function (opts) {
56+
opts = lang.mixin(opts, {
57+
'class': 'cmvMessageBox cmvAlertDialog'
58+
});
59+
return this._createDialog(opts);
60+
})
61+
};
62+
}
63+
},
64+
65+
_createNamespace: function () {
66+
var o, d;
67+
array.forEach(arguments, function (v) {
68+
d = v.split('.');
69+
o = window[d[0]] = window[d[0]] || {};
70+
array.forEach(d.slice(1), function (v2) {
71+
o = o[v2] = o[v2] || {};
72+
});
73+
});
74+
return o;
75+
},
76+
77+
_createDialog: function (opts) {
78+
var deferred = new Deferred(),
79+
signal, signals = [];
80+
81+
var dialog = new ConfirmDialog(opts);
82+
dialog.startup();
83+
domClass.add(dialog.okButton.domNode, 'cmvOKButton');
84+
domClass.add(dialog.cancelButton.domNode, 'cmvCancelButton');
85+
86+
function destroyDialog () {
87+
array.forEach(signals, function (sig) {
88+
sig.remove();
89+
});
90+
}
91+
92+
signal = aspect.after(dialog, 'onExecute', lang.hitch(this, function () {
93+
destroyDialog();
94+
deferred.resolve(this.okMessage);
95+
}));
96+
signals.push(signal);
97+
98+
signal = aspect.after(dialog, 'onCancel', lang.hitch(this, function () {
99+
destroyDialog();
100+
deferred.resolve(this.cancelMessage);
101+
}));
102+
signals.push(signal);
103+
104+
dialog.show();
105+
106+
signal = aspect.after(dialog, 'onHide', function () {
107+
signal.remove();
108+
dialog.destroyRecursive();
109+
});
110+
111+
return deferred;
112+
}
113+
});
114+
});

widgets/MessageBox/css/MessageBox.css

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.cmvMessageBox {
2+
max-width: 275px;
3+
}
4+
5+
.cmvMessageBox .dijitDialogPaneContent {
6+
padding: 12px;
7+
}
8+
9+
.cmvMessageBox .dijitDialogPaneActionBar {
10+
padding: 8px;
11+
}
12+
13+
.cmvMessageBox .dijitDialogPaneActionBar .dijitIcon {
14+
display: inline-block;
15+
margin-top: -4px;
16+
}
17+
18+
.cmvMessageBox .dijitDialogPaneActionBar .dijitIcon:before {
19+
display: block;
20+
font-family: 'FontAwesome';
21+
}
22+
23+
.cmvMessageBox .dijitDialogPaneActionBar .cmvOKButton .dijitIcon:before {
24+
color: #090;
25+
content: '\f00c';
26+
}
27+
28+
.cmvMessageBox .dijitDialogPaneActionBar .cmvCancelButton .dijitIcon:before {
29+
color: #B00;
30+
content: '\f05e';
31+
}
32+
33+
.cmvMessageBox .dijitDialogCloseIcon {
34+
display: none;
35+
}
36+
37+
.cmvMessageBox .dijitDialogTitle:before {
38+
color: #00B;
39+
font-family: 'FontAwesome';
40+
margin-left: -5px;
41+
margin-right: 10px;
42+
}
43+
44+
.cmvMessageBox .dijitDialogPaneActionBar {
45+
text-align: center;
46+
}
47+
48+
.cmvConfirmDialog .dijitDialogTitle:before {
49+
content: '\f059';
50+
}
51+
52+
.cmvAlertDialog .dijitDialogTitle:before {
53+
content: '\f05a';
54+
}
55+
56+
.cmvAlertDialog .dijitDialogPaneActionBar .cmvCancelButton {
57+
display: none;
58+
}

0 commit comments

Comments
 (0)