Added buttons for performing actions on patches.

This commit is contained in:
Scott Erickson 2014-04-11 22:33:09 -07:00
parent 34bf484bf2
commit 0eb74ab287
5 changed files with 46 additions and 14 deletions

View file

@ -91,6 +91,7 @@ class CocoModel extends Backbone.Model
@markToRevert()
@clearBackup()
@trigger "save", @
patch.setStatus 'accepted' for patch in @acceptedPatches or []
return super attrs, options
fetch: ->
@ -116,7 +117,9 @@ class CocoModel extends Backbone.Model
cloneNewMinorVersion: ->
newData = $.extend(null, {}, @attributes)
new @constructor(newData)
clone = new @constructor(newData)
clone.acceptedPatches = @acceptedPatches
clone
cloneNewMajorVersion: ->
clone = @cloneNewMinorVersion()
@ -240,5 +243,10 @@ class CocoModel extends Backbone.Model
getExpandedDelta: ->
delta = @getDelta()
deltasLib.expandDelta(delta, @_revertAttributes, @schema().attributes)
addPatchToAcceptOnSave: (patch) ->
@acceptedPatches ?= []
@acceptedPatches.push patch
@acceptedPatches = _.uniq(@acceptedPatches, false, (p) -> p.id)
module.exports = CocoModel

View file

@ -2,4 +2,7 @@ CocoModel = require('./CocoModel')
module.exports = class PatchModel extends CocoModel
@className: "Patch"
urlRoot: "/db/patch"
urlRoot: "/db/patch"
setStatus: (status) ->
$.ajax("/db/patch/#{@id}/status", {type:"PUT", data: {status:status}})

View file

@ -12,9 +12,12 @@ block modal-body-content
block modal-footer
.modal-footer
button(data-dismiss="modal", data-i18n="common.cancel").btn Cancel
if canReject
button.btn.btn-danger Reject
if canWithdraw
button.btn.btn-danger Withdraw
if canAccept
button.btn.btn-primary Accept
if isPatchCreator
if status != 'withdrawn'
button.btn.btn-danger#withdraw-button Withdraw
if isPatchRecipient
if status != 'accepted'
button.btn.btn-primary#accept-button Accept
if status != 'rejected'
button.btn.btn-danger#reject-button Reject

View file

@ -19,7 +19,7 @@ block content
h3 Edit Thang Type: "#{thangType.attributes.name}"
ul.nav.nav-tabs
li
li.active
a(href="#editor-thang-main-tab-view", data-toggle="tab") Main
li
a(href="#editor-thang-components-tab-view", data-toggle="tab") Components
@ -27,13 +27,13 @@ block content
a(href="#editor-thang-spritesheets-view", data-toggle="tab") Spritesheets
li
a(href="#editor-thang-colors-tab-view", data-toggle="tab")#color-tab Colors
li.active
li
a(href="#editor-thang-patches-view", data-toggle="tab")#patches-tab Patches
div.tab-content
div.tab-pane#editor-thang-colors-tab-view
div.tab-pane#editor-thang-main-tab-view
div.tab-pane#editor-thang-main-tab-view.active
div.main-area.well
div.file-controls
@ -86,7 +86,7 @@ block content
div#spritesheets
div.tab-pane#editor-thang-patches-view.active
div.tab-pane#editor-thang-patches-view
div.patches-view

View file

@ -1,11 +1,17 @@
ModalView = require 'views/kinds/ModalView'
template = require 'templates/editor/patch_modal'
DeltaView = require 'views/editor/delta'
auth = require 'lib/auth'
module.exports = class PatchModal extends ModalView
id: "patch-modal"
template: template
plain: true
events:
'click #withdraw-button': 'withdrawPatch'
'click #reject-button': 'rejectPatch'
'click #accept-button': 'acceptPatch'
constructor: (@patch, @targetModel, options) ->
super(options)
@ -21,6 +27,9 @@ module.exports = class PatchModal extends ModalView
getRenderData: ->
c = super()
c.isPatchCreator = @patch.get('creator') is auth.me.id
c.isPatchRecipient = @targetModel.hasWriteAccess()
c.status = @patch.get 'status'
c
afterRender: ->
@ -38,5 +47,14 @@ module.exports = class PatchModal extends ModalView
acceptPatch: ->
delta = @deltaView.getApplicableDelta()
pendingModel = @originalSource.clone(false)
pendingModel.applyDelta(delta)
@targetModel.applyDelta(delta)
@targetModel.addPatchToAcceptOnSave(@patch)
@hide()
rejectPatch: ->
@patch.setStatus('rejected')
@hide()
withdrawPatch: ->
@patch.setStatus('withdrawn')
@hide()