Index: experimental/webtry/templates/workspace.html |
diff --git a/experimental/webtry/templates/index.html b/experimental/webtry/templates/workspace.html |
similarity index 59% |
copy from experimental/webtry/templates/index.html |
copy to experimental/webtry/templates/workspace.html |
index d2ba8592cb08743278868ab1094c82bb15a75a45..1a5f99036edbd0c2915acae0e7d5ba48ae4e350c 100644 |
--- a/experimental/webtry/templates/index.html |
+++ b/experimental/webtry/templates/workspace.html |
@@ -1,21 +1,24 @@ |
<!DOCTYPE html> |
<html> |
<head> |
- <title>Skia WebTry</title> |
+ <title>Workspace</title> |
<meta charset='utf-8' /> |
<link rel="stylesheet" href="/css/" type="text/css" media="screen"> |
</head> |
<body> |
<section id=title> |
<a href="/">Home</a> |
- <a href="/recent">Recent</a> |
+ <a href="/recent/">Recent</a> |
+ <a href="/w/">Workspace</a> |
<a href="https://github.com/google/skia/tree/master/experimental/webtry">Code</a> |
</section> |
<section id=content> |
+ <h1>Create</h1> |
+ {{if .Name}} |
<pre><code>#include "SkCanvas.h" |
void draw(SkCanvas* canvas) { |
- <textarea name='code' id='code' rows='15' cols='80'>{{.UserCode}}</textarea> |
+ <textarea name='code' id='code' rows='15' cols='80'>{{.Code}}</textarea> |
} |
</code></pre> |
@@ -25,13 +28,28 @@ void draw(SkCanvas* canvas) { |
<img id='img' src=''/> |
<pre><code id='output'></code></pre> |
- |
</section> |
+ <section> |
+ |
+ <section id=tryHistory> |
+ {{range .Tries}} |
+ <div class=tries> |
+ <h2><a href="/c/{{.Hash}}">{{.CreateTS}}</a></h2> |
+ <a href="/c/{{.Hash}}"> |
+ <img width=100 height=100 src="/i/{{.Hash}}.png"> |
+ </a> |
+ </div> |
+ {{end}} |
+ </section> |
+ |
<script type='text/javascript' charset='utf-8'> |
var run = document.getElementById('run'); |
var code = document.getElementById('code'); |
var output = document.getElementById('output'); |
var img = document.getElementById('img'); |
+ var tryHistory = document.getElementById('tryHistory'); |
+ var parser = new DOMParser(); |
+ var workspaceName = "{{.Name}}"; |
function beginWait() { |
document.body.classList.add('waiting'); |
@@ -61,7 +79,15 @@ void draw(SkCanvas* canvas) { |
} else { |
img.src = ''; |
} |
- window.history.pushState(null, null, "/c/" + body.hash); |
+ // Add the image to the history. |
+ |
+ var newHistoryStr = '<div class=tries><h2><a href="/c/' + body.hash + '">CreateTS</a></h2>' + |
+ '<a href="/c/' + body.hash + '">' + |
+ ' <img width=100 height=100 src="/i/' + body.hash + '.png">' + |
+ '</a></div>'; |
+ |
+ var newHistory = parser.parseFromString(newHistoryStr, "text/html"); |
+ tryHistory.insertBefore(newHistory.body.firstChild, tryHistory.firstChild); |
} |
function codeError(e) { |
@@ -76,9 +102,17 @@ void draw(SkCanvas* canvas) { |
req.addEventListener('load', codeComplete); |
req.addEventListener('error', codeError); |
req.overrideMimeType('application/json'); |
- req.open('POST', '.', true); |
- req.send(code.value); |
+ req.open('POST', '/', true); |
+ req.setRequestHeader('content-type', 'application/json'); |
+ req.send(JSON.stringify({"code": code.value, "name": workspaceName})); |
} |
</script> |
+ {{else}} |
+ Create a new workspace: |
+ <form action="." method="POST" accept-charset="utf-8"> |
+ <p><input type="submit" value="Create"></p> |
+ </form> |
+ {{end}} |
+ </section> |
</body> |
</html> |