2018-02-01 19:36:09 +01:00
|
|
|
class SubWindow extends this.OS.GUI.BaseModel
|
2017-08-24 01:53:13 +02:00
|
|
|
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
|
2018-02-01 19:36:09 +01:00
|
|
|
|
2017-08-24 01:53:13 +02:00
|
|
|
quit: () ->
|
|
|
|
evt = new _GUI.BaseEvent("exit")
|
|
|
|
@onexit(evt)
|
|
|
|
if not evt.prevent
|
|
|
|
delete @.observable
|
|
|
|
($ @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'
|
2018-02-16 18:38:14 +01:00
|
|
|
($ @scheme).css "z-index", window._zindex + 2
|
2017-08-24 01:53:13 +02:00
|
|
|
hide: () ->
|
|
|
|
@trigger 'hide'
|
|
|
|
|
2018-02-01 19:36:09 +01:00
|
|
|
SubWindow.type = 3
|
|
|
|
this.OS.GUI.SubWindow = SubWindow
|
|
|
|
|
|
|
|
class BaseDialog extends SubWindow
|
|
|
|
constructor: (name) ->
|
|
|
|
super name
|
|
|
|
@handler = undefined
|
|
|
|
|
|
|
|
onexit: (e) ->
|
|
|
|
@parent.dialog = undefined if @parent
|
|
|
|
|
2017-08-24 01:53:13 +02:00
|
|
|
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
|
2018-03-10 23:16:48 +01:00
|
|
|
html = "<afx-app-window data-id = 'dia-window' width='#{@conf.width}' height='#{@conf.height}'>
|
2018-01-30 19:06:30 +01:00
|
|
|
<afx-vbox>"
|
2018-02-13 04:59:08 +01:00
|
|
|
html += "<#{v.tag} #{v.att} style = 'margin-left:5px; margin-right:5px;' data-id = 'content#{k}'></#{v.tag}>" for k,v of @conf.tags
|
2018-03-12 11:33:33 +01:00
|
|
|
html += "<div data-height = '30' style=' text-align:right;padding-top:3px;'>"
|
2017-08-27 23:40:02 +02:00
|
|
|
html += "<afx-button data-id = 'bt#{k}' text = '#{v.label}' style='margin-right:5px;'></afx-button>" for k,v of @conf.buttons
|
2018-03-12 18:55:40 +01:00
|
|
|
html += "</div><div data-height='5'></div></afx-vbox></afx-app-window>"
|
2017-08-24 01:53:13 +02:00
|
|
|
#render the html
|
|
|
|
_GUI.htmlToScheme html, @, @host
|
|
|
|
|
|
|
|
main: () ->
|
2018-03-10 23:16:48 +01:00
|
|
|
@scheme.set "apptitle", @title
|
2017-08-24 01:53:13 +02:00
|
|
|
@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
|
2018-01-30 19:06:30 +01:00
|
|
|
@conf.xtra @ if @conf.xtra
|
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", {
|
2018-02-01 19:36:09 +01:00
|
|
|
tags: [
|
2018-03-12 11:33:33 +01:00
|
|
|
{ tag: "afx-label" },
|
|
|
|
{ tag: "input", att: "type = 'text' data-height='25'" }
|
2018-02-01 19:36:09 +01:00
|
|
|
],
|
2018-01-25 00:49:02 +01:00
|
|
|
width: 200,
|
2018-03-12 11:33:33 +01:00
|
|
|
height: 120,
|
2018-01-25 00:49:02 +01:00
|
|
|
resizable: false,
|
|
|
|
buttons: [
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Ok)",
|
2018-01-25 00:49:02 +01:00
|
|
|
onclick: (d) ->
|
2018-02-01 19:36:09 +01:00
|
|
|
txt = (d.find "content1").value
|
2018-01-25 00:49:02 +01:00
|
|
|
return d.quit() if txt is ""
|
|
|
|
d.handler txt if d.handler
|
|
|
|
d.quit()
|
|
|
|
},
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Cancel)",
|
2018-01-25 00:49:02 +01:00
|
|
|
onclick: (d) -> d.quit()
|
|
|
|
}
|
|
|
|
],
|
|
|
|
filldata: (d) ->
|
2018-01-25 19:15:41 +01:00
|
|
|
return unless d.data
|
2018-02-01 19:36:09 +01:00
|
|
|
(d.find "content0").set "text", d.data.label
|
|
|
|
(d.find "content1").value = d.data.value if d.data.value
|
2018-01-30 19:06:30 +01:00
|
|
|
xtra: (d) ->
|
2018-02-13 04:59:08 +01:00
|
|
|
$( d.find "content1" ).keyup (e) ->
|
2018-01-30 19:06:30 +01:00
|
|
|
(d.find "bt0").trigger() if e.which is 13
|
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", {
|
2018-02-01 19:36:09 +01:00
|
|
|
tags: [{ tag: 'afx-calendar-view' }],
|
2017-08-24 01:53:13 +02:00
|
|
|
width: 300,
|
|
|
|
height: 220,
|
2017-08-25 00:18:35 +02:00
|
|
|
resizable: false,
|
2017-08-24 01:53:13 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Ok)",
|
2017-08-24 01:53:13 +02:00
|
|
|
onclick: (d) ->
|
2018-02-01 19:36:09 +01:00
|
|
|
date = (d.find "content0").get "selectedDate"
|
2017-08-24 01:53:13 +02:00
|
|
|
if date
|
|
|
|
d.handler date if d.handler
|
|
|
|
d.quit()
|
|
|
|
else
|
2018-03-09 19:54:33 +01:00
|
|
|
d.notify __("Please select a date")
|
2017-08-24 01:53:13 +02:00
|
|
|
},
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Cancel)",
|
2017-08-24 01:53:13 +02:00
|
|
|
onclick: (d) -> d.quit()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
this.OS.register "CalendarDialog", CalendarDialog
|
|
|
|
|
2017-08-25 00:18:35 +02:00
|
|
|
class ColorPickerDialog extends BasicDialog
|
|
|
|
constructor: () ->
|
|
|
|
super "ColorPickerDialog", {
|
2018-02-01 19:36:09 +01:00
|
|
|
tags: [{ tag: 'afx-color-picker' }],
|
2017-08-25 00:18:35 +02:00
|
|
|
width: 313,
|
|
|
|
height: 220,
|
|
|
|
resizable: false,
|
|
|
|
buttons: [
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Ok)",
|
2017-08-25 00:18:35 +02:00
|
|
|
onclick: (d) ->
|
2018-02-01 19:36:09 +01:00
|
|
|
c = (d.find "content0").get "selectedColor"
|
2017-08-25 00:18:35 +02:00
|
|
|
if c
|
|
|
|
d.handler c if d.handler
|
|
|
|
d.quit()
|
|
|
|
else
|
|
|
|
d.notify "Please select a color"
|
|
|
|
},
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Cancel)",
|
2017-08-25 00:18:35 +02:00
|
|
|
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", {
|
2018-02-01 19:36:09 +01:00
|
|
|
tags: [{ tag: 'afx-grid-view' }],
|
2017-08-27 23:40:02 +02:00
|
|
|
width: 250,
|
|
|
|
height: 300,
|
|
|
|
resizable: true,
|
2018-03-10 20:42:09 +01:00
|
|
|
buttons: [ { label: "__(Cancel)", onclick: (d) -> d.quit() } ],
|
2017-08-27 23:40:02 +02:00
|
|
|
filldata: (d) ->
|
|
|
|
return unless d.data
|
|
|
|
rows = []
|
2018-02-01 19:36:09 +01:00
|
|
|
rows.push [ { value: k }, { value: v } ] for k, v of d.data
|
|
|
|
(d.find "content0").set "rows", rows
|
2017-08-27 23:40:02 +02:00
|
|
|
}
|
|
|
|
this.OS.register "InfoDialog", InfoDialog
|
|
|
|
|
2018-01-25 19:15:41 +01:00
|
|
|
|
|
|
|
class YesNoDialog extends BasicDialog
|
|
|
|
constructor: () ->
|
|
|
|
super "YesNoDialog", {
|
2018-02-16 18:38:14 +01:00
|
|
|
tags: [{ tag: "afx-label", att: "style = 'padding-left:10px;'" }],
|
2018-01-25 19:15:41 +01:00
|
|
|
width: 300,
|
|
|
|
height: 100,
|
|
|
|
resizable: true,
|
|
|
|
buttons: [
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Yes)", onclick: (d) ->
|
2018-01-25 19:15:41 +01:00
|
|
|
d.handler true if d.handler
|
|
|
|
d.quit()
|
|
|
|
},
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(No)", onclick: (d) ->
|
2018-01-28 02:01:21 +01:00
|
|
|
d.handler false if d.handler
|
2018-01-25 19:15:41 +01:00
|
|
|
d.quit()
|
|
|
|
}
|
|
|
|
],
|
|
|
|
filldata: (d) ->
|
|
|
|
return unless d.data
|
2018-02-01 19:36:09 +01:00
|
|
|
l = d.find "content0"
|
2018-01-25 19:15:41 +01:00
|
|
|
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", {
|
2018-02-01 19:36:09 +01:00
|
|
|
tags: [{ tag: "afx-list-view" }],
|
2018-01-26 18:57:28 +01:00
|
|
|
width: 250,
|
|
|
|
height: 300,
|
|
|
|
resizable: false,
|
|
|
|
buttons: [
|
|
|
|
{
|
2018-03-10 20:42:09 +01:00
|
|
|
label: "__(Ok)", onclick: (d) ->
|
2018-02-01 19:36:09 +01:00
|
|
|
el = d.find "content0"
|
2018-01-26 18:57:28 +01:00
|
|
|
it = el.get "selected"
|
|
|
|
return unless it
|
|
|
|
d.handler it if d.handler
|
|
|
|
d.quit()
|
|
|
|
},
|
2018-03-10 20:42:09 +01:00
|
|
|
{ label: "__(Cancel)", onclick: (d) -> d.quit() }
|
2018-01-26 18:57:28 +01:00
|
|
|
],
|
|
|
|
filldata: (d) ->
|
|
|
|
return unless d.data
|
2018-02-01 19:36:09 +01:00
|
|
|
(d.find "content0").set "items", d.data
|
2018-01-30 19:06:30 +01:00
|
|
|
xtra: (d) ->
|
2018-02-01 19:36:09 +01:00
|
|
|
( d.find "content0" ).set "onlistdbclick", (e) ->
|
2018-01-30 19:06:30 +01:00
|
|
|
(d.find "bt0").trigger()
|
|
|
|
|
2018-01-26 18:57:28 +01:00
|
|
|
}
|
|
|
|
this.OS.register "SelectionDialog", SelectionDialog
|
|
|
|
|
2017-08-26 16:50:13 +02:00
|
|
|
class AboutDialog extends BaseDialog
|
|
|
|
constructor: () ->
|
|
|
|
super "AboutDialog"
|
|
|
|
|
|
|
|
init: () ->
|
2018-03-11 21:31:40 +01:00
|
|
|
@render "os://resources/schemes/about.html"
|
2017-08-26 16:50:13 +02:00
|
|
|
|
|
|
|
main: () ->
|
|
|
|
mt = @meta()
|
2018-03-09 19:54:33 +01:00
|
|
|
@scheme.set "apptitle", __("About: {0}",mt.name)
|
2017-08-26 16:50:13 +02:00
|
|
|
(@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
|
|
|
|
|
2018-01-28 02:01:21 +01:00
|
|
|
this.OS.register "AboutDialog", AboutDialog
|
|
|
|
|
|
|
|
class FileDiaLog extends BaseDialog
|
|
|
|
constructor: () ->
|
|
|
|
super "FileDiaLog"
|
|
|
|
|
|
|
|
init: () ->
|
2018-03-11 21:31:40 +01:00
|
|
|
@render "os://resources/schemes/filedialog.html"
|
2018-01-28 02:01:21 +01:00
|
|
|
|
|
|
|
main: () ->
|
|
|
|
fileview = @find "fileview"
|
|
|
|
location = @find "location"
|
2018-01-28 16:33:49 +01:00
|
|
|
filename = @find "filename"
|
2018-01-28 02:01:21 +01:00
|
|
|
me = @
|
2018-03-10 23:16:48 +01:00
|
|
|
@scheme.set "apptitle", @title
|
2018-01-28 02:01:21 +01:00
|
|
|
fileview.set "fetch", (e, f) ->
|
|
|
|
return unless e.child
|
|
|
|
e.child.path.asFileHandler().read (d) ->
|
2018-03-09 19:54:33 +01:00
|
|
|
return me.error __("Resource not found: {0}", e.child.path) if d.error
|
2018-01-28 02:01:21 +01:00
|
|
|
f d.result
|
|
|
|
location.set "onlistselect", (e) ->
|
|
|
|
return unless e and e.data.path
|
|
|
|
e.data.path.asFileHandler().read (d) ->
|
|
|
|
if(d.error)
|
2018-03-09 19:54:33 +01:00
|
|
|
return me.error __("Resource not found: {0}", e.data.path)
|
2018-01-28 02:01:21 +01:00
|
|
|
fileview.set "path", e.data.path
|
|
|
|
fileview.set "data", d.result
|
|
|
|
location.set "items", ( i for i in @systemsetting.VFS.mountpoints when i.type isnt "app" )
|
|
|
|
location.set "selected", 0 unless location.get "selected"
|
2018-01-28 16:33:49 +01:00
|
|
|
fileview.set "onfileselect", (f) ->
|
2018-02-19 16:52:05 +01:00
|
|
|
($ filename).val f.filename if f.type is "file"
|
2018-01-28 02:01:21 +01:00
|
|
|
(@find "bt-ok").set "onbtclick", (e) ->
|
|
|
|
f = fileview.get "selectedFile"
|
2018-03-09 19:54:33 +01:00
|
|
|
return me.notify __("Please select a file") unless f
|
2018-02-18 21:11:49 +01:00
|
|
|
if me.data and me.data.mimes
|
|
|
|
#verify the mime
|
|
|
|
m = false
|
|
|
|
for v in me.data.mimes
|
|
|
|
if f.mime.match (new RegExp v, "g")
|
|
|
|
m = true
|
|
|
|
break
|
2018-03-09 19:54:33 +01:00
|
|
|
return me.notify __("Only {0} could be selected", me.data.mimes.join(",")) unless m
|
2018-01-28 16:33:49 +01:00
|
|
|
d = f.path
|
|
|
|
d = f.path.asFileHandler().parent() if f.type is "file"
|
2018-02-19 16:52:05 +01:00
|
|
|
me.handler d, ($ filename).val(), f.path if me.handler
|
2018-01-28 16:33:49 +01:00
|
|
|
#sel = if me.data and me.data.selection then me.data.selection else "file"
|
|
|
|
#me.handler f, ($ filename).val() if me.handler and ((f.type is sel) or (sel is "*"))
|
2018-01-28 02:01:21 +01:00
|
|
|
me.quit()
|
|
|
|
|
|
|
|
(@find "bt-cancel").set "onbtclick", (e) ->
|
|
|
|
me.quit()
|
2018-02-28 15:33:57 +01:00
|
|
|
if @data and @data.file
|
|
|
|
($ filename).css("display", "block").val @data.file.basename or "Untitled"
|
|
|
|
@trigger "resize"
|
2018-03-12 18:55:40 +01:00
|
|
|
fileview.set "showhidden", @data.hidden if @data and @data.hidden
|
2018-01-28 16:33:49 +01:00
|
|
|
|
2018-01-28 02:01:21 +01:00
|
|
|
this.OS.register "FileDiaLog", FileDiaLog
|