Răsfoiți Sursa

Disable batch actions until at least an item has been selected

Alan Lam 3 ani în urmă
părinte
comite
179bcc5d3c

+ 7 - 0
public/js/document-page.js

@@ -3,11 +3,18 @@ class DocumentPage {
 		const $table = $("#document-items-section table");
 		const $table = $("#document-items-section table");
 		const $checkboxes = $table.find("input[type=checkbox]");
 		const $checkboxes = $table.find("input[type=checkbox]");
 		const $allCheckbox = $("#all-items-checkbox");
 		const $allCheckbox = $("#all-items-checkbox");
+		const $batchActions = $(".batch-action");
+
 		$allCheckbox.on("change", () => {
 		$allCheckbox.on("change", () => {
 			const checked = $allCheckbox.prop("checked");
 			const checked = $allCheckbox.prop("checked");
 			$checkboxes.prop("checked", checked);
 			$checkboxes.prop("checked", checked);
 		});
 		});
 
 
+		$checkboxes.on("change", () => {
+			let batchActionsEnabled = $checkboxes.filter(":checked").length > 0;
+			$batchActions.prop("disabled", !batchActionsEnabled);
+		});
+
 		$table.find(".btn-delete-document-item").on("click", event => {
 		$table.find(".btn-delete-document-item").on("click", event => {
 			const documentItemId = $(event.currentTarget).data("document-item-id");
 			const documentItemId = $(event.currentTarget).data("document-item-id");
 			const confirmed = confirm("Are you sure you want to delete this item?");
 			const confirmed = confirm("Are you sure you want to delete this item?");

+ 9 - 2
public/js/sale-page.js

@@ -1,11 +1,18 @@
 class SalePage {
 class SalePage {
 	static InitSaleItemSection() {
 	static InitSaleItemSection() {
 		const $table = $("#sale-items-section table");
 		const $table = $("#sale-items-section table");
-		const $checkboxes = $table.find("input[type=checkbox]");
+		const $checkboxes = $table.find("tbody input[type=checkbox]");
 		const $allCheckbox = $("#sale-items-all-checkbox");
 		const $allCheckbox = $("#sale-items-all-checkbox");
+		const $batchActions = $(".batch-action");
+
 		$allCheckbox.on("change", () => {
 		$allCheckbox.on("change", () => {
 			const checked = $allCheckbox.prop("checked");
 			const checked = $allCheckbox.prop("checked");
-			$checkboxes.prop("checked", checked);
+			$checkboxes.prop("checked", checked).trigger("change");
+		});
+
+		$checkboxes.on("change", () => {
+			let batchActionsEnabled = $checkboxes.filter(":checked").length > 0;
+			$batchActions.prop("disabled", !batchActionsEnabled);
 		});
 		});
 
 
 		$table.find(".btn-delete-sale-item").on("click", event => {
 		$table.find(".btn-delete-sale-item").on("click", event => {

+ 4 - 4
views/document_items_section.php

@@ -191,11 +191,11 @@ if($document->isAru()) {
 			<?php
 			<?php
 			if($document->isAru()) {
 			if($document->isAru()) {
 				?>
 				?>
-				<button type="submit" class="btn btn-primary" name="batch_action" value="create-invoice">
+				<button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-invoice" disabled>
 					<i class="fa fa-fw fa-file-invoice"></i>
 					<i class="fa fa-fw fa-file-invoice"></i>
 					<?=htmlspecialchars(__("Create Invoice"))?>
 					<?=htmlspecialchars(__("Create Invoice"))?>
 				</button>
 				</button>
-				<button type="submit" class="btn btn-primary" name="batch_action" value="create-goods-in">
+				<button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-goods-in" disabled>
 					<i class="fa fa-fw fa-truck"></i>
 					<i class="fa fa-fw fa-truck"></i>
 					<?=htmlspecialchars(__("Create Goods-In"))?>
 					<?=htmlspecialchars(__("Create Goods-In"))?>
 				</button>
 				</button>
@@ -204,7 +204,7 @@ if($document->isAru()) {
 
 
 			if($document->hasCosts() && !$document->isPartOfAru()) {
 			if($document->hasCosts() && !$document->isPartOfAru()) {
 				?>
 				?>
-				<button type="submit" class="btn btn-primary" name="batch_action" value="create-delivery-note">
+				<button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-delivery-note" disabled>
 					<i class="fa fa-fw fa-file-invoice"></i>
 					<i class="fa fa-fw fa-file-invoice"></i>
 					<?=htmlspecialchars(__("Create Delivery Note"))?>
 					<?=htmlspecialchars(__("Create Delivery Note"))?>
 				</button>
 				</button>
@@ -212,7 +212,7 @@ if($document->isAru()) {
 			}
 			}
 			?>
 			?>
 
 
-			<button type="submit" class="btn btn-danger" name="batch_action" value="delete">
+			<button type="submit" class="btn btn-danger batch-action" name="batch_action" value="delete" disabled>
 				<i class="fa fa-fw fa-trash"></i>
 				<i class="fa fa-fw fa-trash"></i>
 				<?=htmlspecialchars(__("Delete"))?>
 				<?=htmlspecialchars(__("Delete"))?>
 			</button>
 			</button>

+ 2 - 2
views/sale_items_section.php

@@ -129,11 +129,11 @@ use NumberFormatter;
 				<?=htmlspecialchars(__("With selected items:"))?>
 				<?=htmlspecialchars(__("With selected items:"))?>
 			</div>
 			</div>
 
 
-			<button type="submit" class="btn btn-primary" name="batch_action" value="create-invoice">
+			<button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-invoice" disabled>
 				<i class="fa fa-fw fa-file-invoice"></i>
 				<i class="fa fa-fw fa-file-invoice"></i>
 				<?=htmlspecialchars(__("Create Invoice"))?>
 				<?=htmlspecialchars(__("Create Invoice"))?>
 			</button>
 			</button>
-			<button type="submit" class="btn btn-danger" name="batch_action" value="delete">
+			<button type="submit" class="btn btn-danger batch-action" name="batch_action" value="delete" disabled>
 				<i class="fa fa-fw fa-trash"></i>
 				<i class="fa fa-fw fa-trash"></i>
 				<?=htmlspecialchars(__("Delete"))?>
 				<?=htmlspecialchars(__("Delete"))?>
 			</button>
 			</button>