fix: category filter, action icons, download filename, reset button #16
@@ -29,17 +29,24 @@ def add_action_columns(df, model_key):
|
|||||||
if df.empty:
|
if df.empty:
|
||||||
return df
|
return df
|
||||||
|
|
||||||
df.insert(0, "Select", df["Id"].apply(
|
# Edit + Delete side by side in one "Action" column, both as icon buttons.
|
||||||
|
df.insert(0, "Action", df["Id"].apply(
|
||||||
|
lambda x: (
|
||||||
|
f'<div class="d-flex gap-1">'
|
||||||
|
f'<a href="/file/edit/{model_key}/{x}" class="btn btn-sm btn-warning edit-btn" title="Edit">'
|
||||||
|
f'<i class="bi bi-pencil-square"></i></a>'
|
||||||
|
f'<button class="btn btn-sm btn-danger delete-btn" data-id="{x}" data-model="{model_key}" title="Delete">'
|
||||||
|
f'<i class="bi bi-trash"></i></button>'
|
||||||
|
f'</div>'
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
|
df.insert(1, "Select", df["Id"].apply(
|
||||||
lambda x: f'<input type="checkbox" class="row-check" data-id="{x}">'
|
lambda x: f'<input type="checkbox" class="row-check" data-id="{x}">'
|
||||||
))
|
))
|
||||||
|
|
||||||
df["Update"] = df["Id"].apply(
|
df["Id"] = range(1, len(df) + 1)
|
||||||
lambda x: f'<a href="/file/edit/{model_key}/{x}" class="btn btn-sm btn-warning edit-btn"><i class="bi bi-pencil-square"></i> Edit</a>'
|
df = df.rename(columns={"Id": "Sr No"})
|
||||||
)
|
|
||||||
|
|
||||||
df["Delete"] = df["Id"].apply(
|
|
||||||
lambda x: f'<button class="btn btn-sm btn-danger delete-btn" data-id="{x}" data-model="{model_key}">Delete</button>'
|
|
||||||
)
|
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
@@ -236,6 +243,30 @@ def report_file():
|
|||||||
else:
|
else:
|
||||||
bill.Fetch(ra_bill_no,subcontractor_id,location)
|
bill.Fetch(ra_bill_no,subcontractor_id,location)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
if (
|
||||||
|
bill.df_tr.empty and
|
||||||
|
bill.df_mh.empty and
|
||||||
|
bill.df_dc.empty and
|
||||||
|
bill.df_laying.empty
|
||||||
|
):
|
||||||
|
flash(
|
||||||
|
f"No records found for RA Bill No '{ra_bill_no}'. "
|
||||||
|
"Please check the RA Bill No and try again."
|
||||||
|
if ra_bill_no else
|
||||||
|
"No records found for the selected filters.",
|
||||||
|
"warning"
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"subcontractor_report.html",
|
||||||
|
subcontractors=subcontractors,
|
||||||
|
selected_sc_id=selected_sc_id,
|
||||||
|
selected_ra_bill=ra_bill_no,
|
||||||
|
selected_location=location,
|
||||||
|
selected_category=category
|
||||||
|
)
|
||||||
|
|
||||||
# -----------------------------------------
|
# -----------------------------------------
|
||||||
# Generate Abstract Report for Web
|
# Generate Abstract Report for Web
|
||||||
# -----------------------------------------
|
# -----------------------------------------
|
||||||
@@ -256,6 +287,32 @@ def report_file():
|
|||||||
bill.df_tr = bill.df_mh = bill.df_dc = pd.DataFrame()
|
bill.df_tr = bill.df_mh = bill.df_dc = pd.DataFrame()
|
||||||
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
category in ("tr", "mh", "dc", "laying")
|
||||||
|
and bill.df_tr.empty and bill.df_mh.empty
|
||||||
|
and bill.df_dc.empty and bill.df_laying.empty
|
||||||
|
):
|
||||||
|
category_labels = {
|
||||||
|
"tr": "Trench Excavation",
|
||||||
|
"mh": "Manhole Excavation",
|
||||||
|
"dc": "Domestic Chamber",
|
||||||
|
"laying": "Pipe Laying",
|
||||||
|
}
|
||||||
|
flash(
|
||||||
|
f"No {category_labels[category]} records found for the "
|
||||||
|
"selected filters.",
|
||||||
|
"warning"
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"subcontractor_report.html",
|
||||||
|
subcontractors=subcontractors,
|
||||||
|
selected_sc_id=selected_sc_id,
|
||||||
|
selected_ra_bill=ra_bill_no,
|
||||||
|
selected_location=location,
|
||||||
|
selected_category=category
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ===================================================
|
# ===================================================
|
||||||
# DOWNLOAD EXCEL
|
# DOWNLOAD EXCEL
|
||||||
# ===================================================
|
# ===================================================
|
||||||
@@ -267,16 +324,46 @@ def report_file():
|
|||||||
abstract = AbstractReportService(subcontractor_id=subcontractor_id,ra_bill_no=ra_bill_no)
|
abstract = AbstractReportService(subcontractor_id=subcontractor_id,ra_bill_no=ra_bill_no)
|
||||||
abstract.generate(workbook)
|
abstract.generate(workbook)
|
||||||
|
|
||||||
bill.df_tr.to_excel(writer,sheet_name="Tr.Ex",index=False)
|
|
||||||
bill.df_mh.to_excel(writer,sheet_name="Mh.Ex",index=False)
|
sheet_map = [
|
||||||
bill.df_dc.to_excel(writer,sheet_name="MH & DC",index=False)
|
(bill.df_tr, "Tr.Ex"),
|
||||||
bill.df_laying.to_excel(writer,sheet_name="Pipe Laying",index=False)
|
(bill.df_mh, "Mh.Ex"),
|
||||||
|
(bill.df_dc, "MH & DC"),
|
||||||
|
(bill.df_laying, "Pipe Laying"),
|
||||||
|
]
|
||||||
|
for df, sheet_name in sheet_map:
|
||||||
|
if not df.empty:
|
||||||
|
df.to_excel(writer, sheet_name=sheet_name, index=False)
|
||||||
writer.close()
|
writer.close()
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
|
|
||||||
|
|
||||||
|
sc_obj = next(
|
||||||
|
(s for s in subcontractors if str(s.id) == str(subcontractor_id)),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
sc_name = sc_obj.subcontractor_name if sc_obj else "Subcontractor"
|
||||||
|
sc_name = re.sub(r'[^A-Za-z0-9_-]+', '_', sc_name).strip('_')
|
||||||
|
|
||||||
|
name_parts = [sc_name]
|
||||||
|
|
||||||
|
if ra_bill_no:
|
||||||
|
name_parts.append(f"RA{re.sub(r'[^A-Za-z0-9_-]+', '_', ra_bill_no)}")
|
||||||
|
|
||||||
|
if location:
|
||||||
|
name_parts.append(re.sub(r'[^A-Za-z0-9_-]+', '_', location).strip('_'))
|
||||||
|
|
||||||
|
if category and category != "all":
|
||||||
|
name_parts.append(category.upper())
|
||||||
|
|
||||||
|
if action == "excel_all":
|
||||||
|
name_parts.append("All")
|
||||||
|
|
||||||
|
filename = "_".join(name_parts) + "_Report.xlsx"
|
||||||
|
|
||||||
return send_file(
|
return send_file(
|
||||||
output,
|
output,
|
||||||
download_name= "subcontractor_Report.xlsx",
|
download_name=filename,
|
||||||
as_attachment=True
|
as_attachment=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -124,109 +124,66 @@
|
|||||||
<i class="bi bi-arrow-left-right me-2"></i> Client vs Subcontractor
|
<i class="bi bi-arrow-left-right me-2"></i> Client vs Subcontractor
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<!-- <li>
|
||||||
|
<a class="dropdown-item" href="/file/client_vs_subcont">
|
||||||
|
<i class="bi bi-arrow-left-right me-2"></i> Comparison Report
|
||||||
|
</a>
|
||||||
|
</li> -->
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Masters -->
|
|
||||||
<li class="nav-item dropdown">
|
<!-- Formats -->
|
||||||
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="/engi">
|
<li class="nav-item">
|
||||||
<i class="bi bi-gear me-2"></i> Masters
|
<a class="nav-link" href="/file_format">
|
||||||
|
<i class="bi bi-file-earmark-text me-1"></i> Formats
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu dropdown-menu-dark">
|
|
||||||
<!-- Client Standard Rates -->
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/engi/subcontractor-rate">
|
|
||||||
<i class="bi bi-file-earmark-text me-1"></i> Rate Master
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<!-- Client Standard Rates -->
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/engi/client-rate">
|
|
||||||
<i class="bi bi-file-earmark-text me-1"></i> Client Standard Rates
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<!-- Formats -->
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/file_format">
|
|
||||||
<i class="bi bi-file-earmark-text me-1"></i> Formats
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
<!-- USER DROPDOWN -->
|
<!-- USER DROPDOWN -->
|
||||||
<li class="nav-item dropdown">
|
{% if session.get("user_id") %}
|
||||||
|
<li class="nav-item dropdown ms-lg-3">
|
||||||
|
|
||||||
<a class="nav-link dropdown-toggle d-flex align-items-center text-white"
|
<a class="nav-link dropdown-toggle d-flex align-items-center gap-2" href="#"
|
||||||
href="#" id="profileDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
data-bs-toggle="dropdown">
|
||||||
|
<i class="bi bi-person-circle fs-5"></i>
|
||||||
<i class="bi bi-person-circle fs-4"></i>
|
<span class="d-none d-lg-inline">
|
||||||
<span class="ms-2 fw-semibold">
|
|
||||||
{{ session.get("user_name") }}
|
{{ session.get("user_name") }}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-dark border-0 shadow-lg bg-dark p-0"
|
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-dark shadow">
|
||||||
style="width:320px;">
|
|
||||||
|
|
||||||
<!-- Profile Header -->
|
<!-- User card -->
|
||||||
<li class="text-center py-4 border-bottom border-secondary">
|
<li class="px-3 py-3 text-center border-bottom">
|
||||||
<i class="bi bi-person-circle text-light" style="font-size:60px;"></i>
|
<i class="bi bi-person-circle fs-1"></i>
|
||||||
<h5 class="mt-2 mb-0 fw-bold">
|
<div class="fw-semibold mt-1">
|
||||||
{{ session.get("user_name") }}
|
{{ session.get("user_name") }}
|
||||||
</h5>
|
</div>
|
||||||
<small class="text-secondary">
|
<small class="text-muted">Logged in user</small>
|
||||||
{{ session.get("email") }}
|
|
||||||
</small>
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Dashboard -->
|
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item text-light py-2" href="{{ url_for('dashboard.dashboard') }}">
|
<a class="dropdown-item" href="/dashboard">
|
||||||
<i class="bi bi-speedometer2 me-2"></i> Dashboard
|
<i class="bi bi-speedometer2 me-2"></i> Dashboard
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Activity Log page -->
|
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item text-light py-2" href="{{ url_for('activity.activity') }}">
|
<a class="dropdown-item" href="{{ url_for('activity.activity') }}">
|
||||||
<i class="bi bi-clock-history me-2"></i> Activity Log
|
<i class="bi bi-clock-history me-2"></i>
|
||||||
|
Activity Log
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Manage Account -->
|
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item py-2" href="#">
|
<a class="dropdown-item text-warning" href="/logout">
|
||||||
<i class="bi bi-gear me-2"></i> Manage Account
|
<i class="bi bi-box-arrow-right me-2"></i> Logout
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li><hr class="dropdown-divider border-secondary m-0"></li>
|
|
||||||
|
|
||||||
<!-- Logout Account -->
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item text-warning py-2" href="{{ url_for('auth.logout') }}">
|
|
||||||
<i class="bi bi-box-arrow-right me-2"></i>
|
|
||||||
Logout
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<!-- Footer -->
|
|
||||||
<li class="text-center py-3 bg-secondary bg-opacity-10 border-top border-secondary">
|
|
||||||
<small class="text-light">
|
|
||||||
<i class="bi bi-shield-check text-success"></i>
|
|
||||||
Secured by <strong>LCEPL</strong>
|
|
||||||
</small>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -379,6 +336,7 @@
|
|||||||
|
|
||||||
showLoader();
|
showLoader();
|
||||||
const btn = this.querySelector("button[type='submit']");
|
const btn = this.querySelector("button[type='submit']");
|
||||||
|
const originalBtnHtml = btn ? btn.innerHTML : null;
|
||||||
|
|
||||||
if(btn){
|
if(btn){
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
@@ -388,10 +346,24 @@
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
hideLoader();
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = originalBtnHtml;
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
window.addEventListener("pageshow", function () {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<option value="dc"
|
<option value="dc"
|
||||||
{% if request.form.get('category')=='dc' %}selected{% endif %}>
|
{% if request.form.get('category')=='dc' %}selected{% endif %}>
|
||||||
Manhole Domestic Chamber
|
Domestic Chamber
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
<option value="laying"
|
<option value="laying"
|
||||||
@@ -155,51 +155,61 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if tables %}
|
{% if tables %}
|
||||||
|
{% set show_all = (not selected_category) or selected_category == 'all' %}
|
||||||
<!-- Tabs -->
|
<!-- Tabs -->
|
||||||
<div class="card shadow-sm border-0 mt-4">
|
<div class="card shadow-sm border-0 mt-4">
|
||||||
<div class="card-header bg-light">
|
<div class="card-header bg-light">
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#abstract">
|
<button class="nav-link {% if show_all %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#abstract">
|
||||||
<i class="bi bi-file-earmark-text"></i> Abstract
|
<i class="bi bi-file-earmark-text"></i> Abstract
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'tr' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link " data-bs-toggle="tab" data-bs-target="#tr">
|
<button class="nav-link {% if selected_category == 'tr' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#tr">
|
||||||
<i class="bi bi-cone-striped"></i> Trench Excavation
|
<i class="bi bi-cone-striped"></i> Trench Excavation
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'mh' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#mh">
|
<button class="nav-link {% if selected_category == 'mh' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#mh">
|
||||||
<i class="bi bi-nut"></i> Manhole Excavation
|
<i class="bi bi-nut"></i> Manhole Excavation
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'dc' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#dc">
|
<button class="nav-link {% if selected_category == 'dc' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#dc">
|
||||||
<i class="bi bi-grid-3x3"></i> Manhole & Domestic Chambers Construction
|
<i class="bi bi-grid-3x3"></i> Manhole & Domestic Chambers Construction
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'laying' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#laying">
|
<button class="nav-link {% if selected_category == 'laying' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#laying">
|
||||||
<i class="bi bi-bezier2"></i> Pipe Laying
|
<i class="bi bi-bezier2"></i> Pipe Laying
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
|
||||||
<div class="tab-pane fade show active" id="abstract">
|
<div class="tab-pane fade {% if show_all %}show active{% endif %}" id="abstract">
|
||||||
{{ abstract_html|safe }}
|
{{ abstract_html|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'tr' %}
|
||||||
<!-- Trench -->
|
<!-- Trench -->
|
||||||
<div class="tab-pane fade "id="tr">
|
<div class="tab-pane fade {% if selected_category == 'tr' %}show active{% endif %}" id="tr">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button onclick="deleteSelected('tr')" class="btn btn-danger">
|
<button onclick="deleteSelected('tr')" class="btn btn-danger">
|
||||||
<i class="bi bi-trash"></i> Delete Selected
|
<i class="bi bi-trash"></i> Delete Selected
|
||||||
@@ -209,9 +219,11 @@
|
|||||||
{{ tables.tr|safe }}
|
{{ tables.tr|safe }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'mh' %}
|
||||||
<!-- MH -->
|
<!-- MH -->
|
||||||
<div class="tab-pane fade" id="mh">
|
<div class="tab-pane fade {% if selected_category == 'mh' %}show active{% endif %}" id="mh">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button onclick="deleteSelected('mh')" class="btn btn-danger">
|
<button onclick="deleteSelected('mh')" class="btn btn-danger">
|
||||||
<i class="bi bi-trash"></i>Delete Selected
|
<i class="bi bi-trash"></i>Delete Selected
|
||||||
@@ -221,9 +233,11 @@
|
|||||||
{{ tables.mh|safe }}
|
{{ tables.mh|safe }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'dc' %}
|
||||||
<!-- DC -->
|
<!-- DC -->
|
||||||
<div class="tab-pane fade" id="dc">
|
<div class="tab-pane fade {% if selected_category == 'dc' %}show active{% endif %}" id="dc">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button onclick="deleteSelected('dc')"class="btn btn-danger">
|
<button onclick="deleteSelected('dc')"class="btn btn-danger">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
@@ -234,9 +248,11 @@
|
|||||||
{{ tables.dc|safe }}
|
{{ tables.dc|safe }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_all or selected_category == 'laying' %}
|
||||||
<!-- Laying -->
|
<!-- Laying -->
|
||||||
<div class="tab-pane fade" id="laying">
|
<div class="tab-pane fade {% if selected_category == 'laying' %}show active{% endif %}" id="laying">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button onclick="deleteSelected('laying')"
|
<button onclick="deleteSelected('laying')"
|
||||||
class="btn btn-danger">
|
class="btn btn-danger">
|
||||||
@@ -248,6 +264,7 @@
|
|||||||
{{ tables.laying|safe }}
|
{{ tables.laying|safe }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -256,31 +273,45 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Reset
|
|
||||||
document.getElementById("resetBtn").addEventListener("click", function () {location.reload();});
|
document.getElementById("resetBtn").addEventListener("click", function () {
|
||||||
|
window.location.href = window.location.pathname;
|
||||||
|
});
|
||||||
|
|
||||||
// DATATABLE
|
// DATATABLE
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('.datatable').DataTable({
|
|
||||||
pageLength: 10,
|
$('.datatable').each(function () {
|
||||||
dom: 'Bfrtip',
|
$(this).DataTable({
|
||||||
buttons: ['copy', 'csv', 'excel', 'print']
|
pageLength: 10,
|
||||||
|
dom: 'Bfrtip',
|
||||||
|
buttons: ['copy', 'csv', 'excel', 'print'],
|
||||||
|
initComplete: function () {
|
||||||
|
|
||||||
|
$(this).closest('.dataTables_wrapper')
|
||||||
|
.find('thead tr th:first-child')
|
||||||
|
.html('<input type="checkbox" class="select-all" title="Select All">');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
$("table thead tr th:first-child").html('<input type="checkbox" id="select-all">');
|
|
||||||
}, 500);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// SELECT ALL
|
// SELECT ALL — scoped to the checkbox's own table only
|
||||||
$(document).on("change", "#select-all", function () {
|
$(document).on("change", ".select-all", function () {
|
||||||
$(".row-check").prop("checked", this.checked);
|
$(this).closest("table").find(".row-check").prop("checked", this.checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET IDS
|
// If a row checkbox is unchecked manually, uncheck that table's select-all
|
||||||
function getSelectedIds() {
|
$(document).on("change", ".row-check", function () {
|
||||||
|
if (!this.checked) {
|
||||||
|
$(this).closest("table").find(".select-all").prop("checked", false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function getSelectedIds(model) {
|
||||||
let ids = [];
|
let ids = [];
|
||||||
$(".row-check:checked").each(function () {
|
$("#" + model + " .row-check:checked").each(function () {
|
||||||
ids.push($(this).data("id"));
|
ids.push($(this).data("id"));
|
||||||
});
|
});
|
||||||
return ids;
|
return ids;
|
||||||
@@ -288,7 +319,7 @@
|
|||||||
|
|
||||||
// BULK DELETE
|
// BULK DELETE
|
||||||
function deleteSelected(model) {
|
function deleteSelected(model) {
|
||||||
let ids = getSelectedIds();
|
let ids = getSelectedIds(model);
|
||||||
if (ids.length === 0) return alert("Select records");
|
if (ids.length === 0) return alert("Select records");
|
||||||
|
|
||||||
if (!confirm(`Delete ${ids.length} record(s)?`)) return;
|
if (!confirm(`Delete ${ids.length} record(s)?`)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user