/**
* Lookup new value for hidden value
*/
var parent_lookup = function(){
var lookup = $(this);
var pid = opener.$("#" + lookup.attr('pid'));
if(!pid.length){
alert(lookup.attr('pid')+ " not found");
return false;
}
var pname = opener.$( "#" + lookup.attr('pname'));
if(!pname.length){
alert(lookup.attr('pname')+ " not found");
return false;
}
var aft_script;
//Run current after script
if(aft_script = lookup.attr('aft_script')){
window.eval(aft_script);
}
pid.val($(this).attr("refid"));
//Only operation from opener could trigger change event
pid.change();
pname.val($(this).attr("refvalue"));
pname.change();
//Parent after_script
if(aft_script = pname.attr('aft_script')){
opener.window.eval(aft_script);
}
if(aft_script = pid.attr('aft_script')){
opener.window.eval(aft_script);
}
window.close();
};
/**
* Default upload complete
*/
//var uploadComplete = function(event, id, fileName, responseJSON) {
var uploadComplete = function(e, data) {
//To be replaced by jquery uploader
var _fileUpload = $(this);
//console.log(_fileUpload);
//console.log(data.result);
if(_fileUpload.attr('reload')!=undefined){
window.location.reload();
}
};
/**
* File upload function ,the following attribute to control action of upload
* 'endpoint' as upload url
* 'sid' as session id
* 'complete' optional to configure the custom upload complete function
*/
var genericUpload = function(dom){
var endpointurl = $(this).attr('endpoint');
var sid = $(this).attr("sid");
var completeFunc = 'uploadComplete';
//Setup custome complete function
var cusComplete = $(this).attr('complete');
if(cusComplete){
completeFunc = cusComplete;
}
$(this).fileupload({
url: endpointurl,
autoUpload:true,
dataType:'json',
formData: [{ 'sessionid': sid }],
paramName: 'Filedata',
}).bind('fileuploaddone',window[completeFunc]);
};
/**
* Matched errors with input
* Only matched errors could be identified here
*/
var advance_validate = function(errors, event) {
var conf = this.getConf();
// loop errors
$.each(errors, function(index, error) {
// add error class into input Dom element
var input = error.input;
input.addClass(conf.errorClass);
// get handle to the error container
var msg = input.data("msg.el");
// create Error data if not present, and add error class for input
// "msg.el" data is linked to error message Dom Element
if (!msg) {
//msg = $(conf.message).addClass(conf.messageClass).insertAfter(input);
msg = $(conf.message).addClass(conf.messageClass).appendTo(input.parent());
input.data("msg.el", msg);
}
// clear the container
msg.css({visibility: 'hidden'}).find("span").remove();
// populate messages
$.each(error.messages, function(i, m) {
$("<span/>").html(m).appendTo(msg);
});
// make sure the width is not full body width so it can be positioned correctly
if (msg.outerWidth() == msg.parent().width()) {
msg.add(msg.find("span"));
}
//insert into correct position (relative to the field)
msg.css({ visibility: 'visible'}) .fadeIn(conf.speed);
msg.parent().addClass("colError");
});
};
var advance_inputs = function(inputs) {
var conf = this.getConf();
inputs.removeClass(conf.errorClass).each(function() {
var msg = $(this).data("msg.el");
if (msg) {
msg.hide();
msg.parent().removeClass("colError");
}
});
if($(".colError").size() == 0){
var form = $(this);
var errHint = form.find(".formError").first();
if(errHint.size() == 0){
errHint = $("#pageError");
errHint.text('').hide();
}
}
};