Commit 3098019a by aa.gusti

perbaikan detable + checkbox

1 parent 7472c8b0
......@@ -136,7 +136,7 @@ class BaseView(object):
self.list_buttons = (btn_add, btn_close)
self.columns = None
self.form_params = dict(scripts="")
self.list_url = []
self.list_url = ""
self.list_route = ''
self.list_schema = colander.Schema
self.allow_view = True
......@@ -145,8 +145,12 @@ class BaseView(object):
self.allow_post = False
self.allow_unpost = False
self.allow_check = False
self.check_field = ""
self.state_save = False
self.server_side = True
self.scroll_y = False
self.scroll_x = False
self.list_form = None
self.form_list = None
self.filter_columns = False
......@@ -238,30 +242,56 @@ class BaseView(object):
return r
def view_list(self, **kwargs):
if self.list_schema:
"""
custom:
allow_view = kwargs.get("allow_view", self.allow_view)
allow_edit = kwargs.get("allow_edit", self.allow_edit)
allow_delete = kwargs.get("allow_delete", self.allow_delete)
allow_post = kwargs.get("allow_post", self.allow_post)
allow_unpost = kwargs.get("allow_unpost", self.allow_unpost)
allow_check = kwargs.get("allow_check", self.allow_check)
state_save = kwargs.get("state_save", self.state_save)
filter_columns = kwargs.get("filter_columns", self.filter_columns)
server_side = kwargs.get("server_side", self.server_side)
new_buttons
list_url
action_suffix
"""
allow_view = kwargs.get("allow_view", self.allow_view)
allow_edit = kwargs.get("allow_edit", self.allow_edit)
allow_delete = kwargs.get("allow_delete", self.allow_delete)
allow_post = kwargs.get("allow_post", self.allow_post)
allow_unpost = kwargs.get("allow_unpost", self.allow_unpost)
allow_check = kwargs.get("allow_check", self.allow_check)
check_field = kwargs.get("check_field", self.check_field)
state_save = kwargs.get("state_save", self.state_save)
filter_columns = kwargs.get("filter_columns", self.filter_columns)
server_side = kwargs.get("server_side", self.server_side)
new_buttons = kwargs.get("new_buttons")
is_object = kwargs.get("is_object")
list_url = kwargs.get("list_url", self.list_url)
action_suffix = kwargs.get("action_suffix", self.action_suffix)
list_schema = kwargs.get("list_schema", self.list_schema)
scroll_y = kwargs.get("scroll_y", self.scroll_y)
scroll_x = kwargs.get("scroll_x", self.scroll_x)
parent = kwargs.get("parent")
if list_schema:
if parent:
action_suffix += f'?parent_id={parent.id}'
schema = self.list_schema()
schema = schema.bind(request=self.req)
new_buttons = kwargs.get("new_buttons")
if not new_buttons:
new_buttons = self.new_buttons
list_url = kwargs.get("list_url", self.list_url)
if not list_url and self.list_route:
list_url = self.req.route_url(self.list_route)
else:
list_url = list_url and list_url[0:1] != "/" and "/" + list_url or list_url
list_url = self.home + list_url
action_suffix = list_url and kwargs.get("action_suffix", "/grid/act") or None
table = DeTable(schema,
action=list_url,
action_suffix=action_suffix,
......@@ -273,14 +303,18 @@ class BaseView(object):
allow_post=allow_post,
allow_unpost=allow_unpost,
allow_check=allow_check,
check_field=check_field,
state_save=state_save,
new_buttons=new_buttons,
filter_columns=filter_columns,
server_side=server_side
server_side=server_side,
scroll_y=scroll_y,
scroll_x=scroll_x
)
resources = table.get_widget_resources()
# resources=dict(css="", js="")
if kwargs.get("is_object"):
if is_object:
return dict(form=table, scripts="", css=resources["css"],
js=resources["js"])
......@@ -307,6 +341,12 @@ class BaseView(object):
return self.next_act(**kwargs)
def get_list(self, **kwargs):
"""
parameter
list_schema optional
list_join callback
list_filter callback
"""
url = []
select_list = {}
list_schema = kwargs.get("list_schema")
......@@ -354,18 +394,17 @@ class BaseView(object):
columns = self.columns
query = self.db_session.query().select_from(self.table)
table_join = kwargs.get('table_join')
if table_join is not None:
query = table_join(query, **kwargs)
list_join = kwargs.get('list_join')
if list_join is not None:
query = list_join(query, **kwargs)
else:
query = self.list_join(query, **kwargs)
if self.req.user and self.req.user.company_id and hasattr(self.table, "company_id"):
query = query.filter(
self.table.company_id == self.req.user.company_id)
table_filter = kwargs.get('table_filter')
if table_filter is not None:
query = table_filter(query, **kwargs)
list_filter = kwargs.get('list_filter')
if list_filter is not None:
query = list_filter(query, **kwargs)
else:
query = self.list_filter(query, **kwargs)
......@@ -462,6 +501,7 @@ class BaseView(object):
def view_view(self, **kwargs): # row = query_id(request).first()
request = self.req
row = self.query_id().first()
self.ses["readonly"]=True
if not row:
return self.id_not_found()
is_object = kwargs.get("is_object", self.is_object)
......@@ -595,6 +635,7 @@ class BaseView(object):
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
table = self.get_item_table(**kwargs)
self.ses["readonly"]=False
if self.req.POST:
if 'save' in self.req.POST:
controls = self.req.POST.items()
......@@ -681,11 +722,12 @@ class BaseView(object):
d[f] = d[f].strip()
return d
def get_item_table(self, row=None, **kwargs):
def get_item_table(self, parent=None, **kwargs):
if not self.form_list:
return None
self.list_schema = self.form_list
kwargs["is_object"] = True
kwargs["parent"] = parent
return self.view_list(**kwargs)
def before_edit(self, form):
......@@ -701,6 +743,7 @@ class BaseView(object):
def view_edit(self, **kwargs):
request = self.req
self.ses["readonly"]=False
row = self.query_id().first()
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
......@@ -754,6 +797,7 @@ class BaseView(object):
def view_delete(self, **kwargs):
request = self.req
q = self.query_id()
self.ses["readonly"]=True
row = q.first()
is_object = kwargs.get("is_object", self.is_object)
kwargs["is_object"] = is_object
......
......@@ -116,7 +116,10 @@ class DeTable(field.Field):
allow_post=False,
allow_unpost=False,
allow_check=False,
check_field=False,
filter_columns=False,
scroll_x=False,
scroll_y=False,
**kw
):
super().__init__(schema, **kw)
......@@ -131,7 +134,10 @@ class DeTable(field.Field):
self.allow_post = json.dumps(allow_post)
self.allow_unpost = json.dumps(allow_unpost)
self.allow_check = json.dumps(allow_check)
self.filter_columns = json.dumps(filter_columns)
self.check_field = json.dumps(check_field)
self.filter_columns = filter_columns
self.scroll_x = json.dumps(scroll_x)
self.scroll_y = json.dumps(scroll_y)
# Button yang dikirim sebagai tambahan
new_buttons = kw.get("new_buttons") or ()
......
......@@ -22,6 +22,7 @@
allow_post allow_post|field.allow_post;
allow_unpost allow_unpost|field.allow_unpost;
allow_check allow_check|field.allow_check;
check_field check_field|field.check_field;
state_save state_save|field.state_save;
filter_columns filter_columns|field.filter_columns;
filter_scripts filter_scripts|field.filter_scripts;
......@@ -47,34 +48,34 @@
</div>
</div>
</div>
<div class="row" tal:condition="allow_check=='true'">
<div class="form-group col-md-3">
<div class="input-group">
<div tal:condition="allow_check=='true'">
<div class="row">
<div class="input-group col-md-2">
<span class="input-group-addon">
<input type="checkbox" class="${tableid}checkAll"/>
<span
class="input-group-addon">Pilih Semua
</span>
<label for="${tableid}checkAll">Pilih Semua</label>
</div>
</div>
<script>
$(document).ready(function () {
$('.${tableid}checkAll').click(function () {
if (this.checked) {
console.log("AAAAAAAAAAAA");
$(".${tableid}_check").prop("checked", true);
} else {
console.log("BBBBBBBBBBBB");
$(".${tableid}_check").prop("checked", false);
}
});
});
</script>
</div>
</div>
<table id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead>
<tr>
<th tal:repeat="child field">${child.title}</th>
<tal:block tal:repeat="child field">
<th tal:condition="python:hasattr(child, 'action') and not getattr(child.condition)==False and False or True">${child.title}</th>
</tal:block>
</tr>
</thead>
......@@ -100,6 +101,7 @@
var o${tableid}Url = o${tableid}Uri + "${url_suffix}";
var m${tableid}ID;
var m${tableid}CheckList = [];
var check_field =${check_field};
deform.addCallback('${tableid}', function (oid) {
// $(document).ready(function () {
......@@ -184,11 +186,20 @@
}
return result;
}
} else if (${tableid}Columns[co].data === "id" && ${tableid}Columns[co].action === true) {
${tableid}Columns[co].render = function (id) {
} else if (${tableid}Columns[co].data === "id") {
${tableid}Columns[co].render = function (id, typ, data, setting) {
if (${tableid}Columns[co].action === false) return ""
let result = "";
if (${allow_check}) {
result = '<input type="checkbox" class="${tableid}_check" value="' + id + '"/>&nbsp;';
var checked = "";
if (check_field !== "") {
checked = data[check_field] !== null ? "checked" : "";
m${tableid}CheckList.push(id);
}
var mtableId = "${tableid}";
result = '<input type="checkbox" class="' + mtableId + '_check" value="' + id + '" ' + checked + ' name="' + mtableId + '_check"/>&nbsp;';
}
if (${allow_view})
result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;';
......@@ -212,9 +223,24 @@
}
let ${tableid}Params = {
let ${tableid}Params = {}
var param_ajax = "";
var param_data = "";
if (!${server_side}) {
param_data = ${data};
} else {
param_ajax = o${tableid}Url;
}
o${tableid} = $('#${tableid}').DataTable({
scrollX: ${field.scroll_x},
scrollY: ${field.scroll_y},
dom: '<"row"<"col-md-8"<"toolbar">Bl><"col-md-4"fr>>tip',
processing: true,
data: param_data,
ajax: param_ajax,
serverSide: ${server_side},
stateSave: ${state_save},
scrollCollapse: true,
......@@ -242,15 +268,7 @@
});
}
}
if (!${server_side}) {
${tableid}Params.data = ${data};
} else {
${tableid}Params.ajax = o${tableid}Url;
}
o${tableid} = $('#${tableid}').DataTable(${tableid}Params);
);
let tb = tb_array.join(' ');
$("div.toolbar").html(tb);
$("div.toolbar").attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;');
......@@ -273,8 +291,7 @@
$(this).addClass('row_selected');
}
});
<tal:block tal:condition="filter_columns">
$(".${tableid}-control-filter").on('keyup', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
......@@ -379,7 +396,7 @@
${structure: btnscripts}
filter_table();
// });
</tal:block>
${structure: filter_scripts}
});
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!