add.pt
9.06 KB
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
<html metal:use-macro="load: ../main.pt">
<!-- content -->
<div metal:fill-slot="content">
<form method="post" accept-charset="utf-8" id="myform" class="form-horizontal" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${request.title}</h3>
</div>
<div class="panel-body">
<div class="alert alert-danger" tal:condition="form and form.error and True or False">
<div class="error-msg-lbl">Kesalahan Pengisian Form</div>
<p class="error-msg">${form.errormsg}</p>
</div>
<div class="form-group" tal:repeat="f form">
<div id="item-${f.oid}" style="${f.widget.hidden and 'display:none;' or 'display:block;'}">
<label for="${f.oid}" class="control-label col-md-1 ${f.required and 'required' or ''} " id="req-${f.oid}">
${f.title}</label>
<div class="col-md-9">
${structure:f.serialize()}
<p id="error-${f.oid}" class="help-block" tal:condition="f.error"
tal:repeat="error f.error.messages()">
${error}
</p>
</div>
<div class="pull-left">
<button type="submit" class="btn btn-primary" id="simpan" name="simpan">Simpan</button>
<button type="submit" class="btn btn-warning" id="batal" name="batal">Tutup</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="jarviswidget" style="border-top:1px solid #ccc!important">
<div role="content">
<table id="table1" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th><input name="select_all" value="1" type="checkbox"></th>
<th>Kode</th>
<th>Nama</th>
<th>Path</th>
<th>Status</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- end content -->
<metal:js fill-slot="js_files">
<script type="text/javascript" src="${request._host}/static/js/tools.js"></script>
</metal:js>
<script type="text/javascript" metal:fill-slot="scripts">
var mID;
var mThn;
var oTable;
var iPos;
var oTableUri = "${request._host}/group/routes";
var oTableUrl = oTableUri + "${request._host}/grid-add/act";
$(document).ready(function() {
oTable = $('#table1').DataTable({
dom: '<"row"<"col-md-8"<"toolbar">l><"col-md-4"f>>rtip',
processing: true,
serverSide: true,
ajax: oTableUrl,
//stateSave: true,
scrollCollapse: true,
sort: true,
info: false,
filter: true,
autoWidth: false,
paginate: true,
paginationType: "full_numbers",
lengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, 'Semua']
],
columns: [{
"data": "id",
"width": "50px",
"className": "text-center",
"render": function(data, type, full, meta) {
str_return = '<input type="checkbox" name="group_route_id" value="' + data + '">';
return str_return;
},
},
{
"data": "kode",
"width": "200px",
"className": "text-left"
},
{
"data": "nama"
},
{
"data": "path",
"width": "200px",
"className": "text-left"
},
{
"data": "route_id",
"width": "200px",
"className": "text-center",
"visible": false,
"render": function(data, type, full, meta) {
console.log(data);
if (data != null) {
str_return = '<input type="text" name="route_id" value="' + data + '">';
var index = $.inArray(data, rows_selected);
if (index === -1) {
rows_selected.push(data);
}
return str_return;
}
return 'kosong'
},
},
],
fnRowCallback: function(nRow, aData, iDisplayIndex) {
var rowId = aData.id;
if ($.inArray(rowId, rows_selected) !== -1) {
$(nRow).find('input[type="checkbox"]').prop('checked', true);
$(nRow).addClass('selected');
}
},
"language": {
"search": "Cari: ",
"paginate": {
"first": "Pertama ",
"last": "Akhir ",
"previous": "",
"next": "",
},
"lengthMenu": "Tampil _MENU_ baris "
},
});
var tb_array = [];
var tb = tb_array.join(' ');
$("div.toolbar").html(tb);
// Handle click on checkbox
$('#table1 tbody').on('click', 'input[type="checkbox"]', function(e) {
var $row = $(this).closest('tr');
// Get row data
//iPos = oTable.fnGetPosition(this);
var data = oTable.row($row).data();
// Get row ID
var rowId = data.id;
// Determine whether row ID is in the list of selected row IDs
var index = $.inArray(rowId, rows_selected);
// If checkbox is checked and row ID is not in list of selected row IDs
if (this.checked && index === -1) {
rows_selected.push(rowId);
// Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
} else if (!this.checked && index !== -1) {
rows_selected.splice(index, 1);
}
if (this.checked) {
$row.addClass('selected');
} else {
$row.removeClass('selected');
}
// Update state of "Select all" control
updateDataTableSelectAllCtrl(oTable);
// Prevent click event from propagating to parent
e.stopPropagation();
});
// Handle click on "Select all" control
$('#table1 thead input[name="select_all"]').on('click', function(e) {
if (this.checked) {
$('#table1 tbody input[type="checkbox"]:not(:checked)').trigger('click');
} else {
$('#table1 tbody input[type="checkbox"]:checked').trigger('click');
}
// Prevent click event from propagating to parent
e.stopPropagation();
});
// Handle table draw event
oTable.on('draw', function() {
// Update state of "Select all" control
updateDataTableSelectAllCtrl(oTable);
});
$('#group_nm').typeahead({
"hint": true,
"highlight": true,
"minLength": 1,
"limit": 10,
"remote": "${request._host}/group/hon/act?term=%QUERY",
}, {
"name": 'group_nm',
"displayKey": 'value',
});
$('#group_nm').bind('typeahead:selected', function(obj, datum, name) {
$('#group_id').val(datum.id);
oTable.ajax.url(oTableUrl + "?group_id=" + datum.id).load();
console.log(datum.id);
});
});
</script>
</html>