summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
authorSimon Rettberg2023-05-12 14:21:28 +0200
committerSimon Rettberg2023-05-12 14:21:28 +0200
commitdf5fd48da3a0163375e4567485b882f14baf6ead (patch)
tree35e423b91fd8a6524e06416d5092d1f716b6a364 /modules-available/locations
parent[eventlog] Remove stray line (c&p error) (diff)
downloadslx-admin-df5fd48da3a0163375e4567485b882f14baf6ead.tar.gz
slx-admin-df5fd48da3a0163375e4567485b882f14baf6ead.tar.xz
slx-admin-df5fd48da3a0163375e4567485b882f14baf6ead.zip
[locations] cleanup: Hide/disable move button if action not available
Hide the button entirely if there are no movable machines in the displayed list. Disable the button as long as the user selected at least one unmovable machine.
Diffstat (limited to 'modules-available/locations')
-rw-r--r--modules-available/locations/inc/locationutil.inc.php5
-rw-r--r--modules-available/locations/pages/cleanup.inc.php3
-rw-r--r--modules-available/locations/templates/mismatch-cleanup.html24
3 files changed, 25 insertions, 7 deletions
diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php
index 960eefa8..acdaed2f 100644
--- a/modules-available/locations/inc/locationutil.inc.php
+++ b/modules-available/locations/inc/locationutil.inc.php
@@ -70,12 +70,9 @@ class LocationUtil
* grouped by the location the client was assigned to via roomplanner.
* Otherwise, just return an assoc array with the requested locationid, name
* and a list of all clients that are wrongfully assigned to that room.
- * @param int $locationId
- * @return array
*/
- public static function getMachinesWithLocationMismatch($locationId = 0, $checkPerms = false)
+ public static function getMachinesWithLocationMismatch(int $locationId = 0, bool $checkPerms = false): array
{
- $locationId = (int)$locationId;
if ($checkPerms) {
if ($locationId !== 0) {
// Query details for specific location -- use assert and fake array
diff --git a/modules-available/locations/pages/cleanup.inc.php b/modules-available/locations/pages/cleanup.inc.php
index d10dbac0..a7562c50 100644
--- a/modules-available/locations/pages/cleanup.inc.php
+++ b/modules-available/locations/pages/cleanup.inc.php
@@ -21,6 +21,9 @@ class SubPage
$list = self::loadForLocation();
if ($list === false)
return true;
+ $list['canmove'] = array_reduce($list['clients'], function (bool $carry, array $item): bool {
+ return $carry || ($item['canmove'] ?? false);
+ }, false);
Permission::addGlobalTags($list['perms'], NULL, ['subnets.edit', 'location.view']);
Render::addTemplate('mismatch-cleanup', $list);
return true;
diff --git a/modules-available/locations/templates/mismatch-cleanup.html b/modules-available/locations/templates/mismatch-cleanup.html
index a6f45d27..53a956df 100644
--- a/modules-available/locations/templates/mismatch-cleanup.html
+++ b/modules-available/locations/templates/mismatch-cleanup.html
@@ -32,7 +32,7 @@
<tr>
<td>
<div class="checkbox checkbox-inline">
- <input id="machine-{{machineuuid}}" type="checkbox" name="machines[]" value="{{machineuuid}}" {{disabled}}>
+ <input class="mcb {{#canmove}}cmov{{/canmove}}" id="machine-{{machineuuid}}" type="checkbox" name="machines[]" value="{{machineuuid}}" {{disabled}}>
<label for="machine-{{machineuuid}}">{{hostname}}{{^hostname}}{{clientip}}{{/hostname}}</label>
</div>
</td>
@@ -60,10 +60,28 @@
<span class="glyphicon glyphicon-repeat"></span>
{{lang_resetMachines}}
</button>
- <button type="submit" class="btn btn-success" name="action" value="movemachines">
+ {{#canmove}}
+ <button id="btn-move" type="submit" class="btn btn-success" name="action" value="movemachines">
<span class="glyphicon glyphicon-arrow-right"></span>
{{lang_moveMachines}}
</button>
+ {{/canmove}}
</div>
</form>
-<div class="clearfix"></div> \ No newline at end of file
+<div class="clearfix"></div>
+
+<script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var $btn = $('#btn-move');
+ if ($btn.length === 0)
+ return;
+ var ccheck = function() {
+ var $e = $('input.mcb:checked');
+ var nope = $e.is(':not(.cmov)');
+ var yep = $e.is('.cmov');
+ $btn.prop('disabled', nope || !yep);
+ };
+ ccheck();
+ $('input.mcb').change(ccheck);
+ });
+</script> \ No newline at end of file