2017-04-06 15:34:42 +02:00
var settings _display = ( function ( ) {
var exports = { } ;
exports . set _up = function ( ) {
$ ( "#display-settings-status" ) . hide ( ) ;
2017-04-02 20:59:22 +02:00
$ ( "#user_timezone" ) . val ( page _params . timezone ) ;
2017-04-06 15:34:42 +02:00
$ ( "#default_language_modal [data-dismiss]" ) . click ( function ( ) {
$ ( "#default_language_modal" ) . fadeOut ( 300 ) ;
} ) ;
$ ( "#default_language_modal .language" ) . click ( function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( '#default_language_modal' ) . fadeOut ( 300 ) ;
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 ( ) ;
$ ( '#default_language_modal' ) . show ( ) . attr ( 'aria-hidden' , false ) ;
} ) ;
$ ( "#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 ( ) {
ui _report . success ( i18n . t ( "Your time zone have been set to " + timezone ) , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error updating time zone" ) , 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 ;
}