(function(){ 'use strict'; if(window.fiEnsureDancerProfile)return; var queue=Promise.resolve(),settings; function escape(value){var el=document.createElement('span');el.textContent=value==null?'':String(value);return el.innerHTML.replace(/"/g,'"');} function config(){if(!settings)settings=fetch('/services/entry-profile.php',{credentials:'same-origin',cache:'no-store'}).then(json).catch(function(e){settings=null;throw e;});return settings;} function json(response){return response.json().then(function(data){if(!response.ok||data.error)throw new Error(data.error||'Не удалось проверить данные ученика');return data;});} function post(config,payload){return fetch('/services/entry-profile.php',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(Object.assign({csrf:config.csrf},payload))}).then(json);} function input(label,name,value,type){return '';} function complete(config,ids,event,profiles){return new Promise(function(resolve,reject){ var dialog=document.createElement('dialog');dialog.className='fi-entry-profile'; var style=document.getElementById('fi-entry-profile-style');if(!style){style=document.createElement('link');style.id='fi-entry-profile-style';style.rel='stylesheet';style.href='/services/entry-profile.css?v=1.540';document.head.appendChild(style);} dialog.innerHTML='
'; document.body.appendChild(dialog);var form=dialog.querySelector('form'),saving=false,finished=false; function cancel(){if(saving||finished)return;finished=true;dialog.close();dialog.remove();reject(new Error('Регистрация отменена. Данные ученика можно заполнить позднее.'));} dialog.querySelectorAll('[data-cancel]').forEach(function(b){b.onclick=cancel;});dialog.addEventListener('cancel',function(e){e.preventDefault();cancel();}); dialog.querySelectorAll('fieldset').forEach(function(fieldset){ var country=fieldset.querySelector('[name=country_id]'),city=fieldset.querySelector('[data-city]'),hidden=fieldset.querySelector('[name=city_id]'),list=fieldset.querySelector('datalist'),revision=0,timer; country.onchange=function(){revision++;clearTimeout(timer);city.value='';hidden.value='';list.replaceChildren();city.setCustomValidity('');}; city.oninput=function(){ clearTimeout(timer);var version=++revision; var match=Array.from(list.options).find(function(o){return o.value===city.value;});hidden.value=match?match.dataset.id:'';city.setCustomValidity(''); if(match||city.value.trim().length<2||!country.value)return; timer=setTimeout(function(){fetch('/services/entry-profile.php?country='+encodeURIComponent(country.value)+'&q='+encodeURIComponent(city.value),{credentials:'same-origin',cache:'no-store'}).then(json).then(function(data){if(version!==revision||!dialog.isConnected)return;list.innerHTML=data.cities.map(function(c){return '';}).join('');var selected=Array.from(list.options).find(function(o){return o.value===city.value;});if(selected)hidden.value=selected.dataset.id;}).catch(function(e){if(version===revision){var box=dialog.querySelector('[data-error]');box.textContent=e.message;box.hidden=false;}});},200); }; }); form.onsubmit=function(e){ e.preventDefault();if(saving)return; var valid=true;dialog.querySelectorAll('fieldset').forEach(function(f){if(!f.querySelector('[name=city_id]').value){f.querySelector('[data-city]').setCustomValidity('Выберите город из предложенного списка');valid=false;}}); if(!form.reportValidity()||!valid)return; var values=Array.from(dialog.querySelectorAll('fieldset')).map(function(f){var v={id:Number(f.dataset.person)};f.querySelectorAll('[name]').forEach(function(n){v[n.name]=n.value;});return v;}); saving=true;dialog.querySelectorAll('button').forEach(function(b){b.disabled=true;}); post(config,{action:'save',event:event,ids:ids,profiles:values}).then(function(data){if(data.profiles.length)throw new Error('Заполните все недостающие данные.');finished=true;dialog.close();dialog.remove();resolve();}) .catch(function(error){var box=dialog.querySelector('[data-error]');box.hidden=false;box.textContent=error.message;}) .finally(function(){saving=false;dialog.querySelectorAll('button').forEach(function(b){b.disabled=false;});}); }; dialog.showModal(); });} window.fiEnsureDancerProfile=function(ids,event){ ids=Array.from(new Set(ids.map(Number)));var current=queue.catch(function(){}).then(function(){return config().then(async function(c){ var selected=Number(event)||c.event; for(var start=0;start