var jenisfileupload=(function(){
	var hal=0;
	var jumlah=30;
	var iddatajenisfileupload=0;
	return{
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "jenisfileupload",
				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){
				jenisfileupload.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			jenisfileupload.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_jenisfileupload").html("");
			var loaderdata=mload.loading({"el":"loader_jenis_file"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "jenisfileupload",
				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){
					
					loaderdata.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_jenisfileupload",
							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":"jenis","judul":"Jenis File Upload","tipe":"data"},
									{"col":"tipefile","judul":"Extension File","tipe":"data","lebar":"160px"},
									{"col":"folder","judul":"Folder","tipe":"data","lebar":"160px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"jenisfileupload"
						};
						tabel.multisub(datatb);
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/jenisfileupload?id="+a+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/jenisfileupload?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			iddatajenisfileupload=a;
		},
		simpan:function(){
			$("#box_error_simpan").html("");
			var jn=$("#nama").val();
			var ext=$("#ext").val();
			var fld=$("#folder").val();
			var idjn=$("#id").val();
			
			var err="";
			if(jn=="") err+="Nama Jenis file upload belum diisi.</br>";
			if(ext=="") err+="Extension file upload yang diijinkan belum diisi.</br>";
			if(fld=="") err+="Folder file upload belum diisi.</br>";
			if(idjn=="") err+="Id Jenis file upload belum diisi.</br>";
			if(err!=""){
				$("#box_error_simpan").html(err);
				return;
			}
			var fg="inputjenisfileupload";
			if(iddatajenisfileupload>0){
				fg="editjenisfileupload";
			}
			var loadersimpan=mload.loading({"el":"box_error_simpan"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "jenisfileupload",
				ikdata: {0:fg,jenis:jn,folder:fld,ext:ext,
					idjenisfileupload:idjn,id:iddatajenisfileupload}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					loadersimpan.tutup();
					if(e==1){
						jenisfileupload.kembali();
					}else{
						$("#box_error_simpan").html("Terjadi kesalahan simpan file");
					}
				}
			});
		},
		hapus:function(a){
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data jenis file upload ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "jenisfileupload",
						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==1){
								loaderhapus.error([{"pesan":"Berhasil"}]);
								jenisfileupload.load();
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
			
		},
		
	};
})();