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'
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
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()
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
initPatches: ->
|
|
|
|
@startedLoading = false
|
|
|
|
@patches = new PatchesCollection([], {}, @model, @status)
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-17 22:16:29 -04:00
|
|
|
load: ->
|
2014-04-28 14:09:21 -04:00
|
|
|
@initPatches()
|
|
|
|
@patches = @supermodel.loadCollection(@patches, 'patches').model
|
|
|
|
@listenTo @patches, 'sync', @onPatchesLoaded
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-28 14:09:21 -04:00
|
|
|
onPatchesLoaded: ->
|
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
|
2014-04-28 14:10:27 -04:00
|
|
|
@supermodel.addRequestResource('user_names', jqxhrOptions).load() if jqxhrOptions
|
2014-04-13 13:29:43 -04:00
|
|
|
|
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
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
afterRender: ->
|
|
|
|
@$el.find(".#{@status}").addClass 'active'
|
|
|
|
|
|
|
|
onStatusButtonsChanged: (e) ->
|
|
|
|
@status = $(e.target).val()
|
2014-04-17 18:44:19 -04:00
|
|
|
@reloadPatches()
|
2014-05-02 15:32:41 -04:00
|
|
|
|
2014-04-17 18:44:19 -04:00
|
|
|
reloadPatches: ->
|
2014-05-28 21:13:20 -04:00
|
|
|
@supermodel.resetProgress()
|
2014-04-28 14:09:21 -04:00
|
|
|
@load()
|
2014-04-11 17:19:17 -04:00
|
|
|
@render()
|
2014-04-12 00:11:52 -04:00
|
|
|
|
|
|
|
openPatchModal: (e) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
console.log 'open patch modal'
|
|
|
|
patch = _.find @patches.models, {id: $(e.target).data('patch-id')}
|
2014-04-12 00:11:52 -04:00
|
|
|
modal = new PatchModal(patch, @model)
|
2014-04-17 17:23:33 -04:00
|
|
|
@openModalView(modal)
|
2014-04-17 18:44:19 -04:00
|
|
|
@listenTo modal, 'accepted-patch', -> @trigger 'accepted-patch'
|
|
|
|
@listenTo modal, 'hide', ->
|
|
|
|
f = => @reloadPatches()
|
|
|
|
setTimeout(f, 400)
|
2014-04-19 01:15:04 -04:00
|
|
|
@stopListening modal
|