2023-05-30 22:15:20 +08:00
|
|
|
/* 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() {
|
2021-04-25 00:43:28 +08:00
|
|
|
$(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();
|
2023-01-23 05:23:18 +08:00
|
|
|
$.get(ev.currentTarget.getAttribute('href')).then(function({ modal, html }) {
|
|
|
|
$(modal || html)
|
2021-11-05 22:42:59 +08:00
|
|
|
.on('shown.bs.modal', function() {
|
2021-11-09 23:16:10 +08:00
|
|
|
if ($(this).hasClass('project-assignments-modal')) {
|
|
|
|
$(this).on('ajax:success', 'form', function() {
|
|
|
|
ProjectsIndex.loadCardsView();
|
|
|
|
});
|
|
|
|
}
|
2023-01-31 17:34:32 +08:00
|
|
|
if ($(this).hasClass('protocol-assignments-modal')) {
|
|
|
|
$(this).on('ajax:success', 'form', function() {
|
|
|
|
ProtocolsIndex.reloadTable();
|
|
|
|
});
|
|
|
|
}
|
2023-05-30 22:15:20 +08:00
|
|
|
if ($(this).hasClass('share-repo-modal')) {
|
|
|
|
animateSpinner(null, false);
|
|
|
|
ShareModal.init();
|
|
|
|
}
|
2023-06-06 21:18:21 +08:00
|
|
|
if (['rename-repo-modal', 'copy-repo-modal'].includes($(this).attr('id'))) {
|
|
|
|
$(this).find('form')
|
|
|
|
.on('ajax:success', function(_e, data) {
|
|
|
|
if (data.url) {
|
|
|
|
window.location = data.url;
|
|
|
|
} else {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('ajax:error', function(_e, data) {
|
|
|
|
$(this).renderFormErrors('repository', data.responseJSON);
|
|
|
|
});
|
|
|
|
}
|
2021-11-05 22:42:59 +08:00
|
|
|
$(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
|
|
|
}
|
|
|
|
|
2021-04-25 00:43:28 +08:00
|
|
|
$(document).one('turbolinks:load', initRemoteModalListeners);
|
2021-05-02 17:36:10 +08:00
|
|
|
}());
|