/*
js for utilize handle your object HTML
*/
/* JSON ATTRIBUTE variable */
var settings = {
keyclass : 'key',
buttonclass : 'btncrud',
saveclass : 'save',
updtclass : 'update',
delclass : 'delete',
clrclass : 'clear',
formclass : 'form-crud',
closeclass : 'jqmClose',
allowExt : 'bmp',
wrapdelim : ' ',
type : 'text',
select : 'selected',
booltrue : 'true',
delim : '|',
default_color : '#000000',
freeze_color : '#ababab',
emptychar : '-'
};
jQuery.fn.extend({
emptyval: function(str1, str2, options){
var z = {} ;$.extend(z,settings,options);
return (str1 == str2)?z.emptychar:str1;
},
unfreeze: function(){$(this).removeAttr("disabled").css("color","#000000");},
freeze: function(options){
var z = {} ;$.extend(z,settings,options);
$color = $(this).css("background-color");
$(this).attr("disabled","true").css("color",z.freeze_color);
}
})
// using namespace
var sk8 =
$.extend({
showKey: function(){
$("."+settings.updtclass+",."+settings.delclass).click(function(){
$("."+settings.keyclass).find("*").removeAttr("disabled");
});
},
min: function(a, b) { return a < b ? a : b; },
max: function(a, b) { return a > b ? a : b ; },
viewAction: function(key){
$("."+settings.buttonclass).removeClass("h");
switch(key){
case settings.saveclass:
$("label.error").remove();
$("."+settings.keyclass).find("*").removeAttr("disabled");
$("."+settings.updtclass).addClass("h");
$("."+settings.delclass).addClass("h");
$("."+settings.formclass).find("input[@type=text]").clear();
//$("."+settings.formclass).find("input[@type=password]").clear();
break;
case (settings.updtclass+settings.delclass):
$("label.error").remove();
$("."+settings.keyclass).find(">*").attr("disabled","true");
//$("."+settings.formclass).find("input[@type=password]").clear();
$("."+settings.clrclass).addClass("h");
$("."+settings.saveclass).addClass("h");
$("."+settings.formclass).find("input[@type=text]").clear();
break;
};
},
wrap: function(d,n){
var x = [];
var y = "";
if(d.length > n){
num = d.length / n;
var stpoint = 0;
var endpoint = 0;
for(i=0; i< n; i++){
endpoint = stpoint+n;
x[i] = d.substring(stpoint,endpoint);
stpoint = endpoint;
y = y+x[i]+settings.wrapdelim;
}
}
return y;
},
validationInput: function(c){
var msg ;
$(c).each(function(){
msg += c.val();
});
return (msg == "" )?true:false;
}
});
$.fn.extend({
trim: function(atr){
var s = $(this).attr(atr);
return jQuery.trim(s);
},
selected: function(val){
obj = $(this).find("option[@value="+val+"]")
$(obj).attr(settings.select,settings.delim);
},
upload: function(){
},
clear: function(){
if($(this).get(0) != undefined){
var tagname = $(this).get(0).tagName;
if(tagname != undefined){
switch(tagname){
case 'INPUT' :
$(this).val("");
break;
case 'SELECT' :
$(this).find("option:eq(0)").attr(settings.select,settings.booltrue);
break;
}
}
}
}
});