2013-05-03 00:29:52 +02:00
var settings = ( function ( ) {
var exports = { } ;
2016-06-14 23:56:38 +02:00
var _streams _deferred = $ . Deferred ( ) ;
var streams = _streams _deferred . promise ( ) ; // promise to the full stream list
2013-05-03 00:29:52 +02:00
2014-02-24 16:50:03 +01:00
function build _stream _list ( $select , extra _names ) {
if ( extra _names === undefined ) {
extra _names = [ ] ;
2014-02-19 16:07:28 +01:00
}
2014-02-24 16:50:03 +01:00
streams . done ( function ( stream _items ) {
var build _option = function ( value _name ) {
return $ ( '<option>' )
. attr ( 'value' , value _name [ 0 ] )
. text ( value _name [ 1 ] ) ;
} ;
var public _names = _ . chain ( stream _items )
2016-12-03 03:08:47 +01:00
. where ( { invite _only : false } )
2014-02-24 16:50:03 +01:00
. pluck ( 'name' )
. map ( function ( x ) { return [ x , x ] ; } )
. value ( ) ;
var public _options = _ . chain ( extra _names . concat ( public _names ) )
. map ( build _option )
. reduce (
function ( $optgroup , option ) { return $optgroup . append ( option ) ; } ,
$ ( '<optgroup label="Public"/>' )
)
. value ( ) ;
var private _options = _ . chain ( stream _items )
2016-12-03 03:08:47 +01:00
. where ( { invite _only : true } )
2014-02-24 16:50:03 +01:00
. pluck ( 'name' )
. map ( function ( x ) { return [ x , x ] ; } )
. map ( build _option )
. reduce (
function ( $optgroup , option ) { return $optgroup . append ( option ) ; } ,
$ ( '<optgroup label="Private"/>' )
)
. value ( ) ;
2014-02-11 19:53:55 +01:00
2014-02-19 16:07:28 +01:00
$select . empty ( ) ;
2014-02-24 16:50:03 +01:00
$select . append ( public _options ) ;
$select . append ( private _options ) ;
2014-02-19 16:07:28 +01:00
} ) ;
}
2013-06-14 20:03:54 +02:00
2014-02-19 16:07:28 +01:00
function add _bot _row ( info ) {
info . id _suffix = _ . uniqueId ( '_bot_' ) ;
2013-07-05 21:52:38 +02:00
var row = $ ( templates . render ( 'bot_avatar_row' , info ) ) ;
2014-02-19 16:07:28 +01:00
var default _sending _stream _select = row . find ( 'select[name=bot_default_sending_stream]' ) ;
var default _events _register _stream _select = row . find ( 'select[name=bot_default_events_register_stream]' ) ;
if ( ! feature _flags . new _bot _ui ) {
row . find ( '.new-bot-ui' ) . hide ( ) ;
}
var to _extra _options = [ ] ;
if ( info . default _sending _stream === null ) {
to _extra _options . push ( [ '' , 'No default selected' ] ) ;
}
build _stream _list (
default _sending _stream _select ,
to _extra _options
) ;
default _sending _stream _select . val (
info . default _sending _stream ,
to _extra _options
) ;
var events _extra _options = [ [ '__all_public__' , 'All public streams' ] ] ;
if ( info . default _events _register _stream === null && ! info . default _all _public _streams ) {
events _extra _options . unshift ( [ '' , 'No default selected' ] ) ;
}
build _stream _list (
default _events _register _stream _select ,
events _extra _options
) ;
if ( info . default _all _public _streams ) {
default _events _register _stream _select . val ( '__all_public__' ) ;
} else {
default _events _register _stream _select . val ( info . default _events _register _stream ) ;
}
2013-07-05 20:59:25 +02:00
$ ( '#bots_list' ) . append ( row ) ;
$ ( '#bots_list' ) . show ( ) ;
2013-05-03 00:29:52 +02:00
}
2016-12-02 15:16:33 +01:00
function add _bot _default _streams _to _form ( formData , default _sending _stream ,
default _events _register _stream ) {
2014-02-19 16:08:18 +01:00
if ( ! feature _flags . new _bot _ui ) { return ; }
if ( default _sending _stream !== '' ) {
formData . append ( 'default_sending_stream' , default _sending _stream ) ;
}
if ( default _events _register _stream === '__all_public__' ) {
formData . append ( 'default_all_public_streams' , JSON . stringify ( true ) ) ;
formData . append ( 'default_events_register_stream' , null ) ;
} else if ( default _events _register _stream !== '' ) {
formData . append ( 'default_all_public_streams' , JSON . stringify ( false ) ) ;
formData . append ( 'default_events_register_stream' , default _events _register _stream ) ;
}
}
2013-05-03 00:29:52 +02:00
function is _local _part ( value , element ) {
// Adapted from Django's EmailValidator
return this . optional ( element ) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i . test ( value ) ;
}
2014-02-27 18:27:58 +01:00
function render _bots ( ) {
$ ( '#bots_list' ) . empty ( ) ;
_ . each ( bot _data . get _editable ( ) , function ( elem ) {
add _bot _row ( {
name : elem . full _name ,
email : elem . email ,
avatar _url : elem . avatar _url ,
api _key : elem . api _key ,
2016-12-07 18:38:59 +01:00
zuliprc : 'zuliprc' , // Most browsers do not allow filename starting with `.`
2014-02-27 18:27:58 +01:00
default _sending _stream : elem . default _sending _stream ,
default _events _register _stream : elem . default _events _register _stream ,
2017-01-12 00:17:43 +01:00
default _all _public _streams : elem . default _all _public _streams ,
2014-02-27 18:27:58 +01:00
} ) ;
} ) ;
}
2017-02-13 23:40:00 +01:00
exports . update _email = function ( new _email ) {
var email _input = $ ( '#email_value' ) ;
if ( email _input ) {
email _input . text ( new _email ) ;
}
} ;
2016-12-07 18:38:59 +01:00
exports . generate _zuliprc _uri = function ( email , api _key ) {
var data = settings . generate _zuliprc _content ( email , api _key ) ;
return "data:application/octet-stream;charset=utf-8," + encodeURIComponent ( data ) ;
} ;
exports . generate _zuliprc _content = function ( email , api _key ) {
return "[api]" +
"\nemail=" + email +
"\nkey=" + api _key +
"\nsite=" + page _params . realm _uri +
// Some tools would not work in files without a trailing new line.
"\n" ;
} ;
2017-03-01 01:31:33 +01:00
$ ( "body" ) . ready ( function ( ) {
var $sidebar = $ ( ".form-sidebar" ) ;
var $targets = $sidebar . find ( "[data-target]" ) ;
var $title = $sidebar . find ( ".title h1" ) ;
var is _open = false ;
var close _sidebar = function ( ) {
$sidebar . removeClass ( "show" ) ;
is _open = false ;
} ;
exports . trigger _sidebar = function ( target ) {
$targets . hide ( ) ;
var $target = $ ( ".form-sidebar" ) . find ( "[data-target='" + target + "']" ) ;
$title . text ( $target . attr ( "data-title" ) ) ;
$target . show ( ) ;
$sidebar . addClass ( "show" ) ;
is _open = true ;
} ;
$ ( ".form-sidebar .exit" ) . click ( function ( e ) {
close _sidebar ( ) ;
e . stopPropagation ( ) ;
} ) ;
$ ( "body" ) . click ( function ( e ) {
if ( is _open && ! $ ( e . target ) . within ( ".form-sidebar" ) ) {
close _sidebar ( ) ;
}
} ) ;
$ ( "body" ) . on ( "click" , "[data-sidebar-form]" , function ( e ) {
exports . trigger _sidebar ( $ ( this ) . attr ( "data-sidebar-form" ) ) ;
e . stopPropagation ( ) ;
} ) ;
$ ( "body" ) . on ( "click" , "[data-sidebar-form-close]" , close _sidebar ) ;
} ) ;
2016-06-10 09:03:36 +02:00
function _setup _page ( ) {
2014-02-19 16:07:28 +01:00
// To build the edit bot streams dropdown we need both the bot and stream
// API results. To prevent a race streams will be initialized to a promise
// at page load. This promise will be resolved with a list of streams after
// the first settings page load. build_stream_list then adds a callback to
// the promise, which in most cases will already be resolved.
2016-12-03 01:12:52 +01:00
var tab = ( function ( ) {
var tab = false ;
var hash _sequence = window . location . hash . split ( /\// ) ;
if ( /#*(settings)/ . test ( hash _sequence [ 0 ] ) ) {
tab = hash _sequence [ 1 ] ;
return tab || "your-account" ;
}
return tab ;
} ( ) ) ;
2016-06-14 23:56:38 +02:00
if ( _streams _deferred . state ( ) !== "resolved" ) {
2014-02-19 16:07:28 +01:00
channel . get ( {
url : '/json/streams' ,
success : function ( data ) {
2016-06-14 23:56:38 +02:00
_streams _deferred . resolve ( data . streams ) ;
2014-02-19 16:07:28 +01:00
build _stream _list ( $ ( '#create_bot_default_sending_stream' ) ) ;
build _stream _list (
$ ( '#create_bot_default_events_register_stream' ) ,
[ [ '__all_public__' , 'All public streams' ] ]
) ;
2017-01-12 00:17:43 +01:00
} ,
2014-02-19 16:07:28 +01:00
} ) ;
}
2016-12-07 18:38:59 +01:00
// Most browsers do not allow filenames to start with `.` without the user manually changing it.
2017-01-20 23:49:20 +01:00
// So we use zuliprc, not .zuliprc.
var settings _tab = templates . render ( 'settings_tab' , {
full _name : people . my _full _name ( ) ,
page _params : page _params ,
zuliprc : 'zuliprc' ,
} ) ;
2016-12-03 01:12:52 +01:00
$ ( ".settings-box" ) . html ( settings _tab ) ;
2014-02-13 23:47:57 +01:00
$ ( "#settings-status" ) . hide ( ) ;
$ ( "#notify-settings-status" ) . hide ( ) ;
2015-08-19 22:35:46 +02:00
$ ( "#display-settings-status" ) . hide ( ) ;
2014-02-13 23:47:57 +01:00
$ ( "#ui-settings-status" ) . hide ( ) ;
2014-03-04 23:37:29 +01:00
alert _words _ui . set _up _alert _words ( ) ;
2016-12-28 14:46:42 +01:00
attachments _ui . set _up _attachments ( ) ;
2014-03-04 23:37:29 +01:00
2014-02-13 23:47:57 +01:00
$ ( "#api_key_value" ) . text ( "" ) ;
$ ( "#get_api_key_box" ) . hide ( ) ;
$ ( "#show_api_key_box" ) . hide ( ) ;
$ ( "#api_key_button_box" ) . show ( ) ;
2016-12-03 01:12:52 +01:00
if ( tab ) {
exports . launch _page ( tab ) ;
}
2014-02-13 23:47:57 +01:00
function clear _password _change ( ) {
// Clear the password boxes so that passwords don't linger in the DOM
// for an XSS attacker to find.
$ ( '#old_password, #new_password, #confirm_password' ) . val ( '' ) ;
}
clear _password _change ( ) ;
2016-12-02 14:06:06 +01:00
$ ( '#api_key_button' ) . click ( function ( ) {
2014-02-13 23:47:57 +01:00
if ( page _params . password _auth _enabled !== false ) {
$ ( "#get_api_key_box" ) . show ( ) ;
} else {
// Skip the password prompt step
$ ( "#get_api_key_box form" ) . submit ( ) ;
}
$ ( "#api_key_button_box" ) . hide ( ) ;
} ) ;
$ ( '#pw_change_link' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
$ ( '#pw_change_link' ) . hide ( ) ;
$ ( '#pw_change_controls' ) . show ( ) ;
2016-06-04 02:19:07 +02:00
if ( page _params . password _auth _enabled !== false ) {
// zxcvbn.js is pretty big, and is only needed on password
// change, so load it asynchronously.
2017-02-07 01:29:00 +01:00
var zxcvbn _path = '/static/min/zxcvbn.js' ;
if ( page _params . development _environment ) {
// Usually the Django templates handle this path stuff
// for us, but in this case we need to hardcode it.
zxcvbn _path = '/static/node_modules/zxcvbn/dist/zxcvbn.js' ;
}
$ . getScript ( zxcvbn _path , function ( ) {
2016-06-04 02:19:07 +02:00
$ ( '#pw_strength .bar' ) . removeClass ( "fade" ) ;
} ) ;
}
2014-02-13 23:47:57 +01:00
} ) ;
$ ( '#new_password' ) . on ( 'change keyup' , function ( ) {
2017-01-09 18:04:23 +01:00
var field = $ ( '#new_password' ) ;
password _quality ( field . val ( ) , $ ( '#pw_strength .bar' ) , field ) ;
2014-02-13 23:47:57 +01:00
} ) ;
2013-10-28 15:49:38 +01:00
2015-08-20 09:11:11 +02:00
if ( ! page _params . show _digest _email ) {
$ ( "#other_notifications" ) . hide ( ) ;
2013-12-02 03:01:09 +01:00
}
2014-02-11 19:53:55 +01:00
if ( ! feature _flags . new _bot _ui ) {
$ ( '.new-bot-ui' ) . hide ( ) ;
}
2013-10-28 15:49:38 +01:00
2015-08-21 01:23:53 +02:00
function settings _change _error ( message , xhr ) {
// Scroll to the top so the error message is visible.
// We would scroll anyway if we end up submitting the form.
viewport . scrollTop ( 0 ) ;
ui . report _error ( message , xhr , $ ( '#settings-status' ) . expectOne ( ) ) ;
}
2014-02-13 23:47:57 +01:00
2015-08-21 01:23:53 +02:00
function settings _change _success ( message ) {
2014-02-13 23:47:57 +01:00
// Scroll to the top so the error message is visible.
// We would scroll anyway if we end up submitting the form.
viewport . scrollTop ( 0 ) ;
2015-08-21 01:23:53 +02:00
ui . report _success ( message , $ ( '#settings-status' ) . expectOne ( ) ) ;
2014-02-13 23:47:57 +01:00
}
$ ( "form.your-account-settings" ) . ajaxForm ( {
dataType : 'json' , // This seems to be ignored. We still get back an xhr.
2016-12-02 14:06:06 +01:00
beforeSubmit : function ( ) {
2014-02-13 23:47:57 +01:00
if ( page _params . password _auth _enabled !== false ) {
// FIXME: Check that the two password fields match
// FIXME: Use the same jQuery validation plugin as the signup form?
2017-01-09 18:04:23 +01:00
var field = $ ( '#new_password' ) ;
2014-02-13 23:47:57 +01:00
var new _pw = $ ( '#new_password' ) . val ( ) ;
if ( new _pw !== '' ) {
2017-01-09 18:04:23 +01:00
var password _ok = password _quality ( new _pw , undefined , field ) ;
2014-02-13 23:47:57 +01:00
if ( password _ok === undefined ) {
// zxcvbn.js didn't load, for whatever reason.
settings _change _error (
'An internal error occurred; try reloading the page. ' +
'Sorry for the trouble!' ) ;
return false ;
} else if ( ! password _ok ) {
settings _change _error ( 'New password is too weak' ) ;
return false ;
}
}
}
return true ;
} ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2015-08-21 01:23:53 +02:00
settings _change _success ( "Updated settings!" ) ;
2014-02-13 23:47:57 +01:00
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2015-08-21 01:23:53 +02:00
settings _change _error ( "Error changing settings" , xhr ) ;
2014-02-13 23:47:57 +01:00
} ,
2016-12-02 14:06:06 +01:00
complete : function ( ) {
2014-02-13 23:47:57 +01:00
// Whether successful or not, clear the password boxes.
// TODO: Clear these earlier, while the request is still pending.
clear _password _change ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2014-02-13 23:47:57 +01:00
} ) ;
2016-12-02 14:06:06 +01:00
function update _notification _settings _success ( resp , statusText , xhr ) {
2016-08-24 23:56:23 +02:00
var result = JSON . parse ( xhr . responseText ) ;
2014-02-13 23:47:57 +01:00
var notify _settings _status = $ ( '#notify-settings-status' ) . expectOne ( ) ;
// Stream notification settings.
if ( result . enable _stream _desktop _notifications !== undefined ) {
2016-12-02 15:16:33 +01:00
page _params . stream _desktop _notifications _enabled =
result . enable _stream _desktop _notifications ;
2014-02-13 23:47:57 +01:00
}
if ( result . enable _stream _sounds !== undefined ) {
page _params . stream _sounds _enabled = result . enable _stream _sounds ;
}
// PM and @-mention notification settings.
if ( result . enable _desktop _notifications !== undefined ) {
page _params . desktop _notifications _enabled = result . enable _desktop _notifications ;
}
if ( result . enable _sounds !== undefined ) {
page _params . sounds _enabled = result . enable _sounds ;
}
if ( result . enable _offline _email _notifications !== undefined ) {
2016-12-02 15:16:33 +01:00
page _params . enable _offline _email _notifications =
result . enable _offline _email _notifications ;
2014-02-13 23:47:57 +01:00
}
if ( result . enable _offline _push _notifications !== undefined ) {
2016-12-02 15:16:33 +01:00
page _params . enable _offline _push _notifications =
result . enable _offline _push _notifications ;
2014-02-13 23:47:57 +01:00
}
2016-09-19 22:55:18 +02:00
if ( result . enable _online _push _notifications !== undefined ) {
page _params . enable _online _push _notifications = result . enable _online _push _notifications ;
}
2016-12-07 17:29:12 +01:00
if ( result . pm _content _in _desktop _notifications !== undefined ) {
page _params . pm _content _in _desktop _notifications
= result . pm _content _in _desktop _notifications ;
}
2014-02-13 23:47:57 +01:00
// Other notification settings.
if ( result . enable _digest _emails !== undefined ) {
page _params . enable _digest _emails = result . enable _digest _emails ;
}
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Updated notification settings!" ) , notify _settings _status ) ;
2014-02-13 23:47:57 +01:00
}
2016-12-02 14:06:06 +01:00
function update _notification _settings _error ( xhr ) {
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error changing settings" ) , xhr , $ ( '#notify-settings-status' ) . expectOne ( ) ) ;
2014-02-13 23:47:57 +01:00
}
function post _notify _settings _changes ( notification _changes , success _func ,
error _func ) {
2016-12-22 18:29:14 +01:00
return channel . patch ( {
url : "/json/settings/notifications" ,
2014-02-13 23:47:57 +01:00
data : notification _changes ,
success : success _func ,
2017-01-12 00:17:43 +01:00
error : error _func ,
2014-02-13 23:47:57 +01:00
} ) ;
}
$ ( "#change_notification_settings" ) . on ( "click" , function ( e ) {
2016-12-14 20:38:41 +01:00
e . preventDefault ( ) ;
2014-02-13 23:47:57 +01:00
var updated _settings = { } ;
_ . each ( [ "enable_stream_desktop_notifications" , "enable_stream_sounds" ,
2016-12-07 17:29:12 +01:00
"enable_desktop_notifications" , "pm_content_in_desktop_notifications" , "enable_sounds" ,
2014-02-13 23:47:57 +01:00
"enable_offline_email_notifications" ,
2016-09-19 22:55:18 +02:00
"enable_offline_push_notifications" , "enable_online_push_notifications" ,
"enable_digest_emails" ] ,
2014-02-13 23:47:57 +01:00
function ( setting ) {
updated _settings [ setting ] = $ ( "#" + setting ) . is ( ":checked" ) ;
} ) ;
post _notify _settings _changes ( updated _settings ,
update _notification _settings _success ,
update _notification _settings _error ) ;
} ) ;
function update _global _stream _setting ( notification _type , new _setting ) {
var data = { } ;
data [ notification _type ] = new _setting ;
2016-12-22 18:29:14 +01:00
channel . patch ( {
url : "/json/settings/notifications" ,
2014-02-13 23:47:57 +01:00
data : data ,
success : update _notification _settings _success ,
2017-01-12 00:17:43 +01:00
error : update _notification _settings _error ,
2014-02-13 23:47:57 +01:00
} ) ;
}
function update _desktop _notification _setting ( new _setting ) {
update _global _stream _setting ( "enable_stream_desktop_notifications" , new _setting ) ;
subs . set _all _stream _desktop _notifications _to ( new _setting ) ;
}
function update _audible _notification _setting ( new _setting ) {
update _global _stream _setting ( "enable_stream_sounds" , new _setting ) ;
subs . set _all _stream _audible _notifications _to ( new _setting ) ;
}
function maybe _bulk _update _stream _notification _setting ( notification _checkbox ,
propagate _setting _function ) {
var html = templates . render ( "propagate_notification_change" ) ;
var control _group = notification _checkbox . closest ( ".control-group" ) ;
var checkbox _status = notification _checkbox . is ( ":checked" ) ;
control _group . find ( ".propagate_stream_notifications_change" ) . html ( html ) ;
2016-12-02 14:06:06 +01:00
control _group . find ( ".yes_propagate_notifications" ) . on ( "click" , function ( ) {
2014-02-13 23:47:57 +01:00
propagate _setting _function ( checkbox _status ) ;
control _group . find ( ".propagate_stream_notifications_change" ) . empty ( ) ;
} ) ;
2016-12-02 14:06:06 +01:00
control _group . find ( ".no_propagate_notifications" ) . on ( "click" , function ( ) {
2014-02-13 23:47:57 +01:00
control _group . find ( ".propagate_stream_notifications_change" ) . empty ( ) ;
} ) ;
}
2016-12-02 14:06:06 +01:00
$ ( "#enable_stream_desktop_notifications" ) . on ( "click" , function ( ) {
2014-02-13 23:47:57 +01:00
var notification _checkbox = $ ( "#enable_stream_desktop_notifications" ) ;
maybe _bulk _update _stream _notification _setting ( notification _checkbox ,
update _desktop _notification _setting ) ;
} ) ;
2016-12-02 14:06:06 +01:00
$ ( "#enable_stream_sounds" ) . on ( "click" , function ( ) {
2014-02-13 23:47:57 +01:00
var notification _checkbox = $ ( "#enable_stream_sounds" ) ;
maybe _bulk _update _stream _notification _setting ( notification _checkbox ,
update _audible _notification _setting ) ;
} ) ;
2015-08-20 23:59:44 +02:00
$ ( "#left_side_userlist" ) . change ( function ( ) {
var left _side _userlist = this . checked ;
var data = { } ;
data . left _side _userlist = JSON . stringify ( left _side _userlist ) ;
2016-07-01 11:55:23 +02:00
var context = { } ;
if ( data . left _side _userlist === "true" ) {
2016-10-10 06:46:09 +02:00
context . side = i18n . t ( 'left' ) ;
2016-07-01 11:55:23 +02:00
} else {
2016-10-10 06:46:09 +02:00
context . side = i18n . t ( 'right' ) ;
2016-07-01 11:55:23 +02:00
}
2015-08-20 23:59:44 +02:00
channel . patch ( {
2016-12-24 11:44:41 +01:00
url : '/json/settings/display' ,
2015-08-20 23:59:44 +02:00
data : data ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2016-07-01 11:55:23 +02:00
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 ) ,
2015-08-20 23:59:44 +02:00
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-07-01 11:55:23 +02:00
ui . report _error ( i18n . t ( "Error updating user list placement setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
2017-01-12 00:17:43 +01:00
} ,
2015-08-20 23:59:44 +02:00
} ) ;
} ) ;
2015-08-19 22:35:46 +02:00
$ ( "#twenty_four_hour_time" ) . change ( function ( ) {
var data = { } ;
2015-09-20 08:17:36 +02:00
var setting _value = $ ( "#twenty_four_hour_time" ) . is ( ":checked" ) ;
data . twenty _four _hour _time = JSON . stringify ( setting _value ) ;
2016-07-01 11:55:23 +02:00
var context = { } ;
if ( data . twenty _four _hour _time === "true" ) {
context . format = '24' ;
} else {
context . format = '12' ;
}
2015-08-19 22:35:46 +02:00
channel . patch ( {
2016-12-21 05:15:55 +01:00
url : '/json/settings/display' ,
2015-08-19 22:35:46 +02:00
data : data ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2016-07-01 11:55:23 +02:00
ui . report _success ( i18n . t ( "Time will be displayed in the __format__-hour format! You will need to reload the window for your changes to take effect" , context ) ,
2015-08-21 01:23:53 +02:00
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
2015-09-20 08:17:36 +02:00
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-07-01 11:55:23 +02:00
ui . report _error ( i18n . t ( "Error updating time format setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
2017-01-12 00:17:43 +01:00
} ,
2016-06-23 11:32:45 +02:00
} ) ;
} ) ;
2016-12-03 01:12:52 +01:00
$ ( "#default_language_modal [data-dismiss]" ) . click ( function ( ) {
$ ( "#default_language_modal" ) . fadeOut ( 300 ) ;
} ) ;
2016-08-02 15:03:42 +02:00
$ ( "#default_language_modal .language" ) . click ( function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2016-12-03 01:12:52 +01:00
$ ( '#default_language_modal' ) . fadeOut ( 300 ) ;
2016-08-02 15:03:42 +02:00
2016-06-23 11:32:45 +02:00
var data = { } ;
2016-10-19 22:20:21 +02:00
var $link = $ ( e . target ) . closest ( "a[data-code]" ) ;
var setting _value = $link . attr ( 'data-code' ) ;
2016-06-23 11:32:45 +02:00
data . default _language = JSON . stringify ( setting _value ) ;
2016-08-02 15:03:42 +02:00
2016-10-19 22:20:21 +02:00
var new _language = $link . attr ( 'data-name' ) ;
2016-08-02 15:03:42 +02:00
$ ( '#default_language_name' ) . text ( new _language ) ;
2016-07-01 11:55:23 +02:00
var context = { } ;
2016-08-02 15:03:42 +02:00
context . lang = new _language ;
2016-06-23 11:32:45 +02:00
channel . patch ( {
2016-12-22 09:54:27 +01:00
url : '/json/settings/display' ,
2016-06-23 11:32:45 +02:00
data : data ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2016-07-01 11:55:23 +02:00
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 ) ,
2016-06-23 11:32:45 +02:00
$ ( '#display-settings-status' ) . expectOne ( ) ) ;
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-07-01 11:55:23 +02:00
ui . report _error ( i18n . t ( "Error updating default language setting" ) , xhr , $ ( '#display-settings-status' ) . expectOne ( ) ) ;
2017-01-12 00:17:43 +01:00
} ,
2015-08-19 22:35:46 +02:00
} ) ;
} ) ;
2017-01-20 12:27:38 +01:00
$ ( '#change_email_button' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( '#change_email_modal' ) . modal ( 'hide' ) ;
var data = { } ;
data . email = $ ( '.email_change_container' ) . find ( "input[name='email']" ) . val ( ) ;
channel . patch ( {
url : '/json/settings/change' ,
data : data ,
success : function ( data ) {
if ( 'account_email' in data ) {
settings _change _success ( data . account _email ) ;
} else {
settings _change _error ( i18n . t ( "Error changing settings: No new data supplied." ) ) ;
}
} ,
error : function ( xhr ) {
settings _change _error ( "Error changing settings" , xhr ) ;
} ,
} ) ;
} ) ;
2016-08-02 15:03:42 +02:00
$ ( '#default_language' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2016-12-03 01:12:52 +01:00
$ ( '#default_language_modal' ) . show ( ) . attr ( 'aria-hidden' , false ) ;
2016-08-02 15:03:42 +02:00
} ) ;
2015-08-19 22:35:46 +02:00
2017-01-20 12:27:38 +01:00
$ ( '#change_email' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( '#change_email_modal' ) . modal ( 'show' ) ;
var email = $ ( '#email_value' ) . text ( ) ;
$ ( '.email_change_container' ) . find ( "input[name='email']" ) . val ( email ) ;
} ) ;
2016-10-13 20:09:32 +02:00
$ ( "#user_deactivate_account_button" ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( "#deactivate_self_modal" ) . modal ( "show" ) ;
} ) ;
2016-12-02 14:06:06 +01:00
$ ( "#do_deactivate_self_button" ) . on ( 'click' , function ( ) {
2016-10-13 20:09:32 +02:00
$ ( "#deactivate_self_modal" ) . modal ( "hide" ) ;
channel . del ( {
url : '/json/users/me' ,
success : function ( ) {
window . location . href = "/login" ;
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-10-13 20:09:32 +02:00
ui . report _error ( i18n . t ( "Error deactivating account" ) , xhr , $ ( '#settings-status' ) . expectOne ( ) ) ;
2017-01-12 00:17:43 +01:00
} ,
2016-10-13 20:09:32 +02:00
} ) ;
} ) ;
2014-02-13 23:47:57 +01:00
$ ( "#get_api_key_box" ) . hide ( ) ;
$ ( "#show_api_key_box" ) . hide ( ) ;
$ ( "#get_api_key_box form" ) . ajaxForm ( {
dataType : 'json' , // This seems to be ignored. We still get back an xhr.
2016-12-02 14:06:06 +01:00
success : function ( resp , statusText , xhr ) {
2016-08-24 23:56:23 +02:00
var result = JSON . parse ( xhr . responseText ) ;
2014-02-13 23:47:57 +01:00
var settings _status = $ ( '#settings-status' ) . expectOne ( ) ;
$ ( "#get_api_key_password" ) . val ( "" ) ;
$ ( "#api_key_value" ) . text ( result . api _key ) ;
$ ( "#show_api_key_box" ) . show ( ) ;
$ ( "#get_api_key_box" ) . hide ( ) ;
settings _status . hide ( ) ;
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error getting API key" ) , xhr , $ ( '#settings-status' ) . expectOne ( ) ) ;
2014-02-13 23:47:57 +01:00
$ ( "#show_api_key_box" ) . hide ( ) ;
$ ( "#get_api_key_box" ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2014-02-13 23:47:57 +01:00
} ) ;
2013-10-28 15:49:38 +01:00
function upload _avatar ( file _input ) {
var form _data = new FormData ( ) ;
form _data . append ( 'csrfmiddlewaretoken' , csrf _token ) ;
jQuery . each ( file _input [ 0 ] . files , function ( i , file ) {
form _data . append ( 'file-' + i , file ) ;
} ) ;
var spinner = $ ( "#upload_avatar_spinner" ) . expectOne ( ) ;
2014-03-13 15:03:01 +01:00
loading . make _indicator ( spinner , { text : 'Uploading avatar.' } ) ;
2013-10-28 15:49:38 +01:00
2016-12-21 21:29:46 +01:00
channel . put ( {
url : '/json/users/me/avatar' ,
2013-10-28 15:49:38 +01:00
data : form _data ,
cache : false ,
processData : false ,
contentType : false ,
success : function ( data ) {
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( $ ( "#upload_avatar_spinner" ) ) ;
2017-02-17 00:44:21 +01:00
$ ( "#user-settings-avatar" ) . expectOne ( ) . attr ( "src" , data . avatar _url ) ;
2016-12-21 18:34:03 +01:00
$ ( "#user_avatar_delete_button" ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-10-28 15:49:38 +01:00
} ) ;
}
avatar . build _user _avatar _widget ( upload _avatar ) ;
2014-03-27 23:50:37 +01:00
if ( page _params . name _changes _disabled ) {
2016-12-29 22:06:10 +01:00
$ ( ".name_change_container" ) . hide ( ) ;
2013-08-05 02:29:01 +02:00
}
2013-05-03 00:29:52 +02:00
2014-02-27 18:27:58 +01:00
// TODO: render bots xxxx
render _bots ( ) ;
$ ( document ) . on ( 'zulip.bot_data_changed' , render _bots ) ;
2013-05-03 00:29:52 +02:00
$ . validator . addMethod ( "bot_local_part" ,
function ( value , element ) {
return is _local _part . call ( this , value + "-bot" , element ) ;
} ,
"Please only use characters that are valid in an email address" ) ;
2013-06-28 17:41:18 +02:00
2013-08-01 15:43:48 +02:00
var create _avatar _widget = avatar . build _bot _create _widget ( ) ;
2013-06-28 17:41:18 +02:00
2013-05-03 00:29:52 +02:00
$ ( '#create_bot_form' ) . validate ( {
errorClass : 'text-error' ,
success : function ( ) {
$ ( '#bot_table_error' ) . hide ( ) ;
} ,
submitHandler : function ( ) {
2013-06-14 20:03:54 +02:00
var full _name = $ ( '#create_bot_name' ) . val ( ) ;
2016-09-14 02:20:13 +02:00
var short _name = $ ( '#create_bot_short_name' ) . val ( ) || $ ( '#create_bot_short_name' ) . text ( ) ;
2014-02-11 19:53:55 +01:00
var default _sending _stream = $ ( '#create_bot_default_sending_stream' ) . val ( ) ;
2014-02-12 23:35:15 +01:00
var default _events _register _stream = $ ( '#create_bot_default_events_register_stream' ) . val ( ) ;
2013-06-14 20:03:54 +02:00
var formData = new FormData ( ) ;
2014-02-13 00:06:34 +01:00
2013-06-14 20:03:54 +02:00
formData . append ( 'csrfmiddlewaretoken' , csrf _token ) ;
formData . append ( 'full_name' , full _name ) ;
formData . append ( 'short_name' , short _name ) ;
2016-12-02 15:16:33 +01:00
add _bot _default _streams _to _form ( formData , default _sending _stream ,
default _events _register _stream ) ;
2013-07-05 17:43:56 +02:00
jQuery . each ( $ ( '#bot_avatar_file_input' ) [ 0 ] . files , function ( i , file ) {
2013-06-14 20:03:54 +02:00
formData . append ( 'file-' + i , file ) ;
} ) ;
2013-11-16 20:03:56 +01:00
$ ( '#create_bot_button' ) . val ( 'Adding bot...' ) . prop ( 'disabled' , true ) ;
2013-12-18 19:55:18 +01:00
channel . post ( {
2014-02-11 16:42:19 +01:00
url : '/json/bots' ,
2013-06-14 20:03:54 +02:00
data : formData ,
cache : false ,
processData : false ,
contentType : false ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2013-05-03 00:29:52 +02:00
$ ( '#bot_table_error' ) . hide ( ) ;
$ ( '#create_bot_name' ) . val ( '' ) ;
$ ( '#create_bot_short_name' ) . val ( '' ) ;
2013-06-14 20:03:54 +02:00
$ ( '#create_bot_button' ) . show ( ) ;
2013-08-01 15:43:48 +02:00
create _avatar _widget . clear ( ) ;
2013-05-03 00:29:52 +02:00
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2013-05-03 00:29:52 +02:00
$ ( '#bot_table_error' ) . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
2013-11-16 20:03:56 +01:00
} ,
2016-12-02 14:06:06 +01:00
complete : function ( ) {
2013-11-16 20:03:56 +01:00
$ ( '#create_bot_button' ) . val ( 'Create bot' ) . prop ( 'disabled' , false ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-05-03 00:29:52 +02:00
} ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-05-03 00:29:52 +02:00
} ) ;
2013-07-10 17:26:30 +02:00
$ ( "#bots_list" ) . on ( "click" , "button.delete_bot" , function ( e ) {
2013-10-21 01:04:25 +02:00
var email = $ ( e . currentTarget ) . data ( 'email' ) ;
2013-12-18 19:55:18 +01:00
channel . del ( {
2014-02-11 17:14:33 +01:00
url : '/json/bots/' + encodeURIComponent ( email ) ,
2013-07-10 17:26:30 +02:00
success : function ( ) {
2013-10-21 01:04:25 +02:00
var row = $ ( e . currentTarget ) . closest ( "li" ) ;
2013-07-10 21:40:01 +02:00
row . hide ( 'slow' , function ( ) { row . remove ( ) ; } ) ;
2013-07-10 22:30:03 +02:00
} ,
error : function ( xhr ) {
$ ( '#bot_delete_error' ) . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-07-10 17:26:30 +02:00
} ) ;
} ) ;
2013-07-22 17:12:35 +02:00
2013-07-26 05:07:59 +02:00
$ ( "#bots_list" ) . on ( "click" , "button.regenerate_bot_api_key" , function ( e ) {
2013-10-21 01:04:25 +02:00
var email = $ ( e . currentTarget ) . data ( 'email' ) ;
2013-12-18 19:55:18 +01:00
channel . post ( {
2013-07-22 17:12:35 +02:00
url : '/json/bots/' + encodeURIComponent ( email ) + '/api_key/regenerate' ,
2014-01-07 23:40:31 +01:00
idempotent : true ,
2013-07-22 17:12:35 +02:00
success : function ( data ) {
2013-10-21 01:04:25 +02:00
var row = $ ( e . currentTarget ) . closest ( "li" ) ;
2013-07-22 17:12:35 +02:00
row . find ( ".api_key" ) . find ( ".value" ) . text ( data . api _key ) ;
row . find ( "api_key_error" ) . hide ( ) ;
} ,
error : function ( xhr ) {
2013-10-21 01:04:25 +02:00
var row = $ ( e . currentTarget ) . closest ( "li" ) ;
2013-07-22 17:12:35 +02:00
row . find ( ".api_key_error" ) . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-07-22 17:12:35 +02:00
} ) ;
} ) ;
2013-07-22 20:09:34 +02:00
2013-07-29 16:27:18 +02:00
var image _version = 0 ;
2013-07-22 20:09:34 +02:00
2017-03-01 01:31:33 +01:00
var avatar _widget = avatar . build _bot _edit _widget ( $ ( "#settings_page" ) ) ;
2013-07-22 20:09:34 +02:00
$ ( "#bots_list" ) . on ( "click" , "button.open_edit_bot_form" , function ( e ) {
2017-02-25 08:49:12 +01:00
var users _list = people . get _realm _persons ( ) . filter ( function ( person ) {
return ! person . is _bot ;
} ) ;
2013-10-21 01:04:25 +02:00
var li = $ ( e . currentTarget ) . closest ( 'li' ) ;
2013-07-22 20:09:34 +02:00
var edit _div = li . find ( 'div.edit_bot' ) ;
2017-03-01 01:31:33 +01:00
var form = $ ( '#settings_page .edit_bot_form' ) ;
2013-07-22 20:09:34 +02:00
var image = li . find ( ".image" ) ;
2017-03-01 01:31:33 +01:00
var bot _info = li ;
2013-07-22 20:09:34 +02:00
var reset _edit _bot = li . find ( ".reset_edit_bot" ) ;
2017-02-25 08:49:12 +01:00
var owner _select = $ ( templates . render ( "bot_owner_select" , { users _list : users _list } ) ) ;
2013-07-22 20:09:34 +02:00
var old _full _name = bot _info . find ( ".name" ) . text ( ) ;
2017-02-25 08:49:12 +01:00
var old _owner = bot _data . get ( bot _info . find ( ".email .value" ) . text ( ) ) . owner ;
2017-03-01 01:31:33 +01:00
var bot _email = bot _info . find ( ".email .value" ) . text ( ) ;
$ ( "#settings_page .edit_bot .edit_bot_name" ) . val ( old _full _name ) ;
$ ( "#settings_page .edit_bot .select-form" ) . text ( "" ) . append ( owner _select ) ;
$ ( "#settings_page .edit_bot .edit-bot-owner select" ) . val ( old _owner ) ;
$ ( "#settings_page .edit_bot_form" ) . attr ( "data-email" , bot _email ) ;
$ ( ".edit_bot_email" ) . text ( bot _email ) ;
2013-07-22 20:09:34 +02:00
2017-03-01 01:31:33 +01:00
avatar _widget . clear ( ) ;
2013-07-22 20:09:34 +02:00
2013-07-29 16:27:18 +02:00
2013-07-22 20:09:34 +02:00
function show _row _again ( ) {
image . show ( ) ;
bot _info . show ( ) ;
edit _div . hide ( ) ;
}
reset _edit _bot . click ( function ( event ) {
2017-01-21 20:19:20 +01:00
form . find ( ".edit_bot_name" ) . val ( old _full _name ) ;
2017-02-25 08:49:12 +01:00
owner _select . remove ( ) ;
2013-07-22 20:09:34 +02:00
show _row _again ( ) ;
$ ( this ) . off ( event ) ;
} ) ;
var errors = form . find ( '.bot_edit_errors' ) ;
form . validate ( {
errorClass : 'text-error' ,
2016-12-02 14:06:06 +01:00
success : function ( ) {
2013-07-22 20:09:34 +02:00
errors . hide ( ) ;
} ,
submitHandler : function ( ) {
2017-03-01 01:31:33 +01:00
var email = form . attr ( 'data-email' ) ;
2013-07-22 20:09:34 +02:00
var full _name = form . find ( '.edit_bot_name' ) . val ( ) ;
2017-02-25 08:49:12 +01:00
var bot _owner = form . find ( '.edit-bot-owner select' ) . val ( ) ;
2017-03-01 01:31:33 +01:00
var file _input = $ ( ".edit_bot" ) . find ( '.edit_bot_avatar_file_input' ) ;
2014-02-19 16:08:18 +01:00
var default _sending _stream = form . find ( '.edit_bot_default_sending_stream' ) . val ( ) ;
var default _events _register _stream = form . find ( '.edit_bot_default_events_register_stream' ) . val ( ) ;
2013-07-22 20:09:34 +02:00
var spinner = form . find ( '.edit_bot_spinner' ) ;
var edit _button = form . find ( '.edit_bot_button' ) ;
var formData = new FormData ( ) ;
2014-02-19 16:08:18 +01:00
2013-07-22 20:09:34 +02:00
formData . append ( 'csrfmiddlewaretoken' , csrf _token ) ;
2014-02-19 16:08:18 +01:00
formData . append ( 'full_name' , full _name ) ;
2017-02-25 08:49:12 +01:00
formData . append ( 'bot_owner' , bot _owner ) ;
2016-12-02 15:16:33 +01:00
add _bot _default _streams _to _form ( formData , default _sending _stream ,
default _events _register _stream ) ;
2013-07-29 16:27:18 +02:00
jQuery . each ( file _input [ 0 ] . files , function ( i , file ) {
formData . append ( 'file-' + i , file ) ;
} ) ;
2014-03-13 15:03:01 +01:00
loading . make _indicator ( spinner , { text : 'Editing bot' } ) ;
2013-07-22 20:09:34 +02:00
edit _button . hide ( ) ;
2013-12-18 19:55:18 +01:00
channel . patch ( {
2013-07-22 20:09:34 +02:00
url : '/json/bots/' + encodeURIComponent ( email ) ,
data : formData ,
cache : false ,
processData : false ,
contentType : false ,
success : function ( data ) {
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( spinner ) ;
2013-07-22 20:09:34 +02:00
errors . hide ( ) ;
edit _button . show ( ) ;
show _row _again ( ) ;
2017-03-01 01:31:33 +01:00
avatar _widget . clear ( ) ;
2013-07-22 20:09:34 +02:00
bot _info . find ( '.name' ) . text ( full _name ) ;
2013-07-29 16:27:18 +02:00
if ( data . avatar _url ) {
// Note that the avatar_url won't actually change on the back end
// when the user had a previous uploaded avatar. Only the content
// changes, so we version it to get an uncached copy.
image _version += 1 ;
image . find ( 'img' ) . attr ( 'src' , data . avatar _url + '&v=' + image _version . toString ( ) ) ;
}
2013-07-22 20:09:34 +02:00
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( spinner ) ;
2013-07-22 20:09:34 +02:00
edit _button . show ( ) ;
errors . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-07-22 20:09:34 +02:00
} ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-07-22 20:09:34 +02:00
} ) ;
} ) ;
2016-12-15 07:26:09 +01:00
$ ( "#bots_list" ) . on ( "click" , "a.download_bot_zuliprc" , function ( ) {
2017-02-23 01:58:50 +01:00
var bot _info = $ ( this ) . closest ( ".bot-information-box" ) ;
2016-12-07 18:38:59 +01:00
var email = bot _info . find ( ".email .value" ) . text ( ) ;
var api _key = bot _info . find ( ".api_key .api-key-value-and-button .value" ) . text ( ) ;
$ ( this ) . attr ( "href" , settings . generate _zuliprc _uri (
$ . trim ( email ) , $ . trim ( api _key )
) ) ;
} ) ;
2016-12-15 07:26:09 +01:00
$ ( "#download_zuliprc" ) . on ( "click" , function ( ) {
2016-12-07 18:38:59 +01:00
$ ( this ) . attr ( "href" , settings . generate _zuliprc _uri (
2017-01-20 21:55:42 +01:00
people . my _current _email ( ) ,
2016-12-07 18:38:59 +01:00
$ ( "#api_key_value" ) . text ( )
) ) ;
} ) ;
2016-12-02 14:06:06 +01:00
$ ( "#show_api_key_box" ) . on ( "click" , "button.regenerate_api_key" , function ( ) {
2013-12-18 19:55:18 +01:00
channel . post ( {
2013-08-08 18:08:30 +02:00
url : '/json/users/me/api_key/regenerate' ,
2014-01-07 23:40:31 +01:00
idempotent : true ,
2013-08-08 18:08:30 +02:00
success : function ( data ) {
$ ( '#api_key_value' ) . text ( data . api _key ) ;
} ,
error : function ( xhr ) {
$ ( '#user_api_key_error' ) . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
2017-01-12 00:17:43 +01:00
} ,
2013-08-08 18:08:30 +02:00
} ) ;
} ) ;
2013-07-22 20:09:34 +02:00
2016-12-21 22:36:27 +01:00
$ ( "#ui-settings" ) . on ( "click" , "input[name='change_settings']" , function ( e ) {
e . preventDefault ( ) ;
2014-02-13 23:47:57 +01:00
var labs _updates = { } ;
_ . each ( [ "autoscroll_forever" , "default_desktop_notifications" ] ,
function ( setting ) {
labs _updates [ setting ] = $ ( "#" + setting ) . is ( ":checked" ) ;
} ) ;
2016-12-22 03:36:18 +01:00
channel . patch ( {
url : '/json/settings/ui' ,
2014-02-13 23:47:57 +01:00
data : labs _updates ,
2016-12-02 14:06:06 +01:00
success : function ( resp , statusText , xhr ) {
2017-01-17 02:40:13 +01:00
var message = i18n . t ( "Updated settings! You will need to reload for these changes to take effect." , page _params ) ;
2016-08-24 23:56:23 +02:00
var result = JSON . parse ( xhr . responseText ) ;
2015-08-20 08:50:35 +02:00
var ui _settings _status = $ ( '#ui-settings-status' ) . expectOne ( ) ;
2014-02-13 23:47:57 +01:00
if ( result . autoscroll _forever !== undefined ) {
page _params . autoscroll _forever = result . autoscroll _forever ;
2014-03-13 19:03:31 +01:00
resize . resize _page _components ( ) ;
2014-02-13 23:47:57 +01:00
}
2015-08-21 01:23:53 +02:00
ui . report _success ( message , ui _settings _status ) ;
2014-02-13 23:47:57 +01:00
} ,
2016-12-02 14:06:06 +01:00
error : function ( xhr ) {
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error changing settings" ) , xhr , $ ( '#ui-settings-status' ) . expectOne ( ) ) ;
2017-01-12 00:17:43 +01:00
} ,
2014-02-13 23:47:57 +01:00
} ) ;
} ) ;
2016-11-26 04:39:53 +01:00
$ ( function ( ) {
$ ( 'body' ) . on ( 'click' , '.settings-unmute-topic' , function ( e ) {
var $row = $ ( this ) . closest ( "tr" ) ;
var stream = $row . data ( "stream" ) ;
var topic = $row . data ( "topic" ) ;
popovers . topic _ops . unmute ( stream , topic ) ;
$row . remove ( ) ;
e . stopImmediatePropagation ( ) ;
} ) ;
muting _ui . set _up _muted _topics _ui ( muting . get _muted _topics ( ) ) ;
} ) ;
2016-06-10 09:03:36 +02:00
}
2016-12-08 21:09:41 +01: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 ) ;
$ ( "#default_language_name" ) . text ( page _params . default _language _name ) ;
$ ( "#enable_stream_desktop_notifications" ) . prop ( 'checked' , page _params . stream _desktop _notifications _enabled ) ;
$ ( "#enable_stream_sounds" ) . prop ( 'checked' , page _params . stream _sounds _enabled ) ;
$ ( "#enable_desktop_notifications" ) . prop ( 'checked' , page _params . desktop _notifications _enabled ) ;
$ ( "#enable_sounds" ) . prop ( 'checked' , page _params . sounds _enabled ) ;
$ ( "#enable_offline_email_notifications" ) . prop ( 'checked' , page _params . enable _offline _email _notifications ) ;
$ ( "#enable_offline_push_notifications" ) . prop ( 'checked' , page _params . enable _offline _push _notifications ) ;
$ ( "#enable_online_push_notifications" ) . prop ( 'checked' , page _params . enable _online _push _notifications ) ;
2016-12-07 17:29:12 +01:00
$ ( "#pm_content_in_desktop_notifications" ) . prop ( 'checked' , page _params . pm _content _in _desktop _notifications ) ;
2016-12-08 21:09:41 +01:00
$ ( "#enable_digest_emails" ) . prop ( 'checked' , page _params . enable _digest _emails ) ;
}
2016-06-10 09:03:36 +02:00
exports . setup _page = function ( ) {
i18n . ensure _i18n ( _setup _page ) ;
2014-02-13 23:47:57 +01:00
} ;
2013-05-03 00:29:52 +02:00
2016-12-08 21:09:41 +01:00
exports . update _page = function ( ) {
i18n . ensure _i18n ( _update _page ) ;
} ;
2016-12-03 01:12:52 +01:00
exports . launch _page = function ( tab ) {
var $active _tab = $ ( "#settings_overlay_container li[data-section='" + tab + "']" ) ;
if ( ! $active _tab . hasClass ( "admin" ) ) {
2017-02-21 19:10:50 +01:00
$ ( ".sidebar .ind-tab[data-tab-key='settings']" ) . click ( ) ;
2016-12-03 01:12:52 +01:00
}
$ ( "#settings_overlay_container" ) . addClass ( "show" ) ;
$active _tab . click ( ) ;
} ;
2013-11-19 17:15:48 +01:00
return exports ;
2013-06-27 23:05:36 +02:00
} ( ) ) ;
2016-12-04 08:59:56 +01:00
if ( typeof module !== 'undefined' ) {
module . exports = settings ;
}