2019-11-20 21:57:53 +08:00
|
|
|
/* global dropdownSelector */
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2019-11-20 21:57:53 +08:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2016-10-04 21:52:48 +08:00
|
|
|
|
|
|
|
// Setup notification checkbox buttons
|
|
|
|
function notificationsSettings() {
|
2016-10-06 19:47:48 +08:00
|
|
|
var notification_settings = [ "recent_notification",
|
2018-09-05 22:36:32 +08:00
|
|
|
"assignments_notification" ]
|
2016-10-06 19:47:48 +08:00
|
|
|
|
|
|
|
for (var i = 0; i < notification_settings.length; i++ ) {
|
|
|
|
var setting = $('[name="' + notification_settings[i] + '"]');
|
|
|
|
var dependant = $('[name="' + notification_settings[i] + '_email"]');
|
2018-05-18 22:24:24 +08:00
|
|
|
dependant.checkboxpicker({ onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle' });
|
2016-10-06 19:47:48 +08:00
|
|
|
setting
|
|
|
|
.checkboxpicker({
|
2018-05-18 22:24:24 +08:00
|
|
|
onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle'
|
2016-10-06 19:47:48 +08:00
|
|
|
}).change(function() {
|
|
|
|
if ( $(this).prop('checked') ) {
|
|
|
|
enableDependant($('[name="' + $(this).attr('name') + '_email"]'));
|
|
|
|
} else {
|
|
|
|
disableDependant($('[name="' + $(this).attr('name') + '_email"]'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( setting.attr('value') === 'true' ) {
|
|
|
|
setting.prop('checked', true);
|
|
|
|
} else {
|
|
|
|
setting.prop('checked', false);
|
|
|
|
disableDependant(dependant);
|
|
|
|
}
|
|
|
|
|
|
|
|
setEmailSwitch(dependant);
|
|
|
|
}
|
2016-10-04 21:52:48 +08:00
|
|
|
|
2016-10-06 19:47:48 +08:00
|
|
|
function setEmailSwitch(setting) {
|
|
|
|
setting
|
|
|
|
.checkboxpicker({
|
2018-05-18 22:24:24 +08:00
|
|
|
onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle'
|
2016-10-06 19:47:48 +08:00
|
|
|
});
|
|
|
|
if ( setting.attr('value') === 'true' ) {
|
|
|
|
setting.prop('checked', true);
|
|
|
|
enableDependant(setting);
|
|
|
|
} else {
|
|
|
|
setting.prop('checked', false);
|
|
|
|
}
|
2016-10-04 21:52:48 +08:00
|
|
|
}
|
|
|
|
|
2016-10-06 19:47:48 +08:00
|
|
|
function disableDependant(dependant) {
|
|
|
|
dependant.checkboxpicker().prop('disabled', true);
|
|
|
|
dependant.checkboxpicker().prop('checked', false);
|
|
|
|
}
|
2016-10-04 21:52:48 +08:00
|
|
|
|
2016-10-06 19:47:48 +08:00
|
|
|
function enableDependant(dependant) {
|
|
|
|
dependant.checkboxpicker().prop('disabled', false);
|
2016-10-04 21:52:48 +08:00
|
|
|
}
|
2016-10-12 16:42:07 +08:00
|
|
|
|
2016-10-12 17:50:26 +08:00
|
|
|
// Initialize system messages
|
2016-10-12 16:42:07 +08:00
|
|
|
var system_message_notification = $('[name="system_message_notification"]');
|
|
|
|
system_message_notification
|
|
|
|
.checkboxpicker({
|
2018-05-18 22:24:24 +08:00
|
|
|
onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle'
|
2016-10-12 16:42:07 +08:00
|
|
|
});
|
|
|
|
system_message_notification.prop('checked', true);
|
|
|
|
system_message_notification.prop('disabled', true);
|
2016-10-12 17:50:26 +08:00
|
|
|
|
|
|
|
// Initialize system messages email
|
|
|
|
var system_message_notification_mail = $('[name="system_message_notification_email"]');
|
|
|
|
system_message_notification_mail
|
|
|
|
.checkboxpicker({
|
2018-05-18 22:24:24 +08:00
|
|
|
onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle'
|
2016-10-12 17:50:26 +08:00
|
|
|
});
|
|
|
|
system_message_notification_mail.prop(
|
|
|
|
'checked',
|
|
|
|
system_message_notification_mail.attr('value') === 'true'
|
|
|
|
);
|
2016-10-04 21:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// triggers submit action when the user clicks
|
2018-09-05 22:36:32 +08:00
|
|
|
function initTogglableSettingsForm() {
|
|
|
|
$('#togglable-settings-panel')
|
2016-10-04 21:52:48 +08:00
|
|
|
.find('.btn-group')
|
|
|
|
.on('click', function() {
|
|
|
|
$(this).submit();
|
|
|
|
});
|
|
|
|
}
|
2019-11-20 21:57:53 +08:00
|
|
|
|
|
|
|
function initTimeZoneSelector() {
|
|
|
|
dropdownSelector.init('#time-zone-input-field', {
|
|
|
|
noEmptyOption: true,
|
|
|
|
singleSelect: true,
|
2019-11-27 22:14:40 +08:00
|
|
|
closeOnSelect: true,
|
2019-11-20 21:57:53 +08:00
|
|
|
selectAppearance: 'simple',
|
|
|
|
onClose: function() {
|
|
|
|
$.ajax({
|
|
|
|
url: $('#time-zone-input-field').data('path-to-update'),
|
|
|
|
type: 'PUT',
|
|
|
|
dataType: 'json',
|
|
|
|
data: { user: { time_zone: dropdownSelector.getValues('#time-zone-input-field') } },
|
|
|
|
success: function() {
|
|
|
|
dropdownSelector.highlightSuccess('#time-zone-input-field');
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
dropdownSelector.highlightError('#time-zone-input-field');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initDateFormatSelector() {
|
|
|
|
dropdownSelector.init('#date-format-input-field', {
|
|
|
|
noEmptyOption: true,
|
|
|
|
singleSelect: true,
|
2019-11-27 22:14:40 +08:00
|
|
|
closeOnSelect: true,
|
2019-11-20 21:57:53 +08:00
|
|
|
selectAppearance: 'simple',
|
|
|
|
onClose: function() {
|
|
|
|
$.ajax({
|
|
|
|
url: $('#date-format-input-field').data('path-to-update'),
|
|
|
|
type: 'PUT',
|
|
|
|
dataType: 'json',
|
|
|
|
data: { user: { date_format: dropdownSelector.getValues('#date-format-input-field') } },
|
|
|
|
success: function() {
|
|
|
|
dropdownSelector.highlightSuccess('#date-format-input-field');
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
dropdownSelector.highlightError('#date-format-input-field');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initTimeZoneSelector();
|
|
|
|
initDateFormatSelector();
|
|
|
|
notificationsSettings();
|
|
|
|
initTogglableSettingsForm();
|
2016-10-04 21:52:48 +08:00
|
|
|
})();
|