Skip to content

Instantly share code, notes, and snippets.

@juandazapata
Last active December 14, 2015 15:59
Show Gist options
  • Save juandazapata/5112174 to your computer and use it in GitHub Desktop.
Save juandazapata/5112174 to your computer and use it in GitHub Desktop.
template = require 'views/templates/hostels/search'
CollectionView= require 'views/base/collection-view'
HostelItemView = require 'views/hostels/item'
module.exports = class HostelSearchView extends CollectionView
className: 'search-results'
itemView: HostelItemView
template: template
listSelector: '.hostels'
fallbackSelector: '.empty-message'
loadingSelector: '.loading'
<h1>Hostel search results</h1>
<div class='loading'>
<h1>LOADING...</h1>
</div>
<div class='hostels'></div>
<div class='empty-message'>
<h1>There are no hostels available</h1>
</div>
Collection = require 'models/base/collection'
Hostel = require 'models/hostels/item'
config = require 'config'
mediator = require 'mediator'
_ = require 'underscore'
module.exports = class HostelsCollection extends Collection
model: Hostel
url: "#{config.API_URL}/hostels/search.json"
parse: (response) ->
arr = new Array()
_.each(response.hostels, (elem) ->
arr.push(elem.hostel)
)
arr
Controller = require 'controllers/base/controller'
HostelShowView = require 'views/hostels/show'
HostelSearchView = require 'views/hostels/search'
HostelsCollection = require 'models/hostels/hostels-collection'
module.exports = class HostelsController extends Controller
search: ->
@publishEvent '!adjustTitle', 'Hostel search results'
@collection = new HostelsCollection()
@collection.fetch()
@view = new HostelSearchView(collection: @collection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment