coffeescript-ui
Version:
Coffeescript User Interface System
217 lines (177 loc) • 4.25 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.Checkbox extends CUI.DataFieldInput
initOpts: ->
super()
onClick:
check: Function
value:
default: true
value_unchecked:
default: false
text:
check: String
multiline:
default: false
check: Boolean
content:
check: (v) ->
CUI.util.isContent(v) or CUI.util.isString(v)
active:
default: false
check: Boolean
onActivate:
check: Function
onDeactivate:
check: Function
radio:
check: String
group:
check: String
radio_allow_null:
check: Boolean
tooltip:
check: "PlainObject"
icon_active:
default: "check"
mandatory: true
check: (v) ->
v instanceof CUI.Icon or CUI.util.isString(v)
icon_inactive:
check: (v) ->
v instanceof CUI.Icon or CUI.util.isString(v)
constructor: (opts) ->
super(opts)
if
enable: ->
super()
?.enable()
disable: ->
super()
?.disable()
registerLabel: (lbl) ->
lbl.setAttribute('data-label-clickable', '1')
CUI.Events.listen
type: 'click'
node: lbl
call: (ev) =>
.onClickAction(ev)
@
getButton: ->
getOptValue: ->
getOptValueUnchecked: ->
getCheckboxClass: ->
"cui-button-checkbox"
destroy: ->
?.destroy()
super()
render: ->
super()
btn_opts =
btn_opts.onActivate = (btn, flags, event) =>
if flags.initial_activate
return
ret = ?(@, flags, event)
if CUI.util.isPromise(ret)
ret.fail =>
ret
btn_opts.onDeactivate = (btn, flags, event) =>
if flags.initial_activate
return
ret = ?(@, flags, event)
if CUI.util.isPromise(ret)
ret.fail =>
ret
if
btn_opts.onClick = (ev) =>
return
# tooltip is managed by "DataField", so do not pass it
# to the Button
for k in [
"text"
"radio_allow_null"
"active"
]
if not CUI.util.isUndef(btn_opts[k])
continue
btn_opts[k] = @["_#{k}"]
if CUI.util.isEmpty(btn_opts.text)
btn_opts.text = ""
btn_opts.disabled =
btn_opts.center =
# btn_opts.class =
= new CUI.defaults.class.Button(btn_opts)
.addClass()
if != "check" or
if CUI.__ng__
.removeClass("cui-button-button")
#
checkValue: (v, flags) ->
if not CUI.util.isBoolean(v)
throw new Error("#{@__cls}.setValue(value): Value needs to be Boolean.")
displayValue: ->
super()
if not
return
# console.debug "Checkbox.displayValue", [0], , , , ,
if ==
.activate(initial_activate: true)
else
.deactivate(initial_activate: true)
@
getButtonOpts: ->
if
role: "radio"
radio:
group:
icon_active:
icon_inactive:
else
role: "checkbox"
switch: true
group:
icon_active:
icon_inactive:
getDefaultValue: ->
if
else
isChanged: ->
if not
return undefined
if not
return super()
# this radio button is selected
if ==
return super()
# this radio button is not selected
# is has changed if the checked value
return == JSON.stringify()