Commit 874dfada authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Clean up js API filenames

parent f2345192
"use strict";
function hash_to_dict() {
splithash = location.hash.substr(1).split('&').filter(function(x){return x.length>0}).map(function(x){return x.split('=')});
dict = {};
for (i in splithash) {
for (j in splithash[i]) {
var splithash = location.hash.substr(1).split('&').filter(function(x){return x.length>0}).map(function(x){return x.split('=')});
var dict = {};
for (var i in splithash) {
for (var j in splithash[i]) {
dict[splithash[i][0]] = splithash[i][j];
}
}
......@@ -14,10 +15,8 @@ window.hashdict = hash_to_dict();
window.load_task_object = function (callback) {
params = {
task: window.hashdict["taskid"]
}
$.get("/load", params,
console.log(callback);
$.get("/load/" + window.hashdict["taskid"], {},
function(data) {
callback(data);
}, "json").fail(function(){
......@@ -28,23 +27,21 @@ window.load_task_object = function (callback) {
window.save_task_object = function (object, callback) {
if (!callback) callback = function(data){}; // is this necessary?
params = {
task: window.hashdict["taskid"],
var params = {
csrf: window.hashdict["csrftoken"],
value: JSON.stringify(object)
data: JSON.stringify(object)
}
$.post("/save", params, callback, "json").fail(function(){
$.post("/save/" + window.hashdict["taskid"], params, callback, "json").fail(function(){
alert("Save failed.");
});
}
window.load_subtask_object = function (subtaskname, callback) {
params = {
task: window.hashdict["taskid"],
var params = {
subtask: subtaskname
}
$.get("/load", params,
$.get("/load/" + window.hashdict["taskid"], params,
function(data) {
callback(data);
}, "json").fail(function(){
......@@ -55,13 +52,12 @@ window.load_subtask_object = function (subtaskname, callback) {
window.save_subtask_object = function (subtaskname, object, callback) {
if (!callback) callback = function(data){}; // is this necessary?
params = {
task: window.hashdict["taskid"],
var params = {
subtask: subtaskname,
csrf: window.hashdict["csrftoken"],
value: JSON.stringify(object)
data: JSON.stringify(object)
}
$.post("/save", params, callback, "json").fail(function(){
$.post("/save/" + window.hashdict["taskid"], params, callback, "json").fail(function(){
alert("Save failed.");
});
}
"use strict";
function hash_to_dict() {
var splithash = location.hash.substr(1).split('&').filter(function(x){return x.length>0}).map(function(x){return x.split('=')});
var dict = {};
for (var i in splithash) {
for (var j in splithash[i]) {
dict[splithash[i][0]] = splithash[i][j];
}
}
return dict;
}
window.hashdict = hash_to_dict();
window.load_task_object = function (callback) {
console.log(callback);
$.get("/load/" + window.hashdict["taskid"], {},
function(data) {
callback(data);
}, "json").fail(function(){
alert("Load failed.");
})
}
window.save_task_object = function (object, callback) {
if (!callback) callback = function(data){}; // is this necessary?
var params = {
csrf: window.hashdict["csrftoken"],
data: JSON.stringify(object)
}
$.post("/save/" + window.hashdict["taskid"], params, callback, "json").fail(function(){
alert("Save failed.");
});
}
window.load_subtask_object = function (subtaskname, callback) {
var params = {
subtask: subtaskname
}
$.get("/load/" + window.hashdict["taskid"], params,
function(data) {
callback(data);
}, "json").fail(function(){
alert("Load failed.");
})
}
window.save_subtask_object = function (subtaskname, object, callback) {
if (!callback) callback = function(data){}; // is this necessary?
var params = {
subtask: subtaskname,
csrf: window.hashdict["csrftoken"],
data: JSON.stringify(object)
}
$.post("/save/" + window.hashdict["taskid"], params, callback, "json").fail(function(){
alert("Save failed.");
});
}
<h1>Actual Task</h1>
<input id="input">
......@@ -8,9 +5,8 @@
<button id="load">Load Data</button>
<button id="save">Save Data</button>
<script src="../../static/lib/jquery/jquery-3.2.1.min.js"></script>
<script src="../../static/lib/medal/medal-0.0.1a.js"></script>
<script src="../../static/lib/medal/medal-0.0.1.js"></script>
<script>
$("#load").click(function(){
window.load_task_object(function(data){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment