scinote-web/app/assets/javascripts/shared/remote_destroy.js

20 lines
623 B
JavaScript
Raw Normal View History

2021-04-30 19:26:06 +08:00
(function() {
'use strict';
function initRemoteDestroyListeners() {
2021-04-30 19:26:06 +08:00
$(document).on('ajax:success', 'a[data-action*="remote-destroy"]', function({ currentTarget, flash }) {
let target = currentTarget.getAttribute('data-target');
document.querySelector(target).remove();
if (flash) {
HelperModule.flashAlertMsg(flash, 'success');
}
});
$(document).on('ajax:error', 'a[data-action*="remote-destroy"]', function(_, data) {
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
2021-04-30 19:26:06 +08:00
});
}
$(document).one('turbolinks:load', initRemoteDestroyListeners);
2021-05-02 17:36:10 +08:00
}());