mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
opt plugin.example.js
This commit is contained in:
parent
e0db2ea8b6
commit
4eb56fd692
@ -1275,24 +1275,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
h, _ := kit.Hash("uniq")
|
|
||||||
name := fmt.Sprintf("var/tmp/file/%s", h)
|
|
||||||
|
|
||||||
m.Assert(os.MkdirAll("var/tmp/file/", 0777))
|
|
||||||
f, e := os.Create(name)
|
|
||||||
m.Assert(e)
|
|
||||||
defer f.Close()
|
|
||||||
f.Write([]byte(arg[0]))
|
|
||||||
|
|
||||||
m.Echo(name)
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"trash": &ctx.Command{Name: "trash file", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
os.Remove(arg[0])
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
|
|
||||||
"hash": &ctx.Command{Name: "hash filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"hash": &ctx.Command{Name: "hash filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
dir, name := path.Split(arg[0])
|
dir, name := path.Split(arg[0])
|
||||||
m.Append("dir", dir)
|
m.Append("dir", dir)
|
||||||
@ -1310,6 +1292,21 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Confm("paths", func(index int, value string) bool {
|
||||||
|
p := path.Join(value, arg[0])
|
||||||
|
if _, e := os.Stat(p); e == nil {
|
||||||
|
m.Echo(p)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}},
|
||||||
"copy": &ctx.Command{Name: "copy to from", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"copy": &ctx.Command{Name: "copy to from", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
dir, _ := path.Split(arg[0])
|
dir, _ := path.Split(arg[0])
|
||||||
m.Assert(os.MkdirAll(dir, 0777))
|
m.Assert(os.MkdirAll(dir, 0777))
|
||||||
@ -1330,19 +1327,21 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
m.Echo(arg[0])
|
m.Echo(arg[0])
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if len(arg) == 0 {
|
h, _ := kit.Hash("uniq")
|
||||||
return
|
name := fmt.Sprintf("var/tmp/file/%s", h)
|
||||||
}
|
|
||||||
|
|
||||||
m.Confm("paths", func(index int, value string) bool {
|
m.Assert(os.MkdirAll("var/tmp/file/", 0777))
|
||||||
p := path.Join(value, arg[0])
|
f, e := os.Create(name)
|
||||||
if _, e := os.Stat(p); e == nil {
|
m.Assert(e)
|
||||||
m.Echo(p)
|
defer f.Close()
|
||||||
return true
|
f.Write([]byte(arg[0]))
|
||||||
}
|
|
||||||
return false
|
m.Echo(name)
|
||||||
})
|
return
|
||||||
|
}},
|
||||||
|
"trash": &ctx.Command{Name: "trash file", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
os.Remove(arg[0])
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
@ -413,8 +413,8 @@ var page = Page({
|
|||||||
pane.which.set(""), river = value, pane.Show()
|
pane.which.set(""), river = value, pane.Show()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pane.Show = function() {
|
pane.Show = function(which) {
|
||||||
output.Update([river], "text", ["key", "count"], "key", ctx.Search("storm")||true)
|
output.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
||||||
}
|
}
|
||||||
pane.Next = function() {
|
pane.Next = function() {
|
||||||
var next = output.querySelector("div.item.select").nextSibling
|
var next = output.querySelector("div.item.select").nextSibling
|
||||||
@ -502,8 +502,7 @@ var page = Page({
|
|||||||
|
|
||||||
form.Run(cmd, function(msg) {
|
form.Run(cmd, function(msg) {
|
||||||
pane.Show()
|
pane.Show()
|
||||||
page.storm.Show()
|
page.storm.Show(ui.name.value)
|
||||||
page.storm.which.set(ui.name.value, true)
|
|
||||||
})
|
})
|
||||||
}]}, {name: "list", view: ["list", "table"]},
|
}]}, {name: "list", view: ["list", "table"]},
|
||||||
]}])
|
]}])
|
||||||
@ -512,8 +511,7 @@ var page = Page({
|
|||||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
||||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
||||||
var old = table.querySelector("tr.select")
|
var old = table.querySelector("tr.select")
|
||||||
tr.className = "select", old && (old.className = "normal")
|
tr.className = "select", old && (old.className = "normal"), form.Run([river, pod.key], function(msg) {
|
||||||
form.Run([river, pod.key], function(msg) {
|
|
||||||
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||||
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
||||||
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
||||||
|
@ -401,31 +401,33 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var total = 0
|
var total = 0, count = 0
|
||||||
var count = 0
|
plugin = plugin || {}, plugin.__proto__ = {
|
||||||
field.Check = option.Check = function(event, index) {
|
show: function() {},
|
||||||
|
init: function() {},
|
||||||
|
Clone: function() {
|
||||||
|
field.Meta.args = kit.Selector(option, ".args", function(item, index) {
|
||||||
|
return item.value
|
||||||
|
})
|
||||||
|
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
||||||
|
},
|
||||||
|
Clear: function() {
|
||||||
|
field.parentNode && field.parentNode.removeChild(field)
|
||||||
|
},
|
||||||
|
Check: function(event, index) {
|
||||||
index == total-1 || (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button")?
|
index == total-1 || (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button")?
|
||||||
option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus()
|
option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus()
|
||||||
}
|
},
|
||||||
field.Clone = option.Clone = function() {
|
Remove: function(who) {
|
||||||
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
|
||||||
}
|
|
||||||
field.Clear = option.Clear = function() {
|
|
||||||
field.parentNode && field.parentNode.removeChild(field)
|
|
||||||
}
|
|
||||||
field.Remove = option.Remove = function(who) {
|
|
||||||
who.parentNode && who.parentNode.removeChild(who)
|
who.parentNode && who.parentNode.removeChild(who)
|
||||||
}
|
},
|
||||||
field.Select = option.Select = function(who) {
|
Append: function(item, name) {
|
||||||
page.plugin = field
|
|
||||||
page.footer.State(".", field.id)
|
|
||||||
}
|
|
||||||
field.Append = option.Append = function(item) {
|
|
||||||
var index = total
|
var index = total
|
||||||
total += 1
|
total += 1
|
||||||
|
name = name || item.name
|
||||||
|
|
||||||
item.onfocus = function(event) {
|
item.onfocus = function(event) {
|
||||||
page.plugin = field
|
page.plugin = plugin
|
||||||
page.input = event.target
|
page.input = event.target
|
||||||
page.footer.State(".", field.id)
|
page.footer.State(".", field.id)
|
||||||
page.footer.State(":", index)
|
page.footer.State(":", index)
|
||||||
@ -453,21 +455,20 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
page.action.scrollTo(0, option.parentNode.offsetTop)
|
page.action.scrollTo(0, option.parentNode.offsetTop)
|
||||||
break
|
break
|
||||||
case "m":
|
case "m":
|
||||||
page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
|
plugin.Clone()
|
||||||
event.stopPropagation()
|
|
||||||
break
|
break
|
||||||
case "b":
|
case "b":
|
||||||
option.Append({})
|
plugin.Append(item, "args"+total).focus()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
event.key == "Enter" && option.Check(event, index)
|
event.key == "Enter" && plugin.Check(event, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
var input = {type: "input", name: item.name, data: item}
|
var input = {type: "input", name: name, data: item}
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case "button":
|
case "button":
|
||||||
item.onclick = function(event) {
|
item.onclick = function(event) {
|
||||||
@ -476,8 +477,8 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case "select":
|
case "select":
|
||||||
input = {type: "select", name: item.name, data: {className: "args", onchange: function(event) {
|
input = {type: "select", name: name, data: {className: "args", onchange: function(event) {
|
||||||
option.Check(event, index)
|
plugin.Check(event, index)
|
||||||
|
|
||||||
}}, list: item.values.map(function(value) {
|
}}, list: item.values.map(function(value) {
|
||||||
return {type: "option", value: value, inner: value}
|
return {type: "option", value: value, inner: value}
|
||||||
@ -493,22 +494,24 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""}, input]}])
|
var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""}, input]}])
|
||||||
|
|
||||||
page.plugin = field
|
page.plugin = field
|
||||||
page.input = ui[item.name]
|
page.input = ui[name]
|
||||||
|
index == 0 && ui[name] && ui[name].focus && ui[name].focus()
|
||||||
item.imports && page.Sync(item.imports).change(function(value, old) {
|
item.imports && page.Sync(item.imports).change(function(value, old) {
|
||||||
ui[item.name].value = value
|
ui[name].value = value
|
||||||
})
|
})
|
||||||
|
return ui[name]
|
||||||
|
},
|
||||||
|
Select: function() {
|
||||||
|
page.plugin = field
|
||||||
|
page.footer.State(".", field.id)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputs = JSON.parse(tool.inputs)
|
var inputs = JSON.parse(tool.inputs)
|
||||||
inputs.map(function(item, index, inputs) {
|
inputs.map(function(item, index, inputs) {
|
||||||
option.Append(item)
|
plugin.Append(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
plugin = plugin || {}, plugin.__proto__ = {
|
|
||||||
show: function() {},
|
|
||||||
init: function() {},
|
|
||||||
}
|
|
||||||
// plugin.init(page, page.action, field, option, output, ui)
|
|
||||||
plugin.init(page, page.action, field, option, output)
|
plugin.init(page, page.action, field, option, output)
|
||||||
page[field.id] = plugin
|
page[field.id] = plugin
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user