From c1a5de867d867c6c5aba3266fd595a8b15fce788 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Mon, 8 Aug 2016 13:09:15 +0200 Subject: fixed bug. --- modules-available/roomplanner/clientscript.js | 58 ++++++++++++++------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'modules-available/roomplanner/clientscript.js') 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'); } + -- cgit v1.2.3-55-g7522