fix minor error

This commit is contained in:
Xuan Sang LE
2018-01-30 19:06:30 +01:00
parent 02422319ca
commit de387ece25
23 changed files with 190 additions and 95 deletions

View File

@ -46,11 +46,11 @@ class BasicDialog extends BaseDialog
init: () ->
@title = @name if not @title
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@title}' width='#{@conf.width}' height='#{@conf.height}'>
<afx-hbox>"
<afx-vbox>"
html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>"
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
html += "</div></afx-hbox></afx-app-window>"
html += "</div></afx-vbox></afx-app-window>"
#render the html
_GUI.htmlToScheme html, @, @host
@ -62,6 +62,7 @@ class BasicDialog extends BaseDialog
# bind action to button
( (me.find "bt#{k}").set "onbtclick", f(v) ) for k, v of @conf.buttons
@conf.filldata @ if @conf.filldata
@conf.xtra @ if @conf.xtra
this.OS.GUI.BasicDialog = BasicDialog
@ -90,6 +91,9 @@ class PromptDialog extends BasicDialog
filldata: (d) ->
return unless d.data
(d.find "content").value = d.data
xtra: (d) ->
$( d.find "content" ).keyup (e) ->
(d.find "bt0").trigger() if e.which is 13
}
this.OS.register "PromptDialog", PromptDialog
@ -157,7 +161,7 @@ class InfoDialog extends BasicDialog
filldata: (d) ->
return unless d.data
rows = []
rows.push [ { value: k }, { value: v } ] for k, v of d.data
rows.push [ { value: k }, { value: v } ] for v, k in d.data
(d.find "content").set "rows", rows
}
this.OS.register "InfoDialog", InfoDialog
@ -213,6 +217,10 @@ class SelectionDialog extends BasicDialog
filldata: (d) ->
return unless d.data
(d.find "content").set "items", d.data
xtra: (d) ->
( d.find "content" ).set "onlistdbclick", (e) ->
(d.find "bt0").trigger()
}
this.OS.register "SelectionDialog", SelectionDialog

View File

@ -77,10 +77,16 @@ self.OS.GUI =
( f m, i if m ) for m, i in mimes
return apps
appsWithServices: () ->
o = {}
o[k] = v for k, v of _OS.setting.system.packages when v.services and v.services.length > 0
o
openWith: (it) ->
return unless it
return _GUI.launch it.app if it.type is "app" and it.app
return _courrier.osinfo "Application#{it.text} is not executable" if it.type is "app"
apps = _GUI.appsByMime ( if it.type is "dir" then "dir" else it.mime )
return _courrier.osinfo "No application available to open #{it.filename}" if apps.length is 0
return _GUI.launch apps[0].app, [it.path] if apps.length is 1
@ -169,6 +175,7 @@ self.OS.GUI =
handler p if p isnt ($ "#workspace").get(0)
handler event.target
event.preventDefault()
initDM: ->
# check login first
_API.resource "schemes/dm.html", (x) ->
@ -236,7 +243,25 @@ self.OS.GUI =
desktop[0].contextmenuHandler = (e, m) ->
desktop[0].set "selected", -1 if e.target is desktop[0]
($ "#sysdock").get(0).set "selectedApp", null
console.log "context menu handler for desktop"
menu = [
{ text: "Open", dataid: "desktop-open" },
{ text: "Refresh", dataid: "desktop-refresh" }
]
menu = menu.concat _OS.setting.desktop.menu
m.set "items", menu
m.set "onmenuselect", (evt) ->
switch evt.item.data.dataid
when "desktop-open"
it = desktop[0].get "selected"
return _GUI.openWith it if it
it = _OS.setting.desktop.path.asFileHandler()
it.mime = "dir"
_GUI.openWith it
when "desktop-refresh"
desktop[0].fetch()
else
_GUI.launch evt.item.data.app if evt.item.data.app
m.show(e)
desktop[0].fetch()
_courrier.observable.on "VFS", (d) ->
@ -303,12 +328,14 @@ self.OS.GUI =
_OS.setting.appearance = conf.appearance if conf.appearance
_OS.setting.user = conf.user
_OS.setting.VFS = conf.VFS if conf.VFS
_OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path
_OS.setting.desktop.menu = [] unless _OS.setting.desktop.menu
_OS.setting.VFS.mountpoints = [
#TODO: multi app try to write to this object, it neet to be cloned
{ text: "Applications", path: 'app:///', iconclass: "fa fa-adn", type: "app" },
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" },
{ text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop", type: "fs" },
{ text: "Desktop", path: _OS.setting.desktop.path , iconclass: "fa fa-desktop", type: "fs" },
] if not _OS.setting.VFS.mountpoints
_OS.setting.system = conf.system if conf.system
@ -317,7 +344,7 @@ self.OS.GUI =
"os:///packages"
] unless _OS.setting.system.pkgpaths
_OS.setting.system.menu = [] unless _OS.setting.system.menu
_OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
# load theme
_GUI.loadTheme _OS.setting.appearance.theme

View File

@ -1,5 +1,5 @@
<afx-app-window data-id = 'about-window' width='300' height='200'>
<afx-hbox>
<afx-vbox>
<div style="text-align:center; margin-top:10px;" data-height="50">
<h3 style = "margin:0;padding:0;">
<afx-label data-id = 'mylabel'></afx-label>
@ -7,5 +7,5 @@
<i><p style = "margin:0; padding:0" data-id = 'mydesc'></p></i>
</div>
<afx-grid-view data-id = 'mygrid'></afx-grid-view>
</afx-hbox>
</afx-vbox>
</afx-app-window>

View File

@ -1,13 +1,13 @@
<afx-app-window data-id = 'file-dialog-window' width='400' height='300'>
<afx-vbox>
<afx-hbox>
<afx-list-view data-id = "location" dropdown = "false" data-width = "120"></afx-list-view>
<afx-hbox>
<afx-vbox>
<afx-file-view data-id = "fileview" view='tree' status = false></afx-file-view>
<input data-height = '26' type = "text" data-id = "filename" style="margin-left:5px; margin-right:5px;display:none;" />
<div data-height = '30' style=' text-align:right;padding-top:3px;'>
<afx-button data-id = "bt-ok" text = "Ok"></afx-button>
<afx-button data-id = "bt-cancel" text = "Cancel"></afx-button>
</div>
</afx-hbox>
</afx-vbox>
</afx-vbox>
</afx-hbox>
</afx-app-window>

View File

@ -1,5 +1,5 @@
<afx-button>
<button disabled={ enable == "false" } onclick="{ _onbtclick }" >
<button disabled={ enable == "false" } onclick="{ _onbtclick }" ref = "mybtn" >
<afx-label color = {color} icon={icon} iconclass = {iconclass} text = {text} ></afx-label>
</button>
<script>
@ -19,6 +19,10 @@
self[k] = v
self.update()
}
self.root.trigger = function()
{
$(self.refs.mybtn).trigger("click")
}
self.root.get = function(k)
{
return self[k]

View File

@ -169,7 +169,14 @@
}
self.refs.treeview.ontreeselect = function(d)
{
if(!d.data) return;
if(!d) return;
if(!d.data)// select the root
{
var r = self.path.asFileHandler()
r.size = 0
r.filename = r.path
d.data = { child: r , i:0 }
}
var data = {id:self.rid, data:d.data.child, idx:d.data.i}
self.root.observable.trigger("fileselect",data)
}

View File

@ -21,7 +21,10 @@
{
if(self.selidx != -1)
self.items[self.selidx].selected =false
if(self.items[v]) self.items[v].selected = true
if(v == -1)
self.selidx = -1
else
if(self.items[v]) self.items[v].selected = true
}
else if(k == "*")
for(var i in v)

View File

@ -1,5 +1,5 @@
<afx-hbox style = "display:block;">
<div ref = "container" class="afx-hbox-container">
<div ref = "container" class="afx-vbox-container">
<yield/>
</div>
<script>
@ -7,27 +7,24 @@
this.on('mount', function(){
$(self.refs.container)
.css("display","flex")
.css("flex-direction","column")
.css("flex-direction","row")
.css("width","100%")
//.css("background-color","red")
//.css("overflow", "hidden")
calibrate_size()
calibrate_size()
if(self.root.observable)
{
self.root.observable.on("resize", function(w,h){
calibrate_size()
})
}
if(self.root.observable)
{
self.root.observable.on("resize", function(w,h){
calibrate_size()
})
}
})
var calibrate_size = function()
{
var auto_height = []
var csize, ocheight = 0, avaiheight;
var auto_width = []
var csize, ocwidth = 0, avaiheight;
avaiheight = $(self.root).height()
avaiwidth = $(self.root).width()
avaiWidth = $(self.root).width()
$(self.refs.container).css("height",avaiheight + "px")
$(self.refs.container)
.children()
@ -36,25 +33,25 @@
this.observable = self.root.observable
$(this)
.css("flex-grow","1")
//.css("border","1px solid black")
var dw = $(this).attr("data-height")
//.css("height",avaiheight + "px")
var dw = $(this).attr("data-width")
if(dw)
{
$(this).css("height",dw + "px")
ocheight += Number(dw)
$(this).css("width",dw + "px")
ocwidth += Number(dw)
}
else
{
auto_height.push(this)
auto_width.push(this)
}
})
csize = (avaiheight - ocheight)/ (auto_height.length)
$.each(auto_height, function(i,v)
csize = (avaiWidth - ocwidth)/ (auto_width.length)
$.each(auto_width, function(i,v)
{
$(v).css("height", csize + "px")
$(v).css("width", csize + "px")
})
self.root.observable.trigger("hboxchange",
{id:$(self.root).attr("data-id"), w:avaiwidth, h:csize})
self.root.observable.trigger("vboxchange",
{id:$(self.root).attr("data-id"), w:csize, h:avaiheight})
}
</script>
</afx-hbox>

View File

@ -24,7 +24,10 @@
{
if(self.selidx != -1)
self.items[self.selidx].selected =false
if(self.items[v]) self.items[v].selected = true
if(v == -1)
self.selidx = -1
else
if(self.items[v]) self.items[v].selected = true
}
else if(k == "*")
for(var i in v)

View File

@ -7,7 +7,7 @@
<afx-label color = {data.color} iconclass = {data.iconclass} icon = {data.icon} text = {data.text} ></afx-label>
</a>
<afx-menu if={data.child != null} child={data.child} onmenuselect = {data.onmenuselect} observable = {parent.root.observable} rootid = {parent.rid}></afx-menu>
<afx-menu if={data.child != null} child={data.child.constructor === Array?data.child:data.child()} onmenuselect = {data.onmenuselect} observable = {parent.root.observable} rootid = {parent.rid}></afx-menu>
</li>
<li class="afx-corner-fix"></li>
</ul>

View File

@ -1,5 +1,5 @@
<afx-vbox style = "display:block;">
<div ref = "container" class="afx-vbox-container">
<div ref = "container" class="afx-hbox-container">
<yield/>
</div>
<script>
@ -7,24 +7,27 @@
this.on('mount', function(){
$(self.refs.container)
.css("display","flex")
.css("flex-direction","row")
.css("flex-direction","column")
.css("width","100%")
//.css("background-color","red")
//.css("overflow", "hidden")
calibrate_size()
calibrate_size()
if(self.root.observable)
{
self.root.observable.on("resize", function(w,h){
calibrate_size()
})
}
if(self.root.observable)
{
self.root.observable.on("resize", function(w,h){
calibrate_size()
})
}
})
var calibrate_size = function()
{
var auto_width = []
var csize, ocwidth = 0, avaiheight;
var auto_height = []
var csize, ocheight = 0, avaiheight;
avaiheight = $(self.root).height()
avaiWidth = $(self.root).width()
avaiwidth = $(self.root).width()
$(self.refs.container).css("height",avaiheight + "px")
$(self.refs.container)
.children()
@ -33,25 +36,25 @@
this.observable = self.root.observable
$(this)
.css("flex-grow","1")
//.css("height",avaiheight + "px")
var dw = $(this).attr("data-width")
//.css("border","1px solid black")
var dw = $(this).attr("data-height")
if(dw)
{
$(this).css("width",dw + "px")
ocwidth += Number(dw)
$(this).css("height",dw + "px")
ocheight += Number(dw)
}
else
{
auto_width.push(this)
auto_height.push(this)
}
})
csize = (avaiWidth - ocwidth)/ (auto_width.length)
$.each(auto_width, function(i,v)
csize = (avaiheight - ocheight)/ (auto_height.length)
$.each(auto_height, function(i,v)
{
$(v).css("width", csize + "px")
$(v).css("height", csize + "px")
})
self.root.observable.trigger("vboxchange",
{id:$(self.root).attr("data-id"), w:csize, h:avaiheight})
self.root.observable.trigger("hboxchange",
{id:$(self.root).attr("data-id"), w:avaiwidth, h:csize})
}
</script>
</afx-vbox>