coffeescript-ui
Version:
Coffeescript User Interface System
126 lines (109 loc) • 3.33 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.ConfirmationDialog extends CUI.Modal
constructor: (opts) ->
super(opts)
.addClass("cui-confirmation-dialog")
initOpts: ->
super()
title:
check: String
text:
check: String
text_icon:
check: (v) ->
v instanceof CUI.Icon or CUI.util.isString(v)
markdown:
mandatory: true
default: false
check: Boolean
padded:
check: Boolean
default: true
markdown_opts:
check: "PlainObject"
html:
check: String
content:
check: (v) ->
CUI.util.isContent(v) or v?.DOM
icon:
check: (v) ->
v instanceof CUI.Icon or CUI.util.isString(v)
buttons:
check: (v) ->
(CUI.util.isArray(v) and v.length > 0) or CUI.util.isFunction(v)
footer_left: {}
header_right: {}
show_inline:
check: (v) ->
CUI.dom.isNode(v)
setPane: ->
super(padded: , force_header: true, force_footer: true)
readOpts: ->
super()
# this needs to be set here, so that Modal / LayerPane are happy
= {}
show: (ev) ->
if
CUI.dom.addClass(, "cui-confirmation-dialog--show-inline")
CUI.dom.addClass(, "cui-confirmation-dialog--has-show-inline")
CUI.dom.prepend(, )
# trigger Layout.all (absolute layouts)
CUI.Events.trigger(type: "viewport-resize")
else
super(ev)
hide: (ev) ->
if
CUI.dom.removeClass(, "cui-confirmation-dialog--show-inline")
CUI.dom.removeClass(, "cui-confirmation-dialog--has-show-inline")
CUI.dom.remove()
# trigger Layout.all (absolute layouts)
CUI.Events.trigger(type: "viewport-resize")
else
super(ev)
init: ->
if not CUI.util.xor(, CUI.util.xor(, ))
console.warn("#{@__cls}.readOpts", "Exactly on opts.content, opts.text, or opts.html needs to be set", opts: )
= ""
if not
if not CUI.util.isEmpty()
= c = new CUI.MultilineLabel(markdown: , markdown_opts: , text: , icon: )
else if not CUI.util.isEmpty()
= c = new CUI.MultilineLabel(content: )
else
c =
if not CUI.util.isEmpty() or not CUI.util.isNull()
l = new CUI.Label(text: , icon: )
pane =
for key, content of {
header_left: l
header_right:
content: c
footer_right:
footer_left:
}
if content
pane.append(content, key)
return
updateText: (txt) ->
?.setText(txt)
@
setText: (text, markdown = , markdown_opts = ) ->
= new CUI.MultilineLabel(markdown: markdown, markdown_opts: markdown_opts, text: text, icon: )
getButtons: ->
[pane, key] = .getPaneAndKey("footer_right")
els = CUI.dom.findElements(pane[key](), ".cui-button")
buttons = []
for el in els
buttons.push(CUI.dom.data(el, "element"))
buttons