diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-06-02 13:53:17 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-06-02 15:08:42 +0200 |
commit | c04875f418197895a512cc77026327c3da99d1d2 (patch) | |
tree | dbc81566b6da483d907ba75b97e9b41b15b29570 /server/sonar-web/src/main/js/apps/groups/search-view.js | |
parent | c0f8ed1eca7185bcb63454ba8757a0290721e1dc (diff) | |
download | sonarqube-c04875f418197895a512cc77026327c3da99d1d2.tar.gz sonarqube-c04875f418197895a512cc77026327c3da99d1d2.zip |
SONAR-6602 refactor groups page
Diffstat (limited to 'server/sonar-web/src/main/js/apps/groups/search-view.js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/groups/search-view.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/groups/search-view.js b/server/sonar-web/src/main/js/apps/groups/search-view.js new file mode 100644 index 00000000000..1540d7eb36e --- /dev/null +++ b/server/sonar-web/src/main/js/apps/groups/search-view.js @@ -0,0 +1,49 @@ +define([ + './templates' +], function () { + + return Marionette.ItemView.extend({ + template: Templates['groups-search'], + + events: { + 'submit #groups-search-form': 'onFormSubmit', + 'search #groups-search-query': 'debouncedOnKeyUp', + 'keyup #groups-search-query': 'debouncedOnKeyUp' + }, + + initialize: function () { + this._bufferedValue = null; + this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); + }, + + onRender: function () { + this.delegateEvents(); + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.debouncedOnKeyUp(); + }, + + onKeyUp: function () { + var q = this.getQuery(); + if (q === this._bufferedValue) { + return; + } + this._bufferedValue = this.getQuery(); + if (this.searchRequest != null) { + this.searchRequest.abort(); + } + this.searchRequest = this.search(q); + }, + + getQuery: function () { + return this.$('#groups-search-query').val(); + }, + + search: function (q) { + return this.collection.fetch({ reset: true, data: { q: q } }); + } + }); + +}); |