@@ -21,6 +21,7 @@ var __ = require('underscore'),
2121 setTheme = require ( '../utils/setTheme.js' ) ,
2222 sanitizeHTML = require ( 'sanitize-html' ) ,
2323 storeWizardVw = require ( './storeWizardVw' ) ,
24+ saveToAPI = require ( '../utils/saveToAPI' ) ,
2425 moderatorSettingsVw = require ( './moderatorSettingsVw' ) ;
2526
2627var defaultItem = {
@@ -138,6 +139,8 @@ module.exports = baseVw.extend({
138139 'click .js-createStore' : 'createStore' ,
139140 'click .js-follow' : 'followUserClick' ,
140141 'click .js-unfollow' : 'unfollowUserClick' ,
142+ 'click .js-addmoderator' : 'addModeratorClick' ,
143+ 'click .js-removemoderator' : 'removeModeratorClick' ,
141144 'click .js-moreButtonsOwnPage' : 'moreButtonsOwnPageClick' ,
142145 'click .js-moreButtonsNotOwnPage' : 'moreButtonsNotOwnPageClick' ,
143146 'click .js-message' : 'sendMessage' ,
@@ -237,7 +240,7 @@ module.exports = baseVw.extend({
237240 this . setItem ( options . contract_hash , null , function ( ) {
238241 self . cloneItem ( ) ;
239242 } ) ;
240- } ) ;
243+ } ) ;
241244
242245 this . listenTo ( window . obEventBus , "itemShortDelete" , function ( options ) {
243246 self . deleteItem ( false , options . contract_hash ) ;
@@ -251,21 +254,21 @@ module.exports = baseVw.extend({
251254 if ( e . guid === this . model . get ( 'page' ) . profile . guid ) {
252255 this . renderUserBlocked ( ) ;
253256 }
254- } ) ;
257+ } ) ;
255258
256259 this . listenTo ( window . obEventBus , 'unblockingUser' , ( e ) => {
257260 if ( e . guid === this . model . get ( 'page' ) . profile . guid ) {
258261 this . renderUserUnblocked ( ) ;
259262 }
260- } ) ;
261-
263+ } ) ;
264+
262265 this . listenTo ( window . obEventBus , 'saveCurrentForm' , function ( ) {
263266 if ( self . editing ) {
264267 self . saveItem ( ) ;
265268 } else if ( self . customizing ) {
266269 self . saveCustomizePage ( ) ;
267270 }
268- } ) ;
271+ } ) ;
269272
270273 //determine if this is the user's own page or another profile's page
271274 //if no userID is passed in, or it matches the user's ID, then this is their page
@@ -330,7 +333,7 @@ module.exports = baseVw.extend({
330333 this . itemFetch && this . itemFetch . abort ( ) ;
331334 }
332335 } ;
333-
336+
334337 if ( this . currentItemHash ) {
335338 config . connectText = window . polyglot . t ( 'pageConnectingMessages.listingConnect' ) . replace ( '${listing}' , this . currentItemHash ) ;
336339 config . failedText = window . polyglot . t ( 'pageConnectingMessages.listingFail' ) ;
@@ -354,14 +357,15 @@ module.exports = baseVw.extend({
354357 isBlocked = blocked . indexOf ( this . pageID ) !== - 1 ;
355358
356359 this . model . set ( 'isBlocked' , isBlocked ) ; //add blocked status to model
357-
360+
358361 //make sure container is cleared
359362 $ ( '#content' ) . html ( this . $el ) ;
360363
361364 loadTemplate ( './js/templates/userPage.html' , function ( loadedTemplate ) {
362365 self . setCustomStyles ( ) ;
363366 self . $el . html ( loadedTemplate ( self . model . toJSON ( ) ) ) ;
364367 self . fetchFollowing ( ) ;
368+ self . getIsModerator ( ) ;
365369 self . fetchListings ( ) ;
366370 //save state of the page
367371 self . undoCustomAttributes . background_color = self . model . get ( 'page' ) . profile . background_color ;
@@ -523,6 +527,7 @@ module.exports = baseVw.extend({
523527 this . $el . find ( '.js-userPageControls, #customizeControls, .js-itemCustomizationButtons, .js-pageCustomizationButtons' ) . addClass ( 'hide' ) ;
524528 this . $el . find ( '.js-deleteItem' ) . removeClass ( 'confirm' ) ;
525529 this . $el . find ( '.js-unfollow' ) . removeClass ( 'confirm' ) ;
530+ this . $el . find ( '.js-removemoderator' ) . removeClass ( 'confirm' ) ;
526531 this . $el . find ( '.user-page-header-slim-bg-cover' ) . removeClass ( 'user-page-header-slim-bg-cover-customize' ) ;
527532 document . getElementById ( 'obContainer' ) . classList . remove ( "box-borderDashed" ) ;
528533 document . getElementById ( 'obContainer' ) . classList . remove ( "noScrollBar" ) ;
@@ -587,6 +592,20 @@ module.exports = baseVw.extend({
587592 unfollowBtn . removeClass ( 'loading' ) ;
588593 } ,
589594
595+ toggleModeratorButtons : function ( moderated ) {
596+ var addBtn = this . $ ( '.js-addmoderator' ) ,
597+ removeBtn = this . $ ( '.js-removemoderator' ) ;
598+ if ( moderated == true ) {
599+ addBtn . addClass ( 'hide' ) ;
600+ removeBtn . removeClass ( 'hide' ) ;
601+ } else {
602+ addBtn . removeClass ( 'hide' ) ;
603+ removeBtn . addClass ( 'hide' ) ;
604+ }
605+ addBtn . removeClass ( 'loading' ) ;
606+ removeBtn . removeClass ( 'loading' ) ;
607+ } ,
608+
590609 fetchListings : function ( ) {
591610 var self = this ;
592611 this . listings . fetch ( {
@@ -696,9 +715,13 @@ module.exports = baseVw.extend({
696715 } ) ;
697716 } ,
698717
718+ getIsModerator : function ( ) {
719+ this . toggleModeratorButtons ( Boolean ( __ . findWhere ( this . model . get ( 'user' ) . moderators , { guid : this . pageID } ) ) ) ;
720+ } ,
721+
699722 renderItems : function ( model , skipNSFWmodal ) {
700723 "use strict" ;
701-
724+
702725 var self = this ;
703726 var select = this . $el . find ( '.js-categories' ) ;
704727 var selectOptions = [ ] ;
@@ -729,23 +752,23 @@ module.exports = baseVw.extend({
729752 arrayItem . imageURL = self . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash + "&guid=" + self . pageID ;
730753 }
731754 } ) ;
732-
755+
733756 Object . keys ( selectOptions ) . sort ( ) . forEach ( function ( selectOption ) {
734757 var opt = document . createElement ( 'option' ) ;
735758 opt . value = selectOption ;
736759 opt . innerHTML = selectOption ;
737760 select . append ( opt ) ;
738761 } ) ;
739-
762+
740763 this . itemList = new itemListView ( {
741- model : model ,
742- el : '.js-list3' ,
743- title : window . polyglot . t ( 'NoListings' ) ,
764+ model : model ,
765+ el : '.js-list3' ,
766+ title : window . polyglot . t ( 'NoListings' ) ,
744767 message : "" ,
745- userModel : this . options . userModel ,
768+ userModel : this . options . userModel ,
746769 category : this . $el . find ( '.js-categories' ) . val ( )
747770 } ) ;
748-
771+
749772 this . registerChild ( this . itemList ) ;
750773
751774 this . $ ( '.js-listingCount' ) . html ( model . length ) ;
@@ -801,7 +824,7 @@ module.exports = baseVw.extend({
801824 reverse : true
802825 } ) ;
803826 this . registerChild ( this . followingList ) ;
804-
827+
805828 this . $ ( '.js-userFollowingCount' ) . html ( model . length ) ;
806829
807830 if ( model . length ) {
@@ -861,7 +884,7 @@ module.exports = baseVw.extend({
861884 if ( self . options . ownPage === false ) {
862885 model . set ( 'imageExtension' , "&guid=" + model . get ( 'vendor_offer' ) . listing . id . guid ) ;
863886 }
864-
887+
865888 model . updateAttributes ( afterUpdate ) ;
866889 onSucceed && onSucceed ( model , response ) ;
867890
@@ -895,7 +918,7 @@ module.exports = baseVw.extend({
895918 renderItemEdit : function ( useCurrentItem , clone ) {
896919 var self = this ,
897920 hash = "" ;
898-
921+
899922 if ( useCurrentItem ) {
900923 //if editing existing product, clone the model
901924 this . itemEdit = this . item . clone ( ) ;
@@ -923,7 +946,7 @@ module.exports = baseVw.extend({
923946 this . registerChild ( this . itemEditView ) ;
924947 this . listenTo ( this . itemEditView , 'saveNewDone' , this . saveNewDone ) ;
925948 self . tabClick ( self . $el . find ( '.js-storeTab' ) , self . $el . find ( '.js-itemEdit' ) ) ;
926-
949+
927950 this . editing = true ;
928951 } ,
929952
@@ -965,7 +988,7 @@ module.exports = baseVw.extend({
965988 this . categoryChanged ( ) ;
966989 }
967990
968- this . storeClick ( e ) ;
991+ this . storeClick ( e ) ;
969992 } ,
970993
971994 storeCatClick : function ( e ) {
@@ -1130,7 +1153,7 @@ module.exports = baseVw.extend({
11301153 // set recommendations
11311154 this . $el . find ( '.customColorChoice' ) . css ( 'background' , '#fff' ) ; // reset to white to give a cool transition
11321155 this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:first' ) . css ( 'background' , 'transparent' ) ; // set to transparent
1133- this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:nth-child(2)' ) . css ( 'background' , '#ffffff' ) ;
1156+ this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:nth-child(2)' ) . css ( 'background' , '#ffffff' ) ;
11341157 this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:last' ) . css ( 'background' , '#000000' ) ;
11351158
11361159 // slide background_color recommendations out + hide others
@@ -1241,7 +1264,7 @@ module.exports = baseVw.extend({
12411264 self . saveUserPageModel ( ) ;
12421265 }
12431266 } ,
1244-
1267+
12451268 saveCustomizePageClick : function ( ) {
12461269 this . saveCustomizePage ( ) ;
12471270 } ,
@@ -1314,16 +1337,16 @@ module.exports = baseVw.extend({
13141337
13151338 saveNewDone : function ( newHash ) {
13161339 "use strict" ;
1317-
1340+
13181341 this . setState ( 'listing' , newHash ) ;
13191342 this . fetchListings ( ) ;
1320-
1343+
13211344 this . editing = false ;
13221345 } ,
13231346
13241347 cancelClick : function ( ) {
13251348 "use strict" ;
1326-
1349+
13271350 this . setState ( this . lastTab ) ;
13281351 $ ( '#obContainer' ) . animate ( { scrollTop : 0 } ) ;
13291352
@@ -1380,17 +1403,17 @@ module.exports = baseVw.extend({
13801403 } ) ;
13811404 }
13821405 } ,
1383-
1406+
13841407 saveItemClick : function ( ) {
13851408 this . saveItem ( ) ;
13861409 } ,
13871410
13881411 saveItem : function ( e ) {
13891412 if ( this . itemEditView ) {
13901413 var $saveBtn = $ ( '.js-saveItem' ) ;
1391-
1414+
13921415 $saveBtn . addClass ( 'loading' ) ;
1393-
1416+
13941417 this . itemEditView . saveChanges ( ) . always ( ( ) => $saveBtn . removeClass ( 'loading' ) )
13951418 . fail ( ( ) => {
13961419 var $firstErr = this . $ ( '.js-itemEdit .invalid, .js-itemEdit :invalid' ) . not ( 'form' ) . eq ( 0 ) ;
@@ -1444,6 +1467,60 @@ module.exports = baseVw.extend({
14441467
14451468 } ,
14461469
1470+ addModeratorClick : function ( e ) {
1471+ var $targ = $ ( e . target ) . closest ( '.js-addmoderator' ) ,
1472+ self = this ,
1473+ modList = { } ;
1474+
1475+ $targ . addClass ( 'loading' ) ;
1476+
1477+ modList . moderators = this . model . get ( 'user' ) . moderator_guids ;
1478+ modList . moderators . push ( this . pageID ) ;
1479+
1480+ saveToAPI ( '' , this . model . get ( 'user' ) , this . model . get ( 'user' ) . serverUrl + "settings" ,
1481+ function ( ) {
1482+ // confirmed
1483+ self . options . userModel . fetch ( {
1484+ success : function ( model , response ) {
1485+ if ( self . isRemoved ( ) ) return ;
1486+ self . model . set ( 'user' , model . toJSON ( ) ) ;
1487+ self . getIsModerator ( ) ;
1488+ }
1489+ } ) ;
1490+ } , '' , modList , '' , '' ) . always ( function ( ) {
1491+ $targ . removeClass ( 'loading' ) ;
1492+ } ) ;
1493+ } ,
1494+
1495+ removeModeratorClick : function ( e ) {
1496+ var $targ = $ ( e . target ) . closest ( '.js-removemoderator' ) ,
1497+ self = this ,
1498+ modList = { } ;
1499+
1500+ if ( $targ . hasClass ( 'confirm' ) ) {
1501+ $targ . addClass ( 'loading' ) . removeClass ( 'confirm' ) ;
1502+
1503+ modList . moderators = __ . without ( this . model . get ( 'user' ) . moderator_guids , self . pageID ) ;
1504+
1505+ saveToAPI ( '' , this . model . get ( 'user' ) , this . model . get ( 'user' ) . serverUrl + "settings" ,
1506+ function ( ) {
1507+ // confirmed
1508+ self . options . userModel . fetch ( {
1509+ success : function ( model , response ) {
1510+ if ( self . isRemoved ( ) ) return ;
1511+ self . model . set ( 'user' , model . toJSON ( ) ) ;
1512+ self . getIsModerator ( ) ;
1513+ }
1514+ } ) ;
1515+ } , '' , modList , '' , '' ) . always ( function ( ) {
1516+ $targ . removeClass ( 'loading' ) ;
1517+ } ) ;
1518+ } else {
1519+ $targ . addClass ( 'confirm' ) ;
1520+ }
1521+
1522+ } ,
1523+
14471524 moreButtonsOwnPageClick : function ( ) {
14481525 if ( $ ( '.js-extraButtonsOwnPage' ) . hasClass ( 'hide' ) ) {
14491526 $ ( '.js-extraButtonsOwnPage' ) . removeClass ( 'hide' ) ;
@@ -1486,7 +1563,7 @@ module.exports = baseVw.extend({
14861563
14871564 unfollowUser : function ( options ) {
14881565 var self = this ;
1489-
1566+
14901567 return $ . ajax ( {
14911568 type : "POST" ,
14921569 data : { 'guid' : options . guid } ,
@@ -1555,7 +1632,7 @@ module.exports = baseVw.extend({
15551632 renderUserUnblocked : function ( ) {
15561633 this . $ ( '.js-unblock' ) . addClass ( 'hide' ) ;
15571634 this . $ ( '.js-block' ) . removeClass ( 'hide' ) ;
1558- } ,
1635+ } ,
15591636
15601637 hideThisUser : function ( reason ) {
15611638 this . $ ( '.js-blockedWarning' ) . fadeIn ( 100 ) ;
0 commit comments