Ticket #1590: 1590.patch
File 1590.patch, 6.7 KB (added by , 8 years ago) |
---|
-
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js
21 21 }, 22 22 23 23 initialize: function() { 24 var subProjects= this.get( 'sub_projects' );24 this.baseCollection = this.get( 'sub_projects' ); 25 25 this.unset( 'sub_projects' ); 26 26 27 this.set( 'subProjects', new projects.model.subProjects( subProjects ) ); 27 this.set( 'subProjects', new projects.model.subProjects( this.baseCollection, { 28 project: this, 29 } ) ); 28 30 this.set( 'checked', _.contains( projects.settings.accessList, parseInt( this.get( 'id' ), 10 ) ) ); 29 31 30 32 this.listenTo( this.get( 'subProjects' ), 'change:checked', this.updateChecked ); … … 83 85 defaults: { 84 86 id: 0, 85 87 name: '', 86 checked: false, 87 isVisible: true 88 checked: false 88 89 }, 89 90 90 91 initialize: function() { … … 98 99 // Search terms 99 100 terms: '', 100 101 101 initialize: function() { 102 initialize: function( models, options ) { 103 this.project = options.project; 102 104 this.on( 'uncheckall', this.uncheckall ); 103 105 }, 104 106 … … 120 122 this.search( this.terms ); 121 123 } 122 124 123 if ( this.terms === '' ) { 124 this.each( function( project ) { 125 project.set( 'isVisible', true ); 126 }); 125 // If search is blank, show all projects. 126 if ( '' === this.terms ) { 127 this.reset( this.project.baseCollection ); 127 128 } 129 130 // Trigger a 'projects:update' event 131 this.trigger( 'projects:update' ); 128 132 }, 129 133 130 134 // Performs a search within the collection 131 135 // @uses RegExp 132 136 search: function( term ) { 133 var match ;137 var match, results; 134 138 139 // Start with a full collection 140 this.reset( this.project.baseCollection, { silent: true } ); 141 135 142 // Escape the term string for RegExp meta characters 136 143 term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); 137 144 … … 140 147 term = term.replace( / /g, ')(?=.*' ); 141 148 match = new RegExp( '^(?=.*' + term + ').+', 'i' ); 142 149 143 // Find results 144 this.each( function( project ) { 150 results = this.filter( function( project ) { 145 151 var haystack = _.union( [ project.get( 'name' ), project.get( 'slug' ) ] ); 146 project.set( 'isVisible', match.test( haystack ));152 return match.test( haystack ); 147 153 }); 154 155 this.reset( results ); 148 156 }, 149 157 150 158 comparator: function( project ) { … … 262 270 this.views.add( new projects.view.SubProjectsList({ 263 271 collection: collection 264 272 }) ); 265 } 273 }, 274 266 275 }); 267 276 268 277 projects.view.SubProjectsList = wp.Backbone.View.extend({ 269 278 tagName: 'ul', 270 279 className: 'sub-projects-list', 271 280 272 initialize: function() { 273 var view = this; 274 this.collection.each( function( project ) { 275 view.views.add( new projects.view.SubProject({ 276 model: project 277 }) ); 281 // How many projects should be rendered. 282 limit: 100, 283 284 initialize: function( options ) { 285 var self = this; 286 287 this.listenTo( self.collection, 'projects:update', function() { 288 self.render( this ); 289 } ); 290 }, 291 292 render: function() { 293 var self = this, subProjects; 294 295 self.$el.empty(); 296 297 subProjects = self.collection.first( self.limit ); 298 _.each( subProjects, function( model ) { 299 var subProjectView = new projects.view.SubProject({ 300 model: model 301 }); 302 303 subProjectView.render(); 304 self.$el.append( subProjectView.el ); 278 305 }); 279 306 } 280 307 }); … … 286 313 this.views.add( new projects.view.Checkbox({ 287 314 model: this.model 288 315 }) ); 289 290 this.listenTo( this.model, 'change:isVisible', this.changeVisibility );291 },292 293 changeVisibility: function() {294 if ( this.model.get( 'isVisible' ) ) {295 this.$el.removeClass( 'hidden' );296 } else {297 this.$el.addClass( 'hidden' );298 }299 316 } 300 317 }); 301 318 … … 332 349 333 350 doSearch: _.debounce( function( event ) { 334 351 this.collection.doSearch( event.target.value ); 335 }, 200 )352 }, 500 ) 336 353 }); 337 354 338 projects.init = function() {355 projects.initFrame = function( projectData ) { 339 356 projects.view.frame = new projects.view.Frame({ 340 collection: new projects.model.Projects( project s.settings.data )357 collection: new projects.model.Projects( projectData ) 341 358 }).render(); 342 359 }; 343 360 361 projects.init = function() { 362 var projectData = localStorage.getItem( 'projectData' ); 363 if ( projectData ) { 364 projectData = JSON.parse( projectData ); 365 projects.initFrame( projectData ); 366 return; 367 } 368 369 wp.ajax.post( 'rosetta-get-project-data' ) 370 .done( function( projectData ) { 371 var r = localStorage.setItem( 'projectData', JSON.stringify( projectData ) ); 372 projects.initFrame( projectData ); 373 } ); 374 }; 375 344 376 $( projects.init ); 345 377 346 378 $( '#project-all' ).on( 'click', function() { -
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php
76 76 77 77 add_action( 'translation_editor_added', array( $this, 'update_wporg_profile_badge' ) ); 78 78 add_action( 'translation_editor_removed', array( $this, 'update_wporg_profile_badge' ) ); 79 80 add_action( 'wp_ajax_rosetta-get-project-data', array( $this, 'ajax_get_project_data' ) ); 79 81 } 80 82 81 83 /** … … 618 620 * Renders the edit page. 619 621 */ 620 622 private function render_edit_translation_editor( $user_id ) { 623 $project_access_list = $this->get_users_projects( $user_id ); 624 625 wp_localize_script( 'rosetta-roles', '_rosettaProjectsSettings', array( 626 'l10n' => array( 627 'searchPlaceholder' => esc_attr__( 'Search...', 'rosetta' ), 628 ), 629 'accessList' => $project_access_list, 630 ) ); 631 632 $feedback_message = $this->get_feedback_message(); 633 634 require __DIR__ . '/views/edit-translation-editor.php'; 635 } 636 637 public function ajax_get_project_data() { 621 638 $projects = $this->get_translate_projects(); 622 639 $project_tree = $this->get_project_tree( $projects, 0, 1 ); 623 640 … … 631 648 } 632 649 $project_tree = array_values( $project_tree ); 633 650 634 $project_access_list = $this->get_users_projects( $user_id ); 635 636 wp_localize_script( 'rosetta-roles', '_rosettaProjectsSettings', array( 637 'l10n' => array( 638 'searchPlaceholder' => esc_attr__( 'Search...', 'rosetta' ), 639 ), 640 'data' => $project_tree, 641 'accessList' => $project_access_list, 642 ) ); 643 644 $feedback_message = $this->get_feedback_message(); 645 646 require __DIR__ . '/views/edit-translation-editor.php'; 651 wp_send_json_success( $project_tree ); 647 652 } 648 653 649 654 /**