antos-frontend/src/core/BaseDialog.coffee

237 lines
7.4 KiB
CoffeeScript
Raw Normal View History

2017-08-24 01:53:13 +02:00
class BaseDialog extends this.OS.GUI.BaseModel
constructor: (name) ->
2017-08-27 23:40:02 +02:00
super name, null
2017-08-24 01:53:13 +02:00
@parent = undefined
@modal = false
@handler = undefined
quit: () ->
evt = new _GUI.BaseEvent("exit")
@onexit(evt)
if not evt.prevent
delete @.observable
@parent.dialog = undefined if @parent
($ @scheme).remove() if @scheme
@dialog.quit() if @dialog
2017-08-26 16:50:13 +02:00
init: () ->
main: () ->
2017-08-24 01:53:13 +02:00
meta: () ->
@parent.meta()
show: () ->
@trigger 'focus'
($ @scheme).css "z-index", window._zindex+2
hide: () ->
@trigger 'hide'
BaseDialog.type = 3
this.OS.GUI.BaseDialog = BaseDialog
###
this dialog rende a tag as main content
and a list of buttons, the behaviour of
the button is specified by user. The conf
object is in the follow form
{
tag: <tag_name>,
buttons:[
{
label: 'buton label',
onclick: function(d){...}
}, ...
]
}
###
class BasicDialog extends BaseDialog
2018-01-25 19:15:41 +01:00
constructor: ( name, @conf, @title) ->
2017-08-24 01:53:13 +02:00
super name
2017-08-26 16:50:13 +02:00
init: () ->
2018-01-25 19:15:41 +01:00
@title = @name if not @title
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@title}' width='#{@conf.width}' height='#{@conf.height}'>
2017-08-24 01:53:13 +02:00
<afx-hbox>"
2018-01-25 00:49:02 +01:00
html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>"
2017-08-27 23:40:02 +02:00
html += "<div data-height = '40' style=' text-align:right;padding-top:3px;'>"
html += "<afx-button data-id = 'bt#{k}' text = '#{v.label}' style='margin-right:5px;'></afx-button>" for k,v of @conf.buttons
2017-08-24 01:53:13 +02:00
html += "</div></afx-hbox></afx-app-window>"
#render the html
_GUI.htmlToScheme html, @, @host
main: () ->
@scheme.set "minimizable", false
2017-08-25 00:18:35 +02:00
@scheme.set "resizable", @conf.resizable if @conf.resizable isnt undefined
2017-08-24 01:53:13 +02:00
me = @
f = (_v) -> () -> _v.onclick me
# bind action to button
( (me.find "bt#{k}").set "onbtclick", f(v) ) for k, v of @conf.buttons
2017-08-27 23:40:02 +02:00
@conf.filldata @ if @conf.filldata
2017-08-24 01:53:13 +02:00
this.OS.GUI.BasicDialog = BasicDialog
2018-01-25 00:49:02 +01:00
class PromptDialog extends BasicDialog
constructor: () ->
super "PromptDialog", {
tag: "input",
width: 200,
height: 90,
2018-01-25 19:15:41 +01:00
att: "type = 'text'"
2018-01-25 00:49:02 +01:00
resizable: false,
buttons: [
{
label: "0k",
onclick: (d) ->
txt = (d.find "content").value
return d.quit() if txt is ""
d.handler txt if d.handler
d.quit()
},
{
label: "Cancel",
onclick: (d) -> d.quit()
}
],
filldata: (d) ->
2018-01-25 19:15:41 +01:00
return unless d.data
(d.find "content").value = d.data
2018-01-25 00:49:02 +01:00
}
this.OS.register "PromptDialog", PromptDialog
2017-08-24 01:53:13 +02:00
class CalendarDialog extends BasicDialog
constructor: () ->
super "CalendarDialog", {
tag: 'afx-calendar-view',
width: 300,
height: 220,
2017-08-25 00:18:35 +02:00
resizable: false,
2017-08-24 01:53:13 +02:00
buttons: [
{
label: 'Ok',
onclick: (d) ->
date = (d.find "content").get "selectedDate"
if date
d.handler date if d.handler
d.quit()
else
d.notify "Please select a date"
},
{
label: 'Cancel',
onclick: (d) -> d.quit()
}
]
}
this.OS.register "CalendarDialog", CalendarDialog
2017-08-25 00:18:35 +02:00
class ColorPickerDialog extends BasicDialog
constructor: () ->
super "ColorPickerDialog", {
tag: 'afx-color-picker',
width: 313,
height: 220,
resizable: false,
buttons: [
{
label: 'Ok',
onclick: (d) ->
c = (d.find "content").get "selectedColor"
if c
d.handler c if d.handler
d.quit()
else
d.notify "Please select a color"
},
{
label: 'Cancel',
onclick: (d) -> d.quit()
}
]
}
2017-08-26 16:50:13 +02:00
this.OS.register "ColorPickerDialog", ColorPickerDialog
2017-08-27 23:40:02 +02:00
class InfoDialog extends BasicDialog
constructor: () ->
super "InfoDialog", {
tag: 'afx-grid-view',
width: 250,
height: 300,
resizable: true,
buttons: [ { label: 'Cancel', onclick: (d) -> d.quit() } ],
filldata: (d) ->
return unless d.data
rows = []
rows.push [ { value: k }, { value: v } ] for k, v of d.data
(d.find "content").set "rows", rows
}
this.OS.register "InfoDialog", InfoDialog
2018-01-25 19:15:41 +01:00
class YesNoDialog extends BasicDialog
constructor: () ->
super "YesNoDialog", {
tag: "afx-label",
width: 300,
height: 100,
att:"style = 'padding:10px;'"
resizable: true,
buttons: [
{
label: "Yes", onclick: (d) ->
d.handler true if d.handler
d.quit()
},
{
label: "No", onclick: (d) ->
d handler false if dhandler
d.quit()
}
],
filldata: (d) ->
return unless d.data
l = d.find "content"
for k, v of d.data
l.set k, v
}
this.OS.register "YesNoDialog", YesNoDialog
2018-01-26 18:57:28 +01:00
class SelectionDialog extends BasicDialog
constructor: () ->
super "SelectionDialog", {
tag: "afx-list-view",
att: "",
width: 250,
height: 300,
resizable: false,
buttons: [
{
label: "Ok", onclick: (d) ->
el = d.find "content"
it = el.get "selected"
return unless it
d.handler it if d.handler
d.quit()
},
{ label: "Cancel", onclick: (d) -> d.quit() }
],
filldata: (d) ->
return unless d.data
(d.find "content").set "items", d.data
}
this.OS.register "SelectionDialog", SelectionDialog
2017-08-26 16:50:13 +02:00
class AboutDialog extends BaseDialog
constructor: () ->
super "AboutDialog"
init: () ->
@render "resources/schemes/about.html"
main: () ->
mt = @meta()
@scheme.set "apptitle", "About: #{mt.name}"
(@find "mylabel").set "*", {icon:mt.icon, iconclass:mt.iconclass, text:"#{mt.name}(v#{mt.version})"}
($ @find "mydesc").html mt.description
# grid data for author info
return unless mt.info
rows = []
rows.push [ { value: k }, { value: v } ] for k, v of mt.info
(@find "mygrid").set "rows", rows
this.OS.register "AboutDialog", AboutDialog