Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/202935

Change subject: WIP: Add ability to remove/add new members to a collection via 
search
......................................................................

WIP: Add ability to remove/add new members to a collection via search

Change-Id: Ie262761519a29ad695695dcdf0f85f82e71d2dd0
---
M resources/ext.gather.page.search/CollectionSearchPanel.hogan
M resources/ext.gather.page.search/CollectionSearchPanel.js
2 files changed, 55 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/35/202935/1

diff --git a/resources/ext.gather.page.search/CollectionSearchPanel.hogan 
b/resources/ext.gather.page.search/CollectionSearchPanel.hogan
index 40c7061..f43b407 100644
--- a/resources/ext.gather.page.search/CollectionSearchPanel.hogan
+++ b/resources/ext.gather.page.search/CollectionSearchPanel.hogan
@@ -1 +1,4 @@
+<div class="search">
+       {{{searchIcon}}}<input type="text">
+</div>
 <div class="results"></div>
diff --git a/resources/ext.gather.page.search/CollectionSearchPanel.js 
b/resources/ext.gather.page.search/CollectionSearchPanel.js
index b2e4961..7315f86 100644
--- a/resources/ext.gather.page.search/CollectionSearchPanel.js
+++ b/resources/ext.gather.page.search/CollectionSearchPanel.js
@@ -14,13 +14,30 @@
         */
        CollectionSearchPanel = Panel.extend( {
                template: mw.template.get( 'ext.gather.page.search', 
'CollectionSearchPanel.hogan' ),
+               /** @inheritdoc */
+               events: $.extend( {}, Panel.prototype.events, {
+                       'input .search input': 'onSearchInput'
+               } ),
                /**
                 * @inheritdoc
                 * @cfg {Array} defaults.pages a list of pages in the collection
                 */
                className: 'panel visible collection-search-panel',
                defaults: {
-                       pages: []
+                       pages: [],
+                       searchIcon: new Icon( {
+                               name: 'search',
+                               // FIXME:
+                               label: mw.msg( 'search' ),
+                               additionalClassNames: 'indicator'
+                       } ).toHtmlString()
+               },
+               /** @inheritdoc */
+               initialize: function ( options ) {
+                       this.collectionMembers = options.collectionMembers;
+                       // FIXME: SearchApi won't cut it - need to return if 
collection are members too
+                       this.api = new SearchApi();
+                       Panel.prototype.initialize.apply( this, arguments );
                },
                postRender: function( options ) {
                        Panel.prototype.postRender.apply( this, arguments );
@@ -31,6 +48,40 @@
                                pages: pages,
                                el: this.$( '.results' )
                        } );
+               },
+               onSearchInput: function () {
+                       var self = this,
+                               $input = this.$( 'input' ),
+                               query = $input.val(),
+                               $results = this.$( '.results' ),
+                               collectionPageList;
+
+                       // it seems the input event can be fired when virtual 
keyboard is closed
+                       // (Chrome for Android)
+                       if ( query !== this.lastQuery ) {
+                               this.api.abort();
+                               clearTimeout( this.timer );
+                               $results.empty();
+
+                               if ( query.length ) {
+                                       this.$( '.spinner' ).show();
+
+                                       this.timer = setTimeout( function () {
+                                               self.api.search( query ).done( 
function ( data ) {
+                                                       // check if we're 
getting the rights response in case of out of
+                                                       // order responses 
(need to get the current value of the input)
+                                                       if ( data.query === 
$input.val() ) {
+                                                               self.$( 
'.spinner' ).hide();
+                                                               
self._renderResults( data.results );
+                                                       }
+                                               } );
+                                       }, this.api.isCached( query ) ? 0 : 
SEARCH_DELAY );
+                               } else {
+                                       self.$( '.spinner' ).hide();
+                               }
+
+                               this.lastQuery = query;
+                       }
                }
        } );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/202935
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie262761519a29ad695695dcdf0f85f82e71d2dd0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to