PageSourceSearch

https://comunaighiu.ro/_nuxt/BLu675ku.js

js comunaighiu.ro collected 2026-09-25 12:30:37 UTC 5,315 bytes, 1 lines download raw bytes

1import{bE as g,bf as _,b2 as o,I as y,O as c,G as i,$ as v,br as r,F as m,bd as k,aQ as V,aN as x,M as h,Y as w,bW as C,_ as S,ba as E}from"./yzds40HC.js";import{E as I}from"./CtbuIuJX.js";import{E as P}from"./BxkYZhzZ.js";import{u as K}from"./P54dWT6D.js";import{a as N}from"./CqawAVUb.js";import"./BgqE2USM.js";import"./C8Dppsyt.js";import"./CbO2Rjsj.js";import"./DhlRdtTC.js";import"./Dz0mkqCC.js";import"./DkpuU7u1.js";import"./DtS_aP2E.js";const O={name:"PollWidget",components:{EditAssetButton:I,EmptyWidgetPlaceholder:P},props:{data:{type:Object,required:!1,default:()=>({})},pollData:{type:Object,required:!1,default:null},pollableType:{type:String,required:!1,default:"widget"},pollableId:{type:[String,Number],required:!1,default:null}},setup(){const e=E(null),{variant:l}=K(e,{sidebar:320,page:640});return{rootEl:e,variant:l}},data(){return{selectedUid:null,expanded:!1}},computed:{widget(){return this.data||{}},poll(){return this.pollData||this.widget.poll||null},hasPoll(){return!!(this.poll&&this.poll.question&&Array.isArray(this.poll.answers)&&this.poll.answers.length>0)},allAnswers(){return Array.isArray(this.poll?.answers)?this.poll.answers:[]},visibleAnswers(){return this.variant==="sidebar"&&!this.expanded&&this.allAnswers.length>4?this.allAnswers.slice(0,4):this.allAnswers},hiddenCount(){return this.variant!=="sidebar"||this.expanded?0:Math.max(0,this.allAnswers.length-4)},storageKey(){return`poll:${this.pollableType}:${this.resolvedPollableId||this.poll?.id||"default"}`},resolvedPollableId(){return this.pollableId!==null&&this.pollableId!==void 0&&this.pollableId!==""?this.pollableId:this.widget?.id||null},hasVoted(){return this.selectedUid!==null},totalVotes(){return(this.allAnswers||[]).reduce((e,l)=>e+(l.votes||0),0)}},mounted(){if(typeof window<"u"){const e=window.localStorage?.getItem(this.storageKey);e&&(this.selectedUid=e)}},methods:{percent(e){const l=this.totalVotes;return l?Math.round((e.votes||0)/l*100):0},wasSelected(e){const l=this.allAnswers.indexOf(e);return this.answerKey(e,l)===String(this.selectedUid)},answerKey(e,l){return e?.uid!==void 0&&e?.uid!==null&&e.uid!==""?String(e.uid):e?.value!==void 0&&e?.value!==null?`v:${e.value}`:`i:${l}`},async onOptionClick(e){if(this.hasVoted)return;const l=this.allAnswers.indexOf(e),n=this.answerKey(e,l),p=typeof e.votes=="number"?e.votes:0;this.selectedUid=n,e.votes=p+1;try{window.localStorage?.setItem(this.storageKey,n)}catch{}const s=this.resolvedPollableId;if(s)try{const{$axios:t}=g(),{data:d}=await t.post(`/api/polls/${this.pollableType}/${s}/vote`,{answer_key:n}),a=d?.data?.poll;a&&Array.isArray(a.answers)&&this.syncPollAnswers(a.answers)}catch{e.votes=p,this.selectedUid=null;try{window.localStorage?.removeItem(this.storageKey)}catch{}{const{$errorAlert:d}=g();
1await d("Votul nu a putut fi salvat. Încearcă din nou.")}}},syncPollAnswers(e){this.allAnswers.forEach((l,n)=>{const p=this.answerKey(l,n),s=e.find((t,d)=>(t?.uid!==void 0&&t?.uid!==null&&t.uid!==""?String(t.uid):t?.value!==void 0&&t?.value!==null?`v:${t.value}`:`i:${d}`)===p);s&&s.votes!==void 0&&(l.votes=Number(s.votes)||0)})}}},q={key:1,ref:"rootEl",class:"poll-widget"},B={class:"poll-widget__header"},W={class:"poll-widget__title"},U={class:"poll-widget__body"},T={class:"poll-widget__question"},$={class:"poll-widget__options"},j=["onClick"],z={key:0,class:"poll-widget__bar"},M={class:"poll-widget__option-row"},D={class:"poll-widget__option-text"},F={key:0,class:"poll-widget__option-pct"},G={class:"poll-widget__footer"};function L(e,l,n,p,s,t){const d=_("EmptyWidgetPlaceholder"),a=_("v-icon"),f=_("EditAssetButton"),b=S;return t.hasPoll?(o(),c("div",q,[i("div",B,[v(a,{icon:"mdi-poll",size:"18",class:"poll-widget__header-icon"}),i("h4",W,r(e.$t("poll.title")||"Sondaj"),1)]),i("div",U,[i("div",T,r(t.poll.question),1),i("div",$,[(o(!0),c(m,null,k(t.visibleAnswers,(u,A)=>(o(),c("div",{key:`a-${u.uid||A}`,class:x(["poll-widget__option",{"poll-widget__option--voted":t.hasVoted,"poll-widget__option--selected":t.hasVoted&&t.wasSelected(u)}]),style:V(t.hasVoted?{"--pct":`${t.percent(u)}%`}:{}),onClick:Q=>t.onOptionClick(u)},[t.hasVoted?(o(),c("div",z)):h("",!0),i("div",M,[i("span",D,r(u.text),1),t.hasVoted?(o(),c("span",F,r(t.percent(u))+"%",1)):h("",!0)])],14,j))),128)),t.hiddenCount>0?(o(),c("button",{key:0,type:"button",class:"poll-widget__more",onClick:l[0]||(l[0]=u=>s.expanded=!s.expanded)},r(s.expanded?e.$t("category.see_less")||"Mai puține":`+${t.hiddenCount} ${e.$t("poll.more_options")||"opțiuni"}`),1)):h("",!0)]),i("div",G,[v(a,{icon:"mdi-account-multiple-outline",size:"13"}),w(" "+r(t.totalVotes)+" "+r(e.$t("poll.votes")||"voturi")+" ",1),t.hasVoted?(o(),c(m,{key:0},[l[1]||(l[1]=w(" · ",-1)),i("strong",null,r(e.$t("poll.you_voted")||"ai votat"),1)],64)):h("",!0)])]),v(b,null,{default:C(()=>[t.widget&&t.widget.id&&n.pollableType==="widget"?(o(),y(f,{key:0,link:`/widgets/edit/${t.widget.id}`},null,8,["link"])):h("",!0)]),_:1})],512)):(o(),y(d,{key:0,"widget-id":t.widget.id,icon:"mdi-poll",title:e.$t("poll.empty_title")||"Sondaj fără întrebare",description:e.$t("poll.empty_desc")||"Adaugă o întrebare și variante pentru ca acest widget să apară public."},null,8,["widget-id","title","description"]))}const de=N(O,[["render",L],["__scopeId","data-v-dd4bc70d"]]);export{de as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.