Skip to content

Commit

Permalink
new MessageBox widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee committed Dec 12, 2016
1 parent 5048c6f commit d4563b4
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
114 changes: 114 additions & 0 deletions widgets/MessageBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
define([
'dojo/_base/declare',
'dijit/_WidgetBase',

'dojo/_base/lang',
'dojo/_base/array',
'dojo/dom-class',
'dojo/Deferred',
'dojo/aspect',

'dijit/ConfirmDialog',

'xstyle/css!./MessageBox/css/MessageBox.css'

], function (
declare,
_WidgetBase,

lang,
array,
domClass,
Deferred,
aspect,

ConfirmDialog
) {

return declare([_WidgetBase], {

nameSpace: null,
okMessage: 'MessageBox.OK',
cancelMessage: 'MessageBox.Cancel',

startup: function () {

// create the namespace if it doesn't exist
if (this.nameSpace && (typeof(this.nameSpace) === 'string')) {
this.nameSpace = this._createNamespace(this.nameSpace);
}
var ns = this.nameSpace || window;

// only create it once
if (!ns.MessageBox) {
ns.MessageBox = {
okMessage: this.okMessage,
cancelMessage: this.cancelMessage,

confirm: lang.hitch(this, function (opts) {
opts = lang.mixin(opts, {
'class': 'cmvMessageBox cmvConfirmDialog'
});
return this._createDialog(opts);
}),

alert: lang.hitch(this, function (opts) {
opts = lang.mixin(opts, {
'class': 'cmvMessageBox cmvAlertDialog'
});
return this._createDialog(opts);
})
};
}
},

_createNamespace: function () {
var o, d;
array.forEach(arguments, function (v) {
d = v.split('.');
o = window[d[0]] = window[d[0]] || {};
array.forEach(d.slice(1), function (v2) {
o = o[v2] = o[v2] || {};
});
});
return o;
},

_createDialog: function (opts) {
var deferred = new Deferred(),
signal, signals = [];

var dialog = new ConfirmDialog(opts);
dialog.startup();
domClass.add(dialog.okButton.domNode, 'cmvOKButton');
domClass.add(dialog.cancelButton.domNode, 'cmvCancelButton');

function destroyDialog () {
array.forEach(signals, function (sig) {
sig.remove();
});
}

signal = aspect.after(dialog, 'onExecute', lang.hitch(this, function () {
destroyDialog();
deferred.resolve(this.okMessage);
}));
signals.push(signal);

signal = aspect.after(dialog, 'onCancel', lang.hitch(this, function () {
destroyDialog();
deferred.resolve(this.cancelMessage);
}));
signals.push(signal);

dialog.show();

signal = aspect.after(dialog, 'onHide', function () {
signal.remove();
dialog.destroyRecursive();
});

return deferred;
}
});
});
58 changes: 58 additions & 0 deletions widgets/MessageBox/css/MessageBox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.cmvMessageBox {
max-width: 275px;
}

.cmvMessageBox .dijitDialogPaneContent {
padding: 12px;
}

.cmvMessageBox .dijitDialogPaneActionBar {
padding: 8px;
}

.cmvMessageBox .dijitDialogPaneActionBar .dijitIcon {
display: inline-block;
margin-top: -4px;
}

.cmvMessageBox .dijitDialogPaneActionBar .dijitIcon:before {
display: block;
font-family: 'FontAwesome';
}

.cmvMessageBox .dijitDialogPaneActionBar .cmvOKButton .dijitIcon:before {
color: #090;
content: '\f00c';
}

.cmvMessageBox .dijitDialogPaneActionBar .cmvCancelButton .dijitIcon:before {
color: #B00;
content: '\f05e';
}

.cmvMessageBox .dijitDialogCloseIcon {
display: none;
}

.cmvMessageBox .dijitDialogTitle:before {
color: #00B;
font-family: 'FontAwesome';
margin-left: -5px;
margin-right: 10px;
}

.cmvMessageBox .dijitDialogPaneActionBar {
text-align: center;
}

.cmvConfirmDialog .dijitDialogTitle:before {
content: '\f059';
}

.cmvAlertDialog .dijitDialogTitle:before {
content: '\f05a';
}

.cmvAlertDialog .dijitDialogPaneActionBar .cmvCancelButton {
display: none;
}

0 comments on commit d4563b4

Please sign in to comment.