Changeset 12525
- Timestamp:
- 01/18/2020 11:34:45 AM (5 years ago)
- Location:
- trunk/src/bp-templates/bp-nouveau/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-templates/bp-nouveau/js/buddypress-messages.js
r12325 r12525 7 7 ( function( exports, $ ) { 8 8 9 // Bail if not set 9 // Bail if not set. 10 10 if ( typeof BP_Nouveau === 'undefined' ) { 11 11 return; … … 47 47 var self = this; 48 48 49 // First adapt the compose nav 49 // First adapt the compose nav. 50 50 $( '#compose-personal-li' ).addClass( 'last' ); 51 51 52 // Then listen to nav click and load the appropriate view 52 // Then listen to nav click and load the appropriate view. 53 53 $( '#subnav a' ).on( 'click', function( event ) { 54 54 event.preventDefault(); … … 56 56 var view_id = $( event.target ).prop( 'id' ); 57 57 58 // Remove the editor to be sure it will be added dynamically later 58 // Remove the editor to be sure it will be added dynamically later. 59 59 self.removeTinyMCE(); 60 60 61 // The compose view is specific (toggle behavior) 61 // The compose view is specific (toggle behavior). 62 62 if ( 'compose' === view_id ) { 63 // If it exists, it means the user wants to remove it 63 // If it exists, it means the user wants to remove it. 64 64 if ( ! _.isUndefined( self.views.get( 'compose' ) ) ) { 65 65 var form = self.views.get( 'compose' ); … … 67 67 self.views.remove( { id: 'compose', view: form } ); 68 68 69 // Back to inbox 69 // Back to inbox. 70 70 if ( 'single' === self.box ) { 71 71 self.box = 'inbox'; 72 72 } 73 73 74 // Navigate back to current box 74 // Navigate back to current box. 75 75 self.router.navigate( self.box + '/', { trigger: true } ); 76 76 77 // Otherwise load it 77 // Otherwise load it. 78 78 } else { 79 79 self.router.navigate( 'compose/', { trigger: true } ); … … 133 133 var feedback; 134 134 135 // Make sure to remove the feedbacks 135 // Make sure to remove the feedbacks. 136 136 this.removeFeedback(); 137 137 … … 151 151 152 152 clearViews: function() { 153 // Clear views 153 // Clear views. 154 154 if ( ! _.isUndefined( this.views.models ) ) { 155 155 _.each( this.views.models, function( model ) { … … 165 165 this.clearViews(); 166 166 167 // Create the loop view 167 // Create the loop view. 168 168 var form = new bp.Views.messageForm( { 169 169 model: new bp.Models.Message() … … 176 176 177 177 threadsView: function() { 178 // Activate the appropriate nav 178 // Activate the appropriate nav. 179 179 $( '#subnav ul li' ).each( function( l, li ) { 180 180 $( li ).removeClass( 'current selected' ); … … 182 182 $( '#subnav a#' + this.box ).closest( 'li' ).addClass( 'current selected' ); 183 183 184 // Create the loop view 184 // Create the loop view. 185 185 var threads_list = new bp.Views.userThreads( { collection: this.threads, box: this.box } ); 186 186 … … 189 189 threads_list.inject( '.bp-messages-content' ); 190 190 191 // Attach filters 191 // Attach filters. 192 192 this.displayFilters( this.threads ); 193 193 }, … … 196 196 var filters_view; 197 197 198 // Create the model 198 // Create the model. 199 199 this.filters = new Backbone.Model( { 200 200 'page' : 1, … … 204 204 } ); 205 205 206 // Use it in the filters viex 206 // Use it in the filters viex. 207 207 filters_view = new bp.Views.messageFilters( { model: this.filters, threads: collection } ); 208 208 … … 218 218 this.box = 'single'; 219 219 220 // Create the single thread view 220 // Create the single thread view. 221 221 var single_thread = new bp.Views.userMessages( { collection: this.messages, thread: thread } ); 222 222 … … 311 311 options.data = options.data || {}; 312 312 313 // Add generic nonce 313 // Add generic nonce. 314 314 options.data.nonce = BP_Nouveau.nonces.messages; 315 315 … … 394 394 options.data = options.data || {}; 395 395 396 // Add generic nonce 396 // Add generic nonce. 397 397 options.data.nonce = BP_Nouveau.nonces.messages; 398 398 … … 448 448 } ); 449 449 450 // Extend wp.Backbone.View with .prepare() and .inject() 450 // Extend wp.Backbone.View with .prepare() and .inject(). 451 451 bp.Nouveau.Messages.View = bp.Backbone.View.extend( { 452 452 inject: function( selector ) { … … 465 465 } ); 466 466 467 // Feedback view 467 // Feedback view. 468 468 bp.Views.Feedback = bp.Nouveau.Messages.View.extend( { 469 469 tagName: 'div', … … 479 479 } ); 480 480 481 // Hook view 481 // Hook view. 482 482 bp.Views.Hook = bp.Nouveau.Messages.View.extend( { 483 483 tagName: 'div', … … 523 523 524 524 initialize: function() { 525 // Clone the model to set the resetted one 525 // Clone the model to set the resetted one. 526 526 this.resetModel = this.model.clone(); 527 527 528 // Add the editor view 528 // Add the editor view. 529 529 this.views.add( '#bp-message-content', new bp.Views.messageEditor() ); 530 530 531 531 this.model.on( 'change', this.resetFields, this ); 532 532 533 // Activate bp_mentions 533 // Activate bp_mentions. 534 534 this.on( 'ready', this.addMentions, this ); 535 535 }, … … 539 539 mention = bp.Nouveau.getLinkParams( null, 'r' ) || null; 540 540 541 // Add autocomplete to send_to field 541 // Add autocomplete to send_to field. 542 542 sendToInput.bp_mentions( { 543 543 data: [], … … 545 545 } ); 546 546 547 // Check for mention 547 // Check for mention. 548 548 if ( ! _.isNull( mention ) ) { 549 549 sendToInput.val( '@' + _.escape( mention ) + ' ' ); … … 553 553 554 554 resetFields: function( model ) { 555 // Clean inputs 555 // Clean inputs. 556 556 _.each( model.previousAttributes(), function( value, input ) { 557 557 if ( 'message_content' === input ) { 558 // tinyMce 558 // tinyMce. 559 559 if ( undefined !== tinyMCE.activeEditor && null !== tinyMCE.activeEditor ) { 560 560 tinyMCE.activeEditor.setContent( '' ); 561 561 } 562 562 563 // All except meta or empty value 563 // All except meta or empty value. 564 564 } else if ( 'meta' !== input && false !== value ) { 565 565 $( 'input[name="' + input + '"]' ).val( '' ); … … 577 577 bp.Nouveau.Messages.removeFeedback(); 578 578 579 // Set the content and meta 579 // Set the content and meta. 580 580 _.each( this.$el.serializeArray(), function( pair ) { 581 581 pair.name = pair.name.replace( '[]', '' ); 582 582 583 // Group extra fields in meta 583 // Group extra fields in meta. 584 584 if ( -1 === _.indexOf( ['send_to', 'subject', 'message_content'], pair.name ) ) { 585 585 if ( _.isUndefined( meta[ pair.name ] ) ) { … … 593 593 } 594 594 595 // Prepare the core model 595 // Prepare the core model. 596 596 } else { 597 // Send to 597 // Send to. 598 598 if ( 'send_to' === pair.name ) { 599 599 var usernames = pair.value.match( /(^|[^@\w\-])@([a-zA-Z0-9_\-]{1,50})\b/g ); … … 614 614 } 615 615 616 // Subject and content 616 // Subject and content. 617 617 } else { 618 // Message content 618 // Message content. 619 619 if ( 'message_content' === pair.name && undefined !== tinyMCE.activeEditor ) { 620 620 pair.value = tinyMCE.activeEditor.getContent(); … … 641 641 } 642 642 643 // Set meta 643 // Set meta. 644 644 this.model.set( 'meta', meta, { silent: true } ); 645 645 646 646 // Send the message. 647 647 this.model.sendMessage().done( function( response ) { 648 // Reset the model 648 // Reset the model. 649 649 self.model.set( self.resetModel ); 650 650 651 651 bp.Nouveau.Messages.displayFeedback( response.feedback, response.type ); 652 652 653 // Remove tinyMCE 653 // Remove tinyMCE. 654 654 bp.Nouveau.Messages.removeTinyMCE(); 655 655 656 // Remove the form view 656 // Remove the form view. 657 657 var form = bp.Nouveau.Messages.views.get( 'compose' ); 658 658 form.get( 'view' ).remove(); … … 691 691 }, this ); 692 692 693 // Load threads for the active view 693 // Load threads for the active view. 694 694 this.requestThreads(); 695 695 … … 849 849 var isChecked = $( event.currentTarget ).prop( 'checked' ); 850 850 851 // To avoid infinite loops 851 // To avoid infinite loops. 852 852 this.model.set( 'checked', isChecked, { silent: true } ); 853 853 … … 895 895 896 896 render: function() { 897 // Only render if we have some content to render 897 // Only render if we have some content to render. 898 898 if ( _.isUndefined( this.model ) || true !== this.model.get( 'active' ) ) { 899 899 return; … … 945 945 mid = model.get( 'id' ); 946 946 947 // Open the full conversation 947 // Open the full conversation. 948 948 if ( 'view' === action ) { 949 949 bp.Nouveau.Messages.router.navigate( … … 974 974 975 975 if ( 'delete' === action || ( 'starred' === self.collection.options.box && 'unstar' === action ) ) { 976 // Remove from the list of messages 976 // Remove from the list of messages. 977 977 self.collection.remove( model.get( 'id' ) ); 978 978 979 // And Requery 979 // And Requery. 980 980 self.collection.fetch( { 981 981 data : _.pick( self.collection.options, ['box', 'search_terms', 'page'] ) … … 1050 1050 } ); 1051 1051 1052 // Default to thread ids 1052 // Default to thread ids. 1053 1053 ids = thread_ids; 1054 1054 1055 // We need to get the starred ids 1055 // We need to get the starred ids. 1056 1056 if ( 'star' === action || 'unstar' === action ) { 1057 1057 ids = _.map( threads, function( model ) { … … 1065 1065 } 1066 1066 1067 // Map with first message starred in the thread 1067 // Map with first message starred in the thread. 1068 1068 attr = 'starred_id'; 1069 1069 } 1070 1070 1071 // Message id to Thread id 1071 // Message id to Thread id. 1072 1072 var m_tid = _.object( _.map( threads, function (model) { 1073 1073 return [model.get( attr ), model.get( 'id' )]; … … 1085 1085 1086 1086 if ( 'delete' === action || ( 'starred' === self.collection.options.box && 'unstar' === action ) ) { 1087 // Remove from the list of messages 1087 // Remove from the list of messages. 1088 1088 self.collection.remove( thread_ids ); 1089 1089 1090 // And Requery 1090 // And Requery. 1091 1091 self.collection.fetch( { 1092 1092 data : _.pick( self.collection.options, ['box', 'search_terms', 'page'] ) 1093 1093 } ); 1094 1094 } else if ( response.messages ) { 1095 // Update each model attributes 1095 // Update each model attributes. 1096 1096 _.each( response.messages, function( updated, id ) { 1097 1097 var model = self.collection.get( m_tid[id] ); … … 1245 1245 bp.Nouveau.Messages.removeFeedback(); 1246 1246 1247 // Display the feedback 1247 // Display the feedback. 1248 1248 bp.Nouveau.Messages.displayFeedback( response.feedback, response.type ); 1249 1249 } ).fail( function( response ) { … … 1282 1282 1283 1283 initialize: function() { 1284 // Load Messages 1284 // Load Messages. 1285 1285 this.requestMessages(); 1286 1286 1287 // Init a reply 1287 // Init a reply. 1288 1288 this.reply = new bp.Models.messageThread(); 1289 1289 1290 1290 this.collection.on( 'add', this.addMessage, this ); 1291 1291 1292 // Add the editor view 1292 // Add the editor view. 1293 1293 this.views.add( '#bp-message-content', new bp.Views.messageEditor() ); 1294 1294 }, … … 1367 1367 var reply = this.collection.parse( response ); 1368 1368 1369 // Reset the form 1369 // Reset the form. 1370 1370 tinyMCE.activeEditor.setContent( '' ); 1371 1371 this.reply.set( 'sending', false ); … … 1400 1400 } 1401 1401 1402 // Try to get the corresponding thread 1402 // Try to get the corresponding thread. 1403 1403 var thread = bp.Nouveau.Messages.threads.get( thread_id ); 1404 1404 … … 1427 1427 } ); 1428 1428 1429 // Launch BP Nouveau Groups 1429 // Launch BP Nouveau Groups. 1430 1430 bp.Nouveau.Messages.start(); 1431 1431 -
trunk/src/bp-templates/bp-nouveau/js/buddypress-notifications.js
r12082 r12525 5 5 ( function( exports, $ ) { 6 6 7 // Bail if not set 7 // Bail if not set. 8 8 if ( typeof BP_Nouveau === 'undefined' ) { 9 9 return; … … 25 25 this.setupGlobals(); 26 26 27 // Listen to events ("Add hooks!") 27 // Listen to events ("Add hooks!"). 28 28 this.addListeners(); 29 29 }, … … 48 48 $( '#buddypress [data-bp-list="notifications"]' ).on( 'click', '[data-bp-notifications-order]', bp.Nouveau, this.sortNotifications ); 49 49 50 // Enable the Apply Button once the bulk action is selected 50 // Enable the Apply Button once the bulk action is selected. 51 51 $( '#buddypress [data-bp-list="notifications"]' ).on( 'change', '#notification-select', this.enableBulkSubmit ); 52 52 53 // Select all displayed notifications 53 // Select all displayed notifications. 54 54 $( '#buddypress [data-bp-list="notifications"]' ).on( 'click', '#select-all-notifications', this.selectAll ); 55 55 56 // Reset The filter before unload 56 // Reset The filter before unload. 57 57 $( window ).on( 'unload', this.resetFilter ); 58 58 }, … … 73 73 } 74 74 75 // Make sure a 'Bulk Action' is selected before submitting the form 75 // Make sure a 'Bulk Action' is selected before submitting the form. 76 76 $( '#notification-bulk-manage' ).prop( 'disabled', 'disabled' ); 77 77 }, … … 135 135 }; 136 136 137 // Launch BP Nouveau Notifications 137 // Launch BP Nouveau Notifications. 138 138 bp.Nouveau.Notifications.start(); 139 139
Note: See TracChangeset
for help on using the changeset viewer.