Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
irul
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ee40039a
authored
Aug 05, 2024
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Penambahan parameter button pada detable
1 parent
3005a754
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
27 deletions
opensipkd/base/views/base_views.py
opensipkd/base/views/partner.py
opensipkd/detable/detable.py
opensipkd/detable/log.txt
opensipkd/detable/templates/detable.pt
opensipkd/base/views/base_views.py
View file @
ee40039
...
...
@@ -156,6 +156,7 @@ class BaseView(object):
self
.
action_suffix
=
"/grid/act"
self
.
upload_keys
=
[
"kode"
]
self
.
report_file
=
""
self
.
new_buttons
=
{}
def
query_register
(
self
,
**
kwargs
):
pass
...
...
@@ -229,6 +230,10 @@ class BaseView(object):
schema
=
self
.
list_schema
()
schema
=
schema
.
bind
(
request
=
self
.
req
)
list_url
=
kwargs
.
get
(
"list_url"
,
None
)
new_buttons
=
kwargs
.
get
(
"new_buttons"
)
if
not
new_buttons
:
new_buttons
=
self
.
new_buttons
if
not
list_url
:
list_url
=
self
.
req
.
route_url
(
self
.
list_route
)
table
=
DeTable
(
schema
,
...
...
@@ -241,6 +246,7 @@ class BaseView(object):
allow_post
=
allow_post
,
allow_unpost
=
allow_unpost
,
state_save
=
state_save
,
new_buttons
=
new_buttons
)
resources
=
table
.
get_widget_resources
()
# resources=dict(css="", js="")
...
...
@@ -302,6 +308,7 @@ class BaseView(object):
def
set_post
(
self
,
**
kwargs
):
pass
def
set_unpost
(
self
,
**
kwargs
):
pass
...
...
opensipkd/base/views/partner.py
View file @
ee40039
import
os
import
colander
from
opensipkd.base
import
get_params
,
get_id_card_folder
from
deform
import
(
widget
,
widget
,
Button
,
)
from
pyramid.i18n
import
TranslationStringFactory
from
pyramid.view
import
(
view_config
,
)
from
opensipkd.base
import
get_id_card_folder
from
opensipkd.models
import
DBSession
,
Partner
from
opensipkd.models
import
(
ResProvinsi
,
ResDati2
,
ResKecamatan
,
ResDesa
)
from
opensipkd.models.common
import
ResCompany
from
opensipkd.tools
import
Upload
,
img_exts
from
.company
import
company_widget
from
.partner_base
import
PartnerSchema
,
NamaSchema
from
opensipkd.models
import
DBSession
,
Partner
from
.partner_base
import
PartnerSchema
# from .. import partner_idcard_url
from
..views
import
BaseView
...
...
@@ -113,7 +109,22 @@ class ViewPartner(BaseView):
@view_config
(
route_name
=
'partner'
,
renderer
=
'templates/table.pt'
,
permission
=
'user-view'
)
def
view_list
(
self
):
return
super
()
.
view_list
()
new_buttons
=
{
"kta"
:
{
"obj"
:
"kta"
,
"js"
:
"""if (m{tableid}ID!=null)
window.location=o{tableid}Uri+'/'+m{tableid}ID+'/kta?{params}';
else displayEmptyID();
"""
},
"ktp"
:
{
"obj"
:
Button
(
"ktp"
,
title
=
_
(
'KTP'
),
css_class
=
"btn-danger"
),
"js"
:
"""if (m{tableid}ID!=null)
window.location=o{tableid}Uri+'/'+m{tableid}ID+'/ktp?{params}';
else displayEmptyID();
"""
}
}
return
super
()
.
view_list
(
new_buttons
=
new_buttons
)
@view_config
(
route_name
=
'partner-act'
,
renderer
=
'json'
,
permission
=
'user-view'
)
...
...
opensipkd/detable/detable.py
View file @
ee40039
"""Form."""
# Standard Library
import
json
import
re
import
logging
import
re
import
colander
import
deform
from
chameleon.utils
import
Markup
from
deform
import
compat
from
deform
import
field
from
.
import
widget
# from deform import widget
...
...
@@ -122,23 +122,29 @@ class DeTable(field.Field):
super
()
.
__init__
(
schema
,
**
kw
)
self
.
request
=
kw
.
get
(
"request"
)
self
.
rows
=
kw
.
get
(
"rows"
)
new_buttons
=
kw
.
get
(
"new_buttons"
)
or
()
params
=
params
and
f
"?{params}"
or
""
btn_close_js
=
"{window.location = '/'; return false;}"
btn_add_js
=
"{window.location = o
%
sUri+'/add
%
s';}"
%
(
tableid
,
params
)
btn_edit_js
=
"""{
dict_buttons
=
{
"close"
:
"{window.location = '/'; return false;}"
,
"add"
:
"{window.location = o
%
sUri+'/add
%
s';}"
%
(
tableid
,
params
),
"edit"
:
"""{
if (m
%
sID) window.location = o
%
sUri+'/'+m
%
sID+'/edit
%
s';
else alert('Pilih Baris');
}"""
%
(
tableid
,
tableid
,
tableid
,
params
)
btn_view_js
=
"{window.location = o
%
sUri+'/'+m
%
sID+'/view
%
s';}"
%
(
tableid
,
tableid
,
params
)
btn_delete_js
=
"{window.location = o
%
sUri+'/'+m
%
sID+'/delete
%
s';}"
%
(
tableid
,
tableid
,
params
)
btn_csv_js
=
"{window.location = o
%
sUri+'/csv/act
%
s';}"
%
(
tableid
,
params
)
btn_pdf_js
=
"{window.open(o
%
sUri+'/pdf/act
%
s');}"
%
(
tableid
,
params
)
btn_upload_js
=
"{window.location = o
%
sUri+'/upload
%
s';}"
%
(
tableid
,
params
)
}"""
%
(
tableid
,
tableid
,
tableid
,
params
),
"view"
:
"{window.location = o
%
sUri+'/'+m
%
sID+'/view
%
s';}"
%
(
tableid
,
tableid
,
params
),
"delete"
:
"{window.location = o
%
sUri+'/'+m
%
sID+'/delete
%
s';}"
%
(
tableid
,
tableid
,
params
),
"csv"
:
"{window.location = o
%
sUri+'/csv/act
%
s';}"
%
(
tableid
,
params
),
"pdf"
:
"{window.open(o
%
sUri+'/pdf/act
%
s');}"
%
(
tableid
,
params
),
"upload"
:
"{window.location = o
%
sUri+'/upload
%
s';}"
%
(
tableid
,
params
),
}
for
k
in
new_buttons
:
buttons
+=
(
new_buttons
[
k
][
"obj"
],)
dict_buttons
[
k
]
=
'{'
+
new_buttons
[
k
][
"js"
]
.
format
(
tableid
=
tableid
,
params
=
params
)
+
'}'
action_suffix
=
f
"{action_suffix}{params}"
_buttons
=
[]
...
...
@@ -159,7 +165,7 @@ class DeTable(field.Field):
{button.title} </button>
\n
"""
)
_scripts
.
append
(
f
'$("#{tableid + button.name}").click(function ()'
+
eval
(
'btn_'
+
button
.
name
+
'_js'
)
+
');'
)
dict_buttons
[
button
.
name
]
+
');'
)
self
.
buttons
=
"','"
.
join
(
_buttons
)
.
replace
(
'
\n
'
,
""
)
.
\
replace
(
';'
,
';
\n
'
)
self
.
tableid
=
tableid
...
...
@@ -172,6 +178,7 @@ class DeTable(field.Field):
table_widget
=
getattr
(
schema
,
"widget"
,
None
)
if
table_widget
is
None
:
table_widget
=
widget
.
TableWidget
()
self
.
widget
=
table_widget
self
.
server_side
=
server_side
self
.
data
=
data
...
...
opensipkd/detable/log.txt
0 → 100644
View file @
ee40039
2024-08-05
Penambahan fungsi Tombol
kwargs = new_buttons
value = {"btn_name":
{"obj": objBtn or btn name,
"js": "jsScript{tableid} {params}"
}
}
contoh pada file partner
def view_list(self):
ktp = Button("ktp", "KTP", )
new_buttons = {"kta":
{"obj": "kta",
"js": """if (m{tableid}ID!=null)
window.location=o{tableid}Uri+'/'+m{tableid}ID+'/kta?{params}';
else displayEmptyID();
"""
},
"ktp":
{"obj": Button("ktp", title=_('KTP'), css_class="btn-danger"),
"js": """if (m{tableid}ID!=null)
window.location=o{tableid}Uri+'/'+m{tableid}ID+'/ktp?{params}';
else displayEmptyID();
"""
}
}
return super().view_list(new_buttons=new_buttons)
new_buttons ini bisa di pasang pada init ataua saat memanggil view_list(new_buttons=new_buttons)
kalau pada init gunakan self.new_buttons
\ No newline at end of file
opensipkd/detable/templates/detable.pt
View file @
ee40039
...
...
@@ -28,6 +28,12 @@
>
<header role="heading" class="txt-color-grayDark">
<h2 tal:condition="title"><i class="fa fa-fw fa-table"></i>${title}</h2>
<div class="alert alert-danger " role="alert" id="emptyID" style="opacity:0.7;display: none;">
<strong>Pilih data terlebih dahulu!!</strong>
<!--? <button type="button" class="close" data-dismiss="alert" aria-label="Close">-->
<!--? <span aria-hidden="true">×</span>-->
<!--? </button>-->
</div>
<div role="content">
<div class="widget-body">
<table
...
...
@@ -51,10 +57,21 @@
var o${tableid};
var o${tableid}Uri = "${url}";
var o${tableid}Url = o${tableid}Uri + "${url_suffix}";
var m${tableid}ID;
deform.addCallback
('${tableid}', function (oid) {
// $(document).ready(function () {
function displayEmptyID() {
$("#emptyID").show();
$('#emptyID').animate({ opacity: 0.8 }, 2000);
setTimeout(function () {
$("#emptyID").fadeTo(500, 0).slideUp(500, function () {
$("#emptyID").hide();
});
}
, 4000);
}
let tb_array = [
'<div class="btn-group pull-left">',
...
...
@@ -84,13 +101,13 @@
${tableid}Columns[co].className = "text-center";
${tableid}Columns[co].width = "30pt";
${tableid}Columns[co].render = function (value) {
if (typeof value === "string" && value.length
>
0) {
if (typeof value === "string" && value.length
>
0) {
return render_checkbox(value)
}
if (["", false, 0].indexOf(value) === -1) {
return render_checkbox(true);
}
return
render_checkbox(false);
return render_checkbox(false);
}
} else if (${tableid}Columns[co].hasOwnProperty("url")) {
let url = ${tableid}Columns[co].url;
...
...
@@ -173,6 +190,7 @@
$('#${tableid} tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
m${tableid}ID = null;
} else {
let aData = o${tableid}.row(this).data();
o${tableid}.$('tr.selected').removeClass('selected');
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment