jexFrame js style with pagination,delete,update,insert....

* STDY PROJECT
* @COPYRIGHT (c) 2009-2012 WebCash, Inc. All Right Reserved.
*
* @File Name :
* @File path :
* @author : Set Yuth ( syuth89@gmail.com )
* @Description : view data from db
* @History : 20150316101411, Set Yuth
* </pre>
**/
//var obj = jex.parse(jex.getQString()['data']);
var giant_pagin ={};
var giant_insert={};
var table={};
var id;
new (Jex.extend({
onload:function() {
//--- todo onload start ---//
giant_pagin.loadData();
}, event:function() {
/*xssPrevent.eventFunction();*/
//--- define event action ---//
$("#btnUsernameShow").popover('show');
giant_insert.eventFunction();
$("#cmbo").change(function(){
giant_pagin.loadData();
});
}
}))();
/*To prevent with XSS*/
function cleanText(str){
var result = str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
return result;
}
/*//To prevent with XSS*/
giant_insert.eventFunction = function(){
$("#txtsearch").keyup(function(){
var input = {};
input["NAME"] = $("#txtsearch").val();
giant_pagin.loadData(input);
});
$("#btnLogout").click(function(){
var jexAjax = jex.createAjaxUtil("giant_logout01");
jexAjax.execute(function(dat) {
//console.log(dat);
window.location.href = "/giant_login01.act";
});
});
$("#goInsert").click(function(){
$("#update").hide();
$("#btnInsert").show();
$('#NAME,#PHONE').val('');
$('#PopupForm').modal('show');
});
$("#btnInsert").click(function(){
var ajax = jex.createAjaxUtil("giant_c01");
if($("#NAME").val()=="" || $("#PHONE").val()==""){
alert('Please input data.');
}else{
ajax.set("NAME",cleanText($('#NAME').val()));
ajax.set("PHONE",cleanText($('#PHONE').val()));
ajax.execute(function(){
$('#PopupForm').modal('hide');
$('#NAME,#PHONE').val('');
giant_pagin.loadData();
/*use toastr alert*/
toastr["success"]("Insert success!");
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-bottom-left",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
/*//use toastr alert*/
//window.location.href = "/giant_view01.act";
});
}
});
$("#btnUpdate").live("click",function(){
$("#update").show();
$("#btnInsert").hide();
id = $(this).parents("tr").find("td#ID").text();
var name = $(this).parents("tr").find("td#NAME").text();
var phone = $(this).parents("tr").find("td#PHONE").text();
$('#NAME').val(name);
$('#PHONE').val(phone);
$('#PopupForm').modal('show');
});
$('#update').click(function(){
var ajax = jex.createAjaxUtil("giant_u01");
ajax.set("ID",id);
ajax.set("NAME",cleanText($('#NAME').val()));
ajax.set("PHONE",cleanText($('#PHONE').val()));
ajax.execute(function() {
$('#PopupForm').modal('hide');
$('#NAME,#PHONE').val('');
/*user toastr alert*/
toastr["success"]("Update success!");
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-bottom-left",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
/*//user toastr alert*/
giant_pagin.loadData();
});
});
$("#btnDelete").live("click",function(){
if(confirm("Are you sure to delete?")){
var thisBtn = $(this);
var ajax = jex.createAjaxUtil("giant_d01");
var input = {};
input["ID"] =thisBtn.parents("tr").find("td#ID").text();
ajax.set(input);
ajax.execute(function(dat) {
giant_pagin.loadData();
});
}
});
$("#check_all").live('click',function(){
//alert('checking');
var row = $(this);
$('input:checkbox').each(function(){
$(this).prop("checked", row.prop("checked"));
});
});
$("#giantDelete").click(function(){
var row = $("td").find("#gcheck");
//var n = false;
// row.each(function(){
// var chk = $(this);
if(!row.is('input:checked')){
/*toastr warning*/
toastr["warning"]("Please check the box to deletes!");
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-bottom-left",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
/*//toastr warning*/
}else{
if(confirm("This will delete all the checked!")){
row.each(function(){
//alert(row);
var item = $(this);
if(item.is('input:checked')){
var ajax = jex.createAjaxUtil("giant_d01");
//n=true;
var id = item.parents("tr").find("td#ID").text();
ajax.set("ID",id);
ajax.execute(function(){
giant_pagin.loadData();
});
}
});
}
/*if(!n){
alert('Dont want!');
};*/
}
// });
});
};
giant_pagin.loadData=function(input){
var ajax = jex.createAjaxUtil("giant_view_r01");
if(!input) input = {};
if(jex.isNull(table.tbl)){
table.tbl = jex.plugin.newInstance("JEX_TBL","#USR_TBL");
table.tbl.addEvent("onSvrPageChange", function(dat) {
var input = {};
input["PAGINATIONS"] = {
"PAGE_NO" : dat,
"PAGE_SZE" : table.tbl.getSvrPageSize()
};
giant_pagin.loadData(input);
});
}
var b = $("#cmbo").val();
table.tbl.setPaging("div:#pagin;per:"+b);
if (jex.isNull(input["PAGINATIONS"])) {
var hash = {};
hash['currentPage'] = "1";
hash['svrPage'] = "1";
jex.setHString(hash);
input["PAGINATIONS"] = {
"PAGE_NO" : "1",
"PAGE_SZE" : table.tbl.getSvrPageSize()
};
}
ajax.set(input);
ajax.execute(function(dat){
table.tbl.setTotalRows(dat["PAGINATIONS"].TOTAL_ROWS);
table.tbl.setLastSvrPageNo(dat["PAGINATIONS"].TOTAL_PAGES);
table.tbl.setAll(dat['COUNTRIESREC']);
if(dat.COUNTRIESREC.length == 0){
$('#EMPTY').show();
}else{
$('#EMPTY').hide();
}
/*$('label#RESULT_COUNT').html("Result Count: "+dat.COUNTRIESREC.length);*/
});
}
/**
* <pre>
Previous Post Next Post