2016-04-04 14:03:07 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
2016-05-10 17:34:17 -04:00
|
|
|
template = require 'templates/artisans/thang-tasks-view'
|
2016-05-13 18:32:59 -04:00
|
|
|
|
2016-04-04 14:03:07 -04:00
|
|
|
ThangType = require 'models/ThangType'
|
2016-05-13 18:32:59 -04:00
|
|
|
|
|
|
|
ThangTypes = require 'collections/ThangTypes'
|
2016-04-04 14:03:07 -04:00
|
|
|
|
|
|
|
module.exports = class ThangTasksView extends RootView
|
|
|
|
template: template
|
|
|
|
id: 'thang-tasks-view'
|
|
|
|
events:
|
2016-05-16 14:45:06 -04:00
|
|
|
'input input': 'processThangs'
|
|
|
|
'change input': 'processThangs'
|
|
|
|
|
|
|
|
thangs: {}
|
|
|
|
processedThangs: {}
|
|
|
|
|
2016-05-13 18:32:59 -04:00
|
|
|
initialize: () ->
|
2016-05-16 14:45:06 -04:00
|
|
|
@processThangs = _.debounce(@processThangs, 250)
|
|
|
|
|
2016-05-13 18:32:59 -04:00
|
|
|
@thangs = new ThangTypes()
|
2016-04-04 14:03:07 -04:00
|
|
|
@listenTo(@thangs, 'sync', @onThangsLoaded)
|
2016-05-13 18:32:59 -04:00
|
|
|
@supermodel.trackRequest(@thangs.fetch(
|
|
|
|
data:
|
|
|
|
project: 'name,tasks,slug'
|
|
|
|
))
|
2016-04-04 14:03:07 -04:00
|
|
|
|
2016-05-16 14:45:06 -04:00
|
|
|
onThangsLoaded: (thangCollection) ->
|
|
|
|
@processThangs()
|
|
|
|
|
|
|
|
processThangs: ->
|
2016-04-04 14:03:07 -04:00
|
|
|
@processedThangs = @thangs.filter (_elem) ->
|
|
|
|
# Case-insensitive search of input vs name.
|
2016-05-18 16:33:02 -04:00
|
|
|
return ///#{$('#name-search')[0].value}///i.test _elem.get('name')
|
2016-04-04 14:03:07 -04:00
|
|
|
for thang in @processedThangs
|
|
|
|
thang.tasks = _.filter thang.attributes.tasks, (_elem) ->
|
|
|
|
# Similar case-insensitive search of input vs description (name).
|
2016-05-18 16:33:02 -04:00
|
|
|
return ///#{$('#desc-search')[0].value}///i.test _elem.name
|
|
|
|
@renderSelectors '#thang-table'
|
2016-04-04 14:03:07 -04:00
|
|
|
|
|
|
|
sortThangs: (a, b) ->
|
|
|
|
a.get('name').localeCompare(b.get('name'))
|
|
|
|
|
|
|
|
# Jade helper
|
|
|
|
hasIncompleteTasks: (thang) ->
|
2016-05-16 14:45:06 -04:00
|
|
|
return thang.tasks and thang.tasks.filter((_elem) -> return not _elem.complete).length > 0
|