dojo.provide("msos.number_ctrl");
dojo.require("msos.common");
msos.number_ctrl.tool=function(_1){
this.num_max_val=999;
this.num_min_val=0;
this.num_start_val=_1.value||0;
this.num_err_msg="???";
this.num_ctrl_left=0;
this.num_ctrl_top=0;
this.num_ctrl_id="number ctrl";
this.num_allow_blank=true;
this.num_container=null;
this.after_change_function=function(_2){
return false;
};
var _3=this;
this.generate_container_div=function(){
var _4=document.createElement("div");
var _5=_1.style.zIndex||_1.parentNode.style.zIndex||100;
_4.style.zIndex=++_5;
_4.style.position="absolute";
_4.style.display="none";
var _6=function(){
var _7=dojo._abs(_1,true);
var _8=_1.offsetWidth;
var _9=_7.x+_8;
var _a=_7.y;
if(_3.num_ctrl_left){
_9+=_3.num_ctrl_left;
}
if(_3.num_ctrl_top){
_a+=_3.num_ctrl_top;
}
_4.style.top=_a+"px";
_4.style.left=_9+"px";
_4.style.display="block";
};
_4.container_position=_6;
_1.parentNode.appendChild(_4);
dojo.connect(window,"onresize",null,_6);
return _4;
};
this.generate_num_ctrl=function(){
var _b,_c;
_3.num_container=_3.generate_container_div();
_b=new msos.common.generate_img_button(_3.num_container);
_b.img_url=djConfig.msos_folder+"/images/";
_b.img_name="up_arrow.gif";
_b.img_title="+1";
_b.img_alt="+1";
_b.img_size="img_num";
_b.img_but_id=_3.num_ctrl_id+" up";
_b.button_mouseup=_3.increase;
_b.img_button_append();
_b.img_elm.style.display="block";
_c=new msos.common.generate_img_button(_3.num_container);
_c.img_url=djConfig.msos_folder+"/images/";
_c.img_name="dn_arrow.gif";
_c.img_title="-1";
_c.img_alt="-1";
_c.img_size="img_num";
_c.img_but_id=_3.num_ctrl_id+" down";
_c.button_mouseup=_3.decrease;
_c.img_button_append();
_c.img_elm.style.display="block";
_1.num_input_obj=_3;
dojo.connect(_1,"onkeypress",null,_3.num_onkeypress);
dojo.connect(_1,"onmousewheel",null,_3.num_onwheel);
dojo.connect(_1,"onblur",null,_3.num_onblur);
console.debug("num. ctrl: "+_3.num_ctrl_id+", z-index -> "+_3.num_container.style.zIndex);
setTimeout(_3.num_container.container_position,100);
};
this.increase=function(){
_3.num_set_value(1);
};
this.decrease=function(){
_3.num_set_value(-1);
};
this.num_onblur=function(){
_3.num_set_value();
};
this.num_set_value=function(_d){
var _e=false;
var _f=_d?true:false;
console.debug("num_set_value: input value -> "+_1.value+", delta -> "+_d);
switch(_1.value){
case 0:
case "+":
case "-":
if(_d){
_1.value=_3.compare_high_low(0+_d);
}
break;
case "":
if(_d){
_1.value=_3.compare_high_low(0+_d);
}else{
if(!_3.num_allow_blank){
_1.value=_3.num_start_val;
}
}
break;
case "0":
case "-0":
case "+0":
if(_d){
_1.value=_3.compare_high_low(0+_d);
}else{
_1.value=_3.compare_high_low(0);
}
break;
case _3.num_err_msg:
if(_d){
_1.value=_3.compare_high_low(0+_d);
}else{
_e=true;
}
break;
default:
var _10=parseInt(_1.value)||null;
if(!_10){
_1.value=_3.num_err_msg;
_e=true;
}else{
if(_d){
_10=_10+_d;
}
_10=_3.compare_high_low(_10);
if(_1.value!=_10){
_1.value=_10;
setTimeout(_3.after_change_function,250);
}
}
}
if(_e){
_1.select();
}else{
if(_f){
_1.focus();
}
}
};
this.num_onkeypress=function(evt){
var key="";
if(evt.keyCode){
key=evt.keyCode;
}else{
if(evt.which){
key=evt.which;
}
}
var _13=String.fromCharCode(key)||"";
var _14="num_onkeypress: "+key+" ("+_13+")";
if(key>=65){
_1.value=_3.num_err_msg;
setTimeout(_3.num_onblur,250);
console.debug(_14+" not allowed!");
return false;
}
switch(key){
case null:
case 0:
case 8:
case 46:
setTimeout(_3.num_onblur,250);
return true;
case 43:
case 45:
setTimeout(_3.num_onblur,250);
return true;
case 40:
_3.num_set_value(-1);
return true;
case 38:
_3.num_set_value(1);
return true;
}
if(/^\d$/.test(_13)){
setTimeout(_3.num_onblur,250);
return true;
}else{
_1.value=_3.num_err_msg;
setTimeout(_3.num_onblur,250);
console.debug(_14+" not an integer!");
return false;
}
};
this.num_onwheel=function(evt){
if(evt.wheelDelta>0){
_3.increase();
}else{
if(evt.wheelDelta<0){
_3.decrease();
}
}
};
this.compare_high_low=function(_16){
if(_16<_3.num_min_val){
_16=_3.num_min_val;
}
if(_16>_3.num_max_val){
_16=_3.num_max_val;
}
return _16;
};
};

