47 lines
1.4 KiB
CoffeeScript
47 lines
1.4 KiB
CoffeeScript
context = window
|
|
rest = window.JK.Rest()
|
|
logger = context.JK.logger
|
|
|
|
@EditableList = React.createClass({
|
|
objects: []
|
|
|
|
listObjects: ->
|
|
objs=[]
|
|
@root = jQuery(this.getDOMNode())
|
|
$(".list-item", @root).each ->
|
|
objs.push $(this).data("object-id")
|
|
objs
|
|
|
|
deleteItem: (e) ->
|
|
e.preventDefault()
|
|
keys = (k for k, v of e.target when typeof v is 'function')
|
|
|
|
logger.debug("Delete item", e.target, keys)
|
|
i = e.target.getAttribute("data-item-index")
|
|
this.props.listItems.splice(i,1)
|
|
this.props.onItemChanged(this.props.objectName, this.props.listItems)
|
|
|
|
render: () ->
|
|
object_options = []
|
|
|
|
logger.debug("Rendering EditableList", this.props, this.props.listItems)
|
|
|
|
if this.props.listItems? && this.props.listItems.length > 0
|
|
for object,i in this.props.listItems
|
|
nm = "item_#{i}"
|
|
displayValue = this.props.formatListItem(object)
|
|
object_options.push `<div className='list-item'>
|
|
<div className='display-value left'>{displayValue}</div>
|
|
<div className='actions'>
|
|
<a className='delete-list-item right' data-item-index={i} onClick={this.deleteItem} >X</a>
|
|
</div></div>`
|
|
else
|
|
object_options.push `<div className='display-value'><em>None</em></div>`
|
|
|
|
`<div className="EditableList react-component">
|
|
<div className="editable-scroller left">
|
|
{object_options}
|
|
</div>
|
|
</div>`
|
|
|
|
}) |