Przeglądaj źródła

Add ability to delete notes from a location

Alan Lam 6 lat temu
rodzic
commit
920894d9fe
3 zmienionych plików z 44 dodań i 6 usunięć
  1. 22 0
      controllers/location_delete_note.php
  2. 1 0
      routes.php
  3. 21 6
      views/location_notes_tab.php

+ 22 - 0
controllers/location_delete_note.php

@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @var int $id
+ * @var int $note_id
+ */
+
+$user = Core::$user;
+
+$location = Location::get($id);
+if(!$location) throw new Exception("Location not found.");
+if(!Core::$user->hasPermission($location)) throw new Exception("You do not have have permission to access this page.");
+
+$note = LocationNote::get($note_id);
+if(!$note || $note->location_id != $location->id) throw new Exception("Note not found.");
+
+$note->dts_deleted = DB::dts();
+$note->commit();
+
+Core::addAlert("success", "Note deleted successfully.");
+
+HTTP::redirect("/account/locations/$location->id");

+ 1 - 0
routes.php

@@ -121,6 +121,7 @@ $routes = [
 	"/^account\/locations$/" => ["controller" => "locations", "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations\/add$/" => ["controller" => "location_add", "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations\/$id_pattern\/add-note$/" => ["controller" => "location_add_note", "params" => ["id"], "require_user_level" => User::LEVEL_CUSTOMER],
+	"/^account\/locations\/$id_pattern\/delete-note\/$id_pattern$/" => ["controller" => "location_delete_note", "params" => ["id", "note_id"], "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations\/$id_pattern$/" => ["controller" => "location_view", "params" => ["id"], "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations\/$id_pattern\/edit$/" => ["controller" => "location_edit", "params" => ["id"], "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations\/$id_pattern\/photo$/" => ["controller" => "location_photo", "params" => ["location_id"]],

+ 21 - 6
views/location_notes_tab.php

@@ -46,14 +46,29 @@ $notes = $location->getNotes();
 				$user = $note->getUser();
 				$dt = $note->getDateTimeCreated();
 				$dt->setTimezone(new DateTimeZone(TIMEZONE));
+				$delete_url = sprintf("/account/locations/%d/delete-note/%d", $location->id, $note->id);
 				?>
 				<div class="list-group-item">
-					<div>
-						<strong><?=htmlspecialchars($user->getDisplayName())?></strong>
-						<span class="float-right text-muted"><?=htmlspecialchars($dt->format("d/m/Y H:i"))?></span>
-					</div>
-					<div>
-						<?=$note->getContentHTML()?>
+					<div class="form-row">
+						<div class="col">
+							<div>
+								<strong><?=htmlspecialchars($user->getDisplayName())?></strong>
+								<span class="float-right text-muted"><?=htmlspecialchars($dt->format("d/m/Y H:i"))?></span>
+							</div>
+							<div>
+								<?=$note->getContentHTML()?>
+							</div>
+						</div>
+						<div class="col-auto">
+							<button class="btn btn-sm btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
+								<?=htmlspecialchars(__("Actions"))?>
+							</button>
+							<div class="dropdown-menu">
+								<a class="dropdown-item text-danger" href="<?=htmlspecialchars($delete_url)?>">
+									<?=htmlspecialchars(__("Delete"))?>
+								</a>
+							</div>
+						</div>
 					</div>
 				</div>
 				<?php