2014-04-11 17:19:17 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
|
|
|
template = require 'templates/editor/patches'
|
|
|
|
PatchesCollection = require 'collections/PatchesCollection'
|
|
|
|
nameLoader = require 'lib/NameLoader'
|
2014-04-12 00:11:52 -04:00
|
|
|
PatchModal = require './patch_modal'
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
module.exports = class PatchesView extends CocoView
|
|
|
|
template: template
|
|
|
|
className: 'patches-view'
|
|
|
|
status: 'pending'
|
|
|
|
|
|
|
|
events:
|
|
|
|
'change .status-buttons': 'onStatusButtonsChanged'
|
2014-04-12 00:11:52 -04:00
|
|
|
'click .patch-icon': 'openPatchModal'
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
constructor: (@model, options) ->
|
|
|
|
super(options)
|
|
|
|
@initPatches()
|
|
|
|
|
|
|
|
initPatches: ->
|
|
|
|
@startedLoading = false
|
|
|
|
@patches = new PatchesCollection([], {}, @model, @status)
|
2014-04-13 13:29:43 -04:00
|
|
|
@patchesRes = @supermodel.addModelResource(@patches, 'patches')
|
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
ids = (p.get('creator') for p in @patches.models)
|
2014-04-13 13:29:43 -04:00
|
|
|
jqxhrOptions = nameLoader.loadNames ids
|
|
|
|
@nameLoaderRes = @supermodel.addRequestResource('name_loader', jqxhrOptions)
|
|
|
|
@nameLoaderRes.addDependency(@patchesRes)
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
load: ->
|
2014-04-13 13:29:43 -04:00
|
|
|
@nameLoaderRes.load()
|
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
|
|
|
patch.userName = nameLoader.getName(patch.get('creator')) for patch in @patches.models
|
|
|
|
c.patches = @patches.models
|
|
|
|
c.status
|
|
|
|
c
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
@$el.find(".#{@status}").addClass 'active'
|
|
|
|
|
|
|
|
onStatusButtonsChanged: (e) ->
|
|
|
|
@loaded = false
|
|
|
|
@status = $(e.target).val()
|
|
|
|
@initPatches()
|
|
|
|
@load()
|
|
|
|
@render()
|
2014-04-12 00:11:52 -04:00
|
|
|
|
|
|
|
openPatchModal: (e) ->
|
|
|
|
patch = _.find @patches.models, {id:$(e.target).data('patch-id')}
|
|
|
|
modal = new PatchModal(patch, @model)
|
|
|
|
@openModalView(modal)
|