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

28 lines
944 B
JavaScript
Raw Normal View History

2021-05-22 20:41:56 +08:00
(function() {
2021-04-18 23:19:16 +08:00
'use strict';
function initSwapRemoteContainerListeners() {
$(document).on('click', 'a[data-action="swap-remote-container"]', function(ev) {
let element = ev.currentTarget;
ev.stopImmediatePropagation();
ev.stopPropagation();
ev.preventDefault();
2021-04-18 23:19:16 +08:00
2021-05-22 20:41:56 +08:00
$.get(element.getAttribute('href')).then(function({ html, flash }) {
2021-04-30 19:26:06 +08:00
let targetID = element.getAttribute('data-target');
let targetElement = $(element).closest(targetID);
let newContainer = $(html).find(targetID).length ? $(html).find(targetID) : $(html);
2021-04-30 19:26:06 +08:00
targetElement.replaceWith(newContainer);
newContainer.find('.selectpicker').selectpicker();
newContainer.find('.new-assignment-user-search').focus();
2021-04-30 19:26:06 +08:00
if (flash) {
HelperModule.flashAlertMsg(flash, 'success');
}
});
});
2021-04-18 23:19:16 +08:00
}
$(document).one('turbolinks:load', initSwapRemoteContainerListeners);
2021-05-02 17:36:10 +08:00
}());