Replace cat and loc search boxes with select dropdowns (#11)

master
Skylar Ittner 6 years ago
parent ab717e6030
commit e1045eed9e

@ -202,8 +202,12 @@ switch ($VARS['action']) {
} }
returnToSender("invalid_parameters"); returnToSender("invalid_parameters");
case "autocomplete_category": case "autocomplete_category":
exit(json_encode($database->select('categories', ['catid (id)', 'catname (name)'], ['catname[~]' => $VARS['q'], 'LIMIT' => 10]))); header("Content-Type: application/json");
$q = (empty($VARS['q']) ? "" : $VARS['q']);
exit(json_encode($database->select('categories', ['catid (id)', 'catname (name)'], ['catname[~]' => $q, 'LIMIT' => 10])));
case "autocomplete_location": case "autocomplete_location":
header("Content-Type: application/json");
$q = (empty($VARS['q']) ? "" : $VARS['q']);
exit(json_encode($database->select('locations', ['locid (id)', 'locname (name)'], ["OR" => ['locname[~]' => $VARS['q'], 'loccode' => $VARS['q']], 'LIMIT' => 10]))); exit(json_encode($database->select('locations', ['locid (id)', 'locname (name)'], ["OR" => ['locname[~]' => $VARS['q'], 'loccode' => $VARS['q']], 'LIMIT' => 10])));
case "autocomplete_user": case "autocomplete_user":
header("Content-Type: application/json"); header("Content-Type: application/json");

@ -1,5 +1,6 @@
{ {
"New Category": "New Category", "New Category": "New Category",
"editing category": "Editing {cat}", "editing category": "Editing {cat}",
"Adding new category": "Adding new category" "Adding new category": "Adding new category",
"Choose a category": "Choose a category"
} }

@ -22,5 +22,7 @@
"login server error": "The login server returned an error: {arg}", "login server error": "The login server returned an error: {arg}",
"login server user data error": "The login server refused to provide account information. Try again or contact technical support.", "login server user data error": "The login server refused to provide account information. Try again or contact technical support.",
"captcha error": "There was a problem with the CAPTCHA (robot test). Try again.", "captcha error": "There was a problem with the CAPTCHA (robot test). Try again.",
"no access permission": "You do not have permission to access this system." "no access permission": "You do not have permission to access this system.",
"no permission": "You do not have permission to access this system.",
"no edit permission": "You do not have permission to modify records."
} }

@ -7,7 +7,6 @@
"Adding Item": "Adding new item", "Adding Item": "Adding new item",
"editing item": "Editing {item}", "editing item": "Editing {item}",
"cloning item": "Copying {oitem} <i class=\"fa fa-angle-right\"></i> {nitem}", "cloning item": "Copying {oitem} <i class=\"fa fa-angle-right\"></i> {nitem}",
"item saved": "Item Saved",
"itemid": "Item ID", "itemid": "Item ID",
"id": "ID" "id": "ID"
} }

@ -1,5 +1,6 @@
{ {
"new location": "New Location", "new location": "New Location",
"Adding new location": "Adding new location", "Adding new location": "Adding new location",
"editing location": "Editing {loc}" "editing location": "Editing {loc}",
"Choose a location": "Choose a location"
} }

@ -104,15 +104,33 @@ if (!empty($VARS['id'])) {
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
<div class="form-group"> <div class="form-group">
<label for="cat"><i class="fas fa-archive"></i> <?php $Strings->get("category"); ?></label> <label for="cat"><i class="fas fa-archive"></i> <?php $Strings->get("category"); ?></label>
<input type="text" name="catstr" class="form-control" id="cat" placeholder="<?php $Strings->get("placeholder category name"); ?>" value="<?php echo htmlspecialchars($itemdata['catname']); ?>" /> <select class="form-control" name="cat" id="cat" required="required">
<input type="hidden" id="realcat" name="cat" value="<?php echo $itemdata['catid']; ?>" required="required" /> <option value=""><?php $Strings->get("Choose a category"); ?></option>
<?php
$categories = $database->select('categories', ['catid (id)', 'catname (name)']);
foreach ($categories as $cat) {
?>
<option value="<?php echo $cat['id']; ?>" <?php echo $itemdata['catid'] == $cat['id'] ? "selected" : ""; ?>><?php echo $cat['name']; ?></option>
<?php
}
?>
</select>
</div> </div>
</div> </div>
<div class="col-12 col-md-6"> <div class="col-12 col-md-6">
<div class="form-group"> <div class="form-group">
<label for="loc"><i class="fas fa-map-marker"></i> <?php $Strings->get("location"); ?></label> <label for="loc"><i class="fas fa-map-marker"></i> <?php $Strings->get("location"); ?></label>
<input type="text" name="locstr" class="form-control" id="loc" placeholder="<?php $Strings->get("placeholder location name"); ?>" value="<?php echo htmlspecialchars($itemdata['locname']); ?>" /> <select class="form-control" name="loc" id="loc" required="required">
<input type="hidden" id="realloc" name="loc" value="<?php echo $itemdata['locid']; ?>" required="required" /> <option value=""><?php $Strings->get("Choose a location"); ?></option>
<?php
$locations = $database->select('locations', ['locid (id)', 'locname (name)']);
foreach ($locations as $loc) {
?>
<option value="<?php echo $loc['id']; ?>" <?php echo $itemdata['locid'] == $loc['id'] ? "selected" : ""; ?>><?php echo $loc['name']; ?></option>
<?php
}
?>
</select>
</div> </div>
</div> </div>
</div> </div>

@ -2,59 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
$("#cat").easyAutocomplete({
url: "action.php",
ajaxSettings: {
dataType: "json",
method: "GET",
data: {
action: "autocomplete_category"
}
},
preparePostData: function (data) {
data.q = $("#cat").val();
return data;
},
getValue: function (element) {
return element.name;
},
list: {
onSelectItemEvent: function () {
var catid = $("#cat").getSelectedItemData().id;
$("#realcat").val(catid).trigger("change");
},
match: {
enabled: true
}
}
});
$("#loc").easyAutocomplete({
url: "action.php",
ajaxSettings: {
dataType: "json",
method: "GET",
data: {
action: "autocomplete_location"
}
},
preparePostData: function (data) {
data.q = $("#loc").val();
return data;
},
getValue: function (element) {
return element.name;
},
list: {
onSelectItemEvent: function () {
var locid = $("#loc").getSelectedItemData().id;
$("#realloc").val(locid).trigger("change");
},
match: {
enabled: true
}
}
});
$("#assignedto").easyAutocomplete({ $("#assignedto").easyAutocomplete({
url: "action.php", url: "action.php",
ajaxSettings: { ajaxSettings: {
@ -81,4 +28,5 @@ $("#assignedto").easyAutocomplete({
$('#name').on('input propertychange paste', function () { $('#name').on('input propertychange paste', function () {
$('#name_title').text($('#name').val()); $('#name_title').text($('#name').val());
}); });

Loading…
Cancel
Save