Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PresentGroupInviteOptions( rgFriendsToInvite )
- {
- // this deferred will succeed if an invite is succesfully sent, fail if the user dismisses the modal or the invite AJAX fails
- var deferred = new jQuery.Deferred();
- 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>' );
- var $ListElement = $J('<div/>', {'class': 'newmodal_content_innerbg'} );
- var bBulkFriendInvite = false;
- var steamIDInvitee = g_rgProfileData['steamid'];
- var strProfileURL = g_rgProfileData['url'];
- // see if this is a request to bulk invite a group of friends
- if ( rgFriendsToInvite && rgFriendsToInvite instanceof Array )
- {
- if ( rgFriendsToInvite.length == 1 )
- {
- steamIDInvitee = rgFriendsToInvite[0];
- strProfileURL = 'https://steamcommunity.com/profiles/' + steamIDInvitee + '/';
- }
- else
- {
- // true bulk invite
- steamIDInvitee = rgFriendsToInvite;
- bBulkFriendInvite = true;
- }
- }
- // 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
- // the deferred object if the user actually picks something (in which case the deferred object will be the success of the AJAX invite action)
- var fnOnModalDismiss = function() { deferred.reject() };
- $J.get( strProfileURL + 'ajaxgroupinvite?new_profile=1' + ( bBulkFriendInvite ? '&bulk=1' : '' ), function( html ) {
- Modal.GetContent().find( '.newmodal_content').html(''); // erase the throbber
- Modal.GetContent().find( '.newmodal_content').append( $ListElement );
- $ListElement.html( html );
- Modal.AdjustSizing();
- $ListElement.children( '.group_list_results' ).children().each( function () {
- var groupid = this.getAttribute( 'data-groupid' );
- if ( groupid )
- {
- $J(this).click( function() {
- fnOnModalDismiss = function () {;}; // don't resolve the deferred on modal dismiss anymore, user has picked something
- InviteUserToGroup( Modal, groupid, steamIDInvitee)
- .done( function() { deferred.resolve(); } )
- .fail( function() { deferred.reject(); } );
- } );
- }
- });
- });
- Modal.done( function() {fnOnModalDismiss();} );
- return deferred.promise();
- }
- function InviteUserToGroup( Modal, groupID, steamIDInvitee )
- {
- var params = {
- json: 1,
- type: 'groupInvite',
- group: groupID,
- sessionID: g_sessionID
- };
- if ( !steamIDInvitee.length )
- {
- ShowAlertDialog( 'Fehler', 'Sie haben keine Freunde ausgewählt.' );
- return;
- }
- if ( steamIDInvitee instanceof Array )
- params.invitee_list = V_ToJSON( steamIDInvitee );
- else
- params.invitee = steamIDInvitee;
- return $J.ajax( { url: 'https://steamcommunity.com/actions/GroupInvite',
- data: params,
- type: 'POST'
- } ).done( function( data ) {
- Modal && Modal.Dismiss();
- var strMessage = 'Einladung verschickt!';
- if ( steamIDInvitee instanceof Array && steamIDInvitee.length > 1 )
- strMessage = 'Einladungen verschickt!';
- ShowAlertDialog( 'In Ihre Gruppe einladen', strMessage );
- }).fail( function( data ) {
- Modal && Modal.Dismiss();
- var rgResults = data.responseJSON;
- var strModalTitle = 'Gruppeneinladung fehlgeschlagen';
- var strAccountListModal = '<div class="ctnClanInviteErrors">';
- strAccountListModal += rgResults.results ? rgResults.results : 'Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.';
- if ( rgResults.rgAccounts )
- {
- strAccountListModal += '<div class="ctnClanInviteErrors"><table class="clanInviteErrorTable" ><thead><tr><th class="inviteTablePersona" >Eingeladener Spieler</th><th class="inviteTableError">Fehler</th></tr></thead><tbody>';
- var cAccounts = 0;
- $J.each( rgResults.rgAccounts, function( accountid, rgError ){
- strAccountListModal += '<tr>';
- strAccountListModal += '<td class="inviteTablePersona ellipsis">' + rgError.persona + '</td>';
- strAccountListModal += '<td class="inviteTableError">' + rgError.strError + "</td>";
- strAccountListModal += '</tr>';
- if ( typeof SelectNone != 'undefined' )
- {
- SelectNone();
- $J( '#fr_' + accountid ).addClass( 'groupInviteFailed' );
- }
- cAccounts++;
- } );
- strAccountListModal += '</tbody></table>';
- if ( cAccounts > 1 )
- strModalTitle = 'Gruppeneinladungen fehlgeschlagen';
- }
- strAccountListModal +='</div>';
- ShowAlertDialog( strModalTitle, strAccountListModal );
- });
- }
- function ManageFriendsInviteToGroup( $Form, groupid )
- {
- $Form.find('input[type="checkbox"]');
- var rgFriendSteamIDs = [];
- $Form.find( 'input[type=checkbox]' ).each( function() {
- if ( this.checked )
- rgFriendSteamIDs.push( $J(this).attr( 'data-steamid' ) );
- } );
- if ( rgFriendSteamIDs.length > 0 )
- {
- if ( groupid )
- {
- // specific group
- InviteUserToGroup( null /* no modal window */, groupid, rgFriendSteamIDs ).done( function() {
- $Form.find('input[type=checkbox]').prop( 'checked', false );
- });
- }
- else
- {
- // ask the user which group to invite to
- PresentGroupInviteOptions( rgFriendSteamIDs).done( function() {
- $Form.find('input[type=checkbox]').prop( 'checked', false );
- });
- }
- }
- else
- {
- ShowAlertDialog( 'In Ihre Gruppe einladen', 'Sie haben keine Freunde ausgewählt.' );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment