inT_Sheriff

Untitled

May 12th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PresentGroupInviteOptions( rgFriendsToInvite )
  2. {
  3.     // this deferred will succeed if an invite is succesfully sent, fail if the user dismisses the modal or the invite AJAX fails
  4.     var deferred = new jQuery.Deferred();
  5.  
  6.     var Modal = ShowDialog( 'In Ihre Gruppe einladen', '<div class="group_invite_throbber"><img src="https://steamcommunity-a.akamaihd.net/public/images/login/throbber.gif"></div>' );
  7.     var $ListElement = $J('<div/>', {'class': 'newmodal_content_innerbg'} );
  8.  
  9.     var bBulkFriendInvite = false;
  10.     var steamIDInvitee = g_rgProfileData['steamid'];
  11.     var strProfileURL = g_rgProfileData['url'];
  12.  
  13.     // see if this is a request to bulk invite a group of friends
  14.     if ( rgFriendsToInvite && rgFriendsToInvite instanceof Array )
  15.     {
  16.         if ( rgFriendsToInvite.length == 1 )
  17.         {
  18.             steamIDInvitee = rgFriendsToInvite[0];
  19.             strProfileURL = 'https://steamcommunity.com/profiles/' + steamIDInvitee + '/';
  20.         }
  21.         else
  22.         {
  23.             // true bulk invite
  24.             steamIDInvitee = rgFriendsToInvite;
  25.             bBulkFriendInvite = true;
  26.         }
  27.     }
  28.  
  29.     // if the modal is dismissed , we'll cancel the deferred object.  We capture this in a closure so that we can dismiss the modal without affecting
  30.     //  the deferred object if the user actually picks something (in which case the deferred object will be the success of the AJAX invite action)
  31.     var fnOnModalDismiss = function() { deferred.reject() };
  32.  
  33.     $J.get( strProfileURL + 'ajaxgroupinvite?new_profile=1' + ( bBulkFriendInvite ? '&bulk=1' : '' ), function( html ) {
  34.         Modal.GetContent().find( '.newmodal_content').html(''); // erase the throbber
  35.         Modal.GetContent().find( '.newmodal_content').append( $ListElement );
  36.         $ListElement.html( html );
  37.         Modal.AdjustSizing();
  38.         $ListElement.children( '.group_list_results' ).children().each( function () {
  39.             var groupid = this.getAttribute( 'data-groupid' );
  40.             if ( groupid )
  41.             {
  42.                 $J(this).click( function() {
  43.                     fnOnModalDismiss = function () {;}; // don't resolve the deferred on modal dismiss anymore, user has picked something
  44.                     InviteUserToGroup( Modal, groupid, steamIDInvitee)
  45.                     .done( function() { deferred.resolve(); } )
  46.                     .fail( function() { deferred.reject(); } );
  47.                 } );
  48.             }
  49.         });
  50.     });
  51.  
  52.     Modal.done( function() {fnOnModalDismiss();} );
  53.  
  54.     return deferred.promise();
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. function InviteUserToGroup( Modal, groupID, steamIDInvitee )
  62. {
  63.     var params = {
  64.         json: 1,
  65.         type: 'groupInvite',
  66.         group: groupID,
  67.         sessionID: g_sessionID
  68.     };
  69.  
  70.     if ( !steamIDInvitee.length )
  71.     {
  72.         ShowAlertDialog( 'Fehler', 'Sie haben keine Freunde ausgewählt.' );
  73.         return;
  74.     }
  75.  
  76.     if ( steamIDInvitee instanceof Array )
  77.         params.invitee_list = V_ToJSON( steamIDInvitee );
  78.     else
  79.         params.invitee = steamIDInvitee;
  80.  
  81.     return $J.ajax( { url: 'https://steamcommunity.com/actions/GroupInvite',
  82.         data: params,
  83.         type: 'POST'
  84.     } ).done( function( data ) {
  85.         Modal && Modal.Dismiss();
  86.  
  87.         var strMessage = 'Einladung verschickt!';
  88.         if ( steamIDInvitee instanceof Array && steamIDInvitee.length > 1 )
  89.             strMessage = 'Einladungen verschickt!';
  90.  
  91.         ShowAlertDialog( 'In Ihre Gruppe einladen', strMessage );
  92.     }).fail( function( data ) {
  93.         Modal && Modal.Dismiss();
  94.  
  95.         var rgResults = data.responseJSON;
  96.  
  97.         var strModalTitle = 'Gruppeneinladung fehlgeschlagen';
  98.         var strAccountListModal = '<div class="ctnClanInviteErrors">';
  99.         strAccountListModal += rgResults.results ? rgResults.results : 'Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.';
  100.         if ( rgResults.rgAccounts )
  101.         {
  102.             strAccountListModal += '<div class="ctnClanInviteErrors"><table class="clanInviteErrorTable" ><thead><tr><th class="inviteTablePersona" >Eingeladener Spieler</th><th class="inviteTableError">Fehler</th></tr></thead><tbody>';
  103.             var cAccounts = 0;
  104.             $J.each( rgResults.rgAccounts, function( accountid, rgError ){
  105.                 strAccountListModal += '<tr>';
  106.                 strAccountListModal += '<td class="inviteTablePersona ellipsis">' + rgError.persona + '</td>';
  107.                 strAccountListModal += '<td class="inviteTableError">' + rgError.strError + "</td>";
  108.                 strAccountListModal += '</tr>';
  109.  
  110.                 if ( typeof SelectNone != 'undefined' )
  111.                 {
  112.                     SelectNone();
  113.                     $J( '#fr_' + accountid ).addClass( 'groupInviteFailed' );
  114.                 }
  115.  
  116.                 cAccounts++;
  117.             } );
  118.             strAccountListModal += '</tbody></table>';
  119.  
  120.             if ( cAccounts > 1 )
  121.                 strModalTitle = 'Gruppeneinladungen fehlgeschlagen';
  122.  
  123.         }
  124.         strAccountListModal +='</div>';
  125.         ShowAlertDialog( strModalTitle, strAccountListModal );
  126.     });
  127. }
  128.  
  129.  
  130.  
  131. function ManageFriendsInviteToGroup( $Form, groupid )
  132. {
  133.     $Form.find('input[type="checkbox"]');
  134.     var rgFriendSteamIDs = [];
  135.     $Form.find( 'input[type=checkbox]' ).each( function() {
  136.         if ( this.checked )
  137.             rgFriendSteamIDs.push( $J(this).attr( 'data-steamid' ) );
  138.     } );
  139.     if ( rgFriendSteamIDs.length > 0 )
  140.     {
  141.         if ( groupid )
  142.         {
  143.             // specific group
  144.             InviteUserToGroup( null /* no modal window */, groupid, rgFriendSteamIDs ).done( function() {
  145.                 $Form.find('input[type=checkbox]').prop( 'checked', false );
  146.             });
  147.         }
  148.         else
  149.         {
  150.             // ask the user which group to invite to
  151.             PresentGroupInviteOptions( rgFriendSteamIDs).done( function() {
  152.                 $Form.find('input[type=checkbox]').prop( 'checked', false );
  153.             });
  154.         }
  155.     }
  156.     else
  157.     {
  158.         ShowAlertDialog( 'In Ihre Gruppe einladen', 'Sie haben keine Freunde ausgewählt.' );
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment