1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* $Id: dialog.js,v 1.13.2.6 2011/02/16 20:54:22 source Exp $
*
* This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
*
* Copyright (C) 2005-2010 OpenLink Software
*
* See LICENSE file for details.
*/
/*
var d = new OAT.Dialog(title,contentDiv,optObj);
*/
/**
* @class Simple wrapper for ok/cancel dialog, that can contain any data.
* @message DIALOG_OK
* @message DIALOG_CANCEL
*/
OAT.Dialog = function(title,contentDiv,optObj) {
var self = this;
var options = {
width:0,
height:0,
modal:0,
zIndex:1000,
buttons:3, // bitmap 0x1=OK 0x2=cancel
resize:1,
close:1,
autoEnter:1,
type:false,
def_layout:true,
cancel_b_txt: "Cancel",
ok_b_txt: "OK"
}
if (optObj) for (var p in optObj) { options[p] = optObj[p]; }
var winbuttons = "";
if (options.close) { winbuttons += "c"; }
if (options.resize) { winbuttons += "r"; }
var win = new OAT.Win({buttons:winbuttons,
outerWidth:options.width,
outerHeight:options.height,
x:0, y:0,
title:title, type:options.type,
stackGroupBase:false});
if (options.buttons) {
var btn_bar = OAT.Dom.create("div",
options.def_layout ?
{marginTop:"1em", textAlign:"center", className: "dialog_btnbar"} :
{className: "dialog_btnbar"});
if (options.buttons & 1) {
var ok = OAT.Dom.create("input", {className: "dlg_b_ok"});
ok.type = "button";
ok.value = options.ok_b_txt;
btn_bar.appendChild (ok);
}
if (options.buttons & 2) {
var cancel = OAT.Dom.create("input",
options.def_layout?{marginLeft:"2em", className: "dlg_b_cancel"}:{className: "dlg_b_cancel"});
cancel.type = "button";
cancel.value = options.cancel_b_txt;
btn_bar.appendChild (cancel);
}
$(contentDiv).appendChild(btn_bar);
}
win.dom.content.appendChild($(contentDiv));
win.dom.container.style.zIndex = options.zIndex;
var message_ok = function() {
OAT.MSG.send(self, "DIALOG_OK", self);
}
var message_cancel = function() {
OAT.MSG.send(self, "DIALOG_CANCEL", self);
}
var onOk = function() {
message_ok();
self._ignoreMessage = true;
win.close();
self._ignoreMessage = false;
}
var onCancel = function() {
message_cancel();
self._ignoreMessage = true;
win.close();
self._ignoreMessage = false;
}
var keyPress = function(event) {
if ((!!self.okBtn) && self.okBtn.disabled) { return; }
if (event.keyCode == 13) { onOk(); }
if (event.keyCode == 27) { onCancel(); }
}
if (options.modal) {
this.close = function() {
win.close();
}
this.open = function() {
win.open();
OAT.Dimmer.show(win.dom.container,{});
OAT.Dom.center(win.dom.container,1,1);
}
OAT.MSG.attach(win, "WINDOW_CLOSE", function() {
OAT.Dimmer.hide();
if (!self._ignoreMessage) { message_cancel(); }
});
} else {
this.close = function() {
self._ignoreMessage = true;
win.close();
self._ignoreMessage = false;
}
this.open = function() {
win.open();
OAT.Dom.center(win.dom.container,1,1);
}
OAT.MSG.attach(win, "WINDOW_CLOSE", function() {
if (!self._ignoreMessage) { message_cancel(); }
});
}
//
// XXX: another backwards-compat hack:
//
this.show = this.open;
this.hide = this.close;
this.accomodate = win.accomodate;
this.okBtn = ok;
this.cancelBtn = cancel;
OAT.Event.attach(ok, "click", onOk);
OAT.Event.attach(cancel, "click", onCancel);
if (options.autoEnter) { OAT.Event.attach(win.dom.container,"keypress",keyPress); }
}
|