2017-04-06 02:28:57 +02:00
var settings _account = ( function ( ) {
var exports = { } ;
exports . update _email = function ( new _email ) {
var email _input = $ ( '#email_value' ) ;
if ( email _input ) {
email _input . text ( new _email ) ;
}
} ;
2018-02-02 01:24:26 +01:00
exports . update _full _name = function ( new _full _name ) {
var full _name _field = $ ( "#change_full_name button #full_name_value" ) ;
if ( full _name _field ) {
full _name _field . text ( new _full _name ) ;
}
// Arguably, this should work more like how the `update_email`
// flow works, where we update the name in the modal on open,
// rather than updating it here, but this works.
var full _name _input = $ ( ".full_name_change_container input[name='full_name']" ) ;
if ( full _name _input ) {
full _name _input . val ( new _full _name ) ;
}
} ;
2018-03-02 21:44:14 +01:00
exports . update _name _change _display = function ( ) {
if ( page _params . realm _name _changes _disabled && ! page _params . is _admin ) {
2018-03-02 21:48:23 +01:00
$ ( '#full_name' ) . attr ( 'disabled' , 'disabled' ) ;
2018-03-02 21:44:14 +01:00
$ ( ".change_name_tooltip" ) . show ( ) ;
} else {
2018-03-02 21:48:23 +01:00
$ ( '#full_name' ) . attr ( 'disabled' , false ) ;
2018-03-02 21:44:14 +01:00
$ ( ".change_name_tooltip" ) . hide ( ) ;
}
} ;
exports . update _email _change _display = function ( ) {
if ( page _params . realm _email _changes _disabled && ! page _params . is _admin ) {
2018-03-02 21:48:23 +01:00
$ ( '#change_email .button' ) . attr ( 'disabled' , 'disabled' ) ;
2018-03-02 21:44:14 +01:00
$ ( ".change_email_tooltip" ) . show ( ) ;
} else {
2018-03-02 21:48:23 +01:00
$ ( '#change_email .button' ) . attr ( 'disabled' , false ) ;
2018-03-02 21:44:14 +01:00
$ ( ".change_email_tooltip" ) . hide ( ) ;
}
} ;
2017-04-06 02:28:57 +02:00
function settings _change _error ( message , xhr ) {
ui _report . error ( message , xhr , $ ( '#account-settings-status' ) . expectOne ( ) ) ;
}
function settings _change _success ( message ) {
ui _report . success ( message , $ ( '#account-settings-status' ) . expectOne ( ) ) ;
}
2018-06-05 12:57:02 +02:00
function update _user _custom _profile _fields ( fields , method ) {
if ( method === undefined ) {
blueslip . error ( "Undefined method in update_user_custom_profile_fields" ) ;
}
2018-05-25 20:58:14 +02:00
var spinner = $ ( "#custom-field-status" ) . expectOne ( ) ;
loading . make _indicator ( spinner , { text : 'Saving ...' } ) ;
2018-06-05 12:57:02 +02:00
settings _ui . do _settings _change ( method , "/json/users/me/profile_data" ,
2018-05-25 20:58:14 +02:00
{ data : JSON . stringify ( fields ) } , spinner ) ;
}
2018-10-22 10:20:33 +02:00
exports . initialize _custom _date _type _fields = function ( element _id ) {
$ ( element _id ) . find ( ".custom_user_field .datepicker" ) . flatpickr ( {
altInput : true ,
altFormat : "F j, Y" } ) ;
} ;
2018-10-23 19:46:12 +02:00
exports . intialize _custom _user _type _fields = function ( element _id , user _id , is _editable ,
set _handler _on _update ) {
var field _types = page _params . custom _profile _field _types ;
var user _pills = { } ;
page _params . custom _profile _fields . forEach ( function ( field ) {
var field _value _raw = people . get _custom _profile _data ( user _id , field . id ) ;
// If field is not editable and field value is null, we don't expect
// pill container for that field and proceed further
if ( field . type === field _types . USER . id && ( field _value _raw || is _editable ) ) {
var pill _container = $ ( element _id ) . find ( '.custom_user_field[data-field-id="' +
field . id + '"] .pill-container' ) . expectOne ( ) ;
var pills = user _pill . create _pills ( pill _container ) ;
function update _custom _user _field ( ) {
var fields = [ ] ;
var user _ids = user _pill . get _user _ids ( pills ) ;
if ( user _ids . length < 1 ) {
fields . push ( field . id ) ;
update _user _custom _profile _fields ( fields , channel . del ) ;
} else {
fields . push ( { id : field . id , value : user _ids } ) ;
update _user _custom _profile _fields ( fields , channel . patch ) ;
}
}
if ( field _value _raw ) {
var field _value = JSON . parse ( field _value _raw ) ;
if ( field _value ) {
field _value . forEach ( function ( pill _user _id ) {
var user = people . get _person _from _user _id ( pill _user _id ) ;
user _pill . append _user ( user , pills ) ;
} ) ;
}
}
if ( is _editable ) {
var input = pill _container . children ( '.input' ) ;
if ( set _handler _on _update ) {
user _pill . set _up _typeahead _on _pills ( input , pills , update _custom _user _field ) ;
pills . onPillRemove ( function ( ) {
update _custom _user _field ( ) ;
} ) ;
} else {
user _pill . set _up _typeahead _on _pills ( input , pills , function ( ) { } ) ;
}
}
user _pills [ field . id ] = pills ;
}
} ) ;
return user _pills ;
} ;
2018-04-04 16:21:05 +02:00
exports . add _custom _profile _fields _to _settings = function ( ) {
2018-06-10 07:03:22 +02:00
if ( ! overlays . settings _open ( ) ) {
return ;
}
2018-10-22 10:20:33 +02:00
var element _id = "#account-settings .custom-profile-fields-form" ;
$ ( element _id ) . html ( "" ) ;
2018-06-07 11:39:12 +02:00
if ( page _params . custom _profile _fields . length > 0 ) {
$ ( "#account-settings #custom-field-header" ) . show ( ) ;
} else {
$ ( "#account-settings #custom-field-header" ) . hide ( ) ;
}
2018-02-26 20:09:07 +01:00
var all _custom _fields = page _params . custom _profile _fields ;
2018-08-15 11:35:18 +02:00
var field _types = page _params . custom _profile _field _types ;
2018-02-26 20:09:07 +01:00
all _custom _fields . forEach ( function ( field ) {
2018-08-15 11:35:18 +02:00
var field _type = field . type ;
2018-02-26 20:09:07 +01:00
var type ;
var value = people . my _custom _profile _data ( field . id ) ;
2018-08-15 11:35:18 +02:00
var is _long _text = field _type === field _types . LONG _TEXT . id ;
var is _choice _field = field _type === field _types . CHOICE . id ;
var is _user _field = field _type === field _types . USER . id ;
var is _date _field = field _type === field _types . DATE . id ;
2018-05-04 16:46:46 +02:00
var field _choices = [ ] ;
2018-02-26 20:09:07 +01:00
2018-08-15 11:35:18 +02:00
if ( is _long _text || field _type === field _types . SHORT _TEXT . id ) {
2018-02-26 20:09:07 +01:00
type = "text" ;
2018-08-15 11:35:18 +02:00
} else if ( is _choice _field ) {
2018-04-08 09:50:05 +02:00
type = "choice" ;
2018-05-04 16:46:46 +02:00
var field _choice _dict = JSON . parse ( field . field _data ) ;
for ( var choice in field _choice _dict ) {
if ( choice ) {
field _choices [ field _choice _dict [ choice ] . order ] = {
value : choice ,
text : field _choice _dict [ choice ] . text ,
selected : choice === value ,
} ;
}
}
2018-08-15 11:35:18 +02:00
} else if ( is _date _field ) {
2018-04-03 18:06:13 +02:00
type = "date" ;
2018-08-15 11:35:18 +02:00
} else if ( field _type === field _types . URL . id ) {
2018-04-25 19:20:58 +02:00
type = "url" ;
2018-08-15 11:35:18 +02:00
} else if ( is _user _field ) {
2018-06-07 20:01:31 +02:00
if ( value ) {
value = JSON . parse ( value ) ;
}
2018-05-06 09:43:38 +02:00
type = "user" ;
2018-02-26 20:09:07 +01:00
} else {
blueslip . error ( "Undefined field type." ) ;
}
2018-08-09 14:02:32 +02:00
2018-08-21 19:18:06 +02:00
if ( value === undefined || value === null ) {
2018-02-26 20:09:07 +01:00
// If user has not set value for field.
value = "" ;
}
2018-05-06 21:43:17 +02:00
var html = templates . render ( "custom-user-profile-field" , {
field : field ,
field _type : type ,
field _value : value ,
is _long _text _field : is _long _text ,
is _choice _field : is _choice _field ,
2018-05-09 13:58:29 +02:00
is _user _field : is _user _field ,
2018-05-16 19:22:43 +02:00
is _date _field : is _date _field ,
2018-05-06 21:43:17 +02:00
field _choices : field _choices ,
} ) ;
2018-02-26 20:09:07 +01:00
$ ( "#account-settings .custom-profile-fields-form" ) . append ( html ) ;
} ) ;
2018-10-23 19:46:12 +02:00
exports . intialize _custom _user _type _fields ( element _id , people . my _current _user _id ( ) , true , true ) ;
2018-10-22 10:20:33 +02:00
exports . initialize _custom _date _type _fields ( element _id ) ;
2018-04-04 16:21:05 +02:00
} ;
2017-04-06 02:28:57 +02:00
exports . set _up = function ( ) {
2018-02-26 20:09:07 +01:00
// Add custom profile fields elements to user account settings.
2018-04-04 16:21:05 +02:00
exports . add _custom _profile _fields _to _settings ( ) ;
2017-04-06 02:28:57 +02:00
$ ( "#account-settings-status" ) . hide ( ) ;
2017-06-13 17:57:33 +02:00
$ ( "#api_key_value" ) . text ( "" ) ;
$ ( "#get_api_key_box" ) . hide ( ) ;
$ ( "#show_api_key_box" ) . hide ( ) ;
$ ( "#api_key_button_box" ) . show ( ) ;
$ ( '#api_key_button' ) . click ( function ( ) {
if ( page _params . realm _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 ( ) ;
} ) ;
$ ( "#get_api_key_box" ) . hide ( ) ;
$ ( "#show_api_key_box" ) . hide ( ) ;
2018-05-18 15:21:44 +02:00
$ ( "#get_api_key_button" ) . on ( "click" , function ( e ) {
var data = { } ;
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
data . password = $ ( "#get_api_key_password" ) . val ( ) ;
channel . post ( {
url : '/json/fetch_api_key' ,
dataType : 'json' ,
data : data ,
success : function ( data ) {
var settings _status = $ ( '#account-settings-status' ) . expectOne ( ) ;
$ ( "#get_api_key_password" ) . val ( "" ) ;
$ ( "#api_key_value" ) . text ( data . api _key ) ;
$ ( "#show_api_key_box" ) . show ( ) ;
$ ( "#get_api_key_box" ) . hide ( ) ;
settings _status . hide ( ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Error getting API key" ) , xhr , $ ( '#account-settings-status' ) . expectOne ( ) ) ;
$ ( "#show_api_key_box" ) . hide ( ) ;
$ ( "#get_api_key_box" ) . show ( ) ;
} ,
} ) ;
2017-06-13 17:57:33 +02:00
} ) ;
$ ( "#show_api_key_box" ) . on ( "click" , "button.regenerate_api_key" , function ( ) {
channel . post ( {
url : '/json/users/me/api_key/regenerate' ,
idempotent : true ,
success : function ( data ) {
$ ( '#api_key_value' ) . text ( data . api _key ) ;
} ,
error : function ( xhr ) {
$ ( '#user_api_key_error' ) . text ( JSON . parse ( xhr . responseText ) . msg ) . show ( ) ;
} ,
} ) ;
} ) ;
$ ( "#download_zuliprc" ) . on ( "click" , function ( ) {
2018-06-04 16:20:14 +02:00
var data = settings _bots . generate _zuliprc _content ( people . my _current _email ( ) ,
$ ( "#api_key_value" ) . text ( ) ) ;
$ ( this ) . attr ( "href" , settings _bots . encode _zuliprc _as _uri ( data ) ) ;
2017-06-13 17:57:33 +02:00
} ) ;
2017-04-06 02:28:57 +02:00
function clear _password _change ( ) {
// Clear the password boxes so that passwords don't linger in the DOM
// for an XSS attacker to find.
2018-01-11 20:28:18 +01:00
$ ( '#old_password, #new_password' ) . val ( '' ) ;
2018-01-24 13:30:27 +01:00
common . password _quality ( '' , $ ( '#pw_strength .bar' ) , $ ( '#new_password' ) ) ;
2017-04-06 02:28:57 +02:00
}
clear _password _change ( ) ;
2018-01-30 08:56:15 +01:00
$ ( "#change_full_name" ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2018-02-02 16:54:26 +01:00
if ( ! page _params . realm _name _changes _disabled || page _params . is _admin ) {
2018-02-02 15:40:15 +01:00
overlays . open _modal ( 'change_full_name_modal' ) ;
}
2018-01-30 08:56:15 +01:00
} ) ;
2017-12-24 19:00:29 +01:00
$ ( '#change_password' ) . on ( 'click' , function ( e ) {
2017-04-06 02:28:57 +02:00
e . preventDefault ( ) ;
2017-12-24 19:00:29 +01:00
e . stopPropagation ( ) ;
overlays . open _modal ( 'change_password_modal' ) ;
2017-04-06 02:28:57 +02:00
$ ( '#pw_change_controls' ) . show ( ) ;
2017-04-20 08:21:31 +02:00
if ( page _params . realm _password _auth _enabled !== false ) {
2017-04-06 02:28:57 +02:00
// zxcvbn.js is pretty big, and is only needed on password
// change, so load it asynchronously.
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 ( ) {
$ ( '#pw_strength .bar' ) . removeClass ( "fade" ) ;
} ) ;
}
} ) ;
2018-01-24 13:30:27 +01:00
$ ( '#change_password_modal' ) . find ( '[data-dismiss=modal]' ) . on ( 'click' , function ( ) {
clear _password _change ( ) ;
} ) ;
2017-12-24 19:00:29 +01:00
$ ( '#change_password_button' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var change _password _info = $ ( '#change_password_modal' ) . find ( ".change_password_info" ) . expectOne ( ) ;
var data = {
old _password : $ ( '#old_password' ) . val ( ) ,
new _password : $ ( '#new_password' ) . val ( ) ,
confirm _password : $ ( '#confirm_password' ) . val ( ) ,
} ;
channel . patch ( {
url : "/json/settings" ,
data : data ,
beforeSubmit : function ( ) {
if ( page _params . realm _password _auth _enabled !== false ) {
// FIXME: Check that the two password fields match
// FIXME: Use the same jQuery validation plugin as the signup form?
var field = $ ( '#new_password' ) ;
var new _pw = $ ( '#new_password' ) . val ( ) ;
if ( new _pw !== '' ) {
var password _ok = common . password _quality ( new _pw , undefined , field ) ;
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 ( i18n . t ( 'New password is too weak' ) ) ;
return false ;
}
}
}
return true ;
} ,
success : function ( ) {
settings _change _success ( i18n . t ( "Updated settings!" ) ) ;
overlays . close _modal ( 'change_password_modal' ) ;
} ,
complete : function ( ) {
// Whether successful or not, clear the password boxes.
// TODO: Clear these earlier, while the request is still pending.
clear _password _change ( ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Failed" ) , xhr , change _password _info ) ;
} ,
} ) ;
} ) ;
2017-04-06 02:28:57 +02:00
$ ( '#new_password' ) . on ( 'change keyup' , function ( ) {
var field = $ ( '#new_password' ) ;
2017-06-22 22:08:43 +02:00
common . password _quality ( field . val ( ) , $ ( '#pw_strength .bar' ) , field ) ;
2017-04-06 02:28:57 +02:00
} ) ;
2018-01-30 08:56:15 +01:00
$ ( "#change_full_name_button" ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var change _full _name _info = $ ( '#change_full_name_modal' ) . find ( ".change_full_name_info" ) . expectOne ( ) ;
var data = { } ;
data . full _name = $ ( '.full_name_change_container' ) . find ( "input[name='full_name']" ) . val ( ) ;
channel . patch ( {
url : '/json/settings' ,
data : data ,
success : function ( data ) {
if ( 'full_name' in data ) {
settings _change _success ( i18n . t ( "Updated settings!" ) ) ;
} else {
settings _change _success ( i18n . t ( "No changes made." ) ) ;
}
overlays . close _modal ( 'change_full_name_modal' ) ;
} ,
error : function ( xhr ) {
ui _report . error ( i18n . t ( "Failed" ) , xhr , change _full _name _info ) ;
} ,
} ) ;
2017-04-06 02:28:57 +02:00
} ) ;
$ ( '#change_email_button' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2018-01-30 09:07:38 +01:00
var change _email _info = $ ( '#change_email_modal' ) . find ( ".change_email_info" ) . expectOne ( ) ;
2017-04-06 02:28:57 +02:00
var data = { } ;
data . email = $ ( '.email_change_container' ) . find ( "input[name='email']" ) . val ( ) ;
channel . patch ( {
2017-07-31 20:44:52 +02:00
url : '/json/settings' ,
2017-04-06 02:28:57 +02:00
data : data ,
success : function ( data ) {
if ( 'account_email' in data ) {
settings _change _success ( data . account _email ) ;
2017-10-04 20:44:10 +02:00
if ( page _params . development _environment ) {
var email _msg = templates . render ( 'dev_env_email_access' ) ;
$ ( "#account-settings-status" ) . append ( email _msg ) ;
}
2017-04-06 02:28:57 +02:00
} else {
2017-08-03 23:03:24 +02:00
settings _change _success ( i18n . t ( "No changes made." ) ) ;
2017-04-06 02:28:57 +02:00
}
2018-01-30 09:07:38 +01:00
overlays . close _modal ( 'change_email_modal' ) ;
2017-04-06 02:28:57 +02:00
} ,
error : function ( xhr ) {
2018-01-30 09:07:38 +01:00
ui _report . error ( i18n . t ( "Failed" ) , xhr , change _email _info ) ;
2017-04-06 02:28:57 +02:00
} ,
} ) ;
} ) ;
$ ( '#change_email' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2018-02-02 16:54:26 +01:00
if ( ! page _params . realm _email _changes _disabled || page _params . is _admin ) {
2018-02-02 15:40:15 +01:00
overlays . open _modal ( 'change_email_modal' ) ;
var email = $ ( '#email_value' ) . text ( ) . trim ( ) ;
$ ( '.email_change_container' ) . find ( "input[name='email']" ) . val ( email ) ;
}
2017-04-06 02:28:57 +02:00
} ) ;
$ ( "#user_deactivate_account_button" ) . on ( 'click' , function ( e ) {
2018-05-23 22:29:00 +02:00
// This click event must not get propagated to parent container otherwise the modal
// will not show up because of a call to `close_active_modal` in `settings.js`.
2017-04-06 02:28:57 +02:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( "#deactivate_self_modal" ) . modal ( "show" ) ;
} ) ;
2018-06-09 15:28:55 +02:00
$ ( '#settings_page' ) . on ( 'click' , '.custom_user_field .remove_date' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2018-07-11 15:42:01 +02:00
var field = $ ( e . target ) . closest ( '.custom_user_field' ) . expectOne ( ) ;
2018-06-09 15:28:55 +02:00
var field _id = parseInt ( $ ( field ) . attr ( "data-field-id" ) , 10 ) ;
2018-07-11 15:42:01 +02:00
field . find ( ".custom_user_field_value" ) . val ( "" ) ;
2018-06-09 15:28:55 +02:00
update _user _custom _profile _fields ( [ field _id ] , channel . del ) ;
} ) ;
2018-05-10 15:12:46 +02:00
$ ( '#settings_page' ) . on ( 'change' , '.custom_user_field_value' , function ( e ) {
2018-02-26 20:42:37 +01:00
var fields = [ ] ;
var value = $ ( this ) . val ( ) ;
2018-06-05 12:57:02 +02:00
var field _id = parseInt ( $ ( e . target ) . closest ( '.custom_user_field' ) . attr ( "data-field-id" ) , 10 ) ;
if ( value ) {
fields . push ( { id : field _id , value : value } ) ;
update _user _custom _profile _fields ( fields , channel . patch ) ;
} else {
fields . push ( field _id ) ;
update _user _custom _profile _fields ( fields , channel . del ) ;
}
2018-02-26 20:42:37 +01:00
} ) ;
2017-04-06 02:28:57 +02:00
$ ( "#do_deactivate_self_button" ) . on ( 'click' , function ( ) {
2018-01-26 08:01:58 +01:00
$ ( "#do_deactivate_self_button .loader" ) . css ( 'display' , 'inline-block' ) ;
$ ( "#do_deactivate_self_button span" ) . hide ( ) ;
$ ( "#do_deactivate_self_button object" ) . on ( "load" , function ( ) {
var doc = this . getSVGDocument ( ) ;
var $svg = $ ( doc ) . find ( "svg" ) ;
$svg . find ( "rect" ) . css ( "fill" , "#000" ) ;
2017-04-06 02:28:57 +02:00
} ) ;
2018-01-26 08:01:58 +01:00
setTimeout ( function ( ) {
channel . del ( {
url : '/json/users/me' ,
success : function ( ) {
$ ( "#deactivate_self_modal" ) . modal ( "hide" ) ;
window . location . href = "/login" ;
} ,
error : function ( xhr ) {
2018-08-21 08:14:46 +02:00
var error _last _admin = i18n . t ( "Error: Cannot deactivate the only organization administrator." ) ;
var error _last _user = i18n . t ( "Error: Cannot deactivate the only user. You can deactivate the whole organization though in your <a target=\"_blank\" href=\"/#organization/organization-profile\">Organization profile settings</a>." ) ;
var rendered _error _msg ;
if ( xhr . responseJSON . code === "CANNOT_DEACTIVATE_LAST_USER" ) {
if ( xhr . responseJSON . is _last _admin ) {
rendered _error _msg = error _last _admin ;
} else {
rendered _error _msg = error _last _user ;
}
}
2018-01-26 08:01:58 +01:00
$ ( "#deactivate_self_modal" ) . modal ( "hide" ) ;
2018-08-21 08:14:46 +02:00
$ ( "#account-settings-status" ) . addClass ( "alert-error" ) . html ( rendered _error _msg ) . show ( ) ;
2018-01-26 08:01:58 +01:00
} ,
} ) ;
} , 5000 ) ;
2017-04-06 02:28:57 +02:00
} ) ;
2018-08-25 15:27:28 +02:00
$ ( "#show_my_user_profile_modal" ) . on ( 'click' , function ( e ) {
overlays . close _overlay ( "settings" ) ;
var user = people . get _person _from _user _id ( people . my _current _user _id ( ) ) ;
setTimeout ( function ( ) {
popovers . show _user _profile ( e . target , user ) ;
} , 100 ) ;
} ) ;
2017-04-06 02:28:57 +02: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 ) {
2018-06-04 21:13:07 +02:00
form _data . append ( 'file-' + i , file ) ;
2017-04-06 02:28:57 +02:00
} ) ;
2018-03-02 18:33:20 +01:00
$ ( "#user-avatar-source" ) . hide ( ) ;
2017-04-06 02:28:57 +02:00
var spinner = $ ( "#upload_avatar_spinner" ) . expectOne ( ) ;
loading . make _indicator ( spinner , { text : 'Uploading avatar.' } ) ;
2017-07-05 19:15:15 +02:00
channel . post ( {
2017-04-06 02:28:57 +02:00
url : '/json/users/me/avatar' ,
data : form _data ,
cache : false ,
processData : false ,
contentType : false ,
2018-10-18 10:04:43 +02:00
success : function ( ) {
2017-04-06 02:28:57 +02:00
loading . destroy _indicator ( $ ( "#upload_avatar_spinner" ) ) ;
$ ( "#user_avatar_delete_button" ) . show ( ) ;
2018-03-02 18:33:20 +01:00
$ ( "#user-avatar-source" ) . hide ( ) ;
2018-10-18 10:04:43 +02:00
// Rest of the work is done via the user_events -> avatar_url event we will get
2018-03-02 18:33:20 +01:00
} ,
error : function ( ) {
if ( page _params . avatar _source === 'G' ) {
$ ( "#user-avatar-source" ) . show ( ) ;
}
2017-04-06 02:28:57 +02:00
} ,
} ) ;
}
avatar . build _user _avatar _widget ( upload _avatar ) ;
2017-04-20 08:13:16 +02:00
if ( page _params . realm _name _changes _disabled ) {
2017-04-06 02:28:57 +02:00
$ ( ".name_change_container" ) . hide ( ) ;
}
} ;
return exports ;
} ( ) ) ;
if ( typeof module !== 'undefined' ) {
module . exports = settings _account ;
}
2018-05-28 08:04:36 +02:00
window . settings _account = settings _account ;