class UomList extends Lanes.Models.State session: default: 'state' expanded: 'state' constructor: (@sku, expanded) -> super() @uoms = @sku.uoms.clone() @default = @uoms.findWhere(code: @sku.default_uom_code) @expanded = expanded or @uoms.first() save: -> @sku.associations.replace(@sku, 'uoms', @uoms) @sku.default_uom_code = @default.code add: -> @uoms.add({}) @default = @uoms.first() if @uoms.length is 1 @trigger('change', @uoms) map: (fn) -> @uoms.map(fn) isDefault: (uom) -> uom is @default setDefault: (uom) -> @trigger('change') @default = uom class UomEdit extends Lanes.React.Component propTypes: list: React.PropTypes.instanceOf(UomList).isRequired uom: React.PropTypes.instanceOf(Skr.Models.Uom).isRequired dataObjects: list: 'props' uom: 'props' onHeaderClick: (ev) -> return if ev.target.tagName is 'I' @list.expanded = @uom onCheckboxChange: (ev) -> return unless ev.target.tagName is 'I' @props.list.setDefault( @props.uom ) render: -> header =
{@props.uom.combined}
class EditBody extends Lanes.React.Component propTypes: selected: React.PropTypes.instanceOf(Skr.Models.Uom) uoms: Lanes.PropTypes.Collection.isRequired dataObjects: uoms: 'props' add: -> @props.uoms.add() render: ->
{@props.uoms.map (uom) => }
class UOMToken extends Lanes.React.BaseComponent propTypes: uom: React.PropTypes.instanceOf(Skr.Models.Uom) onClick: (ev) -> ev.preventDefault() @props.onEdit(@props.uom) render: ->
  • {@props.uom.combined}
  • class Skr.Screens.SkuMaint.SkuUomList extends Lanes.React.Component mixins: [ LC.Form.FieldMixin ] getInitialState: -> editing: false onEdit: (selected = @model.uoms.first()) -> @setState editing: new UomList(@model) selected: selected onAdd: -> @refs.body.add() onOk: -> @state.editing.save() @setState(editing: false) onCancel: -> @setState(editing: false) renderEditingPopup: -> return unless @state.editing header =
    UOMs
    Cancel OK
    renderDisplay: -> value = @model.uoms.map (uom) -> uom.combined {value.join(', ')} renderEdit: (props) -> classNames = _.classnames('sku-uom-list', props.className)
    @onEdit(@model.uoms.first())} >