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