Просмотр исходного кода

Add support to create a project from selected locations

Alan Lam 6 лет назад
Родитель
Сommit
dd8043ff47
6 измененных файлов с 88 добавлено и 47 удалено
  1. 2 1
      composer.json
  2. 2 2
      controllers/locations.php
  3. 1 3
      controllers/project_add.php
  4. 41 22
      public/js/app-locations.js
  5. 26 12
      views/locations.php
  6. 16 7
      views/project_form.php

+ 2 - 1
composer.json

@@ -11,6 +11,7 @@
     "ext-exif": "*",
     "ext-mbstring": "*",
     "robmorgan/phinx": "^0.11.1",
-	  "ext-readline": "*"
+	  "ext-readline": "*",
+	  "ext-simplexml": "*"
   }
 }

+ 2 - 2
controllers/locations.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 Core::addScript("public/js/app-locations.js");
 
@@ -127,4 +127,4 @@ View::includeOnce("header", compact("page_title"));
 View::include("locations", compact("customer", "filter_count", "sorts", "sort", "locations"));
 View::includeOnce("footer");
 
-?>
+?>

+ 1 - 3
controllers/project_add.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 Core::addScript("public/js/app-project-form.js");
 
@@ -117,5 +117,3 @@ $locations = $customer->getLocations(["closed" => 0]);
 View::includeOnce("header", compact("page_title"));
 View::include("project_form", compact("project", "templates", "locations", "location_ids"));
 View::includeOnce("footer");
-
-?>

+ 41 - 22
public/js/app-locations.js

@@ -1,7 +1,8 @@
-var infoWindow = false;
-var exportIds = [];
-var markerMap = {};
+let infoWindow = false;
+let exportIds = [];
+let markerMap = {};
 
+// noinspection JSUnusedGlobalSymbols
 function initialiseLocations() {
 
 	if(!infoWindow) {
@@ -22,6 +23,8 @@ function initialiseLocations() {
 
 		for(let i in response.locations) {
 
+			if(!response.locations.hasOwnProperty(i)) continue;
+
 			let location = response.locations[i];
 			let position = {
 				lat: location.latitude,
@@ -32,7 +35,7 @@ function initialiseLocations() {
 				map: map,
 				position: position,
 				title: location.name
-			}
+			};
 
 			if(location.icon) {
 				options.icon = "/img/markers/building-red.png";
@@ -59,12 +62,12 @@ function initialiseLocations() {
 
 	$(document).on("click", "a[data-export-location-id]", function(event) {
 
-		let locationId = parseInt($(this).attr("data-export-location-id"));
+		let locationId = parseInt($(event.currentTarget).attr("data-export-location-id"));
 		let index = exportIds.indexOf(locationId);
 		let key = "marker-" + locationId;
 		let marker = markerMap[key];
 
-		if(index == -1) {
+		if(index === -1) {
 			exportIds.push(locationId);
 			marker.setOptions({
 				icon: "/img/markers/building-green.png"
@@ -78,26 +81,42 @@ function initialiseLocations() {
 		}
 
 		displayInfoWindow(marker);
-	});
 
-	$("#export-csv-button, #export-kml-button").click(function(event) {
+		const method = (exportIds.length > 0) ? "removeClass" : "addClass";
 
-		if(exportIds.length > 0) {
-			event.preventDefault();
+		$("#location-actions")[method]("d-none");
 
-			let action = $(this).attr("data-action");
+	});
 
-			$("#locations-export-form input[name='ids[]']").remove();
-			$("#locations-export-form input[name='action']").val(action);
+	$("#export-csv-button, #export-kml-button").on("click", function(event) {
 
-			for(let i in exportIds) {
-				let locationId = exportIds[i];
-				$("#locations-export-form").append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
-			}
+		event.preventDefault();
+		if(exportIds.length === 0) return;
+
+		const $form = $("#locations-export-form");
+		const action = $(event.currentTarget).attr("data-action");
 
-			$("#locations-export-form").submit();
+		$form.find("input[name='ids[]']").remove();
+		$form.find("input[name='action']").val(action);
+
+		for(const i in exportIds) {
+			if(!exportIds.hasOwnProperty(i)) continue;
+			let locationId = exportIds[i];
+			$form.append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
 		}
 
+		$form.trigger("submit");
+	});
+
+	$("#create-project-button").on("click", function(event) {
+		event.preventDefault();
+		if(exportIds.length === 0) return;
+
+		const $form = $("#locations-create-project-form");
+		$form.find("input[name='location_ids']").remove();
+		$form.append("<input type=\"hidden\" name=\"location_ids\" value=\"" + exportIds.join(", ") + "\" />");
+
+		$form.trigger("submit");
 	});
 
 }
@@ -107,11 +126,11 @@ function displayInfoWindow(marker) {
 	let locationId = parseInt(marker.location.id);
 	let index = exportIds.indexOf(locationId);
 
-	let exportText = "Select for Export";
+	let exportText = "Select";
 	let exportClass = "btn-primary";
 
 	if(index > -1) {
-		exportText = "Deselect for Export";
+		exportText = "Deselect";
 		exportClass = "btn-success";
 	}
 
@@ -121,11 +140,11 @@ function displayInfoWindow(marker) {
 	content += "<div class=\"row\">";
 
 	content += "<div class=\"col\"><a class=\"btn btn-block " + exportClass + "\" href=\"#\" data-export-location-id=\"" + marker.location.id + "\">" + exportText + "</a></div>";
-	content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View Details</a></div>";
+	content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View</a></div>";
 	content += "</div>";
 	content += "</div>";
 
 	infoWindow.setContent(content);
 	infoWindow.open(map, marker);
 
-}
+}

+ 26 - 12
views/locations.php

@@ -1,4 +1,13 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+/**
+ * @var Customer $customer
+ * @var int $filter_count
+ * @var array $sorts
+ * @var string $sort
+ * @var Location[] $locations
+ */
+
 $query = $_GET;
 unset($query["path"]);
 $query["sort"] = "SORT";
@@ -28,20 +37,21 @@ var customerId = <?=$customer->id?>;
 				?>
 			</button>
 		</div>
-		<div class="col-auto">
-
-
+		<div class="col-auto d-none" id="location-actions">
 			<div class="dropdown">
-				<button class="btn btn-secondary dropdown-toggle" type="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-					Actions
+				<button class="btn btn-primary dropdown-toggle" type="button" id="location-actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+					Location Actions
 				</button>
-				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
-					<a class="dropdown-item" href="/account/locations/add?customer_id=<?=$customer->id?>/edit">Add</a>
+				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="location-actions-button">
+					<a id="create-project-button" href="#" class="dropdown-item">Create Project...</a>
+					<div class="dropdown-divider"></div>
 					<a id="export-csv-button" class="dropdown-item" href="/account/locations?customer_id=<?=$customer->id?>&amp;action=export" data-action="export">Export CSV</a>
 					<a id="export-kml-button" class="dropdown-item" href="/account/locations?customer_id=<?=$customer->id?>&amp;action=export-kml" data-action="export-kml">Export KML</a>
 				</div>
 			</div>
-
+		</div>
+		<div class="col-auto">
+			<a class="btn btn-success" href="/account/locations/add?customer_id=<?=$customer->id?>">Add Location</a>
 		</div>
 	</div>
 
@@ -109,9 +119,9 @@ var customerId = <?=$customer->id?>;
 		<div class="col-sm-auto">
 			<div class="input-group">
 				<div class="input-group-prepend">
-					<span class="input-group-text">
+					<label for="sort-dropdown" class="input-group-text">
 						Sort
-					</span>
+					</label>
 				</div>
 				<select class="form-control" id="sort-dropdown" data-url-template="/account/locations?<?=htmlspecialchars(http_build_query($query))?>">
 				<?php
@@ -134,4 +144,8 @@ var customerId = <?=$customer->id?>;
 
 <form method="post" id="locations-export-form">
 	<input type="hidden" name="action" value="" />
-</form>
+</form>
+
+<form method="post" id="locations-create-project-form" action="/account/projects/add?customer_id=<?=htmlspecialchars($customer->id)?>">
+
+</form>

+ 16 - 7
views/project_form.php

@@ -131,18 +131,21 @@ $time_of_day_options = [
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="date-start-day">Start Date</label>
 					<div class="col-sm">
+						<label class="sr-only" for="date-start-day"></label>
 						<select class="form-control w-auto d-inline-block" name="date_start_day" id="date-start-day">
 							<option value="">Day</option>
 							<?php
 							Form::renderDayOptions($date_start_parts[2]);
 							?>
 						</select>
+						<label class="sr-only" for="date-start-month"></label>
 						<select class="form-control w-auto d-inline-block" name="date_start_month" id="date-start-month">
 							<option value="">Month</option>
 							<?php
 							Form::renderMonthOptions($date_start_parts[1]);
 							?>
 						</select>
+						<label class="sr-only" for="date-start-year"></label>
 						<select class="form-control w-auto d-inline-block" name="date_start_year" id="date-start-year">
 							<option value="">Year</option>
 							<?php
@@ -154,18 +157,21 @@ $time_of_day_options = [
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
 					<div class="col-sm">
+						<label for="date-deadline-day" class="sr-only">Day</label>
 						<select class="form-control w-auto d-inline-block" name="date_deadline_day" id="date-deadline-day">
 							<option value="">Day</option>
 							<?php
 							Form::renderDayOptions($date_deadline_parts[2]);
 							?>
 						</select>
+						<label for="date-deadline-month" class="sr-only">Month</label>
 						<select class="form-control w-auto d-inline-block" name="date_deadline_month" id="date-deadline-month">
 							<option value="">Month</option>
 							<?php
 							Form::renderMonthOptions($date_deadline_parts[1]);
 							?>
 						</select>
+						<label for="date-deadline-year" class="sr-only">Year</label>
 						<select class="form-control w-auto d-inline-block" name="date_deadline_year" id="date-deadline-year">
 							<option value="">Year</option>
 							<?php
@@ -178,12 +184,15 @@ $time_of_day_options = [
 					<label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
 					<div class="col-sm">
 						<input name="date_report_day" id="date-report-day" value="12" type="hidden" />
+
+						<label for="date-report-month"></label>
 						<select class="form-control w-auto d-inline-block" name="date_report_month" id="date-report-month">
 							<option value="">Month</option>
 							<?php
 							Form::renderMonthOptions($date_report_parts[1]);
 							?>
 						</select>
+						<label for="date-report-year"></label>
 						<select class="form-control w-auto d-inline-block" name="date_report_year" id="date-report-year">
 							<option value="">Year</option>
 							<?php
@@ -285,11 +294,11 @@ $time_of_day_options = [
 					<div class="card-body">
 						<div class="input-group">
 							<div class="input-group-prepend">
-								<span class="input-group-text">
+								<label class="input-group-text" for="selected-filter">
 									Filter
-								</span>
+								</label>
 							</div>
-							<input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
+							<input class="form-control" id="selected-filter" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
 						</div>
 
 						<div class="alert alert-info mt-3 mb-0" id="selected-locations-alert">
@@ -349,11 +358,11 @@ $time_of_day_options = [
 					<div class="card-body">
 						<div class="input-group">
 							<div class="input-group-prepend">
-								<span class="input-group-text">
+								<label class="input-group-text" for="not-selected-filter">
 									Filter
-								</span>
+								</label>
 							</div>
-							<input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
+							<input id="not-selected-filter" class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
 						</div>
 						<div class="alert alert-info mt-3 mb-0" id="not-selected-locations-alert">
 							No additional locations are available for testing.
@@ -411,4 +420,4 @@ $time_of_day_options = [
 
 		<button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Submit</button>
 	</form>
-</div>
+</div>