var masterpendidikan=(function(){
    var hal=0;
    var jumlah=30;
    var idmasterpendidikan=0;
    return{
        caricanggih:function(){
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterpendidikan",
                ikdata: {0:"datacari01",1:1}
            };
            
            $.ajax({url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    mload.hd();
                    if(e!=false){
                        var boxcari;
                        var obj=new Object;
                        obj.proses=function(a){
                            $("#cari").val(a);
                            boxcari.tutup();
                            document.getElementById("btcari").click();
                        };
                        var datacari={"data":e,"proses":obj}
                        boxcari=caricanggih.buka(datacari);
                    }
                }
            });
        },
        enter:function(e){
            if(e.which == 13 || e.keyCode == 13){
                masterpendidikan.loade();
            }
        },
        loade:function(){
            $("#hal_ke").val(0);
            masterpendidikan.load();
        },
        load:function(){
            var nohal=$("#hal_ke").val()
            jumlah=$("#jumlah_hal").val();
            hal=(nohal-1)*jumlah;
            var cr=$("#cari").val();
            
            $("#grid_masterpendidikan").html("");
            mload.loader();
            var ik_data = {
                ajax: 1,
                mode: "mod",
                cl: "masterpendidikan",
                ikdata: {0:"getTabel",1:hal,2:jumlah,3:cr}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",
                type: "POST",
                dataType: "json",
                async:true,
                data: ik_data,
                success: function(e){
                    mload.tutup();
                    //alert(JSON.stringify(e));
                    if(e!=false){
                        
                        if(e.length>0 && e[0]['halaman']>0){
                            var htm;
                            for(var i=0;i<e[0]['halaman'];i++){
                                htm+="<option value='"+(i+1)+"'>"+(i+1)+"</option>";
                            }
                            $("#hal_ke").html(htm);
                            
                        }
                        $("#hal_ke").val(nohal);
                        
                        var datatb={
                            box:"grid_masterpendidikan",
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            isi:[
                                    //{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":hal,"jumlah":jumlah},
                                    {"col":"id","judul":"ID/Kode","tipe":"data","lebar":"60px"},
                                    {"col":"nama","judul":"Data Pendidikan","tipe":"data"},
                                    {"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"60px"},
                                    {"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
                                    
                                ],
                            mod:"mod",
                            module:"masterpendidikan"
                        };
                        tabel.multisub(datatb);
                    }
                }
            });
        },
        buat:function(a){
            document.location=lokal+"member/mod/masterpendidikan?id="+a+"&scrmenu="+modmenu.getmenuscr();
        },
        kembali:function(){
            document.location=lokal+"member/mod/masterpendidikan?scrmenu="+modmenu.getmenuscr();
        },
        edit:function(a){
            idmasterpendidikan=a;
        },
        simpan:function(){
            $("#loader_level_err").html("");
            var nm=$("#nama").val();
            var idjenis=$("#idjenis").val();
            var err=[];
            if(nm=="") err.push({"pesan":"Nama Data Pendidikan belum diisi."});
            if(idjenis=="") err.push({"pesan":"ID/Kode Data Pendidikan belum diisi."});
            
            if(err.length>0){
                mload.error(err);
                return;
            }
            var fg="inputmasterpendidikan";
            if(idmasterpendidikan>0){
                fg="editmasterpendidikan";
            }
            mload.loader();
            var ik_data = {
                ajax: 1,
                mode: "mod",
                cl: "masterpendidikan",
                ikdata: {0:fg,nama:nm,idjenis:idjenis,
                    id:idmasterpendidikan}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",
                type: "POST",
                dataType: "json",
                async:true,
                data: ik_data,
                success: function(e){
                    if(e==1){
                        document.location=lokal+"member/mod/masterpendidikan?scrmenu="+modmenu.getmenuscr();
                    }else{
                        mload.error([{"pesan":"Terjadi kesalahan"}]);
                    }
                }
            });
        },
        hapus:function(a){
            if(a<=0) return;
            var ps={"pesan":"Yakin akan menghapus data Pendidikan ini ??",
                    "title":"Peringatan Hapus data"};
                
            var boxyesno=boxpesan.yesno(ps);
            boxyesno.proses.onclick=function(){
                
                mload.loader();
                var ik_data = {
                    ajax: 1,
                    mode: "mod",
                    cl: "masterpendidikan",
                    ikdata: {0:"hapusData",id:a}
                };
                
                $.ajax({
                    url: lokal+"man.ajax.php",
                    type: "POST",
                    dataType: "json",
                    async:true,
                    data: ik_data,
                    success: function(e){
                        
                        if(e!=false){
                            mload.tutup();
                            boxyesno.tutup();
                            masterpendidikan.load();
                        }else{
                            mload.error([{"pesan":"Terjadi kesalahan"}]);
                        }
                    }
                });
            }
        },
        setstatus:function(a,b,c,d){
            var st=0;
            if(tabel.gettabel(b).getdata(c,"status")==0){
                st=1;
            }
            
            mload.loader();
            var ik_data = {
                ajax: 1,
                mode: "mod",
                cl: "masterpendidikan",
                ikdata: {0:"setstatus",id:a,status:st}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",
                type: "POST",
                dataType: "json",
                async:true,
                data: ik_data,
                success: function(e){
                    
                    if(e==1){
                        
                        d.className="mini_dis";
                        if(st==1){
                            d.className="mini_ok";
                        }
                        tabel.gettabel(b).setdata(c,"status",st);
                        mload.tutup();
                    }else{
                        mload.error([{"pesan":"Status error"}]);
                    }
                }
            });
        },

    };
})();