summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules-available/exams/page.inc.php16
-rw-r--r--modules-available/exams/templates/page-add-edit-exam.html2
-rw-r--r--modules-available/exams/templates/page-exams.html13
-rw-r--r--modules-available/locations/inc/location.inc.php2
4 files changed, 22 insertions, 11 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php
index 1d0b8fc5..54fad5cf 100644
--- a/modules-available/exams/page.inc.php
+++ b/modules-available/exams/page.inc.php
@@ -13,14 +13,15 @@ class Page_Exams extends Page
protected function readLocations($examid = null)
{
if ($examid == null) {
- $tmp = Database::simpleQuery("SELECT locationid, locationname FROM location;", []);
+ $active = 0;
} else {
- $tmp = Database::simpleQuery("SELECT locationid, locationname, " .
- "EXISTS(SELECT * FROM exams NATURAL JOIN exams_x_location WHERE locationid = x.locationid AND examid= :examid) AS selected FROM location x", compact('examid'));
- }
- while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) {
- $this->locations[] = $loc;
+ $tmp = Database::simpleQuery("SELECT locationid FROM exams_x_location WHERE examid= :examid", compact('examid'));
+ $active = array();
+ while ($row = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ $active[] = (int)$row['locationid'];
+ }
}
+ $this->locations = Location::getLocations($active);
}
protected function readExams()
@@ -106,7 +107,8 @@ class Page_Exams extends Page
foreach ($this->locations as $l) {
$out[] = [
'id' => $l['locationid'],
- 'content' => $l['locationname']
+ 'content' => $l['locationpad'] . ' ' . $l['locationname'],
+ 'sortIndex' => $l['sortIndex'],
];
}
return json_encode($out);
diff --git a/modules-available/exams/templates/page-add-edit-exam.html b/modules-available/exams/templates/page-add-edit-exam.html
index 98683a54..3cc38cfb 100644
--- a/modules-available/exams/templates/page-add-edit-exam.html
+++ b/modules-available/exams/templates/page-add-edit-exam.html
@@ -10,7 +10,7 @@
<label for="locations">{{lang_location}}</label>
<select id="locations" multiple name="locations[]">
{{#locations}}
- <option value="{{locationid}}" {{#selected}}selected{{/selected}}> {{locationname}}</option>
+ <option value="{{locationid}}" {{#selected}}selected{{/selected}}>{{locationpad}} {{locationname}}</option>
{{/locations}}
</select>
</div>
diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html
index d0be479d..45ec0b50 100644
--- a/modules-available/exams/templates/page-exams.html
+++ b/modules-available/exams/templates/page-exams.html
@@ -43,8 +43,14 @@
<script type="application/javascript"><!--
-function customOrder(a, b) {
- return 1000; // just in order of appeareance
+function itemOrderFun(a, b) {
+ return a.content.localeCompare(b.content);
+}
+
+function groupOrderFun(a, b) {
+ var s = a.sortIndex - b.sortIndex;
+ if (s != 0) return s;
+ return itemOrderFun(a, b);
}
document.addEventListener("DOMContentLoaded", function () {
@@ -67,7 +73,8 @@ document.addEventListener("DOMContentLoaded", function () {
'max' : {{vis_max_date}},
'zoomMin': 6 * 3600 * 1000,
'zoomMax': 2 * 86400 * 1000,
- 'order' : customOrder,
+ 'order' : itemOrderFun,
+ 'groupOrder' : groupOrderFun,
'locale' : language,
'moment' : function(date) { return vis.moment(date).utc(); }
};
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index b1474279..69ddb4ee 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -78,6 +78,7 @@ class Location
}
$del = false;
unset($row);
+ $index = 0;
foreach ($rows as $key => &$row) {
if ($del === false && $row['locationid'] == $excludeId) {
$del = $row['depth'];
@@ -91,6 +92,7 @@ class Location
if ((is_array($selected) && in_array($row['locationid'], $selected)) || (int)$row['locationid'] === $selected) {
$row['selected'] = true;
}
+ $row['sortIndex'] = $index++;
}
if ($addNoParent) {
array_unshift($rows, array(