diff options
Diffstat (limited to 'modules-available')
-rw-r--r-- | modules-available/locationinfo/page.inc.php | 20 | ||||
-rw-r--r-- | modules-available/locationinfo/templates/page-config-panel-url.html | 92 |
2 files changed, 61 insertions, 51 deletions
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index f849aa1d..13d7d459 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -417,6 +417,7 @@ class Page_LocationInfo extends Page $bookmarkUrls = Request::post('bookmarkUrls', [], 'array'); $bookmarkString = ''; for ($i = 0; $i < count($bookmarkNames); $i++) { + if ($bookmarkNames[$i] == '' || $bookmarkUrls[$i] == '') continue; $bookmarkString .= rawurlencode($bookmarkNames[$i]); $bookmarkString .= ","; $bookmarkString .= rawurlencode($bookmarkUrls[$i]); @@ -433,7 +434,7 @@ class Page_LocationInfo extends Page 'split-login' => Request::post('split-login', 0, 'bool'), 'browser' => Request::post('browser', 'slx-browser', 'string'), 'interactive' => Request::post('interactive', '0', 'bool'), - 'bookmarks' => $bookmarkString, + 'bookmarks' => $bookmarkString ? $bookmarkString : '', ); return array('config' => $conf, 'locationids' => []); } @@ -1026,6 +1027,21 @@ class Page_LocationInfo extends Page 'overrides' => json_encode($config['overrides']), )); } elseif ($panel['paneltype'] === 'URL') { + + $bookmarksArray = []; + if ($config['bookmarks'] !== '') { + $bookmarksConfig = explode(' ', $config['bookmarks']); + foreach ($bookmarksConfig AS $bookmark) { + $bookmark = explode(',', $bookmark); + $name = rawurldecode($bookmark[0]); + $url = rawurldecode($bookmark[1]); + $bookmarksArray[] = [ + 'name' => $name, + 'url' => $url, + ]; + } + } + Render::addTemplate('page-config-panel-url', array( 'new' => $id === 'new', 'uuid' => $id, @@ -1038,7 +1054,7 @@ class Page_LocationInfo extends Page 'split-login_checked' => $config['split-login'] ? 'checked' : '', 'browser' => $config['browser'], 'interactive_checked' => $config['interactive'] ? 'checked' : '', - 'bookmarks' => $config['bookmarks'], + 'bookmarks' => $bookmarksArray, )); } else { Render::addTemplate('page-config-panel-summary', array( diff --git a/modules-available/locationinfo/templates/page-config-panel-url.html b/modules-available/locationinfo/templates/page-config-panel-url.html index e34f0477..7b82199e 100644 --- a/modules-available/locationinfo/templates/page-config-panel-url.html +++ b/modules-available/locationinfo/templates/page-config-panel-url.html @@ -166,19 +166,11 @@ </div> <div class="list-group-item" id="bookmarks"> - <div class="row" id="bookmark0"> + <div class="row"> <div class="col-sm-3"> <label for="bookmarks">{{lang_bookmarks}}</label> </div> - <div class="col-sm-3"> - <input class="form-control" name="bookmarkNames[]" type="text" value="" - placeholder="bwLehrpool" required> - </div> - <div class="col-sm-3"> - <input class="form-control" name="bookmarkUrls[]" type="text" value="" - placeholder="http://www.bwlehrpool.de/" pattern=".*://.*" required> - </div> - <div class="col-sm-1"> + <div class="col-sm-7"> <button type="button" class="btn btn-success" onclick="addBookmark()"> <span class="glyphicon glyphicon-plus"></span> </button> @@ -189,6 +181,39 @@ </p> </div> </div> + <div class="row" style="margin-top: 1em;" id="bookmarkRow" hidden> + <div class="col-sm-3 col-sm-offset-3"> + <input class="form-control" name="bookmarkNames[]" type="text" value="" + placeholder="bwLehrpool"> + </div> + <div class="col-sm-3"> + <input class="form-control" name="bookmarkUrls[]" type="text" value="" + placeholder="http://www.bwlehrpool.de/" pattern=".*://.*"> + </div> + <div class="col-sm-1"> + <button type="button" class="btn btn-danger" onclick="this.closest('.row').remove()"> + <span class="glyphicon glyphicon-minus"></span> + </button> + </div> + </div> + + {{#bookmarks}} + <div class="row" style="margin-top: 1em;"> + <div class="col-sm-3 col-sm-offset-3"> + <input class="form-control" name="bookmarkNames[]" type="text" value="{{name}}" + placeholder="bwLehrpool" required> + </div> + <div class="col-sm-3"> + <input class="form-control" name="bookmarkUrls[]" type="text" value="{{url}}" + placeholder="http://www.bwlehrpool.de/" pattern=".*://.*" required> + </div> + <div class="col-sm-1"> + <button type="button" class="btn btn-danger" onclick="this.closest('.row').remove()"> + <span class="glyphicon glyphicon-minus"></span> + </button> + </div> + </div> + {{/bookmarks}} </div> </div> @@ -205,16 +230,12 @@ <script type="text/javascript"><!-- -var bookmarkCount = 0; - document.addEventListener("DOMContentLoaded", function () { // Initialize fancy tooltips $('p.helptext').tooltip(); // load value to dropdown menus $('#browser option[value="{{browser}}"]').attr("selected", "selected"); browserChange(); - // load bookmark fields - getBookmarks(); }); // Hide interactive-input if slx-browser is selected @@ -230,41 +251,14 @@ function browserChange() { // Add another bookmark input field to the form function addBookmark() { - bookmarkCount += 1; - $('#bookmarks').append('<div style="margin-top: 1em;" class="row" id="bookmark' + bookmarkCount + '">' + - '<div class="col-sm-3 col-sm-offset-3">' + - '<input class="form-control" name="bookmarkNames[]" type="text" value="" placeholder="bwLehrpool" required>' + - '</div>' + - '<div class="col-sm-3">' + - '<input class="form-control" name="bookmarkUrls[]" type="text" value="" placeholder="http://www.bwlehrpool.de/" pattern=".*://.*" required>' + - '</div>' + - '<div class="col-sm-1">' + - '<button type="button" class="btn btn-danger" onclick="deleteBookmark(' + bookmarkCount + ')">' + - '<span class="glyphicon glyphicon-minus"></span>' + - '</button>' + - '</div>' + - '</div>'); -} - -// Remove the corresponding bookmark -function deleteBookmark(num) { - $('#bookmark' + num).remove(); - bookmarkCount -= 1; -} - -// Load bookmarks from database and add to form -function getBookmarks() { - var bookmarks = "{{bookmarks}}".split(" "); - if (bookmarks[0] === "") return; - for (var i = 0; i < bookmarks.length; i++) { - var bookmark = bookmarks[i].split(','); - var name = decodeURIComponent(bookmark[0]); - var url = decodeURIComponent(bookmark[1]); - if (i !== 0) addBookmark(); - var bookmarkJquery = $('#bookmark' + bookmarkCount); - bookmarkJquery.find("input[name='bookmarkNames[]']").val(name); - bookmarkJquery.find("input[name='bookmarkUrls[]']").val(url); - } + var rowCopy = $('#bookmarkRow').clone(); + rowCopy.attr('id', ''); + rowCopy.show(); + rowCopy.find('input').each(function() { + $( this ).val(''); + $( this ).prop('required', true); + }); + $('#bookmarks').append(rowCopy); } //--></script> |