Added contextmenu

Added contextmenu with Delete and Duplicate button
This commit is contained in:
tmrdja 2014-03-30 19:38:54 +02:00
parent 470a79e6b0
commit f8de6162d1

View file

@ -48,6 +48,8 @@ module.exports = class ThangsTabView extends View
events: events:
'click #extant-thangs-filter button': 'onFilterExtantThangs' 'click #extant-thangs-filter button': 'onFilterExtantThangs'
'click #delete': 'onDeleteClicked'
'click #duplicate': 'onDuplicateClicked'
shortcuts: shortcuts:
'esc': 'selectAddThang' 'esc': 'selectAddThang'
@ -61,6 +63,7 @@ module.exports = class ThangsTabView extends View
@thangTypes = @supermodel.getCollection new ThangTypeSearchCollection() # should load depended-on Components, too @thangTypes = @supermodel.getCollection new ThangTypeSearchCollection() # should load depended-on Components, too
@thangTypes.once 'sync', @onThangTypesLoaded @thangTypes.once 'sync', @onThangTypesLoaded
@thangTypes.fetch() @thangTypes.fetch()
$(document).bind 'contextmenu', @preventDefaultContextMenu
# just loading all Components for now: https://github.com/codecombat/codecombat/issues/405 # just loading all Components for now: https://github.com/codecombat/codecombat/issues/405
@componentCollection = @supermodel.getCollection new ComponentsCollection() @componentCollection = @supermodel.getCollection new ComponentsCollection()
@ -419,6 +422,29 @@ module.exports = class ThangsTabView extends View
@onThangsChanged() @onThangsChanged()
@$el.find('.thangs-column').show() @$el.find('.thangs-column').show()
preventDefaultContextMenu: (e) ->
e.preventDefault()
onSpriteContextMenu: (e) ->
{clientX, clientY} = e.originalEvent.nativeEvent
if @addThangType
$('#duplicate a').html 'Stop Duplicate'
else
$('#duplicate a').html 'Duplicate'
$('#contextmenu').css { position: 'fixed', left: clientX, top: clientY }
$('#contextmenu').show()
onDeleteClicked: (e) ->
$('#contextmenu').hide()
@deleteSelectedExtantThang e
onDuplicateClicked: (e) ->
$('#contextmenu').hide()
if !@addThangType
thang = @selectedExtantThang.spriteName
e.target = $(".add-thang-palette-icon[data-thang-type='" + thang + "']").get 0
@selectAddThang e
class ThangsNode extends TreemaNode.nodeMap.array class ThangsNode extends TreemaNode.nodeMap.array
valueClass: 'treema-array-replacement' valueClass: 'treema-array-replacement'