@@ -138,6 +138,8 @@ module.exports = baseVw.extend({
138138 'click .js-createStore' : 'createStore' ,
139139 'click .js-follow' : 'followUserClick' ,
140140 'click .js-unfollow' : 'unfollowUserClick' ,
141+ 'click .js-addmoderator' : 'addModeratorClick' ,
142+ 'click .js-removemoderator' : 'removeModeratorClick' ,
141143 'click .js-moreButtonsOwnPage' : 'moreButtonsOwnPageClick' ,
142144 'click .js-moreButtonsNotOwnPage' : 'moreButtonsNotOwnPageClick' ,
143145 'click .js-message' : 'sendMessage' ,
@@ -179,6 +181,7 @@ module.exports = baseVw.extend({
179181 this . pageID = options . userID ;
180182 //set view's userID from the userModel;
181183 this . userID = options . userModel . get ( 'guid' ) ;
184+ this . globalUserModel = options . userModel ;
182185 this . userProfileFetchParameters = { } ;
183186 this . itemFetchParameters = { } ;
184187 this . model = new Backbone . Model ( ) ;
@@ -236,7 +239,7 @@ module.exports = baseVw.extend({
236239 this . setItem ( options . contract_hash , null , function ( ) {
237240 self . cloneItem ( ) ;
238241 } ) ;
239- } ) ;
242+ } ) ;
240243
241244 this . listenTo ( window . obEventBus , "itemShortDelete" , function ( options ) {
242245 self . deleteItem ( false , options . contract_hash ) ;
@@ -250,13 +253,13 @@ module.exports = baseVw.extend({
250253 if ( e . guid === this . model . get ( 'page' ) . profile . guid ) {
251254 this . renderUserBlocked ( ) ;
252255 }
253- } ) ;
256+ } ) ;
254257
255258 this . listenTo ( window . obEventBus , 'unblockingUser' , ( e ) => {
256259 if ( e . guid === this . model . get ( 'page' ) . profile . guid ) {
257260 this . renderUserUnblocked ( ) ;
258261 }
259- } ) ;
262+ } ) ;
260263
261264 //determine if this is the user's own page or another profile's page
262265 //if no userID is passed in, or it matches the user's ID, then this is their page
@@ -320,7 +323,7 @@ module.exports = baseVw.extend({
320323 this . itemFetch && this . itemFetch . abort ( ) ;
321324 }
322325 } ;
323-
326+
324327 if ( this . currentItemHash ) {
325328 config . connectText = window . polyglot . t ( 'pageConnectingMessages.listingConnect' ) . replace ( '${listing}' , this . currentItemHash ) ;
326329 config . failedText = window . polyglot . t ( 'pageConnectingMessages.listingFail' ) ;
@@ -352,6 +355,7 @@ module.exports = baseVw.extend({
352355 self . setCustomStyles ( ) ;
353356 self . $el . html ( loadedTemplate ( self . model . toJSON ( ) ) ) ;
354357 self . fetchFollowing ( ) ;
358+ self . getIsModerator ( ) ;
355359 self . fetchListings ( ) ;
356360 //save state of the page
357361 self . undoCustomAttributes . background_color = self . model . get ( 'page' ) . profile . background_color ;
@@ -519,6 +523,7 @@ module.exports = baseVw.extend({
519523 this . $el . find ( '.js-userPageControls, #customizeControls, .js-itemCustomizationButtons, .js-pageCustomizationButtons' ) . addClass ( 'hide' ) ;
520524 this . $el . find ( '.js-deleteItem' ) . removeClass ( 'confirm' ) ;
521525 this . $el . find ( '.js-unfollow' ) . removeClass ( 'confirm' ) ;
526+ this . $el . find ( '.js-removemoderator' ) . removeClass ( 'confirm' ) ;
522527 this . $el . find ( '.user-page-header-slim-bg-cover' ) . removeClass ( 'user-page-header-slim-bg-cover-customize' ) ;
523528 document . getElementById ( 'obContainer' ) . classList . remove ( "box-borderDashed" ) ;
524529 document . getElementById ( 'obContainer' ) . classList . remove ( "noScrollBar" ) ;
@@ -583,6 +588,20 @@ module.exports = baseVw.extend({
583588 unfollowBtn . removeClass ( 'loading' ) ;
584589 } ,
585590
591+ toggleModeratorButtons : function ( moderated ) {
592+ var addBtn = this . $ ( '.js-addmoderator' ) ,
593+ removeBtn = this . $ ( '.js-removemoderator' ) ;
594+ if ( moderated === true ) {
595+ addBtn . addClass ( 'hide' ) ;
596+ removeBtn . removeClass ( 'hide' ) ;
597+ } else {
598+ addBtn . removeClass ( 'hide' ) ;
599+ removeBtn . addClass ( 'hide' ) ;
600+ }
601+ addBtn . removeClass ( 'loading' ) ;
602+ removeBtn . removeClass ( 'loading' ) ;
603+ } ,
604+
586605 fetchListings : function ( ) {
587606 var self = this ;
588607 this . listings . fetch ( {
@@ -689,9 +708,28 @@ module.exports = baseVw.extend({
689708 } ) ;
690709 } ,
691710
711+ getIsModerator : function ( ) {
712+ console . log ( this . model . get ( 'user' ) . vendor ) ;
713+ if ( this . userProfile . get ( 'profile' ) . moderator == true && this . options . ownPage == false && this . model . get ( 'user' ) . vendor ) {
714+ var pageGuid = this . userProfile . get ( 'profile' ) . guid ;
715+ var mods = this . model . get ( 'user' ) . moderators ;
716+ var found = false ;
717+ var self = this ;
718+ this . toggleModeratorButtons ( false ) ;
719+ __ . each ( mods , function ( mod ) {
720+ if ( mod . guid == pageGuid ) {
721+ found = true ;
722+ }
723+ } ) ;
724+ if ( found == true ) {
725+ this . toggleModeratorButtons ( true ) ;
726+ }
727+ }
728+ } ,
729+
692730 renderItems : function ( model , skipNSFWmodal ) {
693731 "use strict" ;
694-
732+
695733 var self = this ;
696734 var select = this . $el . find ( '.js-categories' ) ;
697735 var selectOptions = [ ] ;
@@ -722,23 +760,23 @@ module.exports = baseVw.extend({
722760 arrayItem . imageURL = self . options . userModel . get ( 'serverUrl' ) + "get_image?hash=" + arrayItem . thumbnail_hash + "&guid=" + self . pageID ;
723761 }
724762 } ) ;
725-
763+
726764 Object . keys ( selectOptions ) . sort ( ) . forEach ( function ( selectOption ) {
727765 var opt = document . createElement ( 'option' ) ;
728766 opt . value = selectOption ;
729767 opt . innerHTML = selectOption ;
730768 select . append ( opt ) ;
731769 } ) ;
732-
770+
733771 this . itemList = new itemListView ( {
734- model : model ,
735- el : '.js-list3' ,
736- title : window . polyglot . t ( 'NoListings' ) ,
772+ model : model ,
773+ el : '.js-list3' ,
774+ title : window . polyglot . t ( 'NoListings' ) ,
737775 message : "" ,
738- userModel : this . options . userModel ,
776+ userModel : this . options . userModel ,
739777 category : this . $el . find ( '.js-categories' ) . val ( )
740778 } ) ;
741-
779+
742780 this . registerChild ( this . itemList ) ;
743781
744782 this . $ ( '.js-listingCount' ) . html ( model . length ) ;
@@ -794,7 +832,7 @@ module.exports = baseVw.extend({
794832 reverse : true
795833 } ) ;
796834 this . registerChild ( this . followingList ) ;
797-
835+
798836 this . $ ( '.js-userFollowingCount' ) . html ( model . length ) ;
799837
800838 if ( model . length ) {
@@ -854,7 +892,7 @@ module.exports = baseVw.extend({
854892 if ( self . options . ownPage === false ) {
855893 model . set ( 'imageExtension' , "&guid=" + model . get ( 'vendor_offer' ) . listing . id . guid ) ;
856894 }
857-
895+
858896 model . updateAttributes ( afterUpdate ) ;
859897 onSucceed && onSucceed ( model , response ) ;
860898
@@ -954,7 +992,7 @@ module.exports = baseVw.extend({
954992 this . categoryChanged ( ) ;
955993 }
956994
957- this . storeClick ( e ) ;
995+ this . storeClick ( e ) ;
958996 } ,
959997
960998 storeCatClick : function ( e ) {
@@ -1116,7 +1154,7 @@ module.exports = baseVw.extend({
11161154 // set recommendations
11171155 this . $el . find ( '.customColorChoice' ) . css ( 'background' , '#fff' ) ; // reset to white to give a cool transition
11181156 this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:first' ) . css ( 'background' , 'transparent' ) ; // set to transparent
1119- this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:nth-child(2)' ) . css ( 'background' , '#ffffff' ) ;
1157+ this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:nth-child(2)' ) . css ( 'background' , '#ffffff' ) ;
11201158 this . $el . find ( '.customizeTextColorRecommendations .customColorChoice:last' ) . css ( 'background' , '#000000' ) ;
11211159
11221160 // slide background_color recommendations out + hide others
@@ -1360,7 +1398,7 @@ module.exports = baseVw.extend({
13601398 saveItem : function ( e ) {
13611399 if ( this . itemEditView ) {
13621400 $ ( e . target ) . addClass ( 'loading' ) ;
1363-
1401+
13641402 this . itemEditView . saveChanges ( ) . always ( ( ) => $ ( e . target ) . removeClass ( 'loading' ) )
13651403 . fail ( ( ) => {
13661404 var $firstErr = this . $ ( '.js-itemEdit .invalid, .js-itemEdit :invalid' ) . not ( 'form' ) . eq ( 0 ) ;
@@ -1414,6 +1452,29 @@ module.exports = baseVw.extend({
14141452
14151453 } ,
14161454
1455+ addModeratorClick : function ( e ) {
1456+ var $targ = $ ( e . target ) . closest ( '.js-addmoderator' ) ;
1457+
1458+ $targ . addClass ( 'loading' ) ;
1459+ /*this.followUser({'guid': this.pageID}).fail(() => {
1460+ $targ.removeClass('loading');
1461+ });*/
1462+ } ,
1463+
1464+ removeModeratorClick : function ( e ) {
1465+ var $targ = $ ( e . target ) . closest ( '.js-removemoderator' ) ;
1466+
1467+ if ( $targ . hasClass ( 'confirm' ) ) {
1468+ $targ . addClass ( 'loading' ) . removeClass ( 'confirm' ) ;
1469+ /*this.unfollowUser({'guid': this.pageID}).fail(() => {
1470+ $(e.target).removeClass('loading')
1471+ });*/
1472+ } else {
1473+ $targ . addClass ( 'confirm' ) ;
1474+ }
1475+
1476+ } ,
1477+
14171478 moreButtonsOwnPageClick : function ( ) {
14181479 if ( $ ( '.js-extraButtonsOwnPage' ) . hasClass ( 'hide' ) ) {
14191480 $ ( '.js-extraButtonsOwnPage' ) . removeClass ( 'hide' ) ;
@@ -1456,7 +1517,7 @@ module.exports = baseVw.extend({
14561517
14571518 unfollowUser : function ( options ) {
14581519 var self = this ;
1459-
1520+
14601521 return $ . ajax ( {
14611522 type : "POST" ,
14621523 data : { 'guid' : options . guid } ,
@@ -1525,7 +1586,7 @@ module.exports = baseVw.extend({
15251586 renderUserUnblocked : function ( ) {
15261587 this . $ ( '.js-unblock' ) . addClass ( 'hide' ) ;
15271588 this . $ ( '.js-block' ) . removeClass ( 'hide' ) ;
1528- } ,
1589+ } ,
15291590
15301591 hideThisUser : function ( reason ) {
15311592 this . $ ( '.js-blockedWarning' ) . fadeIn ( 100 ) ;
0 commit comments