diff options
author | Jannik Schönartz | 2018-06-20 20:02:18 +0200 |
---|---|---|
committer | Jannik Schönartz | 2018-06-20 20:02:18 +0200 |
commit | 35578a5c327baa803e600700ccaee627d4724339 (patch) | |
tree | bf0bf1dbeb38c00439f71e67095dd6c0fdc7e101 /modules-available/serversetup-bwlp | |
parent | [serversetup-bwlp] Start rewrite as purely iPXE-based (diff) | |
download | slx-admin-35578a5c327baa803e600700ccaee627d4724339.tar.gz slx-admin-35578a5c327baa803e600700ccaee627d4724339.tar.xz slx-admin-35578a5c327baa803e600700ccaee627d4724339.zip |
[serversetup-bwlp] Added drag and drop to the editmenu. Fixed radiobutton alignment and it's now saved/updated properly.
Diffstat (limited to 'modules-available/serversetup-bwlp')
-rw-r--r-- | modules-available/serversetup-bwlp/config.json | 3 | ||||
-rw-r--r-- | modules-available/serversetup-bwlp/page.inc.php | 12 | ||||
-rw-r--r-- | modules-available/serversetup-bwlp/templates/menu-edit.html | 44 |
3 files changed, 48 insertions, 11 deletions
diff --git a/modules-available/serversetup-bwlp/config.json b/modules-available/serversetup-bwlp/config.json index 8ce65a85..ff485760 100644 --- a/modules-available/serversetup-bwlp/config.json +++ b/modules-available/serversetup-bwlp/config.json @@ -1,6 +1,7 @@ { "category": "main.settings-server", "dependencies" : [ - "locations" + "locations", + "js_jqueryui" ] }
\ No newline at end of file diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index 4207bd53..f2c422f3 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -189,6 +189,7 @@ class Page_ServerSetup extends Page serversetup_menuentry WHERE menuid = :id", compact('id')); $keyList = array_map(function ($item) { return ['key' => $item]; }, MenuEntry::getKeyList()); $entryList = Database::queryAll("SELECT entryid, title, hotkey FROM serversetup_bootentry ORDER BY title ASC"); + $sortVals = array(); foreach ($menu['entries'] as &$entry) { $entry['isdefault'] = ($entry['menuentryid'] == $menu['defaultentryid']); $entry['keys'] = $keyList; @@ -206,7 +207,12 @@ class Page_ServerSetup extends Page $item['title'] = $item['entryid']; } } + $sortVals[] = $entry['sortval']; } + $arr = $menu['entries']; + $keys = array_keys($arr); + array_multisort( $sortVals, SORT_ASC, $arr, $keys); + $menu['entries'] = $arr; // TODO: Make assigned locations editable Permission::addGlobalTags($menu['perms'], 0, ['ipxe.menu.edit']); Render::addTemplate('menu-edit', $menu); @@ -298,11 +304,12 @@ class Page_ServerSetup extends Page } // TODO: Validate new locations to be saved (and actually save them) - Database::exec('UPDATE serversetup_menu SET title = :title, timeoutms = :timeoutms + Database::exec('UPDATE serversetup_menu SET title = :title, timeoutms = :timeoutms, defaultentryid = :defaultentryid WHERE menuid = :menuid', [ 'menuid' => $id, 'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')), 'timeoutms' => abs(Request::post('timeoutms', 0, 'int') * 1000), + 'defaultentryid' => Request::post('defaultentry', false, 'int'), ]); if (User::hasPermission('ipxe.menu.edit', 0)) { Database::exec('UPDATE serversetup_menu SET isdefault = (menuid = :menuid)', ['menuid' => $id]); @@ -310,6 +317,7 @@ class Page_ServerSetup extends Page $keepIds = []; $entries = Request::post('entry', false, 'array'); + foreach ($entries as $key => $entry) { $params = [ 'entryid' => $entry['entryid'], // TODO validate @@ -340,9 +348,11 @@ class Page_ServerSetup extends Page ]); } } + if ($ret === false) { Message::addWarning('error-saving-entry', $entry['title'], Database::lastError()); } + } Message::addSuccess('menu-saved'); } diff --git a/modules-available/serversetup-bwlp/templates/menu-edit.html b/modules-available/serversetup-bwlp/templates/menu-edit.html index cf10296e..aa748c3a 100644 --- a/modules-available/serversetup-bwlp/templates/menu-edit.html +++ b/modules-available/serversetup-bwlp/templates/menu-edit.html @@ -12,6 +12,7 @@ <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="savemenu"> <input type="hidden" name="menuid" value="{{menuid}}"> + <div class="row list-group-item"> <div class="col-sm-3"> <label for="panel-title">{{lang_menuTitle}}</label> @@ -47,23 +48,29 @@ <thead> <tr> <th></th> + <th></th> <th>{{lang_entryId}}</th> <th>{{lang_title}}</th> <th>{{lang_hotkey}}</th> - <th>{{lang_sortOrder}}</th> <th>{{lang_password}}</th> </tr> </thead> - <tbody> + <tbody id="tableBody" style="overflow: auto;"> {{#entries}} - <tr> - <td class="slx-smallcol"> - <div class="radio radio-inline"> + <tr id="{{menuentryid}}"> + <input type="hidden" class="form-control sort-val" name="entry[{{menuentryid}}][sortval]" id="entry-sortval-{{menuentryid}}" value="{{sortval}}" {{readonly}}> + <td class="drag-handler" style="cursor: pointer;text-align: center; vertical-align: middle;"> + <span class="glyphicon glyphicon-th-list"></span> + </td> + + <td class="slx-smallcol" style="text-align: center; vertical-align: middle;"> + <div class="radio radio-inline" style="margin: 0px;"> <input type="radio" name="defaultentry" value="{{menuentryid}}" {{#isdefault}}checked{{/isdefault}} {{perms.ipxe.menu.edit.disabled}} {{disabled}}> <label></label> </div> </td> + <td class="text-nowrap"> {{#entryid}} <select class="form-control" name="entry[{{menuentryid}}][entryid]" {{readonly}}> @@ -91,9 +98,7 @@ </select> </td> {{/entryid}} - <td> - <input class="form-control" name="entry[{{menuentryid}}][sortval]" value="{{sortval}}" {{readonly}}> - </td> + <td> <input class="form-control" name="entry[{{menuentryid}}][plainpass]" id="panel-passwd" type="{{password_type}}" value="{{plainpass}}" {{readonly}}> @@ -111,4 +116,25 @@ </div> </form> </div> -</div>
\ No newline at end of file +</div> + +<script type="text/javascript"> + document.addEventListener("DOMContentLoaded", function() { + $('#tableBody').sortable({ + opacity: 0.8, + handle: '.drag-handler', + start: function(evt, ui) { + ui.placeholder.css("visibility", "visible"); + ui.placeholder.css("opacity", "0.152"); + ui.placeholder.css("background-color", "LawnGreen"); + }, + stop: function() { + var startValue = 1; + $('.sort-val').each(function(index, element) { + element.value = startValue * 10; + startValue++; + }); + } + }); + }); +</script>
\ No newline at end of file |