@@ -74,10 +74,12 @@ module.exports = Backbone.View.extend({
7474 this . serverUrl = options . userModel . get ( 'serverUrl' ) ;
7575 this . userModel = this . options . userModel ;
7676 this . model = new Backbone . Model ( ) ;
77- this . subViews = [ ] ;
77+ this . subViews = [ ] ; //TODO: get rid of subviews, submodels, use proper remove method
7878 this . subModels = [ ] ;
7979 this . subModels . push ( this . userProfile ) ;
8080
81+ this . shownMods = [ ] ; //array of mods that have been shown, used to prevent duplicates
82+
8183 this . moderatorFeeInput ;
8284 this . moderatorFeeHolder ;
8385 this . oldFeeValue = options . userProfile . get ( 'profile' ) . moderation_fee || 0 ;
@@ -479,6 +481,13 @@ module.exports = Backbone.View.extend({
479481 existingMods = this . userModel . get ( 'moderator_guids' ) ,
480482 isExistingMod = existingMods . indexOf ( moderator . guid ) > - 1 ;
481483
484+ //make sure this moderator is not a duplicate
485+ if ( this . shownMods . indexOf ( moderator . guid ) > - 1 ) {
486+ return ;
487+ } else {
488+ this . shownMods . push ( moderator . guid ) ;
489+ }
490+
482491 if ( moderator . guid != this . model . get ( 'page' ) . profile . guid && this . userModel . get ( 'blocked_guids' ) . indexOf ( moderator . guid ) == - 1 ) {
483492 moderator . serverUrl = self . serverUrl ;
484493 moderator . userID = moderator . guid ;
@@ -547,6 +556,10 @@ module.exports = Backbone.View.extend({
547556 }
548557 } ) ;
549558 }
559+ //hide spinners after a while
560+ setTimeout ( ( ) => {
561+ this . $ ( '.js-loadingMsg' ) . addClass ( 'foldIn' ) ;
562+ } , 3000 ) ;
550563 this . firstLoadModerators = false ;
551564 } else if ( state === 'blocked' ) {
552565 // Since the Blocked Users View kicks off many server calls (one
@@ -796,18 +809,27 @@ module.exports = Backbone.View.extend({
796809 var self = this ,
797810 form = this . $el . find ( "#storeForm" ) ,
798811 settingsData = { } ,
799- moderatorsChecked = this . $el . find ( '.js-userShortView input:checked' ) ,
800- modList = [ ] ,
812+ moderatorsNew = this . $el . find ( '#storeForm .js-settingsNewMods .js-userShortView input:checked' ) ,
813+ moderatorList = this . userModel . get ( 'moderators' ) . map ( function ( moderatorObject ) {
814+ return moderatorObject . guid ;
815+ } ) ,
816+ moderatorsUnChecked = this . $ ( '#storeForm .js-settingsCurrentMods .js-userShortView input:not(:checked)' ) ,
801817 onFail ,
802818 $saveBtn = this . $ ( '.js-saveStore' ) ;
803819
804820 $saveBtn . addClass ( 'loading' ) ;
805821
806- moderatorsChecked . each ( function ( ) {
807- modList . push ( $ ( this ) . data ( 'guid' ) ) ;
822+ //first, remove any existing moderators that have been unchecked. This prevents removing saved moderators that don't show up in the UI for some reason
823+ moderatorsUnChecked . each ( function ( ) {
824+ moderatorList = __ . without ( moderatorList , ( $ ( this ) . data ( 'guid' ) ) ) ;
825+ } ) ;
826+
827+ //add any new moderators that have been checked
828+ moderatorsNew . each ( function ( ) {
829+ moderatorList . push ( $ ( this ) . data ( 'guid' ) ) ;
808830 } ) ;
809831
810- settingsData . moderators = modList . length > 0 ? modList : "" ;
832+ settingsData . moderators = moderatorList . length > 0 ? moderatorList : "" ;
811833
812834 onFail = ( data ) => {
813835 $saveBtn . removeClass ( 'loading' ) ;
0 commit comments