coffeescript-ui
Version:
Coffeescript User Interface System
140 lines (110 loc) • 2.94 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.FormModal extends CUI.FormPopover
constructor: (opts) ->
super(opts)
# console.debug "FormPopover",
= null
= null
initOpts: ->
super()
("popover")
modal:
default: {}
check: "PlainObject"
apply_button:
mandatory: true
default:
text: "Ok"
check: (v) =>
CUI.util.isPlainObject(v)
initPopover: (opts) ->
btn_opts = CUI.util.copyObject(.apply_button, true)
onClick = btn_opts.onClick
btn_opts.onClick = (ev, btn) =>
CUI.decide(onClick?(ev, btn, @))
.done =>
.hide()
btn = new CUI.defaults.class.Button(btn_opts)
if ()
btn.enable()
else
btn.disable()
opts.pane.footer_right = btn
mod = new CUI.Modal(opts)
if
CUI.Events.listen
type: "data-changed"
node: mod
call: =>
if ()
btn.enable()
else
btn.disable()
mod
revertData: ->
CUI.util.assert(, "Form.revertData", "Only supported with opts.name set and opts.data PlainObject.", opts: )
delete()
if
[] =
else
delete([])
()
()
CUI.Events.trigger
type: "data-changed"
node: ()
@
setData: (data) ->
if and not CUI.util.isFunction(data)
if data[]
= CUI.util.copyObject(data[], true)
else
= undefined
= data
super(data)
__closePopover: ->
if
= CUI.util.copyObject([], true)
super()
hasChanges: ->
if
JSON.stringify() != JSON.stringify([])
else
null
getPopoverOpts: ->
pop_opts = CUI.util.copyObject(, true)
if pop_opts.cancel and
onCancel = pop_opts.onCancel
pop_opts.onCancel = (ev, modal) =>
dfr = new CUI.Deferred()
CUI.decide(onCancel?(ev, modal, ()))
.done(dfr.resolve)
.fail(dfr.reject)
dfr.done =>
()
dfr.promise()
delete(pop_opts.apply_button)
if CUI.util.isEmpty(pop_opts.class)
pop_opts.class = ""
# don't center this to an element
pop_opts.element = null
if not pop_opts.pane
pop_opts.pane = {}
CUI.util.assert(CUI.util.isPlainObject(pop_opts.pane), "new CUI.FormModal", "opts.pane must be PlainObject", opts: pop_opts)
pop_opts.class += " cui-form-modal-modal"
pop_opts
disable: ->
super()
?.disable()
enable: ->
super()
?.enable()
destroy: ->
super()
?.destroy()