Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created September 11, 2013 17:53
Show Gist options
  • Select an option

  • Save tkh44/6527260 to your computer and use it in GitHub Desktop.

Select an option

Save tkh44/6527260 to your computer and use it in GitHub Desktop.
wtf mate
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