//--------------------------------
//iCode php framework v2.2.6
//last modified 2013-06-04
//--------------------------------
/*invoke({
* cls:"sample.index", //*require
* method:"getContent", //*require
* ui:"#divContent",
* ui_fadeIn:true,
* data:{
* param1:value1,
* param2:value2
* },
* progress_msg:"Loading…",
* onFinish:function(result){
* $("div#divMsg").text(result.msg);
* }
* });
*/
var invoke_count = 0;
function invoke(instance)
{
if (instance.progress_msg != null)
{
progressWithMsg(instance.progress_msg);
}
var outerHTML = null;
if (instance.ui != null)
{
outerHTML = evalHtml(instance.ui);
}
var callback = instance.onFinish;
var req = {
service:instance.cls,
method:instance.method,
ui:outerHTML,
data:instance.data
};
if (instance.async == null)
{
instance.async = true;
}
if (instance.url == null)
{
instance.url = getServiceUrl();
}
//counter for invoke
invoke_count++;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
async:instance.async,
url: instance.url,
data: JSON.stringify(req),
dataType: "json",
error: function(xhr, ajaxOptions, thrownError) {
if (xhr.responseText != "")
{
alert("[" + instance.cls + "." + instance.method + "] \r\nrequest error with message : \r\n------------------------------\r\n" + xhr.responseText);
}
},
success: function(res)
{
if (instance.debug)
{
alert(JSON.stringify(res));
return;
}
if (res.result != null)
{
if (res.result.eval_js != null)
{
eval(res.result.eval_js);
}
}
if (res.ui != null && instance.ui != null)
{
if (instance.ui_fadeIn)
{
$(instance.ui)[0].outerHTML = $(res.ui).hide()[0].outerHTML;
//(for ie only)
if (navigator.appName == "Microsoft Internet Explorer")
{
$(instance.ui)[0].outerHTML = $(instance.ui)[0].outerHTML.replace(/(\r|\n)+/ig, "");
}
$(instance.ui).fadeIn('slow');
}
else
{
$(instance.ui)[0].outerHTML = res.ui;
}
}
if (callback != null)
{
callback(res.result);
}
},
complete: function()
{
//deduce invoke counter
invoke_count--;
if (instance.progress_msg != null)
{
setTimeout(unprogress, 500);
}
}
});
}
function evalHtml(html)
{
//replace value into html
$(html).find("input").each(function (){
//value
$(this).attr('value',$(this).val());
//checkbox, radio
if ($(this).attr('type') == "checkbox" ||
$(this).attr('type') == "radio")
{
if (this.checked)
{
$(this).attr("checked","checked");
$(this)[0].setAttribute("checked", "checked");
}
else
{
$(this).removeAttr("checked");
}
}
});
$(html).find("textarea").each(function (){
$(this).html($(this).val().replace(/(\r\n|\n|\r)/g, "
"));
});
$(html).find("select").each(function (){
val = $(this).val();
$(this).find("option").each(function(){
if ($(this).val() == val)
{
$(this).attr("selected","selected");
$(this)[0].setAttribute("selected", "selected");
}
else
{
$(this).removeAttr("selected");
}
});
});
var outerHTML = $(html)[0].outerHTML;
//(for ie only)
if (navigator.appName == "Microsoft Internet Explorer")
{
//option selected
outerHTML = outerHTML.replace(/