From 1d8ddd0bfdb8a0bcb16a873a4c48d7f9f794b99d Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Tue, 14 Nov 2017 09:26:39 +0100
Subject: [PATCH] [TASK] Starting work on location filters + create + edit
 function

---
 .../Backend/EditLinkViewHelper.php            | 47 +++++++++++++++++++
 .../Private/Templates/Backend/Index.html      | 23 +++++++++
 Resources/Public/Scripts/Backend.js           |  8 ++--
 3 files changed, 74 insertions(+), 4 deletions(-)
 create mode 100644 Classes/ViewHelpers/Backend/EditLinkViewHelper.php

diff --git a/Classes/ViewHelpers/Backend/EditLinkViewHelper.php b/Classes/ViewHelpers/Backend/EditLinkViewHelper.php
new file mode 100644
index 00000000..f90eeed3
--- /dev/null
+++ b/Classes/ViewHelpers/Backend/EditLinkViewHelper.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace SGalinski\SgJobs\ViewHelpers\Backend;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) sgalinski Internet Services (https://www.sgalinski.de)
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+
+/**
+ * Class EditOnClickViewHelper
+ **/
+class EditLinkViewHelper extends AbstractViewHelper {
+	/**
+	 * Renders the onclick script for editing a record
+	 *
+	 * @param string $table
+	 * @param int $uid
+	 * @param boolean $new
+	 * @return string
+	 */
+	public function render($table, $uid, $new = FALSE) {
+		return BackendUtility::getModuleUrl('record_edit') . '&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit');
+	}
+}
diff --git a/Resources/Private/Templates/Backend/Index.html b/Resources/Private/Templates/Backend/Index.html
index 76a8e612..876a0630 100644
--- a/Resources/Private/Templates/Backend/Index.html
+++ b/Resources/Private/Templates/Backend/Index.html
@@ -18,6 +18,29 @@
 								<f:translate key="backend.filters.locations" />
 							</label>
 							<f:form.select class="form-control" multiple="1" size="4" property="locations" options="{locationOptions}" id="filter-locations" />
+
+							<small>
+								<f:format.raw><f:translate key="backend.filters.locations.description" />
+								</f:format.raw>
+							</small>
+							<script>
+								var LocationEditLinks = {};
+							</script>
+							<f:for each="{locationOptions}" key="uid" as="location">
+								<script>
+									LocationEditLinks["{uid}"] = "{sg:backend.editLink(table: 'tx_sgroutes_domain_model_location', uid: uid) -> f:format.raw()}";
+								</script>
+							</f:for>
+							<br />
+							<a href="#" class="btn btn-default" onclick="editSelectedLocation();">
+								<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-document-new">
+									<span class="icon-markup">
+										<img src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/actions/actions-document-open.svg" width="16" height="16">
+									</span>
+								</span>
+								<f:translate key="backend.filters.editCategory" />
+							</a>
+
 						</div>
 					</div>
 					<div class="col-xs-6">
diff --git a/Resources/Public/Scripts/Backend.js b/Resources/Public/Scripts/Backend.js
index 2b75e509..0ee8b883 100644
--- a/Resources/Public/Scripts/Backend.js
+++ b/Resources/Public/Scripts/Backend.js
@@ -81,10 +81,10 @@ function gotToPageCallback(path){
  *
  * @return {boolean}
  */
-function editSelectedCategory(){
-	var selected = TYPO3.jQuery('#filter-categories').val();
-	if(selected && CategoryEditLinks[selected[0]]) {
-		jumpToUrl(CategoryEditLinks[selected[0]] + '&returnUrl=' + T3_THIS_LOCATION);
+function editSelectedLocation(){
+	var selected = TYPO3.jQuery('#filter-locations').val();
+	if(selected && LocationEditLinks[selected[0]]) {
+		jumpToUrl(LocationEditLinks[selected[0]] + '&returnUrl=' + T3_THIS_LOCATION);
 	}
 	return false;
 }
-- 
GitLab