forked from x/ContextOS
mac mod ctx.context&web.travel
This commit is contained in:
parent
f0bd6d0f0e
commit
ec0b608aa4
@ -1852,7 +1852,13 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"context": &Command{Name: "context back|[[home] [find|search] name] [info|lists|show|switch|[args]", Help: "查找并操作模块,\n查找起点root:根模块、back:父模块、home:本模块,\n查找方法find:路径匹配、search:模糊匹配,\n查找对象name:支持点分和正则,\n操作类型show:显示信息、switch:切换为当前、start:启动模块、spawn:分裂子模块,args:启动参数",
|
"context": &Command{Name: "context back|[[home] [find|search] name] [info|lists|show|switch|[args]", Help: "查找并操作模块,\n查找起点root:根模块、back:父模块、home:本模块,\n查找方法find:路径匹配、search:模糊匹配,\n查找对象name:支持点分和正则,\n操作类型show:显示信息、switch:切换为当前、start:启动模块、spawn:分裂子模块,args:启动参数",
|
||||||
Formats: map[string]int{"back": 0, "home": 0, "find": 1, "search": 1, "info": 1, "lists": 0, "show": 0, "switch": 0},
|
Formats: map[string]int{
|
||||||
|
"back": 0, "home": 0,
|
||||||
|
"find": 1, "search": 1,
|
||||||
|
"info": 1, "lists": 0, "show": 0, "switch": 0,
|
||||||
|
"cache": 0, "config": 0, "command": 0,
|
||||||
|
"module": 0, "domain": 0,
|
||||||
|
},
|
||||||
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
if m.Has("back") { // {{{
|
if m.Has("back") { // {{{
|
||||||
m.target = m.source
|
m.target = m.source
|
||||||
@ -1885,6 +1891,56 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
// v.Meta = m.Meta
|
// v.Meta = m.Meta
|
||||||
// v.Data = m.Data
|
// v.Data = m.Data
|
||||||
switch {
|
switch {
|
||||||
|
case m.Has("cache"):
|
||||||
|
if len(arg) == 0 {
|
||||||
|
for k, v := range v.target.Caches {
|
||||||
|
m.Add("append", "key", k)
|
||||||
|
m.Add("append", "name", v.Name)
|
||||||
|
m.Add("append", "value", v.Value)
|
||||||
|
m.Add("append", "help", v.Help)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m.Echo(v.Cap(arg[0], arg[1:]...))
|
||||||
|
}
|
||||||
|
case m.Has("config"):
|
||||||
|
if len(arg) == 0 {
|
||||||
|
for k, v := range v.target.Configs {
|
||||||
|
m.Add("append", "key", k)
|
||||||
|
m.Add("append", "name", v.Name)
|
||||||
|
m.Add("append", "value", v.Value)
|
||||||
|
m.Add("append", "help", v.Help)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m.Echo(v.Conf(arg[0], arg[1:]...))
|
||||||
|
}
|
||||||
|
case m.Has("command"):
|
||||||
|
if len(arg) == 0 {
|
||||||
|
for k, v := range v.target.Commands {
|
||||||
|
m.Add("append", "key", k)
|
||||||
|
m.Add("append", "name", v.Name)
|
||||||
|
m.Add("append", "help", v.Help)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
v.Cmd(arg)
|
||||||
|
m.Copy(v, "result").Copy(v, "append")
|
||||||
|
}
|
||||||
|
case m.Has("module"):
|
||||||
|
m.Travel(v.target, func(m *Message) bool {
|
||||||
|
m.Add("append", "name", m.target.Name)
|
||||||
|
m.Add("append", "help", m.target.Help)
|
||||||
|
m.Add("append", "module", m.Cap("module"))
|
||||||
|
m.Add("append", "status", m.Cap("status"))
|
||||||
|
m.Add("append", "stream", m.Cap("stream"))
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
case m.Has("domain"):
|
||||||
|
msg := m.Find("ssh", true)
|
||||||
|
msg.Travel(msg.Target(), func(msg *Message) bool {
|
||||||
|
m.Add("append", "name", msg.Target().Name)
|
||||||
|
m.Add("append", "help", msg.Target().Help)
|
||||||
|
m.Add("append", "domain", msg.Cap("domain")+"."+msg.Conf("domains"))
|
||||||
|
return true
|
||||||
|
})
|
||||||
case m.Has("switch"), m.Has("back"):
|
case m.Has("switch"), m.Has("back"):
|
||||||
m.target = v.target
|
m.target = v.target
|
||||||
case m.Has("show"):
|
case m.Has("show"):
|
||||||
|
@ -450,6 +450,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
|
|
||||||
nfs.Caches["target"] = &ctx.Cache{Name: "target", Value: "", Help: "文件名"}
|
nfs.Caches["target"] = &ctx.Cache{Name: "target", Value: "", Help: "文件名"}
|
||||||
|
|
||||||
|
nsend := ""
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, e := nfs.Reader.ReadString('\n')
|
line, e := nfs.Reader.ReadString('\n')
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
@ -473,6 +475,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
msg.Add("detail", ls[1])
|
msg.Add("detail", ls[1])
|
||||||
case "result":
|
case "result":
|
||||||
msg.Add("result", ls[1])
|
msg.Add("result", ls[1])
|
||||||
|
case "nsend":
|
||||||
|
nsend = ls[1]
|
||||||
default:
|
default:
|
||||||
msg.Add("option", ls[0], ls[1])
|
msg.Add("option", ls[0], ls[1])
|
||||||
}
|
}
|
||||||
@ -484,20 +488,21 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
msg.Log("info", nil, "detail: %v", msg.Meta["detail"])
|
msg.Log("info", nil, "detail: %v", msg.Meta["detail"])
|
||||||
msg.Log("info", nil, "option: %v", msg.Meta["option"])
|
msg.Log("info", nil, "option: %v", msg.Meta["option"])
|
||||||
msg.Options("stdio", false)
|
msg.Options("stdio", false)
|
||||||
|
msg.Option("nsend", nsend)
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
cmd := msg
|
cmd := msg
|
||||||
nsend := cmd.Option("nsend")
|
nsends := nsend
|
||||||
cmd.Call(func(sub *ctx.Message) *ctx.Message {
|
cmd.Call(func(sub *ctx.Message) *ctx.Message {
|
||||||
for _, v := range sub.Meta["result"] {
|
for _, v := range sub.Meta["result"] {
|
||||||
_, e := fmt.Fprintf(nfs.Writer, "result: %s\n", url.QueryEscape(v))
|
_, e := fmt.Fprintf(nfs.Writer, "result: %s\n", url.QueryEscape(v))
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub.Append("nsend", nsend)
|
sub.Append("nsend", nsends)
|
||||||
for _, k := range sub.Meta["append"] {
|
for _, k := range sub.Meta["append"] {
|
||||||
for _, v := range sub.Meta[k] {
|
for _, v := range sub.Meta[k] {
|
||||||
_, e := fmt.Fprintf(nfs.Writer, "%s: %s\n", k, v)
|
_, e := fmt.Fprintf(nfs.Writer, "%s: %s\n", k, url.QueryEscape(v))
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,11 +531,13 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
msg.Meta["append"] = msg.Meta["option"]
|
msg.Meta["append"] = msg.Meta["option"]
|
||||||
delete(msg.Meta, "option")
|
delete(msg.Meta, "option")
|
||||||
|
|
||||||
msg.Log("info", nil, "%s send", msg.Meta["nsend"])
|
msg.Log("info", nil, "%s send", nsend)
|
||||||
msg.Log("info", nil, "result: %v", msg.Meta["result"])
|
msg.Log("info", nil, "result: %v", msg.Meta["result"])
|
||||||
msg.Log("info", nil, "append: %v", msg.Meta["append"])
|
msg.Log("info", nil, "append: %v", msg.Meta["append"])
|
||||||
|
|
||||||
send := nfs.send[msg.Appendi("nsend")]
|
n, e := strconv.Atoi(nsend)
|
||||||
|
m.Assert(e)
|
||||||
|
send := nfs.send[n]
|
||||||
send.Copy(msg, "result")
|
send.Copy(msg, "result")
|
||||||
send.Copy(msg, "append")
|
send.Copy(msg, "append")
|
||||||
|
|
||||||
@ -544,6 +551,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
send.Back(send)
|
send.Back(send)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsend = ""
|
||||||
msg = nil
|
msg = nil
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -167,7 +167,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
if m.Options("nsend") { //接收命令
|
if m.Options("nsend") { //接收命令
|
||||||
msg := m.Spawn(m.Target())
|
msg := m.Spawn(m.Target())
|
||||||
msg.Cmd(arg)
|
msg.Cmd(arg)
|
||||||
m.Back(msg)
|
m.Copy(msg, "result").Copy(msg, "append")
|
||||||
|
m.Back(m)
|
||||||
} else { //发送命令
|
} else { //发送命令
|
||||||
ssh.Message.Sesss("nfs").CallBack(m.Options("stdio"), func(host *ctx.Message) *ctx.Message {
|
ssh.Message.Sesss("nfs").CallBack(m.Options("stdio"), func(host *ctx.Message) *ctx.Message {
|
||||||
m.Back(m.Copy(host, "result").Copy(host, "append"))
|
m.Back(m.Copy(host, "result").Copy(host, "append"))
|
||||||
|
@ -370,8 +370,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"query": &ctx.Config{Name: "query", Value: "", Help: "主机参数"},
|
"query": &ctx.Config{Name: "query", Value: "", Help: "主机参数"},
|
||||||
"output": &ctx.Config{Name: "output", Value: "stdout", Help: "响应输出"},
|
"output": &ctx.Config{Name: "output", Value: "stdout", Help: "响应输出"},
|
||||||
"editor": &ctx.Config{Name: "editor", Value: "vim", Help: "响应编辑器"},
|
"editor": &ctx.Config{Name: "editor", Value: "vim", Help: "响应编辑器"},
|
||||||
"upload_tpl": &ctx.Config{Name: "upload_tpl", Value: "usr/upload.html", Help: "上传文件路径"},
|
"upload_tpl": &ctx.Config{Name: "upload_tpl", Value: "usr/template/upload.html", Help: "上传文件路径"},
|
||||||
"travel_tpl": &ctx.Config{Name: "travel_tpl", Value: "usr/travel.html", Help: "上传文件路径"},
|
"travel_tpl": &ctx.Config{Name: "travel_tpl", Value: "usr/template/travel.html", Help: "上传文件路径"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"serve": &ctx.Command{Name: "serve [directory [address [protocol]]]", Help: "开启应用服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"serve": &ctx.Command{Name: "serve [directory [address [protocol]]]", Help: "开启应用服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
@ -715,20 +715,33 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
w := m.Data["response"].(http.ResponseWriter) // {{{
|
w := m.Data["response"].(http.ResponseWriter) // {{{
|
||||||
|
|
||||||
|
if m.Option("method") == "POST" {
|
||||||
|
if m.Options("domain") {
|
||||||
|
msg := m.Find("ssh", true)
|
||||||
|
msg.Detail(0, "send", "domain", m.Option("domain"), "context", "find", m.Option("module"), m.Option("ccc"))
|
||||||
|
if m.Options("name") {
|
||||||
|
msg.Add("detail", m.Option("name"))
|
||||||
|
}
|
||||||
|
if m.Options("value") {
|
||||||
|
msg.Add("detail", m.Option("value"))
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.CallBack(true, func(sub *ctx.Message) *ctx.Message {
|
||||||
|
m.Copy(sub, "result").Copy(sub, "append")
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
module := "ctx"
|
module := "ctx"
|
||||||
if m.Options("module") {
|
if m.Options("module") {
|
||||||
module = m.Option("module")
|
module = m.Option("module")
|
||||||
}
|
}
|
||||||
if m.Options("domain") {
|
|
||||||
module = "ssh"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := m.Find(module, true)
|
msg := m.Find(module, true)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Option("method") == "POST" {
|
|
||||||
switch m.Option("ccc") {
|
switch m.Option("ccc") {
|
||||||
case "cache":
|
case "cache":
|
||||||
m.Echo(msg.Cap(m.Option("name")))
|
m.Echo(msg.Cap(m.Option("name")))
|
||||||
@ -740,96 +753,46 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
case "command":
|
case "command":
|
||||||
msg = msg.Spawn(msg.Target())
|
msg = msg.Spawn(msg.Target())
|
||||||
if m.Options("domain") {
|
|
||||||
module := "ssh"
|
|
||||||
if m.Options("module") {
|
|
||||||
module = m.Option("module")
|
|
||||||
}
|
|
||||||
if m.Options("value") {
|
|
||||||
msg.Detail(0, "send", "context", module, m.Option("name"), m.Option("value"))
|
|
||||||
} else {
|
|
||||||
msg.Detail(0, "send", "context", module, m.Option("name"))
|
|
||||||
}
|
|
||||||
msg.Log("fuck", nil, "why %d ", len(msg.Meta["detail"]))
|
|
||||||
|
|
||||||
msg.Option("domain", m.Option("domain"))
|
|
||||||
msg.CallBack(true, func(sub *ctx.Message) *ctx.Message {
|
|
||||||
m.Copy(sub, "result").Copy(sub, "append")
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if m.Options("value") {
|
|
||||||
msg.Detail(0, m.Option("name"), m.Option("value"))
|
|
||||||
} else {
|
|
||||||
msg.Detail(0, m.Option("name"))
|
msg.Detail(0, m.Option("name"))
|
||||||
|
if m.Options("value") {
|
||||||
|
msg.Add("detail", m.Option("value"))
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Cmd()
|
msg.Cmd()
|
||||||
m.Copy(msg, "result").Copy(msg, "append")
|
m.Copy(msg, "result").Copy(msg, "append")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module := "ctx"
|
||||||
|
if m.Options("module") {
|
||||||
|
module = m.Option("module")
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Add("Content-Type", "text/html")
|
w.Header().Add("Content-Type", "text/html")
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "head", m.Meta))
|
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "head", m.Meta))
|
||||||
|
|
||||||
for k, v := range msg.Target().Caches {
|
if msg := m.Find(module, true); msg != nil {
|
||||||
msg.Add("append", "key", k)
|
for _, v := range []string{"cache", "config", "command", "module", "domain"} {
|
||||||
msg.Add("append", "name", v.Name)
|
if m.Options("domain") {
|
||||||
msg.Add("append", "help", v.Help)
|
msg = m.Find("ssh", true)
|
||||||
msg.Add("append", "value", v.Value)
|
msg.Detail(0, "send", "domain", m.Option("domain"), "context", "find", module, v)
|
||||||
}
|
msg.CallBack(true, func(sub *ctx.Message) *ctx.Message {
|
||||||
if len(msg.Meta["append"]) > 0 {
|
msg.Copy(sub, "result").Copy(sub, "append")
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "cache", msg.Meta))
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
msg = msg.Spawn(msg.Target())
|
|
||||||
for k, v := range msg.Target().Configs {
|
|
||||||
msg.Add("append", "key", k)
|
|
||||||
msg.Add("append", "name", v.Name)
|
|
||||||
msg.Add("append", "help", v.Help)
|
|
||||||
msg.Add("append", "value", v.Value)
|
|
||||||
msg.Add("append", "input", "")
|
|
||||||
}
|
|
||||||
if len(msg.Meta["append"]) > 0 {
|
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "config", msg.Meta))
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = msg.Spawn(msg.Target())
|
|
||||||
for k, v := range msg.Target().Commands {
|
|
||||||
msg.Add("append", "key", k)
|
|
||||||
msg.Add("append", "name", v.Name)
|
|
||||||
msg.Add("append", "help", v.Help)
|
|
||||||
msg.Add("append", "input", "")
|
|
||||||
}
|
|
||||||
if len(msg.Meta["append"]) > 0 {
|
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "command", msg.Meta))
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = msg.Spawn(msg.Target())
|
|
||||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
|
||||||
m.Add("append", "name", m.Target().Name)
|
|
||||||
m.Add("append", "help", m.Target().Help)
|
|
||||||
m.Add("append", "module", m.Cap("module"))
|
|
||||||
m.Add("append", "status", m.Cap("status"))
|
|
||||||
m.Add("append", "stream", m.Cap("stream"))
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
if len(msg.Meta["append"]) > 0 {
|
} else {
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "context", msg.Meta))
|
msg = msg.Spawn(msg.Target())
|
||||||
|
msg.Cmd("context", "find", module, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = msg.Find("ssh", true)
|
|
||||||
msg.Option("domains", m.Option("domain"))
|
|
||||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
|
||||||
m.Add("append", "name", m.Target().Name)
|
|
||||||
m.Add("append", "help", m.Target().Help)
|
|
||||||
m.Add("append", "domain", m.Conf("domains"))
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
if len(msg.Meta["append"]) > 0 {
|
if len(msg.Meta["append"]) > 0 {
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "domain", msg.Meta))
|
msg.Option("current_module", module)
|
||||||
|
msg.Option("current_domain", m.Option("domain"))
|
||||||
|
m.Log("fuck", nil, "fuck %v", msg.Meta)
|
||||||
|
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, v, msg.Meta))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "tail", m.Meta))
|
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "tail", m.Meta))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
ctx = {
|
ctx = {
|
||||||
Cookie: function(name, value) {
|
Cookie: function(key, value) {//{{{
|
||||||
if (value == undefined) {
|
if (value == undefined) {
|
||||||
var pattern = new RegExp(name+"=([^;]*);?");
|
var pattern = new RegExp(key+"=([^;]*);?");
|
||||||
var result = pattern.exec(document.cookie);
|
var result = pattern.exec(document.cookie);
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
return result[1];
|
return result[1];
|
||||||
@ -9,10 +9,10 @@ ctx = {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
document.cookie = name+"="+value;
|
document.cookie = key+"="+value;
|
||||||
return this.Cookie(name);
|
return this.Cookie(key);
|
||||||
},
|
},//}}}
|
||||||
Search: function(name, value) {
|
Search: function(key, value) {//{{{
|
||||||
var args = {};
|
var args = {};
|
||||||
var search = location.search.split("?");
|
var search = location.search.split("?");
|
||||||
if (search.length > 1) {
|
if (search.length > 1) {
|
||||||
@ -23,16 +23,16 @@ ctx = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof name == "object") {
|
if (typeof key == "object") {
|
||||||
for (var k in name) {
|
for (var k in key) {
|
||||||
if (name[k] != undefined) {
|
if (key[k] != undefined) {
|
||||||
args[k] = name[k];
|
args[k] = key[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (value == undefined) {
|
} else if (value == undefined) {
|
||||||
return args[name];
|
return args[key];
|
||||||
} else {
|
} else {
|
||||||
args[name] = value;
|
args[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var arg = [];
|
var arg = [];
|
||||||
@ -40,8 +40,8 @@ ctx = {
|
|||||||
arg.push(k+"="+encodeURIComponent(args[k]));
|
arg.push(k+"="+encodeURIComponent(args[k]));
|
||||||
}
|
}
|
||||||
location.search = arg.join("&");
|
location.search = arg.join("&");
|
||||||
},
|
},//}}}
|
||||||
POST: function(url, form, cb) {
|
POST: function(url, form, cb) {//{{{
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
switch (xhr.readyState) {
|
switch (xhr.readyState) {
|
||||||
@ -50,6 +50,7 @@ ctx = {
|
|||||||
case 200:
|
case 200:
|
||||||
var msg = JSON.parse(xhr.responseText||'{"result":[]}');
|
var msg = JSON.parse(xhr.responseText||'{"result":[]}');
|
||||||
msg && console.log(msg)
|
msg && console.log(msg)
|
||||||
|
msg.result && console.log(msg.result.join(""));
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -59,59 +60,85 @@ ctx = {
|
|||||||
xhr.open("POST", url);
|
xhr.open("POST", url);
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
if (!("dir" in form)) {
|
|
||||||
form = form || {}
|
form = form || {}
|
||||||
form["dir"] = this.Search("dir")
|
form["dir"] = form["dir"] || this.Search("dir") || undefined
|
||||||
}
|
form["module"] = form["module"] || this.Search("module") || undefined
|
||||||
if (!("module" in form)) {
|
form["domain"] = form["domain"] || this.Search("domain") || undefined
|
||||||
form = form || {}
|
|
||||||
form["module"] = this.Search("module")
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = [];
|
var args = [];
|
||||||
for (k in form) {
|
for (k in form) {
|
||||||
|
if (form[k] != undefined) {
|
||||||
args.push(k+"="+encodeURIComponent(form[k]));
|
args.push(k+"="+encodeURIComponent(form[k]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var arg = args.join("&");
|
var arg = args.join("&");
|
||||||
console.log("POST: "+url+"?"+arg);
|
console.log("POST: "+url+"?"+arg);
|
||||||
xhr.send(arg);
|
xhr.send(arg);
|
||||||
},
|
},//}}}
|
||||||
Cap: function(cap, cb) {
|
|
||||||
this.POST("", {ccc:"cache", name:cap}, function(msg) {
|
Cap: function(cap, cb) {//{{{
|
||||||
typeof cb == "function" && cb(msg.result.join(""));
|
if (typeof cap == "function") {
|
||||||
|
cb = cap;
|
||||||
|
cap = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
var args = {ccc:"cache"};
|
||||||
|
if (cap != undefined) {
|
||||||
|
args.name = cap;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.POST("", args, function(msg) {
|
||||||
|
var value = msg.result.join("");
|
||||||
|
typeof cb == "function" && cb(value);
|
||||||
});
|
});
|
||||||
},
|
},//}}}
|
||||||
Conf: function(conf, value, cb) {
|
Conf: function(conf, value, cb) {//{{{
|
||||||
|
if (typeof conf == "function") {
|
||||||
|
value = conf;
|
||||||
|
conf = undefined;
|
||||||
|
}
|
||||||
if (typeof value == "function") {
|
if (typeof value == "function") {
|
||||||
cb = value;
|
cb = value;
|
||||||
value = undefined;
|
value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = {ccc:"config", name:conf};
|
var args = {ccc:"config"};
|
||||||
|
if (name != undefined) {
|
||||||
|
args.name = name
|
||||||
|
}
|
||||||
if (value != undefined) {
|
if (value != undefined) {
|
||||||
args.value = value
|
args.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
this.POST("", args, function(msg) {
|
this.POST("", args, function(msg) {
|
||||||
typeof cb == "function" && cb(msg.result.join(""));
|
var value = msg.result.join("");
|
||||||
|
typeof cb == "function" && cb(value);
|
||||||
});
|
});
|
||||||
},
|
},//}}}
|
||||||
Cmd: function(cmd, value, cb) {
|
Cmd: function(cmd, value, cb) {//{{{
|
||||||
|
if (typeof cmd == "function") {
|
||||||
|
value = cmd;
|
||||||
|
cmd = undefined;
|
||||||
|
}
|
||||||
if (typeof value == "function") {
|
if (typeof value == "function") {
|
||||||
cb = value;
|
cb = value;
|
||||||
value = undefined;
|
value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = {ccc:"command", name:cmd};
|
var args = {ccc:"command"};
|
||||||
|
if (cmd != undefined) {
|
||||||
|
args.name = cmd
|
||||||
|
}
|
||||||
if (value != undefined) {
|
if (value != undefined) {
|
||||||
args.value = value
|
args.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
this.POST("", args, cb);
|
this.POST("", args, cb);
|
||||||
},
|
},//}}}
|
||||||
Module: function(module, domain) {
|
Module: function(module, domain) {//{{{
|
||||||
this.Search({module:module, domain:domain})
|
this.Search({module:module, domain:domain})
|
||||||
},
|
},//}}}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
@ -125,8 +125,8 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "context"}}
|
{{define "module"}}
|
||||||
<fieldset><legend><input type="text" id="module" value="{{index .module 0}}" onkeydown="return Change(event)"></legend>
|
<fieldset><legend><input type="text" id="module" value="{{index .current_module 0}}" onkeydown="return Change(event, 'module')"></legend>
|
||||||
<table>
|
<table>
|
||||||
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
||||||
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
||||||
@ -138,7 +138,7 @@
|
|||||||
{{range $key := index $meta "append"}}
|
{{range $key := index $meta "append"}}
|
||||||
{{if eq $key "name"}}
|
{{if eq $key "name"}}
|
||||||
<td class="{{$key}}">
|
<td class="{{$key}}">
|
||||||
<code><a href="/travel?module={{index $meta "module" $i}}">{{index $meta $key $i}}</a></code>
|
<code><a href="" onclick="ctx.Search('module', '{{index $meta "module" $i}}'); return false">{{index $meta $key $i}}</a></code>
|
||||||
</td>
|
</td>
|
||||||
{{else}}
|
{{else}}
|
||||||
<td class="{{$key}}">
|
<td class="{{$key}}">
|
||||||
@ -154,7 +154,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "domain"}}
|
{{define "domain"}}
|
||||||
<fieldset><legend><input type="text" id="domain" value="{{index . "domains" 0}}" onkeydown="return Change(event)"></legend>
|
<fieldset><legend><input type="text" id="domain" value="{{index . "current_domain" 0}}" onkeydown="return Change(event, 'domain')"></legend>
|
||||||
<table>
|
<table>
|
||||||
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
||||||
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
||||||
@ -166,7 +166,7 @@
|
|||||||
{{range $key := index $meta "append"}}
|
{{range $key := index $meta "append"}}
|
||||||
{{if eq $key "name"}}
|
{{if eq $key "name"}}
|
||||||
<td class="{{$key}}">
|
<td class="{{$key}}">
|
||||||
<code><a href="/travel?domain={{index $meta "domain" $i}}">{{index $meta $key $i}}</a></code>
|
<code><a href="" onclick="ctx.Search('domain', '{{index $meta "domain" $i}}'); return false">{{index $meta $key $i}}</a></code>
|
||||||
</td>
|
</td>
|
||||||
{{else}}
|
{{else}}
|
||||||
<td class="{{$key}}">
|
<td class="{{$key}}">
|
||||||
@ -223,9 +223,15 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Change(event) {
|
function Input(event, cb, key) {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
ctx.Search("module", event.target.value);
|
cb(key, event.target.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Change(event, key) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
ctx.Search(key, event.target.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user