DialogSystem = {
_layers: []
};
DialogSystem.showDialog = function(elmt, onCancel) {
var overlay = $('
')
.addClass("dialog-overlay")
.css("z-index", 101 + DialogSystem._layers.length * 2)
.appendTo(document.body);
var container = $('')
.addClass("dialog-container")
.css("z-index", 102 + DialogSystem._layers.length * 2)
.appendTo(document.body);
elmt.css("visibility", "hidden").appendTo(container);
container.css("top", Math.round((overlay.height() - elmt.height()) / 2) + "px");
elmt.css("visibility", "visible");
container.draggable({ handle: '.dialog-header', cursor: 'move' });
var layer = {
overlay: overlay,
container: container,
onCancel: onCancel
};
DialogSystem._layers.push(layer);
var level = DialogSystem._layers.length;
layer.keyHandler = function(evt) {
if (evt.keyCode == 27 && !evt.shiftKey && !evt.metaKey && !evt.altKey && !evt.ctrlKey &&
evt.target.tagName.toLowerCase() != "input" &&
evt.target.tagName.toLowerCase() != "textarea") {
DialogSystem.dismissUntil(level - 1);
evt.stopImmediatePropagation();
evt.stopPropagation();
evt.preventDefault();
return false;
}
};
$(document).stack("keydown", layer.keyHandler);
return level;
};
DialogSystem.dismissAll = function() {
DialogSystem.dismissUntil(0);
};
DialogSystem.dismissUntil = function(level) {
for (var i = DialogSystem._layers.length - 1; i >= level; i--) {
var layer = DialogSystem._layers[i];
$(document).unbind("keydown", layer.keyHandler);
layer.overlay.remove();
layer.container.remove();
layer.container.unbind();
if (layer.onCancel) {
try {
layer.onCancel();
} catch (e) {
Refine.reportException(e);
}
}
}
DialogSystem._layers = DialogSystem._layers.slice(0, level);
};
DialogSystem.createDialog = function() {
return $('').addClass("dialog-frame");
};
DialogSystem.showBusy = function(message) {
var frame = DialogSystem.createDialog();
frame.addClass("dialog-busy");
var body = $('').attr('id', 'loading-message').appendTo(frame);
$('
![]()
').attr("src", "images/large-spinner.gif").appendTo(body);
$('
').text(" " + (message || "Working...")).appendTo(body);
var level = DialogSystem.showDialog(frame);
return function() {
DialogSystem.dismissUntil(level - 1);
};
};