2018-04-01 07:00:27 +10:00
|
|
|
function listToggle(){
|
|
|
|
if ($("#list-box").hasClass("hide")) {
|
|
|
|
$("#list-box").removeClass("hide");
|
|
|
|
$("#list-box").addClass("show");
|
2018-07-28 07:25:12 +10:00
|
|
|
$("#list-box").css("bottom","40px");
|
|
|
|
$("#list-box").css("left",$('#list-tgl').offset().left-$('#list-box').width()/2+"px");
|
2018-04-01 07:00:27 +10:00
|
|
|
//リストロード
|
|
|
|
} else {
|
|
|
|
$("#list-box").removeClass("show");
|
|
|
|
$("#list-box").addClass("hide")
|
|
|
|
}
|
2018-07-28 07:25:12 +10:00
|
|
|
}
|
|
|
|
|
2018-04-01 07:00:27 +10:00
|
|
|
|
|
|
|
function list(){
|
|
|
|
$("#lists-user").html("");
|
|
|
|
var acct_id = $("#list-acct-sel").val();
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists"
|
|
|
|
console.log(start)
|
|
|
|
fetch(start, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Bearer ' + at
|
|
|
|
},
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
if (json) {
|
|
|
|
var lists = "";
|
|
|
|
Object.keys(json).forEach(function(key) {
|
|
|
|
var list = json[key];
|
|
|
|
lists = lists + list.title+':<a onclick="listShow(' + list.id + ',\'' + list.title + '\',\'' + acct_id +
|
2019-01-26 14:24:26 +11:00
|
|
|
'\')" class="pointer">'+lang.lang_list_show+'</a>/<a onclick="listUser(' + list.id + ',' + acct_id +
|
|
|
|
')" class="pointer">'+lang.lang_list_users+'</a><br> ';
|
2018-04-01 07:00:27 +10:00
|
|
|
});
|
|
|
|
$("#lists").html(lists);
|
|
|
|
}else{
|
2019-01-26 14:24:26 +11:00
|
|
|
$("#lists").html(lang.lang_list_nodata);
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function makeNewList(){
|
|
|
|
var acct_id = $("#list-acct-sel").val();
|
|
|
|
var text=$("#list-add").val();
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists"
|
|
|
|
console.log(start)
|
2018-04-17 03:10:35 +10:00
|
|
|
var httpreq = new XMLHttpRequest();
|
|
|
|
httpreq.open('POST', start, true);
|
|
|
|
httpreq.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
|
|
|
|
httpreq.responseType = 'json';
|
|
|
|
httpreq.send(JSON.stringify({
|
|
|
|
title: text
|
|
|
|
}));
|
|
|
|
httpreq.onreadystatechange = function() {
|
|
|
|
if (httpreq.readyState == 4) {
|
|
|
|
var json = httpreq.response;
|
|
|
|
list();
|
|
|
|
$("#list-add").val("")
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
function listShow(id,title,acct_id){
|
|
|
|
localStorage.setItem("list_"+id+"_"+acct_id,title);
|
|
|
|
tl('list',id,acct_id,'add');
|
|
|
|
}
|
|
|
|
function listUser(id,acct_id){
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts"
|
|
|
|
console.log(start)
|
|
|
|
fetch(start, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Bearer ' + at
|
|
|
|
},
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
if (json) {
|
|
|
|
var lists = "";
|
|
|
|
var templete = userparse(json,'',acct_id);
|
|
|
|
if(!json[0]){
|
2019-01-26 14:24:26 +11:00
|
|
|
templete=lang.lang_list_nouser;
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
$("#lists-user").html(templete);
|
|
|
|
}else{
|
2019-01-26 14:24:26 +11:00
|
|
|
$("#lists-user").html(lang.lang_list_nouser);
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function hisList(user,acct_id){
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists"
|
|
|
|
console.log(start)
|
|
|
|
fetch(start, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Bearer ' + at
|
|
|
|
},
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
if (json) {
|
2019-01-26 14:24:26 +11:00
|
|
|
var lists = lang.lang_list_add+"<br>";
|
2018-04-01 07:00:27 +10:00
|
|
|
Object.keys(json).forEach(function(key) {
|
|
|
|
var list = json[key];
|
|
|
|
lists = lists + '<a onclick="listAdd(' + list.id + ',\'' + user + '\',\'' + acct_id +
|
2018-08-29 20:17:34 +10:00
|
|
|
'\')" class="pointer">'+escapeHTML(list.title)+'</a><br> ';
|
2018-04-01 07:00:27 +10:00
|
|
|
});
|
|
|
|
$("#his-lists-a").html(lists);
|
|
|
|
}else{
|
2019-01-26 14:24:26 +11:00
|
|
|
$("#his-lists-a").html(lang.lang_list_nodata);
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
var start = "https://" + domain + "/api/v1/accounts/"+user+"/lists"
|
|
|
|
console.log(start)
|
|
|
|
fetch(start, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Bearer ' + at
|
|
|
|
},
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
if (json) {
|
2019-01-26 14:24:26 +11:00
|
|
|
var lists = lang.lang_list_remove+"<br>";
|
2018-04-01 07:00:27 +10:00
|
|
|
Object.keys(json).forEach(function(key) {
|
|
|
|
var list = json[key];
|
|
|
|
lists = lists + '<a onclick="listRemove(' + list.id + ',\'' + user + '\',\'' + acct_id +
|
|
|
|
'\')" class="pointer">'+list.title+'</a><br> ';
|
|
|
|
});
|
|
|
|
$("#his-lists-b").html(lists);
|
|
|
|
}else{
|
2019-01-26 14:24:26 +11:00
|
|
|
$("#his-lists-b").html(lang.lang_list_nodata);
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function listAdd(id,user,acct_id){
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts"
|
|
|
|
console.log(start)
|
2018-04-17 03:10:35 +10:00
|
|
|
var httpreq = new XMLHttpRequest();
|
|
|
|
httpreq.open('POST', start, true);
|
|
|
|
httpreq.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
|
|
|
|
httpreq.responseType = 'json';
|
|
|
|
httpreq.send(JSON.stringify({
|
|
|
|
account_ids: [user]
|
|
|
|
}));
|
|
|
|
httpreq.onreadystatechange = function() {
|
|
|
|
if (httpreq.readyState == 4) {
|
|
|
|
var json = httpreq.response;
|
|
|
|
hisList(user,acct_id)
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|
|
|
|
function listRemove(id,user,acct_id){
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-07-07 03:51:48 +10:00
|
|
|
var at = localStorage.getItem("acct_"+ acct_id + "_at");
|
2018-04-01 07:00:27 +10:00
|
|
|
var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts"
|
|
|
|
console.log(start)
|
2018-04-17 03:10:35 +10:00
|
|
|
var httpreq = new XMLHttpRequest();
|
|
|
|
httpreq.open('DELETE', start, true);
|
|
|
|
httpreq.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
|
|
|
|
httpreq.responseType = 'json';
|
|
|
|
httpreq.send(JSON.stringify({
|
|
|
|
account_ids: [user]
|
|
|
|
}));
|
|
|
|
httpreq.onreadystatechange = function() {
|
|
|
|
if (httpreq.readyState == 4) {
|
|
|
|
var json = httpreq.response;
|
|
|
|
hisList(user,acct_id)
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 07:00:27 +10:00
|
|
|
}
|