Emice.HolidayMaintain = function(){
var dlg, opt, mask, waitTimer;
var bodyEl, msgEl, frameEl;
var buttons, bwidth;
var partTemplate;
var btnNew, btnDelete;
var tblParts, partRow;
var holidayListDiv,newHolidayDiv;
// private
var handleButton = function(button){
dlg.hide();
Ext.callback(opt.fn, opt.scope||window, [button, ''], 1);
};
// private
var handleHide = function(){
if(opt && opt.cls){
dlg.el.removeClass(opt.cls);
}
if(waitTimer){
Ext.TaskMgr.stop(waitTimer);
waitTimer = null;
}
};
var get = function(id,root){
if(!root){
root=bodyEl.dom
}
return Ext.DomQuery.select('#'+id,root)[0];
};
// private
var updateButtons = function(b){
var width = 0;
if(!b){
buttons["ok"].hide();
buttons["cancel"].hide();
dlg.footer.dom.style.display = 'none';
return width;
}
dlg.footer.dom.style.display = '';
for(var k in buttons){
if(typeof buttons[k] != "function"){
if(b[k]){
buttons[k].show();
//buttons[k].disabled=true;
buttons[k].setText(typeof b[k] == "string" ? b[k] : Emice.HolidayMaintain.buttonText[k]);
width += buttons[k].el.getWidth()+15;
}else{
buttons[k].hide();
}
}
}
return width;
};
// private
var handleEsc = function(d, k, e){
if(opt && opt.closable !== false){
dlg.hide();
}
if(e){
e.stopEvent();
}
};
return {
/**
* Returns a reference to the underlying {@link Ext.BasicDialog} element
* @return {Ext.BasicDialog} The BasicDialog element
*/
getDialog : function(){
if(!dlg){
dlg = new Ext.BasicDialog("x-msg-box", {
title: opt.holidayDate,
autoCreate : true,
shadow: true,
draggable: true,
proxyDrag: false,
closable: false,
resizable:false,
constraintoviewport:false,
fixedcenter:true,
collapsible : false,
shim:true,
modal: true,
width:400,
height:100,
buttonAlign:"center",
closeClick : function(){
if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
handleButton("no");
}else{
handleButton("cancel");
}
}
});
dlg.on("hide", handleHide);
mask = dlg.mask;
dlg.addKeyListener(27, handleEsc);
buttons = {};
var bt = this.buttonText;
buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
//disable
buttons["ok"].disable();
//buttons["cancel"].show();
bodyEl = dlg.body.createChild({
html:'<div class="ext-mb-text" id="_part_template" style="background:white;border: 1px solid #6593CF;height:130px"><span id="_temp"></span></div>'
});
partTemplate = bodyEl.dom.firstChild;
}
return dlg;
},
/**
* Returns true if the message box is currently displayed
* @return {Boolean} True if the message box is visible, else false
*/
isVisible : function(){
return dlg && dlg.isVisible();
},
/**
* Hides the message box if it is displayed
*/
hide : function(){
if(this.isVisible()){
dlg.hide();
}
},
getxx : function(id,root){
if(!root){
root=Emice.HolidayMaintain.getDialog().body.dom;
}
return Ext.DomQuery.select('#'+id,root)[0];
},
updateSize : function(){
if(!dlg.isVisible() && !opt.width){
dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
}
var w = Math.max(Math.min(opt.width || partTemplate.offsetWidth, this.maxWidth),
Math.max(opt.minWidth || this.minWidth, bwidth));
if(dlg.isVisible()){
dlg.fixedcenter = false;
}
if(!w){
w = 1;
}
dlg.setContentSize(w, bodyEl.getHeight());
if(dlg.isVisible()){
dlg.fixedcenter = true;
}
return this;
},
innerOkHandler : function(el,trueOkHandler){
return function(){
try{
Emice.HolidayMaintain.hide();
if(trueOkHandler){
trueOkHandler();
}
}catch(e){
alert("Edit part error: " + e.message);
}
}
},
innerCancelHandler : function(el,trueCancelHandler){
return function(){
Emice.HolidayMaintain.hide();
if(trueCancelHandler){
trueCancelHandler();
}
}
},
//////////////////////////////////////////////////////////////////////////
loadTemplate:function(oElement, bSuccess){
if(!bSuccess){
return;
}
Emice.HolidayMaintain.trueLoadTemplate();
},
trueLoadTemplate:function(){
Ext.get("_name").dom.value = opt.name;
Ext.get("_remarks").dom.value = opt.remarks;
var d = Emice.HolidayMaintain.getDialog();
//Emice.HolidayMaintain.fillHolidays(opt.holidays);
bwidth = updateButtons(Emice.HolidayMaintain.OKCANCEL);
buttons["ok"].setHandler(Emice.HolidayMaintain.update);
//buttons["cancel"].setHandler(Emice.HolidayMaintain.innerCancelHandler(opt.field,opt.cancelHandler));
dlg.setDefaultButton(buttons["cancel"]);
//Ext.get(partRow).setVisible(false);
newHolidayDiv = get("_new_holiday_div",partTemplate);
//Ext.get(newHolidayDiv).mask();
Ext.get(newHolidayDiv).setDisplayed(false);
//chooseRadio = Ext.get("_choose");
//newHolidayRadio = Ext.get("_newholiday");
editHolidayRadio = Ext.get("_editholiday");
deleteHolidayRadio = Ext.get("_deleteholiday");
//newHolidayRadio.on('click',function(){
//buttons["ok"].setHandler(Emice.HolidayMaintain.save);
//Ext.get(holidayListDiv).mask();
//Ext.get(holidayListDiv).setDisplayed(false);
//Ext.get(newHolidayDiv).unmask();
//Ext.get(newHolidayDiv).setDisplayed(true);
//});
editHolidayRadio.on('click',function(){
buttons["ok"].setHandler(Emice.HolidayMaintain.update);
//Ext.get(holidayListDiv).mask();
//Ext.get(holidayListDiv).setDisplayed(false);
//Ext.get(newHolidayDiv).unmask();
Ext.get(newHolidayDiv).setDisplayed(true);
});
deleteHolidayRadio.on('click',function(){
buttons["ok"].setHandler(Emice.HolidayMaintain.deleteMe);
//Ext.get(holidayListDiv).mask();
//Ext.get(holidayListDiv).setDisplayed(false);
//Ext.get(newHolidayDiv).mask();
Ext.get(newHolidayDiv).setDisplayed(false);
});
Emice.HolidayMaintain.updateSize();
d.mask = opt.modal !== false ? mask : false;
if(!d.isVisible()){
// force it to the end of the z-index stack so it gets a cursor in FF
document.body.appendChild(dlg.el.dom);
d.animateTarget = null;
d.show();
}
Emice.HolidayMaintain.onReady();
Ext.get(newHolidayDiv).setDisplayed(true);
this.multipleLanguages();
},
multipleLanguages : function(){
Ext.get("_edit_holiday_text").dom.innerHTML =opt.msg_edit;
//Ext.get("_new_holiday_text").dom.innerHTML ='New';
Ext.get("_delete_text").dom.innerHTML =opt.msg_delete;
Ext.get("name").dom.innerHTML =opt.msg_holidayName;
Ext.get("remarks").dom.innerHTML =opt.msg_disc;
},
show : function(options){
opt = options;
if(this.isVisible()){
this.hide();
}
var d = this.getDialog();
d.setTitle(opt.holidayDate);
this.initDialog();
Ext.get(partTemplate).load({
url: opt.url ,
callback: this.loadTemplate,
text: ''
});
},
initDialog: function(){
partTemplate.innerHTML = "";
},
onReady : function(){
buttons["ok"].enable();
},
/*fillHolidays: function(obj){
//alert(obj.length);
var index = 0;
for(var i=0;i<obj.length;i++){
var name = obj[i].name;
var key = obj[i].id;
var option = new Option(name,key);
option.title=name;
Ext.get("_holidaylist").dom.options[i] = option;
}
*/
/*if(opt.holidayId){
Ext.get("_holidaylist").dom.value = opt.holidayId;
}*//*
Emice.HolidayMaintain.updateSize();
},*/
update : function(){
Emice.HolidayMaintain.updateHoliday({
params : {
name : get("_name",partTemplate).value ,
remarks : get("_remarks",partTemplate).value,
holidayDate : opt.holidayDate,
holidayId : opt.holidayId
},
success: function(resp){
if(Ext.util.JSON.decode(resp.responseText)!=false){
dlg.hide();
window.view();
}else{
alert(opt.msg_updatefailed);
dlg.hide();
}
}.createDelegate(this),
failure: function(){
alert(opt.msg_updatefailed);
}.createDelegate(this)
});
},
save : function(){
if(get("_name",partTemplate).value==""){
alert(opt.msg_notnull);
return;
}
Emice.HolidayMaintain.saveToServer({
params : {
name : get("_name",partTemplate).value ,
remarks : get("_remarks",partTemplate).value,
holidayDate : opt.holidayDate,
holidayId : opt.holidayId
},
success: function(resp){
if(Ext.util.JSON.decode(resp.responseText)!=false){
dlg.hide();
window.view();
}else{
alert(opt.msg_save);
dlg.hide();
}
}.createDelegate(this),
failure: function(){
alert(opt.msg_savefailed);
}.createDelegate(this)
});
},
deleteMe: function(){
if(!confirm(opt.msg_suredel)){
return;
}
Emice.HolidayMaintain.deleteFromServer({
params : {
holidayId : opt.holidayId
},
success: function(resp){
if(Ext.util.JSON.decode(resp.responseText)==false){
alert(opt.msg_delete);
dlg.hide();
}else{
dlg.hide();
window.view();
}
}.createDelegate(this),
failure: function(){
alert(opt.msg_delfailed);
}.createDelegate(this)
});
},
saveToServer: function(opt2){
Ext.Ajax.request(
{
url: "holidayShow.do?method=addNewHoliday",
params : opt2.params,
method : "POST",
success: opt2.success,
failure: opt2.failure
});
},
deleteFromServer: function(opt2){
Ext.Ajax.request(
{
url: "holidayShow.do?method=deleteHoliday",
params : opt2.params,
method : "POST",
success: opt2.success,
failure: opt2.failure
});
},
updateHoliday: function(opt2){
Ext.Ajax.request(
{
url: "holidayShow.do?method=updateHoliday",
params : opt2.params,
method : "POST",
success: opt2.success,
failure: opt2.failure
});
},
OKCANCEL : {ok:true, cancel:true},
defaultTextHeight : 75,
/**
* The maximum width in pixels of the message box (defaults to 600)
* @type Number
*/
maxWidth : 600,
/**
* The minimum width in pixels of the message box (defaults to 100)
* @type Number
*/
minWidth : 100,
/**
* The minimum width in pixels of the message box progress bar if displayed (defaults to 250)
* @type Number
*/
minProgressWidth : 250,
/**
* An object containing the default button text strings that can be overriden for localized language support.
* Supported properties are: ok, cancel, yes and no.
* Customize the default text like so: Ext.MessageBox.buttonText.yes = "";
* @type Object
*/
buttonText : {
ok : "Ok",
cancel : "Cancel"
}
};
}();