forked from asrifin/sister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_penerbit.js
236 lines (215 loc) · 7.28 KB
/
c_penerbit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
var mnu ='penerbit';
var dir ='models/m_'+mnu+'.php';
var contentFR ='';
// main function ---
$(document).ready(function(){
contentFR += '<form autocomplete="off" onsubmit="simpan();return false;" id="'+mnu+'FR">'
+'<input id="idformH" type="hidden">'
+'<label>Nama Penerbit</label>'
+'<div class="input-control text">'
+'<input placeholder="Penerbit" required type="text" name="namaTB" id="namaTB">'
+'<button class="btn-clear"></button>'
+'</div>'
+'<label>Keterangan</label>'
+'<div class="input-control textarea">'
+'<textarea placeholder="keterangan" name="keteranganTB" id="keteranganTB"></textarea>'
+'</div>'
+'<div class="form-actions">'
+'<button class="button primary">simpan</button> '
+'<button class="button" type="button" onclick="$.Dialog.close()">Batal</button> '
+'</div>'
+'</form>';
//combo departemen
// cmbdepartemen();
//load table
viewTB();
//add form
$("#tambahBC").on('click', function(){
viewFR('');
});
//search action
$('#namaS').keydown(function (e){
if(e.keyCode == 13)
viewTB();
});$('#keteranganS').keydown(function (e){
if(e.keyCode == 13)
viewTB();
});
// search button
$('#cariBC').on('click',function(){
$('#cariTR').toggle('slow');
$('#namaS').val('');
$('#keteranganS').val('');
});
});
// end of main function ---
//save process ---
function simpan(){
var urlx ='&aksi=simpan';
// edit mode
if($('#idformH').val()!=''){
urlx += '&replid='+$('#idformH').val();
}
$.ajax({
url:dir,
cache:false,
type:'post',
dataType:'json',
data:$('form').serialize()+urlx,
success:function(dt){
if(dt.status!='sukses'){
cont = 'Gagal menyimpan data';
clr = 'red';
}else{
$.Dialog.close();
kosongkan();
viewTB($('').val());
cont = 'Berhasil menyimpan data';
clr = 'green';
}
notif(cont,clr);
}
});
}
//end of save process ---
// view table ---
function viewTB(kode){
var aksi ='aksi=tampil';
var cari = '&namaS='+$('#namaS').val()
+'&keteranganS='+$('#keteranganS').val();
$.ajax({
url : dir,
type: 'post',
data: aksi+cari,
beforeSend:function(){
$('#tbody').html('<tr><td align="center" colspan="6"><img src="img/w8loader.gif"></td></tr></center>');
},success:function(dt){
setTimeout(function(){
$('#tbody').html(dt).fadeIn();
// $('#tbody').delay(4000).fadeIn().html(data);
},1000);
}
});
}
// end of view table ---
// form ---
function viewFR(id){
$.Dialog({
shadow: true,
overlay: true,
draggable: true,
width: 500,
padding: 10,
onShow: function(){
var titlex;
if(id==''){ //add mode
titlex='<span class="icon-plus-2"></span> Tambah ';
$.ajax({
url:dir,
data:'aksi=replid',
type:'post',
dataType:'json',
success:function(dt){
// $('#lokasiH').val($('#lokasiS').val());
$('#lokasiTB').val(dt.lokasi[0].kode);
}
});
}else{ // edit mode
titlex='<span class="icon-pencil"></span> Ubah';
$.ajax({
url:dir,
data:'aksi=ambiledit&replid='+id,
type:'post',
dataType:'json',
success:function(dt){
$('#idformH').val(id);
// $('#lokasiH').val($('#lokasiS').val());
// $('#kodeTB').val(dt.kode);
$('#namaTB').val(dt.nama);
// $('#alamatTB').val(dt.alamat);
$('#keteranganTB').val(dt.keterangan);
}
});
}$.Dialog.title(titlex+' '+mnu);
$.Dialog.content(contentFR);
}
});
}
// end of form ---
//paging ---
function pagination(page,aksix,subaksi){
var aksi ='aksi='+aksix+'&subaksi='+subaksi+'&starting='+page;
var cari ='';
var el,el2;
if(subaksi!=''){ // multi paging
el = '.'+subaksi+'_cari';
el2 = '#'+subaksi+'_tbody';
}else{ // single paging
el = '.cari';
el2 = '#tbody';
}
$(el).each(function(){
var p = $(this).attr('id');
var v = $(this).val();
cari+='&'+p+'='+v;
});
$.ajax({
url:dir,
type:"post",
data: aksi+cari,
beforeSend:function(){
$(el2).html('<tr><td align="center" colspan="8"><img src="img/w8loader.gif"></td></tr></center>');
},success:function(dt){
setTimeout(function(){
$(el2).html(dt).fadeIn();
},1000);
}
});
}
//end of paging ---
//del process ---
function del(id){
if(confirm('melanjutkan untuk menghapus data?'))
$.ajax({
url:dir,
type:'post',
data:'aksi=hapus&replid='+id,
dataType:'json',
success:function(dt){
var cont,clr;
if(dt.status!='sukses'){
cont = '..Gagal Menghapus '+dt.terhapus+' ..';
clr ='red';
}else{
viewTB($('').val());
cont = '..Berhasil Menghapus '+dt.terhapus+' ..';
clr ='green';
}
notif(cont,clr);
}
});
}
//end of del process ---
// notifikasi
function notif(cont,clr) {
var not = $.Notify({
caption : "<b>Notifikasi</b>",
content : cont,
timeout : 3000,
style :{
background: clr,
color:'white'
},
});
}
// end of notifikasi
//reset form ---
function kosongkan(){
$('#idformTB').val('');
$('#namaTB').val('');
$('#keteranganTB').val('');
}
//end of reset form ---
// ---------------------- //
// -- created by rovi -- //
// ---------------------- //