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