2013-08-12 23:31:23 +02:00
var admin = ( function ( ) {
var exports = { } ;
2016-05-20 22:08:42 +02:00
var all _streams = [ ] ;
2016-11-15 12:08:31 +01:00
var user _row _to _deactivate ;
2013-08-12 23:31:23 +02:00
2014-01-22 01:43:11 +01:00
exports . show _or _hide _menu _item = function ( ) {
var item = $ ( '.admin-menu-item' ) . expectOne ( ) ;
if ( page _params . is _admin ) {
item . show ( ) ;
} else {
item . hide ( ) ;
}
} ;
2016-11-15 04:27:32 +01:00
function get _user _info ( email ) {
var self = { } ;
self . user _row = $ ( "tr[id='user_" + email + "']" ) ;
self . form _row = $ ( "tr[id='user_form_" + email + "']" ) ;
return self ;
}
2016-11-15 12:37:02 +01:00
function get _email _for _user _row ( row ) {
var email = row . find ( '.email' ) . text ( ) ;
return email ;
}
2016-09-27 14:25:52 +02:00
exports . update _user _full _name = function ( email , new _full _name ) {
2016-11-15 04:27:32 +01:00
var user _info = get _user _info ( email ) ;
var user _row = user _info . user _row ;
var form _row = user _info . form _row ;
2016-09-27 14:25:52 +02:00
// Update the full name in the table
2016-11-15 04:27:32 +01:00
user _row . find ( ".user_name" ) . text ( new _full _name ) ;
form _row . find ( "input[name='full_name']" ) . val ( new _full _name ) ;
2016-09-27 14:25:52 +02:00
// Hide name change form
form _row . hide ( ) ;
user _row . show ( ) ;
} ;
2013-11-22 01:12:53 +01:00
function failed _listing _users ( xhr , error ) {
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( $ ( '#subs_page_loading_indicator' ) ) ;
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error listing users or bots" ) , xhr , $ ( "#administration-status" ) ) ;
2013-11-22 01:12:53 +01:00
}
function failed _listing _streams ( xhr , error ) {
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error listing streams" ) , xhr , $ ( "#administration-status" ) ) ;
2013-11-22 01:12:53 +01:00
}
2016-02-12 21:08:56 +01:00
function failed _listing _emoji ( xhr , error ) {
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Error listing emoji" ) , xhr , $ ( "#administration-status" ) ) ;
2016-02-12 21:08:56 +01:00
}
2016-09-27 14:25:52 +02:00
function failed _changing _name ( xhr , error ) {
ui . report _error ( i18n . t ( "Error changing name" ) , xhr , $ ( "#administration-status" ) ) ;
}
2013-11-16 17:07:55 +01:00
function populate _users ( realm _people _data ) {
2013-11-16 16:36:45 +01:00
var users _table = $ ( "#admin_users_table" ) ;
2013-11-16 17:07:55 +01:00
var deactivated _users _table = $ ( "#admin_deactivated_users_table" ) ;
2013-11-16 16:36:45 +01:00
var bots _table = $ ( "#admin_bots_table" ) ;
2013-11-16 17:04:50 +01:00
// Clear table rows, but not the table headers
users _table . find ( "tr.user_row" ) . remove ( ) ;
deactivated _users _table . find ( "tr.user_row" ) . remove ( ) ;
bots _table . find ( "tr.user_row" ) . remove ( ) ;
2013-08-12 23:31:23 +02:00
2013-11-16 17:07:55 +01:00
var active _users = [ ] ;
var deactivated _users = [ ] ;
2013-11-15 20:34:23 +01:00
var bots = [ ] ;
2013-11-16 17:07:55 +01:00
_ . each ( realm _people _data . members , function ( user ) {
2014-01-14 21:51:09 +01:00
user . is _active _human = user . is _active && ! user . is _bot ;
2013-11-15 20:34:23 +01:00
if ( user . is _bot ) {
bots . push ( user ) ;
2013-11-16 17:07:55 +01:00
} else if ( user . is _active ) {
active _users . push ( user ) ;
2013-11-15 20:34:23 +01:00
} else {
2013-11-16 17:07:55 +01:00
deactivated _users . push ( user ) ;
2013-08-12 23:31:23 +02:00
}
} ) ;
2013-11-15 20:34:23 +01:00
2013-11-16 17:07:55 +01:00
active _users = _ . sortBy ( active _users , 'full_name' ) ;
deactivated _users = _ . sortBy ( deactivated _users , 'full_name' ) ;
2013-11-15 20:34:23 +01:00
bots = _ . sortBy ( bots , 'full_name' ) ;
2013-11-16 16:36:45 +01:00
_ . each ( bots , function ( user ) {
bots _table . append ( templates . render ( "admin_user_list" , { user : user } ) ) ;
} ) ;
2013-11-16 17:07:55 +01:00
_ . each ( active _users , function ( user ) {
2013-11-16 16:36:45 +01:00
users _table . append ( templates . render ( "admin_user_list" , { user : user } ) ) ;
2013-11-15 20:34:23 +01:00
} ) ;
2013-11-16 17:07:55 +01:00
_ . each ( deactivated _users , function ( user ) {
deactivated _users _table . append ( templates . render ( "admin_user_list" , { user : user } ) ) ;
} ) ;
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( $ ( '#admin_page_users_loading_indicator' ) ) ;
loading . destroy _indicator ( $ ( '#admin_page_bots_loading_indicator' ) ) ;
loading . destroy _indicator ( $ ( '#admin_page_deactivated_users_loading_indicator' ) ) ;
2013-08-12 23:31:23 +02:00
}
2016-07-28 06:17:31 +02:00
function populate _streams ( streams _data ) {
2013-12-10 23:12:16 +01:00
var streams _table = $ ( "#admin_streams_table" ) . expectOne ( ) ;
2016-05-20 22:08:42 +02:00
all _streams = streams _data ;
2013-12-10 23:12:16 +01:00
streams _table . find ( "tr.stream_row" ) . remove ( ) ;
2013-11-22 01:12:53 +01:00
_ . each ( streams _data . streams , function ( stream ) {
streams _table . append ( templates . render ( "admin_streams_list" , { stream : stream } ) ) ;
} ) ;
2014-03-13 15:03:01 +01:00
loading . destroy _indicator ( $ ( '#admin_page_streams_loading_indicator' ) ) ;
2013-11-22 01:12:53 +01:00
}
2013-11-16 17:07:55 +01:00
2016-05-20 22:08:42 +02:00
function populate _default _streams ( streams _data ) {
var default _streams _table = $ ( "#admin_default_streams_table" ) . expectOne ( ) ;
_ . each ( streams _data , function ( stream ) {
default _streams _table . append ( templates . render ( "admin_default_streams_list" , { stream : stream } ) ) ;
} ) ;
loading . destroy _indicator ( $ ( '#admin_page_default_streams_loading_indicator' ) ) ;
}
function get _non _default _streams _names ( streams _data ) {
var non _default _streams _names = [ ] ;
var default _streams _names = [ ] ;
_ . each ( page _params . realm _default _streams , function ( default _stream ) {
default _streams _names . push ( default _stream . name ) ;
} ) ;
_ . each ( streams _data . streams , function ( stream ) {
if ( default _streams _names . indexOf ( stream . name ) < 0 ) {
2016-07-28 06:17:31 +02:00
non _default _streams _names . push ( stream . name ) ;
2016-05-20 22:08:42 +02:00
}
} ) ;
return non _default _streams _names ;
}
exports . update _default _streams _table = function ( ) {
2016-08-09 20:36:29 +02:00
if ( $ ( '#administration' ) . hasClass ( 'active' ) ) {
$ ( "#admin_default_streams_table" ) . expectOne ( ) . find ( "tr.default_stream_row" ) . remove ( ) ;
populate _default _streams ( page _params . realm _default _streams ) ;
}
2016-05-20 22:08:42 +02:00
} ;
function make _stream _default ( stream _name ) {
var data = {
stream _name : stream _name
} ;
var default _streams _table = $ ( "#admin_default_streams_table" ) . expectOne ( ) ;
channel . put ( {
url : '/json/default_streams' ,
data : data ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
$ ( ".active_stream_row button" ) . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg ) ) ;
2016-05-20 22:08:42 +02:00
} else {
$ ( ".active_stream_row button" ) . text ( "Failed!" ) ;
}
}
} ) ;
}
2016-09-28 00:08:36 +02:00
function stringify _list _with _conjunction ( lst , conjunction ) {
if ( lst . length === 0 ) {
return '' ;
} else if ( lst . length === 1 ) {
return lst . toString ( ) ;
} else if ( lst . length === 2 ) {
return lst . join ( " " + conjunction + " " ) ;
} else {
return lst . slice ( 0 , lst . length - 1 ) . join ( ", " ) + ", " + conjunction + " " + lst [ lst . length - 1 ] . toString ( ) ;
}
}
2016-05-03 00:03:48 +02:00
exports . populate _emoji = function ( emoji _data ) {
2016-02-12 21:08:56 +01:00
var emoji _table = $ ( '#admin_emoji_table' ) . expectOne ( ) ;
emoji _table . find ( 'tr.emoji_row' ) . remove ( ) ;
2016-04-28 06:43:40 +02:00
_ . each ( emoji _data , function ( data , name ) {
2016-07-28 06:17:31 +02:00
emoji _table . append ( templates . render ( 'admin_emoji_list' , {
emoji : {
name : name , source _url : data . source _url ,
display _url : data . display _url
}
} ) ) ;
2016-02-12 21:08:56 +01:00
} ) ;
loading . destroy _indicator ( $ ( '#admin_page_emoji_loading_indicator' ) ) ;
2016-05-03 00:03:48 +02:00
} ;
2016-02-12 21:08:56 +01:00
2016-02-13 19:17:15 +01:00
exports . populate _filters = function ( filters _data ) {
var filters _table = $ ( "#admin_filters_table" ) . expectOne ( ) ;
filters _table . find ( "tr.filter_row" ) . remove ( ) ;
_ . each ( filters _data , function ( filter ) {
filters _table . append (
templates . render (
"admin_filter_list" , {
filter : {
pattern : filter [ 0 ] ,
url _format _string : filter [ 1 ] ,
id : filter [ 2 ]
}
}
)
) ;
} ) ;
loading . destroy _indicator ( $ ( '#admin_page_filters_loading_indicator' ) ) ;
} ;
2016-08-04 17:32:41 +02:00
exports . reset _realm _default _language = function ( ) {
$ ( "#id_realm_default_language" ) . val ( page _params . realm _default _language ) ;
} ;
2016-11-02 21:51:56 +01:00
exports . populate _auth _methods = function ( auth _methods ) {
var auth _methods _table = $ ( "#admin_auth_methods_table" ) . expectOne ( ) ;
auth _methods _table . find ( 'tr.method_row' ) . remove ( ) ;
_ . each ( _ . keys ( auth _methods ) . sort ( ) , function ( key ) {
auth _methods _table . append ( templates . render ( 'admin_auth_methods_list' , {
method : {
method : key ,
enabled : auth _methods [ key ]
}
} ) ) ;
} ) ;
loading . destroy _indicator ( $ ( '#admin_page_auth_methods_loading_indicator' ) ) ;
} ;
2016-11-15 12:08:31 +01:00
exports . set _up _deactivate _user _modal = function ( row ) {
$ ( "#do_deactivate_user_button" ) . expectOne ( ) . click ( function ( e ) {
var email = row . find ( ".email" ) . text ( ) ;
if ( $ ( "#deactivation_user_modal .email" ) . html ( ) !== email ) {
blueslip . error ( "User deactivation canceled due to non-matching fields." ) ;
ui . report _message ( "Deactivation encountered an error. Please reload and try again." ,
$ ( "#home-error" ) , 'alert-error' ) ;
}
$ ( "#deactivation_user_modal" ) . modal ( "hide" ) ;
row . find ( "button" ) . prop ( "disabled" , true ) . text ( "Working…" ) ;
channel . del ( {
url : '/json/users/' + email ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
row . find ( "button" ) . closest ( "td" ) . html (
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg )
) ;
} else {
row . find ( "button" ) . text ( "Failed!" ) ;
}
} ,
success : function ( ) {
var button = row . find ( "button.deactivate" ) ;
button . prop ( "disabled" , false ) ;
button . addClass ( "btn-warning" ) ;
button . removeClass ( "btn-danger" ) ;
button . addClass ( "reactivate" ) ;
button . removeClass ( "deactivate" ) ;
button . text ( i18n . t ( "Reactivate" ) ) ;
row . addClass ( "deactivated_user" ) ;
row . find ( ".user-admin-settings" ) . hide ( ) ;
}
} ) ;
} ) ;
} ;
2016-06-10 09:03:36 +02:00
function _setup _page ( ) {
2016-09-28 00:08:36 +02:00
var domains _string = stringify _list _with _conjunction ( page _params . domains , "or" ) ;
var atdomains = page _params . domains . slice ( ) ;
var i ;
for ( i = 0 ; i < atdomains . length ; i ++ ) {
atdomains [ i ] = '@' + atdomains [ i ] ;
}
var atdomains _string = stringify _list _with _conjunction ( atdomains , "or" ) ;
2015-08-20 02:38:32 +02:00
var options = {
2016-07-28 06:17:31 +02:00
realm _name : page _params . realm _name ,
2016-09-28 00:08:36 +02:00
domains _string : domains _string ,
atdomains _string : atdomains _string ,
2015-08-20 02:38:32 +02:00
realm _restricted _to _domain : page _params . realm _restricted _to _domain ,
2016-07-28 06:17:31 +02:00
realm _invite _required : page _params . realm _invite _required ,
2016-05-12 10:28:00 +02:00
realm _invite _by _admins _only : page _params . realm _invite _by _admins _only ,
2016-11-02 21:51:56 +01:00
realm _authentication _methods : page _params . realm _authentication _methods ,
2016-06-21 21:34:41 +02:00
realm _create _stream _by _admins _only : page _params . realm _create _stream _by _admins _only ,
2016-07-08 02:25:55 +02:00
realm _allow _message _editing : page _params . realm _allow _message _editing ,
2016-08-04 17:32:41 +02:00
realm _message _content _edit _limit _minutes : Math . ceil ( page _params . realm _message _content _edit _limit _seconds / 60 ) ,
language _list : page _params . language _list ,
realm _default _language : page _params . realm _default _language
2015-08-20 02:38:32 +02:00
} ;
var admin _tab = templates . render ( 'admin_tab' , options ) ;
2014-01-27 21:48:23 +01:00
$ ( "#administration" ) . html ( admin _tab ) ;
2015-09-20 07:54:03 +02:00
$ ( "#administration-status" ) . expectOne ( ) . hide ( ) ;
$ ( "#admin-realm-name-status" ) . expectOne ( ) . hide ( ) ;
$ ( "#admin-realm-restricted-to-domain-status" ) . expectOne ( ) . hide ( ) ;
$ ( "#admin-realm-invite-required-status" ) . expectOne ( ) . hide ( ) ;
$ ( "#admin-realm-invite-by-admins-only-status" ) . expectOne ( ) . hide ( ) ;
2016-11-02 21:51:56 +01:00
$ ( "#admin-realm-authentication-methods-status" ) . expectOne ( ) . hide ( ) ;
2016-05-12 10:28:00 +02:00
$ ( "#admin-realm-create-stream-by-admins-only-status" ) . expectOne ( ) . hide ( ) ;
2016-06-21 21:34:41 +02:00
$ ( "#admin-realm-message-editing-status" ) . expectOne ( ) . hide ( ) ;
2016-08-04 17:32:41 +02:00
$ ( "#admin-realm-default-language-status" ) . expectOne ( ) . hide ( ) ;
2016-02-12 21:08:56 +01:00
$ ( "#admin-emoji-status" ) . expectOne ( ) . hide ( ) ;
2016-02-13 19:17:15 +01:00
$ ( '#admin-filter-status' ) . expectOne ( ) . hide ( ) ;
$ ( '#admin-filter-pattern-status' ) . expectOne ( ) . hide ( ) ;
$ ( '#admin-filter-format-status' ) . expectOne ( ) . hide ( ) ;
2014-01-27 21:48:23 +01:00
2016-08-04 17:32:41 +02:00
$ ( "#id_realm_default_language" ) . val ( page _params . realm _default _language ) ;
2013-11-22 01:12:53 +01:00
// create loading indicators
2014-03-13 15:03:01 +01:00
loading . make _indicator ( $ ( '#admin_page_users_loading_indicator' ) ) ;
loading . make _indicator ( $ ( '#admin_page_bots_loading_indicator' ) ) ;
loading . make _indicator ( $ ( '#admin_page_streams_loading_indicator' ) ) ;
loading . make _indicator ( $ ( '#admin_page_deactivated_users_loading_indicator' ) ) ;
2016-02-12 21:08:56 +01:00
loading . make _indicator ( $ ( '#admin_page_emoji_loading_indicator' ) ) ;
2016-11-02 21:51:56 +01:00
loading . make _indicator ( $ ( '#admin_page_auth_methods_loading_indicator' ) ) ;
2016-02-13 19:17:15 +01:00
loading . make _indicator ( $ ( '#admin_page_filters_loading_indicator' ) ) ;
2013-11-22 01:12:53 +01:00
// Populate users and bots tables
2013-12-18 19:55:18 +01:00
channel . get ( {
2013-11-16 17:07:55 +01:00
url : '/json/users' ,
2014-01-07 23:40:31 +01:00
idempotent : true ,
2013-11-16 17:07:55 +01:00
timeout : 10 * 1000 ,
success : populate _users ,
2013-11-22 01:12:53 +01:00
error : failed _listing _users
} ) ;
// Populate streams table
2014-01-24 19:47:18 +01:00
channel . get ( {
2016-05-20 22:08:42 +02:00
url : '/json/streams?include_public=true&include_subscribed=true&include_default=true' ,
2013-11-22 01:12:53 +01:00
timeout : 10 * 1000 ,
2014-01-07 23:40:31 +01:00
idempotent : true ,
2013-11-22 01:12:53 +01:00
success : populate _streams ,
error : failed _listing _streams
2013-11-16 17:07:55 +01:00
} ) ;
2013-08-12 23:31:23 +02:00
2016-11-02 21:51:56 +01:00
// Populate authentication methods table
exports . populate _auth _methods ( page _params . realm _authentication _methods ) ;
2016-02-12 21:08:56 +01:00
// Populate emoji table
2016-05-03 00:03:48 +02:00
exports . populate _emoji ( page _params . realm _emoji ) ;
2016-05-20 22:08:42 +02:00
exports . update _default _streams _table ( ) ;
2016-02-12 21:08:56 +01:00
2016-02-13 19:17:15 +01:00
// Populate filters table
exports . populate _filters ( page _params . realm _filters ) ;
2013-11-22 01:12:53 +01:00
// Setup click handlers
2013-11-16 16:36:45 +01:00
$ ( ".admin_user_table" ) . on ( "click" , ".deactivate" , function ( e ) {
2013-08-12 23:31:23 +02:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".user_row" ) ;
2013-08-12 23:31:23 +02:00
2015-11-04 17:15:55 +01:00
var user _name = row . find ( '.user_name' ) . text ( ) ;
2016-11-15 12:37:02 +01:00
var email = get _email _for _user _row ( row ) ;
2013-08-12 23:31:23 +02:00
2013-11-22 01:12:53 +01:00
$ ( "#deactivation_user_modal .email" ) . text ( email ) ;
$ ( "#deactivation_user_modal .user_name" ) . text ( user _name ) ;
$ ( "#deactivation_user_modal" ) . modal ( "show" ) ;
2016-11-15 12:08:31 +01:00
exports . set _up _deactivate _user _modal ( row ) ;
2013-11-22 01:12:53 +01:00
} ) ;
$ ( ".admin_stream_table" ) . on ( "click" , ".deactivate" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( ".active_stream_row" ) . removeClass ( "active_stream_row" ) ;
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".stream_row" ) ;
row . addClass ( "active_stream_row" ) ;
2013-11-22 01:12:53 +01:00
2015-11-04 17:15:55 +01:00
var stream _name = row . find ( '.stream_name' ) . text ( ) ;
2013-11-22 01:12:53 +01:00
$ ( "#deactivation_stream_modal .stream_name" ) . text ( stream _name ) ;
$ ( "#deactivation_stream_modal" ) . modal ( "show" ) ;
2013-08-12 23:31:23 +02:00
} ) ;
2016-05-20 22:08:42 +02:00
$ ( ".admin_default_stream_table" ) . on ( "click" , ".remove-default-stream" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
$ ( ".active_default_stream_row" ) . removeClass ( "active_default_stream_row" ) ;
var row = $ ( e . target ) . closest ( ".default_stream_row" ) ;
row . addClass ( "active_default_stream_row" ) ;
var stream _name = row . find ( '.default_stream_name' ) . text ( ) ;
channel . del ( {
url : '/json/default_streams' + '?' + $ . param ( { "stream_name" : stream _name } ) ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
$ ( ".active_default_stream_row button" ) . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg ) ) ;
2016-05-20 22:08:42 +02:00
} else {
$ ( ".active_default_stream_row button" ) . text ( "Failed!" ) ;
}
} ,
success : function ( ) {
var row = $ ( ".active_default_stream_row" ) ;
row . remove ( ) ;
}
} ) ;
} ) ;
$ ( '.create_default_stream' ) . keypress ( function ( e ) {
if ( e . which === 13 ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
}
} ) ;
$ ( '.create_default_stream' ) . typeahead ( {
items : 5 ,
fixed : true ,
source : function ( query ) {
return get _non _default _streams _names ( all _streams ) ;
} ,
highlight : true ,
updater : function ( stream _name ) {
make _stream _default ( stream _name ) ;
}
} ) ;
2015-10-28 17:40:30 +01:00
$ ( ".admin_bot_table" ) . on ( "click" , ".deactivate" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".user_row" ) ;
2015-10-28 17:40:30 +01:00
2015-11-04 17:15:55 +01:00
var user _name = row . find ( '.user_name' ) . text ( ) ;
2016-11-15 12:37:02 +01:00
var email = get _email _for _user _row ( row ) ;
2015-10-28 17:40:30 +01:00
channel . del ( {
url : '/json/bots/' + email ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
2015-11-04 17:15:55 +01:00
row . find ( "button" ) . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg )
2015-10-28 17:40:30 +01:00
) ;
} else {
2015-11-04 17:15:55 +01:00
row . find ( "button" ) . text ( "Failed!" ) ;
2015-10-28 17:40:30 +01:00
}
} ,
success : function ( ) {
2015-11-04 17:15:55 +01:00
var button = row . find ( "button.deactivate" ) ;
2015-10-28 17:40:30 +01:00
button . addClass ( "btn-warning" ) ;
button . removeClass ( "btn-danger" ) ;
button . addClass ( "reactivate" ) ;
button . removeClass ( "deactivate" ) ;
2016-06-13 08:40:35 +02:00
button . text ( i18n . t ( "Reactivate" ) ) ;
2015-10-28 17:40:30 +01:00
row . addClass ( "deactivated_user" ) ;
}
} ) ;
} ) ;
$ ( ".admin_user_table, .admin_bot_table" ) . on ( "click" , ".reactivate" , function ( e ) {
2013-11-16 16:26:40 +01:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
// Go up the tree until we find the user row, then grab the email element
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".user_row" ) ;
2016-11-15 12:37:02 +01:00
var email = get _email _for _user _row ( row ) ;
2013-11-16 16:26:40 +01:00
2013-12-18 19:55:18 +01:00
channel . post ( {
2015-10-28 17:40:30 +01:00
url : '/json/users/' + email + "/reactivate" ,
2013-11-16 16:26:40 +01:00
error : function ( xhr , error _type ) {
2015-11-04 17:15:55 +01:00
var button = row . find ( "button" ) ;
2013-11-16 16:26:40 +01:00
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
2015-11-04 17:15:55 +01:00
button . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg )
2013-11-16 16:26:40 +01:00
) ;
} else {
2016-06-13 08:40:35 +02:00
button . text ( i18n . t ( "Failed!" ) ) ;
2013-11-16 16:26:40 +01:00
}
} ,
success : function ( ) {
2015-11-04 17:15:55 +01:00
var button = row . find ( "button.reactivate" ) ;
2013-11-16 16:26:40 +01:00
button . addClass ( "btn-danger" ) ;
button . removeClass ( "btn-warning" ) ;
button . addClass ( "deactivate" ) ;
button . removeClass ( "reactivate" ) ;
2016-06-13 08:40:35 +02:00
button . text ( i18n . t ( "Deactivate" ) ) ;
2014-01-17 21:07:54 +01:00
row . removeClass ( "deactivated_user" ) ;
2013-11-16 16:26:40 +01:00
}
} ) ;
} ) ;
2015-08-20 21:25:30 +02:00
$ ( "#id_realm_invite_required" ) . change ( function ( ) {
2016-06-09 22:47:12 +02:00
if ( this . checked ) {
2015-09-20 08:01:55 +02:00
$ ( "#id_realm_invite_by_admins_only" ) . removeAttr ( "disabled" ) ;
2016-09-14 02:20:13 +02:00
$ ( "#id_realm_invite_by_admins_only_label" ) . parent ( ) . removeClass ( "control-label-disabled" ) ;
2015-09-20 08:01:55 +02:00
} else {
$ ( "#id_realm_invite_by_admins_only" ) . attr ( "disabled" , true ) ;
2016-09-14 02:20:13 +02:00
$ ( "#id_realm_invite_by_admins_only_label" ) . parent ( ) . addClass ( "control-label-disabled" ) ;
2015-09-20 08:01:55 +02:00
}
2015-08-20 21:25:30 +02:00
} ) ;
2016-07-08 02:25:55 +02:00
$ ( "#id_realm_allow_message_editing" ) . change ( function ( ) {
if ( this . checked ) {
$ ( "#id_realm_message_content_edit_limit_minutes" ) . removeAttr ( "disabled" ) ;
2016-09-14 02:20:13 +02:00
$ ( "#id_realm_message_content_edit_limit_minutes_label" ) . parent ( ) . removeClass ( "control-label-disabled" ) ;
2016-07-08 02:25:55 +02:00
} else {
$ ( "#id_realm_message_content_edit_limit_minutes" ) . attr ( "disabled" , true ) ;
2016-09-14 02:20:13 +02:00
$ ( "#id_realm_message_content_edit_limit_minutes_label" ) . parent ( ) . addClass ( "control-label-disabled" ) ;
2016-07-08 02:25:55 +02:00
}
} ) ;
2016-03-17 23:36:35 +01:00
$ ( ".administration" ) . on ( "submit" , "form.admin-realm-form" , function ( e ) {
2015-08-20 02:38:32 +02:00
var name _status = $ ( "#admin-realm-name-status" ) . expectOne ( ) ;
var restricted _to _domain _status = $ ( "#admin-realm-restricted-to-domain-status" ) . expectOne ( ) ;
var invite _required _status = $ ( "#admin-realm-invite-required-status" ) . expectOne ( ) ;
2015-09-20 08:01:55 +02:00
var invite _by _admins _only _status = $ ( "#admin-realm-invite-by-admins-only-status" ) . expectOne ( ) ;
2016-11-02 21:51:56 +01:00
var authentication _methods _status = $ ( "#admin-realm-authentication-methods-status" ) . expectOne ( ) ;
2016-05-12 10:28:00 +02:00
var create _stream _by _admins _only _status = $ ( "#admin-realm-create-stream-by-admins-only-status" ) . expectOne ( ) ;
2016-06-21 21:34:41 +02:00
var message _editing _status = $ ( "#admin-realm-message-editing-status" ) . expectOne ( ) ;
2016-08-04 17:32:41 +02:00
var default _language _status = $ ( "#admin-realm-default-language-status" ) . expectOne ( ) ;
2016-11-02 21:51:56 +01:00
var auth _methods _table = $ ( '.admin_auth_methods_table' ) ;
2015-08-20 02:38:32 +02:00
name _status . hide ( ) ;
restricted _to _domain _status . hide ( ) ;
invite _required _status . hide ( ) ;
2015-09-20 08:01:55 +02:00
invite _by _admins _only _status . hide ( ) ;
2016-11-02 21:51:56 +01:00
authentication _methods _status . hide ( ) ;
2016-05-12 10:28:00 +02:00
create _stream _by _admins _only _status . hide ( ) ;
2016-06-21 21:34:41 +02:00
message _editing _status . hide ( ) ;
2016-08-04 17:32:41 +02:00
default _language _status . hide ( ) ;
2015-08-20 02:38:32 +02:00
2015-08-20 21:25:30 +02:00
e . preventDefault ( ) ;
2014-02-03 20:14:18 +01:00
e . stopPropagation ( ) ;
2015-08-20 02:38:32 +02:00
var new _name = $ ( "#id_realm_name" ) . val ( ) ;
var new _restricted = $ ( "#id_realm_restricted_to_domain" ) . prop ( "checked" ) ;
var new _invite = $ ( "#id_realm_invite_required" ) . prop ( "checked" ) ;
2015-09-20 08:01:55 +02:00
var new _invite _by _admins _only = $ ( "#id_realm_invite_by_admins_only" ) . prop ( "checked" ) ;
2016-05-12 10:28:00 +02:00
var new _create _stream _by _admins _only = $ ( "#id_realm_create_stream_by_admins_only" ) . prop ( "checked" ) ;
2016-06-21 21:34:41 +02:00
var new _allow _message _editing = $ ( "#id_realm_allow_message_editing" ) . prop ( "checked" ) ;
2016-07-08 02:25:55 +02:00
var new _message _content _edit _limit _minutes = $ ( "#id_realm_message_content_edit_limit_minutes" ) . val ( ) ;
2016-08-04 17:32:41 +02:00
var new _default _language = $ ( "#id_realm_default_language" ) . val ( ) ;
2016-11-02 21:51:56 +01:00
var new _auth _methods = { } ;
_ . each ( $ ( "#admin_auth_methods_table" ) . find ( 'tr.method_row' ) , function ( method _row ) {
new _auth _methods [ $ ( method _row ) . data ( 'method' ) ] = $ ( method _row ) . find ( 'input' ) . prop ( 'checked' ) ;
} ) ;
2016-07-08 02:25:55 +02:00
// If allow_message_editing is unchecked, message_content_edit_limit_minutes
// is irrelevant. Hence if allow_message_editing is unchecked, and
// message_content_edit_limit_minutes is poorly formed, we set the latter to
// a default value to prevent the server from returning an error.
if ( ! new _allow _message _editing ) {
if ( ( parseInt ( new _message _content _edit _limit _minutes , 10 ) . toString ( ) !==
new _message _content _edit _limit _minutes ) ||
new _message _content _edit _limit _minutes < 0 ) {
new _message _content _edit _limit _minutes = 10 ; // Realm.DEFAULT_MESSAGE_CONTENT_EDIT_LIMIT_SECONDS / 60
}
}
2014-02-03 20:14:18 +01:00
var url = "/json/realm" ;
var data = {
2015-08-20 02:38:32 +02:00
name : JSON . stringify ( new _name ) ,
restricted _to _domain : JSON . stringify ( new _restricted ) ,
2015-08-20 21:25:30 +02:00
invite _required : JSON . stringify ( new _invite ) ,
2016-05-12 10:28:00 +02:00
invite _by _admins _only : JSON . stringify ( new _invite _by _admins _only ) ,
2016-11-02 21:51:56 +01:00
authentication _methods : JSON . stringify ( new _auth _methods ) ,
2016-06-21 21:34:41 +02:00
create _stream _by _admins _only : JSON . stringify ( new _create _stream _by _admins _only ) ,
2016-07-08 02:25:55 +02:00
allow _message _editing : JSON . stringify ( new _allow _message _editing ) ,
2016-08-04 17:32:41 +02:00
message _content _edit _limit _seconds : JSON . stringify ( parseInt ( new _message _content _edit _limit _minutes , 10 ) * 60 ) ,
default _language : JSON . stringify ( new _default _language )
2014-02-03 20:14:18 +01:00
} ;
channel . patch ( {
url : url ,
data : data ,
2016-07-12 21:16:54 +02:00
success : function ( response _data ) {
if ( response _data . name !== undefined ) {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Name changed!" ) , name _status ) ;
2015-09-20 08:01:55 +02:00
}
2016-07-12 21:16:54 +02:00
if ( response _data . restricted _to _domain !== undefined ) {
if ( response _data . restricted _to _domain ) {
2016-09-28 00:08:36 +02:00
ui . report _success ( i18n . t ( "New users must have e-mails ending in __atdomains_string__!" , { 'atdomains_string' : atdomains _string } ) , restricted _to _domain _status ) ;
2016-06-09 23:02:49 +02:00
} else {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "New users may have arbitrary e-mails!" ) , restricted _to _domain _status ) ;
2015-08-20 02:38:32 +02:00
}
2015-09-20 08:01:55 +02:00
}
2016-07-12 21:16:54 +02:00
if ( response _data . invite _required !== undefined ) {
if ( response _data . invite _required ) {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "New users must be invited by e-mail!" ) , invite _required _status ) ;
2016-06-09 23:02:49 +02:00
} else {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "New users may sign up online!" ) , invite _required _status ) ;
2015-08-20 02:38:32 +02:00
}
2015-09-20 08:01:55 +02:00
}
2016-07-12 21:16:54 +02:00
if ( response _data . invite _by _admins _only !== undefined ) {
if ( response _data . invite _by _admins _only ) {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "New users must be invited by an admin!" ) , invite _by _admins _only _status ) ;
2016-06-09 23:02:49 +02:00
} else {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Any user may now invite new users!" ) , invite _by _admins _only _status ) ;
2015-08-20 21:25:30 +02:00
}
2015-09-20 08:01:55 +02:00
}
2016-07-12 21:16:54 +02:00
if ( response _data . create _stream _by _admins _only !== undefined ) {
if ( response _data . create _stream _by _admins _only ) {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Only Admins may now create new streams!" ) , create _stream _by _admins _only _status ) ;
2016-06-09 23:02:49 +02:00
} else {
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Any user may now create new streams!" ) , create _stream _by _admins _only _status ) ;
2016-05-12 10:28:00 +02:00
}
}
2016-11-02 21:51:56 +01:00
if ( response _data . authentication _methods !== undefined ) {
if ( response _data . authentication _methods ) {
ui . report _success ( i18n . t ( "Authentication methods saved!" ) , authentication _methods _status ) ;
}
}
2016-07-12 21:16:54 +02:00
if ( response _data . allow _message _editing !== undefined ) {
2016-07-08 02:25:55 +02:00
// We expect message_content_edit_limit_seconds was sent in the
// response as well
var data _message _content _edit _limit _minutes = Math . ceil ( response _data . message _content _edit _limit _seconds / 60 ) ;
2016-07-12 21:16:54 +02:00
if ( response _data . allow _message _editing ) {
2016-07-08 02:25:55 +02:00
if ( response _data . message _content _edit _limit _seconds > 0 ) {
ui . report _success ( i18n . t ( "Users can now edit topics for all their messages, and the content of messages which are less than __num_minutes__ minutes old." ,
{ 'num_minutes' : data _message _content _edit _limit _minutes } ) ,
message _editing _status ) ;
} else {
ui . report _success ( i18n . t ( "Users can now edit the content and topics of all their past messages!" ) , message _editing _status ) ;
}
2016-06-21 21:34:41 +02:00
} else {
ui . report _success ( i18n . t ( "Users can no longer edit their past messages!" ) , message _editing _status ) ;
}
2016-07-08 02:25:55 +02:00
// message_content_edit_limit_seconds could have been changed earlier
// in this function, so update the field just in case
$ ( "#id_realm_message_content_edit_limit_minutes" ) . val ( data _message _content _edit _limit _minutes ) ;
2016-06-21 21:34:41 +02:00
}
2016-08-04 17:32:41 +02:00
if ( response _data . default _language !== undefined ) {
if ( response _data . default _language ) {
ui . report _success ( i18n . t ( "Default language changed!" ) , default _language _status ) ;
}
}
2014-02-03 20:14:18 +01:00
} ,
error : function ( xhr , error ) {
2016-11-02 21:51:56 +01:00
var reason = $ . parseJSON ( xhr . responseText ) . reason ;
if ( reason === "no authentication" ) {
ui . report _error ( i18n . t ( "Failed!" ) , xhr , authentication _methods _status ) ;
} else {
ui . report _error ( i18n . t ( "Failed!" ) , xhr , name _status ) ;
}
2014-02-03 20:14:18 +01:00
}
} ) ;
} ) ;
2014-01-14 21:51:09 +01:00
$ ( ".admin_user_table" ) . on ( "click" , ".make-admin" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
// Go up the tree until we find the user row, then grab the email element
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".user_row" ) ;
2016-11-15 12:37:02 +01:00
var email = get _email _for _user _row ( row ) ;
2014-01-14 21:51:09 +01:00
var url = "/json/users/" + email ;
var data = {
is _admin : JSON . stringify ( true )
} ;
channel . patch ( {
url : url ,
data : data ,
success : function ( ) {
2015-11-04 17:15:55 +01:00
var button = row . find ( "button.make-admin" ) ;
2014-01-14 21:51:09 +01:00
button . addClass ( "btn-danger" ) ;
button . removeClass ( "btn-warning" ) ;
button . addClass ( "remove-admin" ) ;
button . removeClass ( "make-admin" ) ;
2016-06-13 08:40:35 +02:00
button . text ( i18n . t ( "Remove admin" ) ) ;
2014-01-14 21:51:09 +01:00
} ,
error : function ( xhr , error ) {
2015-11-04 17:15:55 +01:00
var status = row . find ( ".admin-user-status" ) ;
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Failed!" ) , xhr , status ) ;
2014-01-14 21:51:09 +01:00
}
} ) ;
} ) ;
$ ( ".admin_user_table" ) . on ( "click" , ".remove-admin" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
// Go up the tree until we find the user row, then grab the email element
2015-11-04 17:15:55 +01:00
var row = $ ( e . target ) . closest ( ".user_row" ) ;
2016-11-15 12:37:02 +01:00
var email = get _email _for _user _row ( row ) ;
2014-01-14 21:51:09 +01:00
var url = "/json/users/" + email ;
var data = {
is _admin : JSON . stringify ( false )
} ;
channel . patch ( {
url : url ,
data : data ,
success : function ( ) {
2015-11-04 17:15:55 +01:00
var button = row . find ( "button.remove-admin" ) ;
2014-01-14 21:51:09 +01:00
button . addClass ( "btn-warning" ) ;
button . removeClass ( "btn-danger" ) ;
button . addClass ( "make-admin" ) ;
button . removeClass ( "remove-admin" ) ;
2016-06-13 08:40:35 +02:00
button . text ( i18n . t ( "Make admin" ) ) ;
2014-01-14 21:51:09 +01:00
} ,
error : function ( xhr , error ) {
2015-11-04 17:15:55 +01:00
var status = row . find ( ".admin-user-status" ) ;
2016-06-23 13:05:17 +02:00
ui . report _error ( i18n . t ( "Failed!" ) , xhr , status ) ;
2014-01-14 21:51:09 +01:00
}
} ) ;
} ) ;
2016-09-27 14:25:52 +02:00
$ ( ".admin_user_table, .admin_bot_table" ) . on ( "click" , ".open-user-form" , function ( e ) {
var email = $ ( e . currentTarget ) . data ( "email" ) ;
2016-11-15 12:48:33 +01:00
var user _info = get _user _info ( email ) ;
var user _row = user _info . user _row ;
var form _row = user _info . form _row ;
2016-09-27 14:25:52 +02:00
var reset _button = form _row . find ( ".reset_edit_user" ) ;
var submit _button = form _row . find ( ".submit_name_changes" ) ;
var full _name = form _row . find ( "input[name='full_name']" ) ;
var admin _status = $ ( '#administration-status' ) . expectOne ( ) ;
// Show user form.
user _row . hide ( ) ;
form _row . show ( ) ;
reset _button . on ( "click" , function ( e ) {
form _row . hide ( ) ;
user _row . show ( ) ;
} ) ;
submit _button . on ( "click" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var url = "/json/users/" + email ;
var data = {
full _name : JSON . stringify ( full _name . val ( ) )
} ;
channel . patch ( {
url : url ,
data : data ,
success : function ( ) {
ui . report _success ( i18n . t ( 'Name successfully updated!' ) , admin _status ) ;
} ,
error : failed _changing _name
} ) ;
} ) ;
} ) ;
2013-11-22 01:12:53 +01:00
$ ( "#do_deactivate_stream_button" ) . click ( function ( e ) {
if ( $ ( "#deactivation_stream_modal .stream_name" ) . text ( ) !== $ ( ".active_stream_row" ) . find ( '.stream_name' ) . text ( ) ) {
blueslip . error ( "Stream deactivation canceled due to non-matching fields." ) ;
ui . report _message ( "Deactivation encountered an error. Please reload and try again." ,
$ ( "#home-error" ) , 'alert-error' ) ;
}
$ ( "#deactivation_stream_modal" ) . modal ( "hide" ) ;
$ ( ".active_stream_row button" ) . prop ( "disabled" , true ) . text ( "Working…" ) ;
2013-12-18 19:55:18 +01:00
channel . del ( {
2013-11-22 01:12:53 +01:00
url : '/json/streams/' + encodeURIComponent ( $ ( ".active_stream_row" ) . find ( '.stream_name' ) . text ( ) ) ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
$ ( ".active_stream_row button" ) . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg )
2013-11-22 01:12:53 +01:00
) ;
} else {
$ ( ".active_stream_row button" ) . text ( "Failed!" ) ;
}
} ,
success : function ( ) {
var row = $ ( ".active_stream_row" ) ;
row . remove ( ) ;
}
} ) ;
} ) ;
2016-02-12 21:08:56 +01:00
$ ( '.admin_emoji_table' ) . on ( 'click' , '.delete' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var btn = $ ( this ) ;
channel . del ( {
url : '/json/realm/emoji/' + encodeURIComponent ( btn . attr ( 'data-emoji-name' ) ) ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
btn . closest ( "td" ) . html (
2016-08-24 23:56:23 +02:00
$ ( "<p>" ) . addClass ( "text-error" ) . text ( JSON . parse ( xhr . responseText ) . msg )
2016-02-12 21:08:56 +01:00
) ;
} else {
btn . text ( "Failed!" ) ;
}
} ,
success : function ( ) {
var row = btn . parents ( 'tr' ) ;
row . remove ( ) ;
}
} ) ;
} ) ;
$ ( ".administration" ) . on ( "submit" , "form.admin-emoji-form" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var emoji _status = $ ( '#admin-emoji-status' ) ;
var emoji = { } ;
$ ( this ) . serializeArray ( ) . map ( function ( x ) { emoji [ x . name ] = x . value ; } ) ;
channel . put ( {
url : "/json/realm/emoji" ,
data : $ ( this ) . serialize ( ) ,
success : function ( ) {
2016-09-14 00:56:36 +02:00
$ ( '#admin-emoji-status' ) . hide ( ) ;
2016-06-23 12:56:00 +02:00
ui . report _success ( i18n . t ( "Custom emoji added!" ) , emoji _status ) ;
2016-10-25 21:12:54 +02:00
$ ( "form.admin-emoji-form input[type='text']" ) . val ( "" ) ;
2016-02-12 21:08:56 +01:00
} ,
error : function ( xhr , error ) {
2016-09-14 00:56:36 +02:00
$ ( '#admin-emoji-status' ) . hide ( ) ;
2016-08-24 23:56:23 +02:00
var errors = JSON . parse ( xhr . responseText ) . msg ;
2016-09-14 00:56:36 +02:00
xhr . responseText = JSON . stringify ( { msg : errors } ) ;
ui . report _error ( i18n . t ( "Failed!" ) , xhr , emoji _status ) ;
2016-02-12 21:08:56 +01:00
}
} ) ;
} ) ;
2016-02-13 19:17:15 +01:00
$ ( '.admin_filters_table' ) . on ( 'click' , '.delete' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var btn = $ ( this ) ;
channel . del ( {
url : '/json/realm/filters/' + encodeURIComponent ( btn . attr ( 'data-filter-id' ) ) ,
error : function ( xhr , error _type ) {
if ( xhr . status . toString ( ) . charAt ( 0 ) === "4" ) {
btn . closest ( "td" ) . html (
$ ( "<p>" ) . addClass ( "text-error" ) . text ( $ . parseJSON ( xhr . responseText ) . msg )
) ;
} else {
btn . text ( "Failed!" ) ;
}
} ,
success : function ( ) {
var row = btn . parents ( 'tr' ) ;
row . remove ( ) ;
}
} ) ;
} ) ;
$ ( ".administration" ) . on ( "submit" , "form.admin-filter-form" , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
var filter _status = $ ( '#admin-filter-status' ) ;
var pattern _status = $ ( '#admin-filter-pattern-status' ) ;
var format _status = $ ( '#admin-filter-format-status' ) ;
filter _status . hide ( ) ;
pattern _status . hide ( ) ;
format _status . hide ( ) ;
var filter = { } ;
$ ( this ) . serializeArray ( ) . map ( function ( x ) { filter [ x . name ] = x . value ; } ) ;
channel . post ( {
url : "/json/realm/filters" ,
data : $ ( this ) . serialize ( ) ,
success : function ( data ) {
filter . id = data . id ;
ui . report _success ( i18n . t ( "Custom filter added!" ) , filter _status ) ;
} ,
error : function ( xhr , error ) {
var errors = $ . parseJSON ( xhr . responseText ) . errors ;
if ( errors . pattern !== undefined ) {
xhr . responseText = JSON . stringify ( { msg : errors . pattern } ) ;
ui . report _error ( i18n . t ( "Failed" ) , xhr , pattern _status ) ;
}
if ( errors . url _format _string !== undefined ) {
xhr . responseText = JSON . stringify ( { msg : errors . url _format _string } ) ;
ui . report _error ( i18n . t ( "Failed" ) , xhr , format _status ) ;
}
if ( errors . _ _all _ _ !== undefined ) {
xhr . responseText = JSON . stringify ( { msg : errors . _ _all _ _ } ) ;
ui . report _error ( i18n . t ( "Failed" ) , xhr , filter _status ) ;
}
}
} ) ;
} ) ;
2016-06-10 09:03:36 +02:00
}
exports . setup _page = function ( ) {
i18n . ensure _i18n ( _setup _page ) ;
2013-08-12 23:31:23 +02:00
} ;
return exports ;
} ( ) ) ;