Explorar el Código

Add select2 for location dropdowns

Alan Lam hace 3 años
padre
commit
a5930beb4d

+ 1 - 1
controllers/locations_ajax.php

@@ -29,7 +29,7 @@ $controller = new class($action) {
 		foreach($locations as $location) {
 			$options[] = [
 				"value" => $location->id,
-				"display" => $location->name
+				"display" => $location->getDisplayName()
 			];
 		}
 		Json::success([

+ 4 - 0
public/js/new-document-modal.js

@@ -22,6 +22,10 @@ class NewDocumentModal {
 		this.$itemDescriptionField = this.getField("item_description");
 		this.$itemSerialNumberField = this.getField("item_serial_number");
 
+		this.$locationDropdown.select2({
+			theme: "bootstrap-5",
+			dropdownParent: this.$locationDropdown.closest("div")
+		});
 	}
 
 	getField(name) {

+ 6 - 0
public/js/new-sale-modal.js

@@ -13,6 +13,12 @@ class NewSaleModal {
 		this.$form.on("submit", event => this.onSubmit(event));
 
 		this.$companyDropdown = this.getField("company_id");
+		this.$locationDropdown = this.getField("location_id");
+
+		this.$locationDropdown.select2({
+			theme: "bootstrap-5",
+			dropdownParent: this.$locationDropdown.closest("div")
+		});
 	}
 
 	getField(name) {

+ 5 - 0
public/js/ticket-modal.js

@@ -27,6 +27,11 @@ class TicketModal {
 		});
 
 		this.$noLocationRow = $("#no-location-row");
+
+		this.$locationDropdown.select2({
+			theme: "bootstrap-5",
+			dropdownParent: this.$locationDropdown.closest("div")
+		});
 	}
 
 	getField(name) {

+ 5 - 0
views/header.php

@@ -52,6 +52,11 @@ $google_api_key = $_ENV["GOOGLE_API_KEY"] ?? null;
 	}
 	?>
 
+	<!-- Select2 -->
+	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" />
+	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" />
+	<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
+
 	<style>
 		input:invalid, select:invalid {
 			border: 1px solid red;

+ 6 - 12
views/modals/new_document.php

@@ -45,19 +45,13 @@ $settings = $core->getSettings();
 						<option value=""><?=htmlspecialchars(__("Select Location"))?></option>
 						<?php
 						foreach(Customer::getAll() as $customer) {
-							?>
-							<optgroup label="<?=htmlspecialchars($customer->name)?>">
-								<?php
-								foreach($customer->getLocations() as $location) {
-									?>
-									<option value="<?=$location->id?>">
-										<?=htmlspecialchars($location->name)?>
-									</option>
-									<?php
-								}
+							foreach($customer->getLocations() as $location) {
 								?>
-							</optgroup>
-							<?php
+								<option value="<?=$location->id?>">
+									<?=htmlspecialchars($location->getDisplayName())?>
+								</option>
+								<?php
+							}
 						}
 						?>
 					</select>

+ 6 - 12
views/modals/new_sale.php

@@ -38,19 +38,13 @@ $default_company_id = $settings->defaultCompanyId ?? null;
 					<select class="form-control" name="location_id" id="location-id">
 						<?php
 						foreach($customers as $customer) {
-							?>
-							<optgroup label="<?=htmlspecialchars($customer->name)?>">
-								<?php
-								foreach($customer->getLocations() as $location) {
-									?>
-									<option value="<?=$location->id?>">
-										<?=htmlspecialchars($location->name)?>
-									</option>
-									<?php
-								}
+							foreach($customer->getLocations() as $location) {
 								?>
-							</optgroup>
-							<?php
+								<option value="<?=$location->id?>">
+									<?=htmlspecialchars($location->getDisplayName())?>
+								</option>
+								<?php
+							}
 						}
 						?>
 					</select>