2017-04-06 15:34:42 +02:00
var settings _display = ( function ( ) {
var exports = { } ;
2017-11-14 20:42:31 +01:00
exports . set _night _mode = function ( bool ) {
var night _mode = bool ;
var data = { night _mode : JSON . stringify ( night _mode ) } ;
var context = {
enable _text : data . night _mode === "true" ?
i18n . t ( "enabled" ) :
i18n . t ( "disabled" ) ,
} ;
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
page _params . night _mode = night _mode ;
if ( overlays . settings _open ( ) ) {
ui _report . success ( i18n . t ( "Night mode __enable_text__!" , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
}
} ,
error : function ( xhr ) {
if ( overlays . settings _open ( ) ) {
ui _report . error ( i18n . t ( "Error updating night mode setting." ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
}
} ,
} ) ;
} ;
2017-04-06 15:34:42 +02:00
exports . set _up = function ( ) {
$ ( "#display-settings-status" ) . hide ( ) ;
2017-04-02 20:59:22 +02:00
$ ( "#user_timezone" ) . val ( page _params . timezone ) ;
2017-11-02 21:25:36 +01:00
$ ( ".emojiset_choice[value=" + page _params . emojiset + "]" ) . prop ( "checked" , true ) ;
2017-04-02 20:59:22 +02:00
2017-04-06 15:34:42 +02:00
$ ( "#default_language_modal [data-dismiss]" ) . click ( function ( ) {
2017-08-29 19:05:30 +02:00
overlays . close _modal ( 'default_language_modal' ) ;
2017-04-06 15:34:42 +02:00
} ) ;
$ ( "#default_language_modal .language" ) . click ( function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2017-08-29 19:05:30 +02:00
overlays . close _modal ( 'default_language_modal' ) ;
2017-04-06 15:34:42 +02:00
var data = { } ;
var $link = $ ( e . target ) . closest ( "a[data-code]" ) ;
var setting _value = $link . attr ( 'data-code' ) ;
data . default _language = JSON . stringify ( setting _value ) ;
var new _language = $link . attr ( 'data-name' ) ;
$ ( '#default_language_name' ) . text ( new _language ) ;
var context = { } ;
context . lang = new _language ;
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
ui _report . success ( i18n . t ( "__lang__ is now the default language! You will need to reload the window for your changes to take effect" , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating default language setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
$ ( '#default_language' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2017-08-29 19:05:30 +02:00
overlays . open _modal ( 'default_language_modal' ) ;
2017-04-06 15:34:42 +02:00
} ) ;
2017-07-07 18:15:10 +02:00
$ ( "#high_contrast_mode" ) . change ( function ( ) {
var high _contrast _mode = this . checked ;
var data = { } ;
data . high _contrast _mode = JSON . stringify ( high _contrast _mode ) ;
var context = { } ;
if ( data . high _contrast _mode === "true" ) {
context . enabled _or _disabled = i18n . t ( 'Enabled' ) ;
} else {
context . enabled _or _disabled = i18n . t ( 'Disabled' ) ;
}
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
ui _report . success ( i18n . t ( "High contrast mode __enabled_or_disabled__!" , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating high contrast setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
2017-04-06 15:34:42 +02:00
2017-11-14 20:42:31 +01:00
$ ( "#night_mode" ) . change ( function ( ) {
exports . set _night _mode ( this . checked ) ;
} ) ;
2017-04-06 15:34:42 +02:00
$ ( "#left_side_userlist" ) . change ( function ( ) {
var left _side _userlist = this . checked ;
var data = { } ;
data . left _side _userlist = JSON . stringify ( left _side _userlist ) ;
var context = { } ;
if ( data . left _side _userlist === "true" ) {
context . side = i18n . t ( 'left' ) ;
} else {
context . side = i18n . t ( 'right' ) ;
}
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
ui _report . success ( i18n . t ( "User list will appear on the __side__ hand side! You will need to reload the window for your changes to take effect." , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating user list placement setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
$ ( "#emoji_alt_code" ) . change ( function ( ) {
var emoji _alt _code = this . checked ;
var data = { } ;
data . emoji _alt _code = JSON . stringify ( emoji _alt _code ) ;
var context = { } ;
if ( data . emoji _alt _code === "true" ) {
context . text _or _images = i18n . t ( 'text' ) ;
} else {
context . text _or _images = i18n . t ( 'images' ) ;
}
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
ui _report . success ( i18n . t ( "Emoji reactions will appear as __text_or_images__!" , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating emoji appearance setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
$ ( "#twenty_four_hour_time" ) . change ( function ( ) {
var data = { } ;
var setting _value = $ ( "#twenty_four_hour_time" ) . is ( ":checked" ) ;
data . twenty _four _hour _time = JSON . stringify ( setting _value ) ;
var context = { } ;
if ( data . twenty _four _hour _time === "true" ) {
context . format = '24' ;
} else {
context . format = '12' ;
}
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
ui _report . success ( i18n . t ( "Time will now be displayed in the __format__-hour format!" , context ) ,
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating time format setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
2017-04-02 20:59:22 +02:00
$ ( "#user_timezone" ) . change ( function ( ) {
var data = { } ;
var timezone = this . value ;
data . timezone = JSON . stringify ( timezone ) ;
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
2017-09-05 09:00:32 +02:00
ui _report . success ( i18n . t ( "Your time zone have been set to __timezone__" , { timezone : timezone } ) , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
2017-04-02 20:59:22 +02:00
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating time zone" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
2017-04-23 20:47:18 +02:00
2017-11-02 21:25:36 +01:00
$ ( ".emojiset_choice" ) . click ( function ( ) {
2017-04-23 20:47:18 +02:00
var emojiset = $ ( this ) . val ( ) ;
var data = { } ;
data . emojiset = JSON . stringify ( emojiset ) ;
channel . patch ( {
url : '/json/settings/display' ,
data : data ,
success : function ( ) {
var spinner = $ ( "#emojiset_spinner" ) . expectOne ( ) ;
loading . make _indicator ( spinner , { text : 'Changing emojiset.' } ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error changing emojiset." ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
} ) ;
} ) ;
2017-04-06 15:34:42 +02:00
} ;
function _update _page ( ) {
$ ( "#twenty_four_hour_time" ) . prop ( 'checked' , page _params . twenty _four _hour _time ) ;
$ ( "#left_side_userlist" ) . prop ( 'checked' , page _params . left _side _userlist ) ;
$ ( "#emoji_alt_code" ) . prop ( 'checked' , page _params . emoji _alt _code ) ;
$ ( "#default_language_name" ) . text ( page _params . default _language _name ) ;
}
exports . update _page = function ( ) {
i18n . ensure _i18n ( _update _page ) ;
} ;
return exports ;
} ( ) ) ;
if ( typeof module !== 'undefined' ) {
module . exports = settings _display ;
}