2021-05-22 20:41:56 +08:00
|
|
|
(function() {
|
2021-04-18 23:19:16 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function initSwapRemoteContainerListeners() {
|
2021-04-25 00:43:28 +08:00
|
|
|
$(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);
|
|
|
|
targetElement.replaceWith(newContainer);
|
2021-04-25 00:43:28 +08:00
|
|
|
newContainer.find('.selectpicker').selectpicker();
|
2021-04-30 19:26:06 +08:00
|
|
|
|
|
|
|
if (flash) {
|
|
|
|
HelperModule.flashAlertMsg(flash, 'success');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-04-18 23:19:16 +08:00
|
|
|
}
|
|
|
|
|
2021-04-25 00:43:28 +08:00
|
|
|
$(document).one('turbolinks:load', initSwapRemoteContainerListeners);
|
2021-05-02 17:36:10 +08:00
|
|
|
}());
|