thedesk/app/js/userdata/prof-edit.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//プロフ編集
//文字系
function profedit() {
var acct_id = $('#his-data').attr("use-acct");
todo("Updating...");
var domain = localStorage.getItem("domain_" + acct_id);
2019-05-19 17:39:30 +10:00
var at = localStorage.getItem("acct_" + acct_id + "_at");
2018-01-28 23:22:43 +11:00
var start = "https://" + domain + "/api/v1/accounts/update_credentials";
var name = $("#his-name-val").val();
var des = $("#his-des-val").val();
2018-04-17 03:10:35 +10:00
var httpreq = new XMLHttpRequest();
httpreq.open('PATCH', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
2019-03-08 05:19:26 +11:00
httpreq.responseType = "json";
2018-04-17 03:10:35 +10:00
httpreq.send(JSON.stringify({
display_name: name,
2018-06-12 01:44:28 +10:00
note: des,
2018-04-17 03:10:35 +10:00
}));
2019-05-19 17:39:30 +10:00
httpreq.onreadystatechange = function () {
2019-03-08 05:19:26 +11:00
if (httpreq.readyState === 4) {
2018-04-17 03:10:35 +10:00
$('#his-data').modal('close');
todc();
}
}
2018-01-28 23:22:43 +11:00
}
//画像系
function imgChange(imgfile, target) {
var acct_id = $('#his-data').attr("use-acct");
todo("アップロードしています")
if (!imgfile.files.length) {
2019-05-19 16:17:05 +10:00
console.warn("No Image to upload");
2018-01-28 23:22:43 +11:00
return;
}
var file = imgfile.files[0];
var fr = new FileReader();
2019-05-19 17:39:30 +10:00
fr.onload = function (evt) {
2018-01-28 23:22:43 +11:00
var b64 = this.result;
var blob = toBlob(b64, 'image/png');
var fd = new FormData();
fd.append(target, blob);
var domain = localStorage.getItem("domain_" + acct_id);
2019-05-19 17:39:30 +10:00
var at = localStorage.getItem("acct_" + acct_id + "_at");
2018-01-28 23:22:43 +11:00
var start = "https://" + domain + "/api/v1/accounts/update_credentials";
2018-04-17 03:10:35 +10:00
var httpreq = new XMLHttpRequest();
httpreq.open('PATCH', start, true);
httpreq.upload.addEventListener("progress", progshow, false);
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
2019-03-08 05:19:26 +11:00
httpreq.responseType = "json";
2018-04-17 03:10:35 +10:00
httpreq.send(fd);
2019-05-19 17:39:30 +10:00
httpreq.onreadystatechange = function () {
2019-03-08 05:19:26 +11:00
if (httpreq.readyState === 4) {
2018-04-17 03:10:35 +10:00
var json = httpreq.response;
2019-10-31 02:30:26 +11:00
if(this.status!==200){ setLog(start, this.status, this.response); }
2018-04-17 03:10:35 +10:00
$('#his-data').modal('close');
todc();
localStorage.removeItem("image");
}
}
2018-01-28 23:22:43 +11:00
}
$("#prof-change").html($("#prof-change").html());
$("#header-change").html($("#header-change").html());
fr.readAsDataURL(file);
}