add error msg when there are more than one device selected for add or remove one tag

This commit is contained in:
Cayo Puigdefabregas 2022-03-02 13:08:23 +01:00
parent ad09d298a0
commit c52480231b
5 changed files with 43 additions and 8 deletions

View File

@ -62,15 +62,26 @@ function deviceSelect() {
function removeTag() { function removeTag() {
var devices = $(".deviceSelect").filter(':checked'); var devices = $(".deviceSelect").filter(':checked');
var devices_id = $.map(devices, function(x) { return $(x).attr('data')}); var devices_id = $.map(devices, function(x) { return $(x).attr('data')});
if (devices_id.length > 0) { if (devices_id.length == 1) {
var url = "/inventory/tag/devices/"+devices_id[0]+"/del/"; var url = "/inventory/tag/devices/"+devices_id[0]+"/del/";
window.location.href = url; window.location.href = url;
} else {
$("#unlinkTagAlertModal").click();
} }
} }
function addTag() { function addTag() {
deviceSelect(); var devices = $(".deviceSelect").filter(':checked');
$("#addingTagModal").click(); var devices_id = $.map(devices, function(x) { return $(x).attr('data')});
if (devices_id.length == 1) {
$("#addingTagModal .pol").hide();
$("#addingTagModal .btn-primary").show();
} else {
$("#addingTagModal .pol").show();
$("#addingTagModal .btn-primary").hide();
}
$("#addTagAlertModal").click();
} }
function newTrade(action) { function newTrade(action) {

View File

@ -18,7 +18,7 @@
</select> </select>
<input class="devicesList" type="hidden" name="device" /> <input class="devicesList" type="hidden" name="device" />
<p class="text-danger pol"> <p class="text-danger pol">
You need select first some device for adding this in a tag You need select first one device and only one for add this in a tag
</p> </p>
</div> </div>

View File

@ -0,0 +1,21 @@
<div class="modal fade" id="unlinkTagErrorModal" tabindex="-1" style="display: none;" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Error Unlink Tag</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="text-danger pol">
You need select first one device and only one for Unlink one Tag
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

View File

@ -231,17 +231,19 @@
<i class="bi bi-tag"></i> <i class="bi bi-tag"></i>
Tags Tags
</button> </button>
<span class="d-none" id="unlinkTagAlertModal" data-bs-toggle="modal" data-bs-target="#unlinkTagErrorModal"></span>
<span class="d-none" id="addTagAlertModal" data-bs-toggle="modal" data-bs-target="#addingTagModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnTags"> <ul class="dropdown-menu" aria-labelledby="btnTags">
<li> <li>
<a href="javascript:addTag()" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#addingTagModal"> <a href="javascript:addTag()" class="dropdown-item">
<i class="bi bi-plus"></i> <i class="bi bi-plus"></i>
Add Tag to selected Devices Add Tag to selected Device
</a> </a>
</li> </li>
<li> <li>
<a href="javascript:removeTag()" class="dropdown-item"> <a href="javascript:removeTag()" class="dropdown-item">
<i class="bi bi-x"></i> <i class="bi bi-x"></i>
Remove Tag from selected Devices Remove Tag from selected Device
</a> </a>
</li> </li>
</ul> </ul>
@ -384,6 +386,7 @@
{% include "inventory/data_wipe.html" %} {% include "inventory/data_wipe.html" %}
{% include "inventory/trade.html" %} {% include "inventory/trade.html" %}
{% include "inventory/alert_export_error.html" %} {% include "inventory/alert_export_error.html" %}
{% include "inventory/alert_unlink_tag_error.html" %}
<!-- Custom Code --> <!-- Custom Code -->
<script> <script>

View File

@ -50,7 +50,7 @@
<div class="col-12"> <div class="col-12">
<a href="{{ referrer }}" class="btn btn-danger">Cancel</a> <a href="{{ referrer }}" class="btn btn-danger">Cancel</a>
<button class="btn btn-primary" type="submit">Save</button> <button class="btn btn-primary" type="submit">Unlink</button>
</div> </div>
</form> </form>