summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner
diff options
context:
space:
mode:
authorChristian Klinger2016-08-08 14:30:18 +0200
committerChristian Klinger2016-08-08 14:30:18 +0200
commit19eec4188d6d871d980deee2255507ac7d265b6c (patch)
tree0ed082703c39033eafbaa79861b53487fa857014 /modules-available/roomplanner
parentfixed bug. (diff)
downloadslx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.tar.gz
slx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.tar.xz
slx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.zip
subnet select.
Diffstat (limited to 'modules-available/roomplanner')
-rw-r--r--modules-available/roomplanner/clientscript.js64
-rw-r--r--modules-available/roomplanner/page.inc.php91
-rw-r--r--modules-available/roomplanner/templates/page.html3
3 files changed, 91 insertions, 67 deletions
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index b7bd5d55..c19e63ec 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -48,37 +48,6 @@ function loadMachines(query, callback) {
}
-var searchSettings = {
- plugins : ["remove_button"],
- valueField: 'machineuuid',
- searchField: "combined",
- //labelField: "combined",
- openOnFocus: false,
- create: false,
- render : { option : renderMachineEntry, item: renderMachineEntry},
- load: loadMachines,
- maxItems: 1,
- sortField: 'clientip',
- sortDirection: 'asc',
- onChange: clearSubnetBox
-
-}
-
-var subnetSettings = {
- plugins : ["remove_button"],
- valueField: 'machineuuid',
- searchField: "combined",
- //labelField: "combined",
- openOnFocus: false,
- create: false,
- render : { option : renderMachineEntry, item: renderMachineEntry},
- load: loadMachines,
- maxItems: 1,
- sortField: 'clientip',
- sortDirection: 'asc',
- onChange: clearSearchBox
-
-}
function clearSearchBox() {
$selectizeSearch[0].selectize.setValue([], true);
@@ -92,8 +61,37 @@ function initSelectize() {
console.log("initializing selectize");
/* init modal */
$modal = $('#selectMachineModal');
- $selectizeSearch = $('#machineSearchBox').selectize(searchSettings);
- $selectizeSubnet = $('#subnetBox').selectize(subnetSettings);
+
+ /* for the search */
+ $selectizeSearch = $('#machineSearchBox').selectize({
+ plugins : ["remove_button"],
+ valueField: 'machineuuid',
+ searchField: "combined",
+ openOnFocus: false,
+ create: false,
+ render : { option : renderMachineEntry, item: renderMachineEntry},
+ load: loadMachines,
+ maxItems: 1,
+ sortField: 'clientip',
+ sortDirection: 'asc',
+ onChange: clearSubnetBox
+ });
+
+
+ /* for the subnet box */
+ $selectizeSubnet = $('#subnetBox').selectize({
+ options: subnetMachines,
+ plugins : ["remove_button"],
+ valueField: 'machineuuid',
+ searchField: "combined",
+ openOnFocus: true,
+ create: false,
+ render : { option : renderMachineEntry, item: renderMachineEntry},
+ maxItems: 1,
+ sortField: 'clientip',
+ sortDirection: 'asc',
+ onChange: clearSearchBox
+ });
$('#selectMachineButton').on('click', onBtnSelect);
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index b533cf2f..222192c1 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -2,30 +2,38 @@
class Page_Roomplanner extends Page
{
- protected function doPreprocess()
- {
- User::load();
+ protected function doPreprocess()
+ {
+ User::load();
- if (!User::hasPermission('superadmin')) {
- Message::addError('main.no-permission');
- Util::redirect('?do=Main');
- }
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('main.no-permission');
+ Util::redirect('?do=Main');
+ }
+ }
- }
+ protected function doRender()
+ {
+ $locationid = Request::get('locationid', null, 'integer');
- protected function doRender()
- {
- Render::addTemplate('page', []);
- }
+ if ($locationid === null) {
+ die('please specify locationid');
+ }
- protected function doAjax()
- {
- $action = Request::get('action', null, 'string');
+ $subnetMachines = $this->getPotentialMachines($locationid);
- if ($action === 'getmachines') {
- $query = Request::get('query', null, 'string');
+ Render::addTemplate('page', ['subnetMachines' => json_encode($subnetMachines),
+ ]);
+ }
- /* the query could be anything: UUID, IP or macaddr */
+ protected function doAjax()
+ {
+ $action = Request::get('action', null, 'string');
+
+ if ($action === 'getmachines') {
+ $query = Request::get('query', null, 'string');
+
+ /* the query could be anything: UUID, IP or macaddr */
// $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
// . ', MATCH (machineuuid, macaddr, clientip, hostname) AGAINST (:query) AS relevance '
// . 'FROM machine '
@@ -34,20 +42,35 @@ class Page_Roomplanner extends Page
// . 'LIMIT 5'
// , ['query' => $query]);
//
- $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
- . 'FROM machine '
- . "WHERE machineuuid LIKE :query "
- . " OR macaddr LIKE :query "
- . " OR clientip LIKE :query "
- . " OR hostname LIKE :query ", ['query' => "%$query%"]);
-
- $returnObject = ['machines' => []];
-
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- $returnObject['machines'][] = $row;
- }
- echo json_encode($returnObject, JSON_PRETTY_PRINT);
-
- }
- }
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ .'FROM machine '
+ .'WHERE machineuuid LIKE :query '
+ .' OR macaddr LIKE :query '
+ .' OR clientip LIKE :query '
+ .' OR hostname LIKE :query ', ['query' => "%$query%"]);
+
+ $returnObject = ['machines' => []];
+
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $returnObject['machines'][] = $row;
+ }
+ echo json_encode($returnObject, JSON_PRETTY_PRINT);
+ }
+ }
+
+ protected function getPotentialMachines($locationid)
+ {
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ .'FROM machine INNER JOIN subnet ON (INET_ATON(clientip) BETWEEN startaddr AND endaddr) '
+ .'WHERE subnet.locationid = :locationid', ['locationid' => $locationid]);
+
+ $machines = [];
+
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $row['combined'] = implode(' ', array_values($row));
+ $machines[] = $row;
+ }
+
+ return $machines;
+ }
}
diff --git a/modules-available/roomplanner/templates/page.html b/modules-available/roomplanner/templates/page.html
index a8294dc5..f4d97a6e 100644
--- a/modules-available/roomplanner/templates/page.html
+++ b/modules-available/roomplanner/templates/page.html
@@ -333,6 +333,8 @@
<script type="application/javascript"><!--
document.addEventListener("DOMContentLoaded", function () {
+ subnetMachines = {{{subnetMachines}}};
+
$.when(
$.getScript("modules/roomplanner/js/lib/jquery-collision.js"),
$.getScript("modules/roomplanner/js/lib/jquery-ui-draggable-collision.js"),
@@ -343,6 +345,7 @@ document.addEventListener("DOMContentLoaded", function () {
).done(function() {
$.getScript("modules/roomplanner/js/init.js", function() {
initRoomplanner();
+ console.log(subnetMachines);
});
});
});