summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/clientscript.js
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-01 13:25:39 +0100
committerSimon Rettberg2017-12-01 13:25:39 +0100
commitd11ebcb652fb76391928bbbc0c338d4a5737e3a9 (patch)
tree404420d63e8c0162aac9773e10a761d4aca545ab /modules-available/roomplanner/clientscript.js
parent[roomplanner] Fallback to ip if hostname is empty (diff)
downloadslx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.tar.gz
slx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.tar.xz
slx-admin-d11ebcb652fb76391928bbbc0c338d4a5737e3a9.zip
[roomplanner] Sort already placed machines to the bottom
Diffstat (limited to 'modules-available/roomplanner/clientscript.js')
-rw-r--r--modules-available/roomplanner/clientscript.js40
1 files changed, 28 insertions, 12 deletions
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index 1cd65132..722e3909 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -11,10 +11,16 @@ var selectMachinInitialized = false;
var placedMachines = [];
+function makeCombinedFieldSingle(item)
+{
+ item.combined = (item.machineuuid + " " + item.hostname + " " + item.clientip + " " + item.macaddr + " " + item.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ item.sortField = (item.fixedlocationid === null ? 'a' : 'z') + item.hostname;
+}
+
function makeCombinedField(machineArray)
{
machineArray.forEach(function (v,i,a){
- machineArray[i].combined = (v.machineuuid + " " + v.hostname + " " + v.clientip + " " + v.macaddr + " " + v.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ makeCombinedFieldSingle(machineArray[i]);
});
return machineArray;
}
@@ -25,15 +31,14 @@ function renderMachineEntry(item, escape) {
// console.log('used uuids is ');
// console.log(placedMachines);
- var isUsed = $.inArray(item.machineuuid, placedMachines) > -1;
var extraClass = '';
var extraText = '';
- if (isUsed) {
- extraText = ' (already placed)';
- extraClass = 'used';
- } else if (item.otherroom) {
+ if (item.otherroom) {
extraText = ' (in ' + item.otherroom + ')';
extraClass = 'used';
+ } else if (item.fixedlocationid !== null) {
+ extraText = ' (already placed)';
+ extraClass = 'used';
}
return '<div class="machine-entry ' + extraClass +'">'
//+ ' <div class="machine-logo"><i class="glyphicon glyphicon-hdd"></i></div>'
@@ -120,7 +125,7 @@ function initSelectize() {
render : { option : renderMachineEntry, item: renderMachineSelected},
load: loadMachines,
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSubnetBox
});
@@ -136,7 +141,7 @@ function initSelectize() {
create: false,
render : { option : renderMachineEntry, item: renderMachineSelected},
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSearchBox
});
@@ -148,13 +153,16 @@ function initSelectize() {
}
function onBtnSelect() {
/* check which one has a value */
- console.assert($selectizeSubnet.length == 1);
- console.assert($selectizeSearch.length == 1);
+ console.assert($selectizeSubnet.length === 1);
+ console.assert($selectizeSearch.length === 1);
var bySubnet = machineCache[$selectizeSubnet[0].selectize.getValue()];
var bySearch = machineCache[$selectizeSearch[0].selectize.getValue()];
- var value = (bySubnet === undefined || bySubnet == "") ? bySearch : bySubnet;
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = -1;
+ makeCombinedFieldSingle(value);
+
var result = {muuid: value.machineuuid, ip: value.clientip, mac_address : value.macaddr, hostname: value.hostname};
currentCallback(result);
@@ -165,6 +173,14 @@ function onBtnSelect() {
clearSearchBox();
}
+function onPcDelete(muuid) {
+ var bySubnet = machineCache[muuid];
+ var bySearch = machineCache[muuid];
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = null;
+ makeCombinedFieldSingle(value);
+}
+
/* to be called from berryous' code */
function selectMachine(usedUuids, callback) {
initSelectize();
@@ -172,7 +188,7 @@ function selectMachine(usedUuids, callback) {
placedMachines = usedUuids;
$modal.modal('show');
$modal.one('hidden.bs.modal', function () {
- if (currentCallback != null) {
+ if (currentCallback) {
currentCallback(false);
}
});