summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/clientscript.js
diff options
context:
space:
mode:
authorChristian Klinger2016-08-08 13:09:15 +0200
committerChristian Klinger2016-08-08 13:09:15 +0200
commitc1a5de867d867c6c5aba3266fd595a8b15fce788 (patch)
tree9c6d8c2271e5cfd460f134d6dafe8e98c1429837 /modules-available/roomplanner/clientscript.js
parentadded additional ressources to js_jqueryui. (diff)
downloadslx-admin-c1a5de867d867c6c5aba3266fd595a8b15fce788.tar.gz
slx-admin-c1a5de867d867c6c5aba3266fd595a8b15fce788.tar.xz
slx-admin-c1a5de867d867c6c5aba3266fd595a8b15fce788.zip
fixed bug.
Diffstat (limited to 'modules-available/roomplanner/clientscript.js')
-rw-r--r--modules-available/roomplanner/clientscript.js58
1 files changed, 30 insertions, 28 deletions
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index ed91c9fd..b7bd5d55 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -4,9 +4,11 @@
* Copyright 2016 Christian Klinger
* */
-/* uuid -> obj */
+/* Map: uuid -> obj */
machineCache = {};
+selectMachinInitialized = false;
+
function renderMachineEntry(item, escape) {
@@ -79,47 +81,47 @@ var subnetSettings = {
}
function clearSearchBox() {
- console.log("clearSearchBox()");
- $selectizeSearch[0].selectize.clear(false);
+ $selectizeSearch[0].selectize.setValue([], true);
}
function clearSubnetBox() {
- console.log("clearSubnetBox()");
- $selectizeSubnet[0].selectize.clear(false);
+ $selectizeSubnet[0].selectize.setValue([], true);
}
-function selectMachine(usedUuids, callback) {
- /* show a popup */
- $modal = $('#selectMachineModal');
- $selectizeSearch = $('#machineSearchBox').selectize(searchSettings);
- $selectizeSubnet = $('#subnetBox').selectize(subnetSettings);
-
- /* connect subnet tab and search tab such that on change of one the other gets emptied */
+function initSelectize() {
+ if(!selectMachinInitialized) {
+ console.log("initializing selectize");
+ /* init modal */
+ $modal = $('#selectMachineModal');
+ $selectizeSearch = $('#machineSearchBox').selectize(searchSettings);
+ $selectizeSubnet = $('#subnetBox').selectize(subnetSettings);
+ $('#selectMachineButton').on('click', onBtnSelect);
- $modal.modal('show');
-
- $('#selectMachineButton').on('click', function() {
-
+ selectMachinInitialized = true;
+ }
+}
+function onBtnSelect() {
/* check which one has a value */
+ 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 selected = bySubnet; // (bySubnet === undefined || bySubnet == "")? bySearch : bySubnet;
+ var value = (bySubnet === undefined || bySubnet == "") ? bySearch : bySubnet;
+ var result = {muuid: value.machineuuid, ip: value.clientip, mac_address : value.macaddr, hostname: value.hostname};
- console.log('value is ');
- console.log($selectizeSubnet[0].selectize.getValue());
- console.log(machineCache);
- console.log('selected is ');
- console.log(selected);
+ currentCallback(result);
- var result = {muuid: selected.machineuuid, ip: selected.clientip, mac_address : selected.macaddr, hostname: selected.hostname};
$modal.modal('hide');
clearSubnetBox();
clearSearchBox();
- callback(result);
- });
-
- var result = {muuid: "blabla", ip: "blabla", mac_address: "blub", hostname: "lalala"};
+}
- callback(result);
+/* to be called from berryous' code */
+function selectMachine(usedUuids, callback) {
+ initSelectize();
+ currentCallback = callback;
+ $modal.modal('show');
}
+