2023-02-17 21:27:20 +08:00
|
|
|
/* global dropdownSelector HelperModule */
|
|
|
|
(function() {
|
2023-03-09 22:57:05 +08:00
|
|
|
const protocolModal = '#newProtocolModal';
|
2023-05-23 15:50:34 +08:00
|
|
|
const submitButton = $('.create-protocol-button');
|
2023-02-17 21:27:20 +08:00
|
|
|
|
2023-03-09 22:57:05 +08:00
|
|
|
let roleSelector = `${protocolModal} #protocol_role_selector`;
|
2023-02-17 21:27:20 +08:00
|
|
|
dropdownSelector.init(roleSelector, {
|
|
|
|
noEmptyOption: true,
|
|
|
|
singleSelect: true,
|
|
|
|
closeOnSelect: true,
|
|
|
|
selectAppearance: 'simple',
|
|
|
|
onChange: function() {
|
|
|
|
$('#protocol_default_public_user_role_id').val(dropdownSelector.getValues(roleSelector));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-09 22:57:05 +08:00
|
|
|
$(protocolModal)
|
2023-05-23 15:50:34 +08:00
|
|
|
.on('change', '#protocol_visibility', function() {
|
|
|
|
let checked = $(this)[0].checked;
|
|
|
|
$('#roleSelectWrapper').toggleClass('hidden', !checked);
|
|
|
|
$('#protocol_default_public_user_role_id').prop('disabled', !checked);
|
|
|
|
})
|
|
|
|
.on('submit', function() {
|
|
|
|
submitButton.attr('disabled', 'disabled');
|
|
|
|
})
|
2023-03-14 21:20:03 +08:00
|
|
|
.on('shown.bs.modal', function() {
|
2023-05-23 15:50:34 +08:00
|
|
|
$(`${protocolModal} #protocol_name`).parent().removeClass('error');
|
|
|
|
$(`${protocolModal} #protocol_name`).val('');
|
2023-03-14 21:20:03 +08:00
|
|
|
$(this).find('.sci-input-field').focus();
|
|
|
|
})
|
2023-02-17 21:27:20 +08:00
|
|
|
.on('ajax:error', 'form', function(e, error) {
|
|
|
|
let msg = error.responseJSON.error;
|
2023-05-23 15:50:34 +08:00
|
|
|
submitButton.removeAttr('disabled');
|
2023-03-09 22:57:05 +08:00
|
|
|
$(`${protocolModal} #protocol_name`).parent().addClass('error').attr('data-error-text', msg);
|
2023-02-17 21:27:20 +08:00
|
|
|
})
|
|
|
|
.on('ajax:success', 'form', function(e, data) {
|
|
|
|
if (data.message) {
|
|
|
|
HelperModule.flashAlertMsg(data.message, 'success');
|
|
|
|
}
|
2023-03-09 22:57:05 +08:00
|
|
|
$(`${protocolModal} #protocol_name`).parent().removeClass('error');
|
2023-05-23 15:50:34 +08:00
|
|
|
submitButton.removeAttr('disabled');
|
2023-03-09 22:57:05 +08:00
|
|
|
$(protocolModal).modal('hide');
|
2023-02-17 21:27:20 +08:00
|
|
|
});
|
|
|
|
}());
|