Commit 1a3f80a1 by aa.gusti

penambahan checkbox pada datatable

1 parent 9097cc10
...@@ -487,7 +487,6 @@ def add_view_config(config, module, view_name): ...@@ -487,7 +487,6 @@ def add_view_config(config, module, view_name):
class_view = row.class_view and f".{row.class_view}" or "" class_view = row.class_view and f".{row.class_view}" or ""
class_name = f"{view_name}{class_view}" class_name = f"{view_name}{class_view}"
attr = f"view_{row.def_func}" attr = f"view_{row.def_func}"
log.debug(f"Class: {class_name} Attr: {attr}")
try: try:
_views = importlib.import_module(class_name) _views = importlib.import_module(class_name)
views = _views views = _views
...@@ -649,18 +648,22 @@ def main(global_config, **settings): ...@@ -649,18 +648,22 @@ def main(global_config, **settings):
config.add_renderer('json_rpc', json_rpc()) config.add_renderer('json_rpc', json_rpc())
set_routes(config) set_routes(config)
# New Routes By Array routes_by_array(config)
for route in routes:
if len(route) > 4 and str(route[4]) == '1':
config.add_jsonrpc_endpoint(
route[0], route[1], default_renderer="json_rpc")
else:
config.add_route(route[0], route[1])
titles[route[0]] = route[2]
config.registry['mailer'] = mailer_factory_from_settings(settings) config.registry['mailer'] = mailer_factory_from_settings(settings)
config.scan() config.scan()
for m in modules: for m in modules:
config.scan(m) config.scan(m)
return config.make_wsgi_app()
\ No newline at end of file \ No newline at end of file
return config.make_wsgi_app()
def routes_by_array(config, routs=routes):
# New Routes By Array
for route in routs:
if len(route) > 4 and str(route[4]) == '1':
config.add_jsonrpc_endpoint(
route[0], route[1], default_renderer="json_rpc")
else:
config.add_route(route[0], route[1])
titles[route[0]] = route[2]
\ No newline at end of file \ No newline at end of file
import logging import logging
from datetime import timedelta from datetime import timedelta
import colander import colander
from deform import ( from deform import (
Form, ValidationFailure, widget, Button, FileData) Form, ValidationFailure, widget, Button, FileData)
from opensipkd.base import get_params, get_urls
from opensipkd.models import (
DBSession, UserService, )
from opensipkd.tools import mem_tmp_store
from pyramid.httpexceptions import ( from pyramid.httpexceptions import (
HTTPFound, HTTPForbidden, HTTPNotFound, HTTPInternalServerError, HTTPFound, HTTPForbidden, HTTPNotFound, HTTPInternalServerError,
HTTPSeeOther) HTTPSeeOther)
...@@ -16,11 +11,19 @@ from pyramid.interfaces import IRoutesMapper ...@@ -16,11 +11,19 @@ from pyramid.interfaces import IRoutesMapper
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from pyramid.view import view_config from pyramid.view import view_config
from .base_views import BaseView, DataTables, ColumnDT from opensipkd.base import get_params, get_urls
from opensipkd.models import (
DBSession, UserService, )
from opensipkd.tools import mem_tmp_store
from .base_views import BaseView, DataTables
_ = TranslationStringFactory('login') _ = TranslationStringFactory('login')
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
from datatables import ColumnDT
# , DataTables, get_urls)
def no_action():
test = ColumnDT
@view_config(context=HTTPNotFound, renderer='templates/404.pt') @view_config(context=HTTPNotFound, renderer='templates/404.pt')
def not_found(request): def not_found(request):
...@@ -40,6 +43,13 @@ def not_found(request): ...@@ -40,6 +43,13 @@ def not_found(request):
return {} return {}
# @view_config(context=HTTPNotFound, renderer='json')
# def not_found_json(request):
# pass
# request.response.status = 404
# return {"JSON"}
@view_config(context=HTTPInternalServerError, renderer='templates/500.pt') @view_config(context=HTTPInternalServerError, renderer='templates/500.pt')
def internal_server_error(request): def internal_server_error(request):
return {} return {}
...@@ -74,7 +84,6 @@ class FilesSchema(colander.SequenceSchema): ...@@ -74,7 +84,6 @@ class FilesSchema(colander.SequenceSchema):
self["file_name"].title = "" self["file_name"].title = ""
######## ########
# Home # # Home #
######## ########
......
...@@ -144,6 +144,7 @@ class BaseView(object): ...@@ -144,6 +144,7 @@ class BaseView(object):
self.allow_delete = True self.allow_delete = True
self.allow_post = False self.allow_post = False
self.allow_unpost = False self.allow_unpost = False
self.allow_check = False
self.state_save = False self.state_save = False
self.server_side = True self.server_side = True
self.list_form = None self.list_form = None
...@@ -243,6 +244,7 @@ class BaseView(object): ...@@ -243,6 +244,7 @@ class BaseView(object):
allow_delete = kwargs.get("allow_delete", self.allow_delete) allow_delete = kwargs.get("allow_delete", self.allow_delete)
allow_post = kwargs.get("allow_post", self.allow_post) allow_post = kwargs.get("allow_post", self.allow_post)
allow_unpost = kwargs.get("allow_unpost", self.allow_unpost) 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) state_save = kwargs.get("state_save", self.state_save)
filter_columns = kwargs.get("filter_columns", self.filter_columns) filter_columns = kwargs.get("filter_columns", self.filter_columns)
server_side = kwargs.get("server_side", self.server_side) server_side = kwargs.get("server_side", self.server_side)
...@@ -270,6 +272,7 @@ class BaseView(object): ...@@ -270,6 +272,7 @@ class BaseView(object):
allow_delete=allow_delete, allow_delete=allow_delete,
allow_post=allow_post, allow_post=allow_post,
allow_unpost=allow_unpost, allow_unpost=allow_unpost,
allow_check=allow_check,
state_save=state_save, state_save=state_save,
new_buttons=new_buttons, new_buttons=new_buttons,
filter_columns=filter_columns, filter_columns=filter_columns,
......
...@@ -180,6 +180,7 @@ class Views(BaseView): ...@@ -180,6 +180,7 @@ class Views(BaseView):
self.table = Route self.table = Route
self.list_schema = ListSchema self.list_schema = ListSchema
self.allow_delete = True self.allow_delete = True
self.allow_check = True
self.form_scripts = """ self.form_scripts = """
$('#parent_nm').bind('typeahead:selected', function (obj, datum, name) { $('#parent_nm').bind('typeahead:selected', function (obj, datum, name) {
$('#parent_id').val(datum.id); $('#parent_id').val(datum.id);
......
...@@ -115,6 +115,7 @@ class DeTable(field.Field): ...@@ -115,6 +115,7 @@ class DeTable(field.Field):
allow_view=True, allow_view=True,
allow_post=False, allow_post=False,
allow_unpost=False, allow_unpost=False,
allow_check=False,
filter_columns=False, filter_columns=False,
**kw **kw
): ):
...@@ -124,14 +125,24 @@ class DeTable(field.Field): ...@@ -124,14 +125,24 @@ class DeTable(field.Field):
self.action = action self.action = action
self.tableid = tableid self.tableid = tableid
self.data = data self.data = data
self.allow_edit = json.dumps(allow_edit)
self.allow_delete = json.dumps(allow_delete)
self.allow_view = json.dumps(allow_view)
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)
# Button yang dikirim sebagai tambahan # Button yang dikirim sebagai tambahan
new_buttons = kw.get("new_buttons") or () new_buttons = kw.get("new_buttons") or ()
action_suffix = f"{action_suffix}{params}" action_suffix = f"{action_suffix}{params}"
close_url = self.action.split("/")
close_url = "/".join(close_url[:-1])
close_url.replace(":/","://")
params = params and f"?{params}" or "" params = params and f"?{params}" or ""
dict_buttons = { dict_buttons = {
"close": "{window.location = '/'; return false;}", "close": "{window.location = '"+close_url+"'; return false;}",
"add": "{window.location = o%sUri+'/add%s';}" % (tableid, params), "add": "{window.location = o%sUri+'/add%s';}" % (tableid, params),
"edit": """{ "edit": """{
if (m%sID) window.location = o%sUri+'/'+m%sID+'/edit%s'; if (m%sID) window.location = o%sUri+'/'+m%sID+'/edit%s';
...@@ -185,12 +196,7 @@ class DeTable(field.Field): ...@@ -185,12 +196,7 @@ class DeTable(field.Field):
replace(';', ';\n') replace(';', ';\n')
self.tableid = tableid self.tableid = tableid
self.scripts = ''.join(_scripts).replace(';', ";\n") self.scripts = ''.join(_scripts).replace(';', ";\n")
self.allow_edit = json.dumps(allow_edit)
self.allow_delete = json.dumps(allow_delete)
self.allow_view = json.dumps(allow_view)
self.allow_post = json.dumps(allow_post)
self.allow_unpost = json.dumps(allow_unpost)
self.filter_columns = json.dumps(filter_columns)
table_widget = getattr(schema, "widget", None) table_widget = getattr(schema, "widget", None)
if table_widget is None: if table_widget is None:
table_widget = widget.TableWidget() table_widget = widget.TableWidget()
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
allow_view allow_view|field.allow_view; allow_view allow_view|field.allow_view;
allow_post allow_post|field.allow_post; allow_post allow_post|field.allow_post;
allow_unpost allow_unpost|field.allow_unpost; allow_unpost allow_unpost|field.allow_unpost;
allow_check allow_check|field.allow_check;
state_save state_save|field.state_save; state_save state_save|field.state_save;
filter_columns filter_columns|field.filter_columns; filter_columns filter_columns|field.filter_columns;
filter_scripts filter_scripts|field.filter_scripts; filter_scripts filter_scripts|field.filter_scripts;
...@@ -46,7 +47,49 @@ ...@@ -46,7 +47,49 @@
</div> </div>
</div> </div>
</div> </div>
<div tal:condition="allow_check">
<input type="checkbox" class="${tableid}checkAll">Pilih Semua
<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);
}
});
$('.modal-inner-content td').click(function (event) {
if (!$(event.target).is('input')) {
$('input:checkbox', this).prop('checked', function (i, value) {
console.log(i, value);
//return !value;
});
//$('.${tableid}_check').on("click", function (event) {
// console.log(event);
// if (this.checked) {
// m${tableid}ChekList.push($(this).val());
// } else {
// m${tableid}CheckList.splice(m${tableid}CheckList.indexOf($(this).val()), 1);
// }
//});
}
});
$('.${tableid}_check').on("click", function (event) {
console.log(event);
if (this.checked) {
m${tableid}ChekList.push($(this).val());
} else {
m${tableid}CheckList.splice(m${tableid}CheckList.indexOf($(this).val()), 1);
}
})
});
</script>
</div>
<table id="${tableid}" <table id="${tableid}"
class="table table-bordered table-hover table-condensed dataTable no-footer"> class="table table-bordered table-hover table-condensed dataTable no-footer">
<thead> <thead>
...@@ -76,7 +119,11 @@ ...@@ -76,7 +119,11 @@
var o${tableid}Uri = "${url}"; var o${tableid}Uri = "${url}";
var o${tableid}Url = o${tableid}Uri + "${url_suffix}"; var o${tableid}Url = o${tableid}Uri + "${url_suffix}";
var m${tableid}ID; var m${tableid}ID;
var m${tableid}ChekList = [];
deform.addCallback('${tableid}', function (oid) { deform.addCallback('${tableid}', function (oid) {
// $(document).ready(function () {
function displayEmptyID() { function displayEmptyID() {
$("#emptyID").show(); $("#emptyID").show();
$('#emptyID').animate({opacity: 0.8}, 2000); $('#emptyID').animate({opacity: 0.8}, 2000);
...@@ -151,7 +198,7 @@ ...@@ -151,7 +198,7 @@
} else if (${tableid}Columns[co].hasOwnProperty("url")) { } else if (${tableid}Columns[co].hasOwnProperty("url")) {
let url = ${tableid}Columns[co].url; let url = ${tableid}Columns[co].url;
${tableid}Columns[co].render = function (data) { ${tableid}Columns[co].render = function (data) {
let result = "No Data" let result = "No Data";
if (data != null) { if (data != null) {
result = '<a href="' + url + data + '" target="_blank">Link</a>&nbsp;'; result = '<a href="' + url + data + '" target="_blank">Link</a>&nbsp;';
} }
...@@ -159,22 +206,25 @@ ...@@ -159,22 +206,25 @@
} }
} else if (${tableid}Columns[co].data === "id" && ${tableid}Columns[co].action === true) { } else if (${tableid}Columns[co].data === "id" && ${tableid}Columns[co].action === true) {
${tableid}Columns[co].render = function (id) { ${tableid}Columns[co].render = function (id) {
let result = "" let result = "";
if (${allow_view}) { if (${allow_check}) {
result = '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;'; result = '<input type="checkbox" class="${tableid}_check" value="' + id + '" id="${tableid}check' + id + '">&nbsp;';
} }
if (${allow_edit}) { if (${allow_view})
result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;';
if (${allow_edit})
result += '<a href="${url}/' + id + '/edit"><i class="fas fa-edit" aria-hidden="true" title="Edit"></i></a>&nbsp;' result += '<a href="${url}/' + id + '/edit"><i class="fas fa-edit" aria-hidden="true" title="Edit"></i></a>&nbsp;'
}
if (${allow_delete}) { if (${allow_delete})
result += '<a href="${url}/' + id + '/delete"><i class="fas fa-trash" aria-hidden="true" title="Delete"></i></a>'; result += '<a href="${url}/' + id + '/delete"><i class="fas fa-trash" aria-hidden="true" title="Delete"></i></a>';
}
if (${allow_post}) { if (${allow_post})
result += '<a href="${url}/' + id + '/post"><i class="fas fa-signs-post" aria-hidden="true" title="Post"></i></a>'; result += '<a href="${url}/' + id + '/post"><i class="fas fa-signs-post" aria-hidden="true" title="Post"></i></a>';
}
if (${allow_unpost}) { if (${allow_unpost})
result += '<a href="${url}/' + id + '/unpost"><i class="fas fa-delete-left" aria-hidden="true" title="Unpost"></i></a>'; result += '<a href="${url}/' + id + '/unpost"><i class="fas fa-delete-left" aria-hidden="true" title="Unpost"></i></a>';
}
return result; return result;
} }
//columns[1].order = "order_asc"; //columns[1].order = "order_asc";
...@@ -219,10 +269,8 @@ ...@@ -219,10 +269,8 @@
${tableid}Params.ajax = o${tableid}Url; ${tableid}Params.ajax = o${tableid}Url;
} }
${structure: filter_scripts}
o${tableid} = $('#${tableid}').DataTable(${tableid}Params); o${tableid} = $('#${tableid}').DataTable(${tableid}Params);
let tb = tb_array.join(' '); let tb = tb_array.join(' ');
$("div.toolbar").html(tb); $("div.toolbar").html(tb);
$("div.toolbar").attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;'); $("div.toolbar").attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;');
...@@ -240,7 +288,6 @@ ...@@ -240,7 +288,6 @@
$(this).addClass('row_selected'); $(this).addClass('row_selected');
} }
}); });
$(".${tableid}-control-filter").on('keyup', function (e) { $(".${tableid}-control-filter").on('keyup', function (e) {
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if (code === 13) { if (code === 13) {
...@@ -323,7 +370,6 @@ ...@@ -323,7 +370,6 @@
} }
}); });
console.log("Read Data"); console.log("Read Data");
$(".${tableid}-control-filter").each(function (e) { $(".${tableid}-control-filter").each(function (e) {
var col_id = $(this).attr("id") var col_id = $(this).attr("id")
...@@ -344,7 +390,10 @@ ...@@ -344,7 +390,10 @@
console.log(col_id, $(this).attr('id'), value); console.log(col_id, $(this).attr('id'), value);
}); });
${structure: btnscripts} ${structure: btnscripts}
filter_table();
// });
${structure: filter_scripts}
}); });
</script> </script>
</div> </div>
\ No newline at end of file \ No newline at end of file
from sqlalchemy.ext.declarative import declarative_base # from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base
from sqlalchemy.schema import MetaData from sqlalchemy.schema import MetaData
# Recommended naming convention used by Alembic, as various different database # Recommended naming convention used by Alembic, as various different database
...@@ -13,4 +14,4 @@ NAMING_CONVENTION = { ...@@ -13,4 +14,4 @@ NAMING_CONVENTION = {
} }
metadata = MetaData(naming_convention=NAMING_CONVENTION) metadata = MetaData(naming_convention=NAMING_CONVENTION)
Base = declarative_base(metadata=metadata) Base = declarative_base(metadata=metadata)
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!