antos-frontend/src/packages/MarketPlace/dialog.coffee

93 lines
3.7 KiB
CoffeeScript
Raw Normal View History

2018-03-15 11:00:24 +01:00
# Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
# AnTOS Web desktop is is licensed under the GNU General Public
# License v3.0, see the LICENCE file for more information
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
2018-02-01 19:36:09 +01:00
class RepositoryDialog extends this.OS.GUI.BaseDialog
constructor: () ->
super "RepositoryDialog"
init: () ->
2018-03-05 00:20:25 +01:00
@_gui.htmlToScheme RepositoryDialog.scheme, @, @host
#@render "#{@meta().path}/repositorydia.html"
2018-02-01 19:36:09 +01:00
main: () ->
me = @
@list = @find "repo-list"
2018-03-05 23:49:25 +01:00
@list.set "onlistdbclick", (e) ->
selidx = me.list.get "selidx"
return unless selidx >= 0
sel = me.systemsetting.system.repositories[selidx]
me.openDialog "PromptDialog", (e) ->
m = e.match /\[([^\]]*)\]\s*(.*)/
return me.error "Wrong format: it should be [name] url" if not m or m.length isnt 3
sel.name = m[1]
sel.text = sel.name
sel.url = m[2]
me.refreshList()
2018-03-10 01:05:34 +01:00
, __("Edit repository"), { label: __("Format : [name] url"), value: "[#{e.data.text}] #{e.data.url}" }
2018-03-05 23:49:25 +01:00
@list.set "buttons", [
{
text: "+",
onbtclick: () ->
me.openDialog "PromptDialog", (e) ->
m = e.match /\[([^\]]*)\]\s*(.*)/
return me.error __("Wrong format: it should be [name] url") if not m or m.length isnt 3
me.systemsetting.system.repositories.push {
name: m[1],
url: m[2],
text: m[1],
i: me.systemsetting.system.repositories.length
}
me.refreshList()
, __("Add repository"), { label: __("Format : [name] url") }
},
{
text: "-",
onbtclick: () ->
selidx = me.list.get "selidx"
return unless selidx >= 0
me.systemsetting.system.repositories.splice selidx, selidx
me.refreshList()
}
]
2018-03-05 23:49:25 +01:00
(@find "btquit").set "onbtclick", (e) -> me.quit()
@refreshList()
refreshList: () ->
ls = ({
text: v.name,
iconclass: "fa fa-link",
url: v.url,
complex: true,
detail: [{ text: v.url }]
2018-02-01 19:36:09 +01:00
} for v in @systemsetting.system.repositories)
@list.set "items", ls
2018-03-05 23:49:25 +01:00
onexit: (e) ->
@parent.repo.set "items", @systemsetting.system.repositories
@parent.dialog = undefined if @parent
2018-03-05 00:20:25 +01:00
RepositoryDialog.scheme = """
2018-03-10 01:05:34 +01:00
<afx-app-window data-id = "repository-dialog-win" apptitle="__(Repositories)" width="250" height="250">
2018-03-05 00:20:25 +01:00
<afx-vbox >
<afx-list-view data-id="repo-list"></afx-list-view>
<div style = "text-align:right; padding:5px" data-height="30" >
<afx-button data-id = "btquit" text = "__(Cancel)"></afx-button>
</div>
2018-03-05 00:20:25 +01:00
</afx-vbox>
</afx-app-window>
"""