2022-09-29 05:18:36 +08:00
|
|
|
(function() {
|
|
|
|
function initNewMyModuleModal() {
|
2022-11-24 21:49:42 +08:00
|
|
|
let experimentWrapper = '.experiment-new-my_module';
|
2022-09-29 05:18:36 +08:00
|
|
|
let newMyModuleModal = '#new-my-module-modal';
|
|
|
|
|
|
|
|
// Modal's submit handler function
|
|
|
|
$(experimentWrapper)
|
|
|
|
.on('ajax:success', newMyModuleModal, function() {
|
|
|
|
$(newMyModuleModal).modal('hide');
|
|
|
|
})
|
|
|
|
.on('ajax:error', newMyModuleModal, function(ev, data) {
|
|
|
|
$(this).renderFormErrors('my_module', data.responseJSON);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(experimentWrapper)
|
|
|
|
.on('ajax:success', '.new-my-module-button', function(ev, data) {
|
|
|
|
// Add and show modal
|
|
|
|
$(experimentWrapper).append($.parseHTML(data.html));
|
|
|
|
$(newMyModuleModal).modal('show');
|
|
|
|
$(newMyModuleModal).find("input[type='text']").focus();
|
|
|
|
|
|
|
|
// Remove modal when it gets closed
|
|
|
|
$(newMyModuleModal).on('hidden.bs.modal', function() {
|
|
|
|
$(newMyModuleModal).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initNewMyModuleModal();
|
|
|
|
}());
|