Skip to:
Content

BuddyPress.org

Changeset 10208


Ignore:
Timestamp:
10/07/2015 05:23:13 PM (9 years ago)
Author:
imath
Message:

Avatar UI, Cover Image UI: Introduce a "client side hook"

When the avatar is uploaded or deleted and when the Cover Image is uploaded or deleted, the corresponding Attachment Backbone.Model will trigger an event containing the url, the object type (group or user) and the item id of the object.

Fixes #6647

Location:
trunk/src/bp-core/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/js/avatar.js

    r10160 r10208  
    3434            // Avatars are uploaded files
    3535            this.avatars = bp.Uploader.filesUploaded;
     36
     37            // The Avatar Attachment object.
     38            this.Attachment = new Backbone.Model();
    3639
    3740            // Wait till the queue is reset
     
    257260                bp.Avatar.navItems.get( 'delete' ).set( { hide: 0 } );
    258261
     262                /**
     263                 * Set the Attachment object
     264                 *
     265                 * You can run extra actions once the avatar is set using:
     266                 * bp.Avatar.Attachment.on( 'change:url', function( data ) { your code } );
     267                 *
     268                 * In this case data.attributes will include the url to the newly
     269                 * uploaded avatar, the object and the item_id concerned.
     270                 */
     271                self.Attachment.set( _.extend(
     272                    _.pick( avatar.attributes, ['object', 'item_id'] ),
     273                    { url: response.avatar, action: 'uploaded' }
     274                ) );
     275
    259276            } ).fail( function( response ) {
    260277                var feedback = BP_Uploader.strings.default_error;
     
    330347                } );
    331348
    332                  // Remove the Delete nav
    333                  bp.Avatar.navItems.get( 'delete' ).set( { active: 0, hide: 1 } );
     349                // Remove the Delete nav
     350                bp.Avatar.navItems.get( 'delete' ).set( { active: 0, hide: 1 } );
     351
     352                /**
     353                 * Reset the Attachment object
     354                 *
     355                 * You can run extra actions once the avatar is set using:
     356                 * bp.Avatar.Attachment.on( 'change:url', function( data ) { your code } );
     357                 *
     358                 * In this case data.attributes will include the url to the gravatar,
     359                 * the object and the item_id concerned.
     360                 */
     361                self.Attachment.set( _.extend(
     362                    _.pick( model.attributes, ['object', 'item_id'] ),
     363                    { url: response.avatar, action: 'deleted' }
     364                ) );
    334365
    335366            } ).fail( function( response ) {
  • trunk/src/bp-core/js/cover-image.js

    r10160 r10208  
    2020            this.views   = new Backbone.Collection();
    2121            this.warning = null;
     22
     23            // The Cover Image Attachment object.
     24            this.Attachment = new Backbone.Model();
    2225
    2326            // Set up views
     
    126129                BP_Uploader.settings.defaults.multipart_params.bp_params.has_cover_image = false;
    127130
     131                /**
     132                 * Reset the Attachment object
     133                 *
     134                 * You can run extra actions once the cover image is set using:
     135                 * bp.CoverImage.Attachment.on( 'change:url', function( data ) { your code } );
     136                 *
     137                 * In this case data.attributes will include the default url for the
     138                 * cover image (most of the time: ''), the object and the item_id concerned.
     139                 */
     140                self.Attachment.set( _.extend(
     141                    _.pick( model.attributes, ['object', 'item_id'] ),
     142                    { url: response.reset_url, action: 'deleted' }
     143                ) );
     144
    128145            } ).fail( function( response ) {
    129146                var feedback = BP_Uploader.strings.default_error;
     
    204221                // Add the delete view
    205222                bp.CoverImage.deleteView();
     223
     224                /**
     225                 * Set the Attachment object
     226                 *
     227                 * You can run extra actions once the cover image is set using:
     228                 * bp.CoverImage.Attachment.on( 'change:url', function( data ) { your code } );
     229                 *
     230                 * In this case data.attributes will include the url to the newly
     231                 * uploaded cover image, the object and the item_id concerned.
     232                 */
     233                bp.CoverImage.Attachment.set( _.extend(
     234                    _.pick( BP_Uploader.settings.defaults.multipart_params.bp_params, ['object', 'item_id'] ),
     235                    { url: model.get( 'url' ), action: 'uploaded' }
     236                ) );
    206237            }
    207238        }
Note: See TracChangeset for help on using the changeset viewer.