Ext.MessageBoxPassword = function(){
var dlg, opt, mask, waitTimer,
bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,
buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',
buttonNames = ['ok', 'yes', 'no', 'cancel'];
var handleButton = function(button){
buttons[button].blur();
if(dlg.isVisible()){
dlg.hide();
handleHide();
Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1);
}
};
var handleHide = function(){
if(opt && opt.cls){
dlg.el.removeClass(opt.cls);
}
progressBar.reset();
};
var handleEsc = function(d, k, e){
if(opt && opt.closable !== false){
dlg.hide();
handleHide();
}
if(e){
e.stopEvent();
}
};
var updateButtons = function(b){
var width = 0,
cfg;
if(!b){
Ext.each(buttonNames, function(name){
buttons[name].hide();
});
return width;
}
dlg.footer.dom.style.display = '';
Ext.iterate(buttons, function(name, btn){
cfg = b[name];
if(cfg){
btn.show();
btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);
width += btn.getEl().getWidth() + 15;
}else{
btn.hide();
}
});
return width;
};
return {
getDialog : function(titleText){
if(!dlg){
var btns = [];
buttons = {};
Ext.each(buttonNames, function(name){
btns.push(buttons[name] = new Ext.Button({
text: this.buttonText[name],
handler: handleButton.createCallback(name),
hideMode: 'offsets'
}));
}, this);
dlg = new Ext.Window({
autoCreate : true,
title:titleText,
resizable:false,
constrain:true,
constrainHeader:true,
minimizable : false,
maximizable : false,
stateful: false,
modal: true,
shim:true,
buttonAlign:"center",
width:400,
height:100,
minHeight: 80,
plain:true,
footer:true,
closable:true,
close : function(){
if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
handleButton("no");
}else{
handleButton("cancel");
}
},
fbar: new Ext.Toolbar({
items: btns,
enableOverflow: false
})
});
dlg.render(document.body);
dlg.getEl().addClass('x-window-dlg');
mask = dlg.mask;
bodyEl = dlg.body.createChild({
html:'<div class="ext-mb-icon"></div><div class="ext-mb-content"><span class="ext-mb-text"></span><br /><div class="ext-mb-fix-cursor"><input type="password" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea></div></div>'
});
iconEl = Ext.get(bodyEl.dom.firstChild);
var contentEl = bodyEl.dom.childNodes[1];
msgEl = Ext.get(contentEl.firstChild);
textboxEl = Ext.get(contentEl.childNodes[2].firstChild);
textboxEl.enableDisplayMode();
textboxEl.addKeyListener([10,13], function(){
if(dlg.isVisible() && opt && opt.buttons){
if(opt.buttons.ok){
handleButton("ok");
}else if(opt.buttons.yes){
handleButton("yes");
}
}
});
textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]);
textareaEl.enableDisplayMode();
progressBar = new Ext.ProgressBar({
renderTo:bodyEl
});
bodyEl.createChild({cls:'x-clear'});
}
return dlg;
},
updateText : function(text){
if(!dlg.isVisible() && !opt.width){
dlg.setSize(this.maxWidth, 100);
}
msgEl.update(text || ' ');
var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
mw = msgEl.getWidth() + msgEl.getMargins('lr'),
fw = dlg.getFrameWidth('lr'),
bw = dlg.body.getFrameWidth('lr'),
w;
if (Ext.isIE && iw > 0){
iw += 3;
}
w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
Math.max(opt.minWidth || this.minWidth, bwidth || 0));
if(opt.prompt === true){
activeTextEl.setWidth(w-iw-fw-bw);
}
if(opt.progress === true || opt.wait === true){
progressBar.setSize(w-iw-fw-bw);
}
if(Ext.isIE && w == bwidth){
w += 4;
}
dlg.setSize(w, 'auto').center();
return this;
},
updateProgress : function(value, progressText, msg){
progressBar.updateProgress(value, progressText);
if(msg){
this.updateText(msg);
}
return this;
},
isVisible : function(){
return dlg && dlg.isVisible();
},
hide : function(){
var proxy = dlg ? dlg.activeGhost : null;
if(this.isVisible() || proxy){
dlg.hide();
handleHide();
if (proxy){
dlg.unghost(false, false);
}
}
return this;
},
show : function(options){
if(this.isVisible()){
this.hide();
}
opt = options;
var d = this.getDialog(opt.title || " ");
d.setTitle(opt.title || " ");
var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
d.tools.close.setDisplayed(allowClose);
activeTextEl = textboxEl;
opt.prompt = opt.prompt || (opt.multiline ? true : false);
if(opt.prompt){
if(opt.multiline){
textboxEl.hide();
textareaEl.show();
textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
activeTextEl = textareaEl;
}else{
textboxEl.show();
textareaEl.hide();
}
}else{
textboxEl.hide();
textareaEl.hide();
}
activeTextEl.dom.value = opt.value || "";
if(opt.prompt){
d.focusEl = activeTextEl;
}else{
var bs = opt.buttons;
var db = null;