coffeescript-ui
Version:
Coffeescript User Interface System
219 lines (179 loc) • 4.39 kB
text/coffeescript
###
* coffeescript-ui - Coffeescript User Interface System (CUI)
* Copyright (c) 2013 - 2016 Programmfabrik GmbH
* MIT Licence
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
###
class CUI.MultiInput extends CUI.DataFieldInput
constructor: (opts) ->
super(opts)
if
initOpts: ->
super()
textarea:
default: false
check: Boolean
spellcheck:
default: false
check: Boolean
placeholder:
check: "PlainObject"
onFocus:
check: Function
onClick:
check: Function
onKeyup:
check: Function
onBlur:
check: Function
control:
mandatory: true
check: (v) ->
v instanceof CUI.MultiInputControl
content_size:
default: false
check: Boolean
readOpts: ->
super()
= null
disable: ->
super()
if not
return
for inp in
inp.disable()
return
enable: ->
super()
if not
return
for inp in
inp.enable()
return
remove: ->
if
for input in
input.destroy()
delete
return super()
initValue: ->
if CUI.util.isNull(v = [])
v = [] = {}
for key in .getKeys()
if not v.hasOwnProperty(key.name)
v[key.name] = ""
@
setData: (data) ->
super(data)
setDataOnInputs: ->
if not
return
input_data = CUI.util.copyObject(, true)
for input in
input.setData(input_data)
if
v = [input.getName()]
else
v = [input.getName()]
input.setCheckChangedValue(v)
setInputVisibility: ->
# the "append" re-orders the input, if needed
names = (key.name for key in .getKeys())
# sort input by key
.sort (a, b) =>
CUI.util.compareIndex(
names.indexOf(a.getOpt("name"))
names.indexOf(b.getOpt("name"))
)
ok = false
for inp in
CUI.dom.append(, inp.DOM)
if .isEnabled(inp.getName())
inp.show()
ok = true
else
inp.hide()
if not ok
console.warn("MulitInput.setInputVisibility: No input visible.", input: , control: )
CUI.Events.trigger
type: "content-resize"
node:
return
getUniqueIdForLabel: ->
for inp in
if .isEnabled(inp.getName())
return inp.getUniqueIdForLabel()
null
focus: ->
for inp in
if .isEnabled(inp.getName())
inp.focus()
return
return
displayValue: ->
super()
for input in
input.displayValue()
@
__initInputs: ->
if
return
= CUI.dom.div("cui-multi-input-container")
CUI.Events.listen
type: "multi-input-control-update"
node:
call: (ev) =>
# console.debug ev.getType(), [0], .getKeys()
# DOM.registerEvent(multiInputDiv, "easydbui-multi-input-control-update")
# multiInputDiv.on "easydbui-multi-input-control-update", (ev)
= []
for key, idx in .getKeys()
input_opts =
class: "cui-multi-input-input"
textarea:
spellcheck:
onBlur:
onClick:
onFocus:
onKeyup:
name: key.name
undo_support: false
content_size:
placeholder: ?[key.name]
input = new CUI.MultiInputInput(input_opts)
input.render()
do (input, key) =>
btn = new CUI.defaults.class.Button
text: key.tag
tabindex: null
disabled: !.hasUserControl()
onClick: (ev, btn) =>
.showUserControl(ev, btn, )
role: "multi-input-tag"
class: "cui-multi-input-tag-button"
tooltip: key.tooltip
input.append(btn, "right")
CUI.Events.listen
type: "data-changed"
node: input
call: (ev) =>
values = CUI.util.copyObject()
values[key.name] = input.getValue()
ev.stopImmediatePropagation()
.push(input)
return
render: ->
super()
if
@