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

42 lines
1.3 KiB
JavaScript
Raw Normal View History

/* global animateSpinner ProtocolsIndex ProjectsIndex ShareModal */
2021-05-22 20:41:56 +08:00
(function() {
2021-04-18 23:19:16 +08:00
'use strict';
function initRemoteModalListeners() {
$(document).on('click', 'a[data-action="remote-modal"]', function(ev) {
ev.stopImmediatePropagation();
ev.stopPropagation();
ev.preventDefault();
2021-05-08 16:05:22 +08:00
animateSpinner();
$.get(ev.currentTarget.getAttribute('href')).then(function({ modal, html }) {
$(modal || html)
.on('shown.bs.modal', function() {
if ($(this).hasClass('project-assignments-modal')) {
$(this).on('ajax:success', 'form', function() {
ProjectsIndex.loadCardsView();
});
}
if ($(this).hasClass('protocol-assignments-modal')) {
$(this).on('ajax:success', 'form', function() {
ProtocolsIndex.reloadTable();
});
}
if ($(this).hasClass('share-repo-modal')) {
animateSpinner(null, false);
ShareModal.init();
}
$(this).find('.selectpicker').selectpicker();
})
.on('hidden.bs.modal', function() {
$(this).remove();
})
.modal('show');
2021-05-08 16:05:22 +08:00
animateSpinner(null, false);
2021-05-02 17:36:10 +08:00
});
});
2021-04-18 23:19:16 +08:00
}
$(document).one('turbolinks:load', initRemoteModalListeners);
2021-05-02 17:36:10 +08:00
}());