diff --git a/static/js/user_profile_2.js b/static/js/user_profile_2.js index 540f940..8e03dc7 100644 --- a/static/js/user_profile_2.js +++ b/static/js/user_profile_2.js @@ -165,19 +165,31 @@ function getBase64(file,el) { }) } -async function fileListToBase64(fileList) { +async function fileListToBase64(fileList=null,file=null) { // create function which return resolved promise // with data:base64 string // here will be array of promisified functions const promises = [] - // loop through fileList with for loop - for (let i = 0; i < fileList.length; i++) { - let el = fileList[i] - promises.push(getBase64(fileList[i],el)) + const promise = {} + let return_ = null + if (fileList) { + return_ = promises + // loop through fileList with for loop + for (let i = 0; i < fileList.length; i++) { + let el = fileList[i] + promises.push(getBase64(fileList[i], el)) + } + return await Promise.all(return_) + } else if (file){ + const promise = {} + return_ = promise + promise[file.name] = getBase64(file, file) + return await return_[file.name] } - // array with base64 strings - return await Promise.all(promises) + + // array with base64 strings + // return await Promise.all(return_) } async function attachFilemeassge (el,id_ticket=null,sender=null,receiver=null,change_avatar=null){ @@ -191,7 +203,8 @@ async function attachFilemeassge (el,id_ticket=null,sender=null,receiver=null,ch } } else { if (el.files.length > 0) { - const files_for_data = await fileListToBase64(fileList) + let file = fileList[0] + const files_for_data = await fileListToBase64(null,file) let data = files_for_data return data } @@ -230,6 +243,38 @@ async function attachFilemeassge (el,id_ticket=null,sender=null,receiver=null,ch } +function change_profile_confirm (el){ + let form = el.form + for (let i = 0;i < form.length;i++){ + + } + + + $.ajax({ + headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, + url: '/user_account/change_avatar_confirm/', + type: "POST", + // async: true, + cache: false, + processData: false, + contentType: false, + // enctype: 'json', + data: JSON.stringify(data), + success: function(data){ + middleWareJS() + + document.querySelector(".avatar_user_profile").src = data.url; + + }, + error: function (data){ + + document.querySelector(".avatar_user_profile").innerHTML = data.responseJSON.html; + + } + }); +} + + async function upload_photo_f_profile (el,files) { // if (!files){