Created
September 11, 2013 17:53
-
-
Save tkh44/6527260 to your computer and use it in GitHub Desktop.
wtf mate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| search: function(e) { | |
| var $input = this.$('input[name="contact"]'), | |
| self = this; | |
| $input.addClass('loading'); | |
| _.debounce(function(e) { | |
| var $emptySearch = self.$('.empty-search'), | |
| $noRecentGuests = self.$('no-recent-guests'), | |
| users = self.users, | |
| contacts = self.contacts, | |
| value = $.trim(e.currentTarget.value), | |
| data; | |
| if (value.length < 2) { | |
| if (Mast.data.recentGuests.length) { | |
| $noRecentGuests.hide(); | |
| self.showRecentGuests(); | |
| } else { | |
| $noRecentGuests.show(); | |
| } | |
| } else { | |
| $('[data-id="recentGuests"]').hide(0, function() { | |
| $emptySearch.hide(); | |
| }); | |
| data = { | |
| search: value | |
| }; | |
| async.parallel([ | |
| // Fetch Buildings | |
| function searchUsers(next) { | |
| users.fetch({ | |
| data: data, | |
| reset: true, | |
| success: function(collection, res, options) { | |
| self.collection.remove(options.previousModels); | |
| if (collection.length) { | |
| self.collection.add(collection.models); | |
| } | |
| next(); | |
| }, | |
| error: function (col, res, options) { | |
| next(res); | |
| } | |
| }); | |
| }, | |
| function searchContacts(next) { | |
| var options = { | |
| filter: data.search, | |
| limit: 50 | |
| }; | |
| contacts.fetch({ | |
| data: options, | |
| reset: true, | |
| success: function(collection, res, options) { | |
| self.collection.remove(options.previousModels); | |
| if (collection.length) { | |
| self.collection.add(collection.models); | |
| } | |
| next(); | |
| }, | |
| error: function (col, res, options) { | |
| next(res); | |
| } | |
| }); | |
| } | |
| ], function resultsCallback(err, results) { | |
| $input.removeClass('loading'); | |
| }); | |
| } | |
| }, 500) | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment