forked from x/ContextOS
mac add context.js
This commit is contained in:
parent
934fab38df
commit
5c1a8d9b92
@ -6,11 +6,11 @@ import ( // {{{
|
||||
"toolkit"
|
||||
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"text/template"
|
||||
|
||||
"bytes"
|
||||
"mime/multipart"
|
||||
@ -632,7 +632,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
|
||||
_, e = io.Copy(f, file)
|
||||
m.Assert(e)
|
||||
m.Option("message", name)
|
||||
m.Option("message", name, "upload success!")
|
||||
} else {
|
||||
m.Option("message", name, "already exist!")
|
||||
}
|
||||
@ -703,6 +703,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
m.Add("append", "time", v.ModTime().Format("2006-01-02 15:04:05"))
|
||||
m.Add("append", "size", kit.FmtSize(v.Size()))
|
||||
m.Add("append", "name", name)
|
||||
m.Add("append", "path", path.Join(m.Option("file"), name))
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
@ -733,6 +734,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "head", m.Meta))
|
||||
|
||||
for k, v := range msg.Target().Caches {
|
||||
@ -769,6 +771,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
msg.Copy(m, "option")
|
||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
||||
m.Add("append", "name", m.Target().Name)
|
||||
m.Add("append", "help", m.Target().Help)
|
||||
@ -777,8 +780,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
m.Add("append", "stream", m.Cap("stream"))
|
||||
return true
|
||||
})
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
msg.Put("option", "target", msg.Target())
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "context", msg.Meta))
|
||||
}
|
||||
|
@ -126,7 +126,7 @@
|
||||
{{end}}
|
||||
|
||||
{{define "context"}}
|
||||
<fieldset><legend>context</legend>
|
||||
<fieldset><legend><input type="text" id="dir" value="{{index .dir 0}}" onkeydown="return Change(event)"></legend>
|
||||
<table>
|
||||
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
||||
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
||||
@ -154,63 +154,9 @@
|
||||
{{end}}
|
||||
|
||||
{{define "tail"}}
|
||||
<script src="library/context.js"></script>
|
||||
<script>
|
||||
function Cookie(name, value) {
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(name+"=([^;]*);?");
|
||||
var result = pattern.exec(document.cookie);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
document.cookie = name+"="+value;
|
||||
return Cookie(name);
|
||||
}
|
||||
|
||||
function Search(name) {
|
||||
var pattern = new RegExp(name+"=([^&#]*)");
|
||||
var result = pattern.exec(location.search);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function POST(url, form, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
switch (xhr.readyState) {
|
||||
case 4:
|
||||
switch (xhr.status) {
|
||||
case 200:
|
||||
var msg = JSON.parse(xhr.responseText);
|
||||
console.log(msg)
|
||||
typeof cb == "function" && cb(msg)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xhr.open("POST", url);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
if (!("dir" in form)) {
|
||||
form = form || {}
|
||||
form["dir"] = Search("dir")
|
||||
}
|
||||
|
||||
var args = [];
|
||||
for (k in form) {
|
||||
args.push(k+"="+encodeURIComponent(form[k]));
|
||||
}
|
||||
|
||||
var arg = args.join("&");
|
||||
console.log(url)
|
||||
console.log(arg)
|
||||
xhr.send(arg);
|
||||
}
|
||||
|
||||
function Refresh() {
|
||||
location.assign(location.href);
|
||||
@ -218,7 +164,7 @@
|
||||
|
||||
function Config(event, name) {
|
||||
if (event.keyCode == 13) {
|
||||
POST("", {ccc:"config", name:name, value:event.currentTarget.value}, function(msg) {Refresh()})
|
||||
ctx.POST("", {ccc:"config", name:name, value:event.currentTarget.value}, function(msg) {Refresh()})
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,9 +178,9 @@
|
||||
var direct = document.getElementById("direct");
|
||||
if (name) {
|
||||
direct.value = name;
|
||||
POST("", {ccc:"command", name:name, value:event.currentTarget.value}, Result)
|
||||
ctx.POST("", {ccc:"command", name:name, value:event.currentTarget.value}, Result)
|
||||
} else {
|
||||
POST("", {ccc:"command", name:event.currentTarget.value}, Result)
|
||||
ctx.POST("", {ccc:"command", name:event.currentTarget.value}, Result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -247,13 +193,19 @@
|
||||
|
||||
var direct = document.getElementById("direct");
|
||||
direct.value = name;
|
||||
POST("", {ccc:"command", name:name, value:value||""}, Result)
|
||||
ctx.POST("", {ccc:"command", name:name, value:value||""}, Result)
|
||||
return false;
|
||||
}
|
||||
|
||||
function Change(event) {
|
||||
if (event.keyCode == 13) {
|
||||
ctx.Search("dir", event.target.value);
|
||||
}
|
||||
}
|
||||
|
||||
function list(what) {
|
||||
Cookie("list", what);
|
||||
Cookie("order", Cookie("order")*1 + 1);
|
||||
ctx.Cookie("list", what);
|
||||
ctx.Cookie("order", ctx.Cookie("order")*1 + 1);
|
||||
location.assign(location.href);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
||||
</fieldset>
|
||||
{{end}}
|
||||
|
||||
<fieldset><legend>list</legend>
|
||||
<fieldset><legend><input type="text" id="dir" value="{{index .file 0}}" onkeydown="return Change(event)"></legend>
|
||||
<table>
|
||||
<colgroup>
|
||||
{{range .append}}
|
||||
@ -83,13 +83,16 @@
|
||||
{{end}}
|
||||
{{end}}
|
||||
</tr>
|
||||
{{$meta := .}} {{$first := index .append 0}}
|
||||
|
||||
{{$meta := .}}
|
||||
{{if .append}}
|
||||
{{$first := index .append 0}}
|
||||
{{range $i, $k := index . $first}}
|
||||
<tr>
|
||||
{{range $key := index $meta "append"}}
|
||||
{{if eq $key "name"}}
|
||||
<td class="{{$key}}">
|
||||
<a href="/upload?file={{index $meta "file" 0}}/{{index $meta $key $i}}"><code>{{index $meta $key $i}}</code></a>
|
||||
<a href="/upload?file={{index $meta "path" $i}}"><code>{{index $meta $key $i}}</code></a>
|
||||
</td>
|
||||
{{else}}
|
||||
<td class="{{$key}}">
|
||||
@ -99,6 +102,7 @@
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
@ -111,24 +115,17 @@
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
<script src="library/context.js"></script>
|
||||
<script>
|
||||
function Cookie(name, value) {
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(name+"=([^;]*);?");
|
||||
var result = pattern.exec(document.cookie);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return ""
|
||||
function Change(event) {
|
||||
if (event.keyCode == 13) {
|
||||
ctx.Search("file", event.target.value);
|
||||
}
|
||||
|
||||
document.cookie = name+"="+value;
|
||||
return Cookie(name);
|
||||
}
|
||||
|
||||
function list(what) {
|
||||
Cookie("list", what);
|
||||
Cookie("order", Cookie("order")*1 + 1)
|
||||
ctx.Cookie("list", what);
|
||||
ctx.Cookie("order", ctx.Cookie("order")*1 + 1)
|
||||
location.assign(location.href)
|
||||
}
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user