Enhance button functionality and validation in various views; add delete button …

…and improve checklist handling
1 parent 742b4e69
...@@ -137,6 +137,7 @@ class ApiViews(APIView): ...@@ -137,6 +137,7 @@ class ApiViews(APIView):
if result.get("error"): if result.get("error"):
_log.error(result.get("error")) _log.error(result.get("error"))
_log.error(str(result)) _log.error(str(result))
return result return result
def not_found(self, msg=None): def not_found(self, msg=None):
......
...@@ -140,6 +140,8 @@ class BaseView(object): ...@@ -140,6 +140,8 @@ class BaseView(object):
self.is_object = False self.is_object = False
self.init_session(request) self.init_session(request)
if self.allow_check and self.allow_delete:
self.list_buttons.append(btn_delete)
def init_session(self, request): def init_session(self, request):
# # if not request.user: # # if not request.user:
......
import colander import colander
from deform import (widget, ) from deform import (widget, )
from opensipkd.models import DBSession, ResDesa, kategori_desa, ResKecamatan, ResProvinsi, ResDati2 from opensipkd.models import DBSession, ResDesa, kategori_desa, ResKecamatan, ResProvinsi, ResDati2
from opensipkd.tools.buttons import btn_upload, btn_close, btn_add from opensipkd.tools.buttons import btn_upload, btn_close, btn_add, btn_delete
from pyramid.i18n import TranslationStringFactory from pyramid.i18n import TranslationStringFactory
from pyramid.view import (view_config, ) from pyramid.view import (view_config, )
from .dati2 import dati2_widget from .dati2 import dati2_widget
...@@ -74,7 +74,10 @@ class Views(BaseView): ...@@ -74,7 +74,10 @@ class Views(BaseView):
self.edit_schema = EditSchema self.edit_schema = EditSchema
self.table = ResDesa self.table = ResDesa
self.list_schema = ListSchema self.list_schema = ListSchema
self.list_buttons = (btn_add, btn_close, btn_upload) self.list_buttons = [btn_add, btn_delete, btn_upload]
self.allow_check = True
self.allow_view = True
self.list_view_field = 'nama'
def form_validator(self, form, value): def form_validator(self, form, value):
def err_kode(): def err_kode():
...@@ -140,7 +143,7 @@ class Views(BaseView): ...@@ -140,7 +143,7 @@ class Views(BaseView):
# return super(ViewDesa, self).view_list() # return super(ViewDesa, self).view_list()
def list_join(self, query): def list_join(self, query):
return query.outerjoin(ResKecamatan) return query.outerjoin(ResKecamatan, ResKecamatan.id==ResDesa.kecamatan_id)
# @view_config(route_name='desa-act', renderer='json', # @view_config(route_name='desa-act', renderer='json',
# permission='view') # permission='view')
......
...@@ -2,9 +2,8 @@ import colander ...@@ -2,9 +2,8 @@ import colander
from deform import (widget, ) from deform import (widget, )
from opensipkd.base.views.provinsi import provinsi_widget from opensipkd.base.views.provinsi import provinsi_widget
from opensipkd.models import DBSession, ResKecamatan, ResDati2, ResProvinsi from opensipkd.models import DBSession, ResKecamatan, ResDati2, ResProvinsi
from opensipkd.tools.buttons import btn_upload, btn_close, btn_add from opensipkd.tools.buttons import btn_upload, btn_add, btn_delete
from pyramid.i18n import TranslationStringFactory from pyramid.i18n import TranslationStringFactory
from pyramid.view import (view_config, )
from ..widgets import widget_os from ..widgets import widget_os
from .dati2 import dati2_widget from .dati2 import dati2_widget
from ..views import BaseView from ..views import BaseView
...@@ -68,8 +67,11 @@ class Views(BaseView): ...@@ -68,8 +67,11 @@ class Views(BaseView):
self.edit_schema = EditSchema self.edit_schema = EditSchema
self.table = ResKecamatan self.table = ResKecamatan
self.list_schema = ListSchema self.list_schema = ListSchema
self.list_buttons = (btn_add, btn_close, btn_upload) self.list_buttons = [btn_add, btn_delete, btn_upload]
self.allow_check = True
self.allow_view = True
self.allow_delete = True
self.list_view_field = 'nama'
def form_validator(self, form, value): def form_validator(self, form, value):
def err_kode(): def err_kode():
raise colander.Invalid(form, 'Kode %s sudah digunakan oleh %s' % ( raise colander.Invalid(form, 'Kode %s sudah digunakan oleh %s' % (
......
...@@ -164,10 +164,13 @@ class DeTable(field.Field): ...@@ -164,10 +164,13 @@ class DeTable(field.Field):
tableid, tableid, params) or \ tableid, tableid, params) or \
"""{ """{
var cnt = m%sCheckList.length; var cnt = m%sCheckList.length;
if (cnt > 0){
if (confirm('Menghapus '+cnt+' data, pastikan data yang dipilih sudah benar!')){ if (confirm('Menghapus '+cnt+' data, pastikan data yang dipilih sudah benar!')){
ids = m%sCheckList.join(','); ids = m%sCheckList.join(',');
window.location = o%sUri+'/all/delete?ids='+ids; window.location = o%sUri+'/all/delete?ids='+ids;
}; };
}else{ alert('Pilih Baris'); }
event.stopPropagation(); event.stopPropagation();
}""" % (tableid, tableid, tableid), }""" % (tableid, tableid, tableid),
"csv": "{window.location = o%sUri+'/csv/act%s';}" % ( "csv": "{window.location = o%sUri+'/csv/act%s';}" % (
...@@ -199,9 +202,15 @@ class DeTable(field.Field): ...@@ -199,9 +202,15 @@ class DeTable(field.Field):
class="btn {button.css_class}"> class="btn {button.css_class}">
{button.title} </button>\n {button.title} </button>\n
""") """)
if dict_buttons[button.name]: if dict_buttons.get(button.name):
_scripts.append(f'$("#{tableid + button.name}").click(function ()' + _scripts.append(f'$("#{tableid + button.name}").click(function ()' +
dict_buttons[button.name] + ');') dict_buttons[button.name] + ');')
else:
url = "{window.location = o%sUri+'/" % tableid
url += f"{button.name}';"+"}"
_scripts.append(f'$("#{tableid + button.name}").click(function ()' +
url +
');')
if html_buttons: if html_buttons:
for html in html_buttons: for html in html_buttons:
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
} }
function render_checklist(value) { function render_checklist(value) {
return '<input type="checkbox" class="${tableid}_check" checked="' + { value } + '"></input>'; return '<input type="checkbox" class="${tableid}_check" checked="' + { value } + ' checked=false"></input>';
} }
var mtableId = "${tableid}"; var mtableId = "${tableid}";
...@@ -178,33 +178,33 @@ ...@@ -178,33 +178,33 @@
} }
}else if (${tableid}Columns[co].data === "id") { }else if (${tableid}Columns[co].data === "id") {
${tableid}Columns[co].render = function (id, typ, data, setting) { ${tableid}Columns[co].render = function (id, typ, data, setting) {
if (${tableid}Columns[co].action === false) return "" if (${tableid}Columns[co].action === false) return "";
let result = ""; let result = "";
<tal:block tal:condition="allow_check=='true'"> <tal:block tal:condition="allow_check=='true'">
var checked = ""; var checked = "";
if (check_field !== "") { if (check_field !== "") {
checked = data[check_field] !== null ? "checked" : ""; //checked = data[check_field] !== null ? "checked" : "";
m${tableid}CheckList.push(id); // m${tableid}CheckList.push(id);
} }
result = '<input type="checkbox" class="' + mtableId + '_check" id="' + mtableId + '_check_' + id +'" value="' + id + '" ' + checked + ' name="' + mtableId + '_check"/>&nbsp;'; result = '<input type="checkbox" class="' + mtableId + '_check" id="' + mtableId + '_check_' + id +'" value="' + id + '" name="' + mtableId + '_check"/>&nbsp;';
</tal:block> </tal:block>
<tal:block tal:condition="allow_check=='false'"> <tal:block tal:condition="allow_check=='false'">
<tal:block tal:condition="allow_view=='true'"> <tal:block tal:condition="allow_view=='true'">
result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;'; result += '<a href="${url}/' + id + '/view"><i class="fas fa-eye" aria-hidden="true" title="View"></i></a>&nbsp;';
</tal:block> </tal:block>
<tal:block tal:condition="allow_edit=='true'"> <tal:block tal:condition="allow_edit=='true'">
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;'
</tal:block> </tal:block>
<tal:block tal:condition="allow_delete=='true'"> <tal:block tal:condition="allow_delete=='true'">
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>';
</tal:block> </tal:block>
<tal:block tal:condition="allow_post=='true'"> <tal:block tal:condition="allow_post=='true'">
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>';
</tal:block> </tal:block>
<tal:block tal:condition="allow_post=='true'"> <tal:block tal:condition="allow_post=='true'">
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>';
</tal:block> </tal:block>
</tal:block> </tal:block>
return result; return result;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!