* Отправляет запрос на редактирование профиля
1314 * @param {Object} formData 1315 * @param {HTMLElement} form 1316 * @param {Function} callback - функция обратного вызова 1318function tmst_profile__sendEditProfileRequest(formData, form, callback) { 1319 var submitButton = form.querySelector('button[type="submit"]'); 1320 tma__request('/api/editprofile/', JSON.stringify(formData), submitButton, callback); 1324 * Обрабатывает ответ сервера 1325 * @param {Object} response 1326 * @param {HTMLFormElement} form 1327 * @param {Object} options 1329function tmst_profile__handleResponse(response, form, options) { 1330 if (response.status === 'ok' && typeof response.data === 'object') { 1331 tmst_profile__handleSuccessResponse(response, form, options); 1333 tmst_profile__handleErrorResponse(response, form); 1338 * Обрабатывает успешный ответ 1339 * @param {Object} response 1340 * @param {HTMLFormElement} form 1341 * @param {Object} options 1343function tmst_profile__handleSuccessResponse(response, form, options) { 1344 var updatedOptions = options || {}; 1345 var objProfile = tma__getProfileObjFromLS(); 1346 var profile = response.data; 1348 function cleanNumber(phoneNumber) { 1349 return phoneNumber ? phoneNumber.replace(/[^\d]/g, '') : ''; 1352 /** @type {HTMLInputElement} */ 1353 var selectLang = form.querySelector('.tlk-profile__change-lang'); 1354 var isLangChanged = selectLang && selectLang.value !== window.tildaMembers.userLang; 1356 var allowEditProfile = typeof objProfile.allowEditProfile !== 'undefined' ? objProfile.allowEditProfile : true; 1358 /** @type {HTMLInputElement} */ 1359 var login = form.querySelector('input[name="login"]'); 1360 var isLoginChangedAndNeedToBeDisabled = 1361 objProfile.login !== login.value && getIsLoginFieldDisabled({ login: login.value, allowEditProfile }); 1363 /** @type {HTMLInputElement} */ 1364 var phone = form.querySelector('input[name="phone"]'); 1365 var isPhoneChangedAndNeedToBeDisabled = 1366 cleanNumber(objProfile.phone) !== cleanNumber(phone.value) && 1367 getIsPhoneFieldDisabled({ phone: phone.value, allowEditProfile }); 1369 updatedOptions.needReload = isLangChanged || isLoginChangedAndNeedToBeDisabled || isPhoneChangedAndNeedToBeDisabled; 1371 Object.assign(objProfile, { 1373 login: profile.login, 1374 emailneedcaptcha: profile.emailneedcaptcha, 1375 phoneneedcaptcha: profile.phoneneedcaptcha, 1376 phone: profile.phone || objProfile.phone, 1377 memberlogo: profile.memberlogo || '', 1378 memberlogo_uuid: profile.memberlogo_uuid || '', 1381 if (profile.phone && typeof tma__validatePhone === 'function') { 1382 tma__validatePhone(profile.phone.toString()).then(function (isValid) { 1383 objProfile.isPhoneValid = isValid; 1384 tmst_profile__finalizeProfileUpdate(objProfile, updatedOptions); 1387 tmst_profile__finalizeProfileUpdate(objProfile, updatedOptions); 1392 * Завершает обновление профиля 1393 * @param {Object} objProfile 1394 * @param {Object} options 1395 * @param {Function} [options.onSuccess] 1396 * @param {boolean} [options.needReload] 1398function tmst_profile__finalizeProfileUpdate(objProfile, options) { 1399 setTimeout(function () { 1400 tmst_profile__updateSaveButtonState('success');