librenms-librenms/includes/html/modal/alert_ack.inc.php
Tony Murray 0b8b97bb68 Push Notifications (Mobile and PC) (#13277)
* Update manifest and add service worker
cleanup icons a bit

* Push notifications WIP

* navigate working

* cleanup

* acknowledge wired up

* Set VAPID keys on composer install

* Component to control notification permissions.

* Allow all user option to validate

* Enable on browser load if transport exists.

* Check for transport before showing user permissions
translations

* Documentation

* style fixes

* access via the attribute model

* fix alerting test

* update schema

* cleanup subscription on disable

* non-configurable db and table for webpush subscriptions (respect system connection)

* revert AlertTransport change
hopefully phpstan can figure it out

* phpstan fixes

* Support custom details display

* Match transport names to brand's preferred display

* less duplicate id errors

* Tests are done in Laravel code now so
remove legacy function usage... could be better, but ok

* Style fixes

* Style fixes 2

* Fix alert test

* Doc updates requires HTTPS and GMP

* unregister subscription when permission is set to denied

* cleanup after user deletion

* delete the right thing

* fix whitespace

* update install docs to include php-gmp

* suggest ext-gmp

* update javascript

* Update functions.php

Co-authored-by: Jellyfrog <Jellyfrog@users.noreply.github.com>
2021-10-06 07:29:47 -05:00

82 lines
3.8 KiB
PHP

<?php
use LibreNMS\Config;
?>
<form class="form-horizontal">
<?php echo csrf_field() ?>
<div class="modal fade" id="alert_ack_modal" tabindex="-1" role="dialog" aria-labelledby="alert_notes" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h5 class="modal-title" id="alert_notes">Acknowledge Alert</h5>
</div>
<div class="modal-body">
<div class='form-group'>
<label for='ack_msg' class='col-sm-4 col-md-3 control-label' title="Add a message to the acknowledgement">(Un)Acknowledgement note: </label>
<div class="col-sm-8 col-md-9">
<input type='text' id='ack_msg' name='ack_msg' class='form-control' autofocus>
</div>
</div>
<div class="form-group" id="ack_section">
<label for="ack_until_clear" class="col-sm-4 col-md-3 control-label" title="Acknowledge until alert clears">Acknowledge until clear:</label>
<div class="col-sm-8 col-md-9">
<input type='checkbox' name='ack_until_clear' id='ack_until_clear'>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-md-offset-3 col-sm-3 col-md-2">
<input type="hidden" id="ack_alert_id" name="ack_alert_id" value="">
<input type="hidden" id="ack_alert_state" name="ack_alert_state" value="">
<button class="btn btn-success" id="ack-alert" name="ack-alert">Ack alert</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script>
$('#alert_ack_modal').on('show.bs.modal', function () {
if ($("#ack_alert_state").val() == 2) {
var button_label = 'Un-acknowledge alert';
$('#ack_section').hide();
} else {
var button_label = 'Acknowledge alert';
$('#ack_section').show();
}
document.getElementById('ack-alert').innerText = button_label;
$("#ack_until_clear").bootstrapSwitch('state', <?php echo Config::get('alert.ack_until_clear') ? 'true' : 'false'; ?>);
});
$("#ack-alert").on("click", function(event) {
event.preventDefault();
var ack_alert_id = $("#ack_alert_id").val();
var ack_alert_note = $('#ack_msg').val();
var ack_alert_state = $("#ack_alert_state").val();
var ack_until_clear = $("#ack_until_clear").bootstrapSwitch('state');
$.ajax({
type: "POST",
url: '<?php echo route('alert.ack', ['alert' => ':alert_id']) ?>'.replace(':alert_id', ack_alert_id),
dataType: "json",
data: { state: ack_alert_state, ack_msg: ack_alert_note, ack_until_clear: ack_until_clear },
success: function (data) {
if (data.status === "ok") {
toastr.success(data.message);
var $table = $('table.alerts');
var sortDictionary = $table.bootgrid("getSortDictionary");
$table.bootgrid('reload');
$table.bootgrid("sort", sortDictionary);
$("#alert_ack_modal").modal('hide');
} else {
toastr.error(data.message || 'Failed to update acknowledgement');
}
},
error: function(){
toastr.error(data.message);
}
});
});
</script>