site-libsoc/Server/public/js/components/trade-unions-add-component.js

2 lines
12 KiB
JavaScript

import{S as t,i as n,a as e,b as i,u as o,s as r,e as l,n as a,d as s,c as u,g as c,o as m,f as p,h as d,j as f,k as b,l as h,m as g,r as w,x as v,t as y}from"./index-0d9f0c09.js";import{w as k}from"./index-1c123138.js";import{getData as x,loadLocaleContent as j,sendData as C}from"../../../../../../../../../js/libraries/serverTools.js";import{addMarkersEntries as T,translate as $}from"../../../../../../../../../js/libraries/mapTools.js";import{validatePosNumber as S}from"../../../../../../../../../js/libraries/miscTools.js";import"../../../../../../../../../js/components/map-component.js";function z(t){let n,e,o,l,a,u,c,m,p,v,y,k,x,j,L,C,T,$,S,z,A=t[7];function H(t,n){return t[14]?t[14]&&!t[8]?M:N:O}let U=H(t),E=U(t),I=G(t),R=!(t[14]&&t[8])&&J(t);return{c(){n=d("div"),e=d("button"),o=f(),l=d("div"),E.c(),a=f(),u=d("div"),c=d("label"),c.textContent="Location:",m=f(),p=d("div"),v=d("input"),y=f(),k=d("div"),x=f(),I.c(),j=f(),L=d("button"),L.textContent="Submit",C=f(),T=d("p"),$=f(),R&&R.c(),b(e,"class","close-button"),b(c,"for","address-input"),b(v,"id","address-input"),b(v,"type","text"),v.readOnly=!0,b(k,"class","ghost-input"),b(p,"class","input-wrapper"),b(u,"id","address-input-wrapper"),b(u,"class","input-label-wrapper"),b(L,"id","submit-button"),b(T,"id","confirmation-msg"),b(l,"id","text-container"),b(n,"id","container")},m(r,s){i(r,n,s),h(n,e),h(n,o),h(n,l),E.m(l,null),h(l,a),h(l,u),h(u,c),h(u,m),h(u,p),h(p,v),t[33](v),h(p,y),h(p,k),h(l,x),I.m(l,null),h(l,j),h(l,L),h(l,C),h(l,T),t[39](T),h(l,$),R&&R.m(l,null),S||(z=[g(e,"click",t[13]),g(v,"input",t[34]),g(L,"click",t[17])],S=!0)},p(t,n){U===(U=H(t))&&E?E.p(t,n):(E.d(1),E=U(t),E&&(E.c(),E.m(l,a))),128&n[0]&&r(A,A=t[7])?(I.d(1),I=G(t),I.c(),I.m(l,j)):I.p(t,n),t[14]&&t[8]?R&&(R.d(1),R=null):R?R.p(t,n):(R=J(t),R.c(),R.m(l,null))},d(e){e&&s(n),E.d(),t[33](null),I.d(e),t[39](null),R&&R.d(),S=!1,w(z)}}}function N(t){let n,e,o,r;return{c(){n=d("div"),e=d("button"),e.textContent="Leave",b(n,"id","button-line")},m(l,a){i(l,n,a),h(n,e),t[30](e),t[32](n),o||(r=g(e,"click",t[31]),o=!0)},p:a,d(e){e&&s(n),t[30](null),t[32](null),o=!1,r()}}}function M(t){let n,e,o,r,l,a,u,c;return{c(){n=d("div"),e=d("button"),o=y("Move"),l=f(),a=d("button"),a.textContent="Leave",b(e,"style",r="display: "+(t[8]?"none":"initial")),b(n,"id","button-line")},m(r,s){i(r,n,s),h(n,e),h(e,o),t[25](e),h(n,l),h(n,a),t[27](a),t[29](n),u||(c=[g(e,"click",t[26]),g(a,"click",t[28])],u=!0)},p(t,n){256&n[0]&&r!==(r="display: "+(t[8]?"none":"initial"))&&b(e,"style",r)},d(e){e&&s(n),t[25](null),t[27](null),t[29](null),u=!1,w(c)}}}function O(t){let n,e,o,r,l,u;return{c(){n=d("div"),e=d("button"),e.textContent="Create",o=f(),r=d("button"),r.textContent="Join",b(n,"id","button-line")},m(a,s){i(a,n,s),h(n,e),t[20](e),h(n,o),h(n,r),t[22](r),t[24](n),l||(u=[g(e,"click",t[21]),g(r,"click",t[23])],l=!0)},p:a,d(e){e&&s(n),t[20](null),t[22](null),t[24](null),l=!1,w(u)}}}function A(t){let n,e,o,r,l,u,c;return{c(){n=d("div"),e=d("label"),e.textContent="Members:",o=f(),r=d("div"),l=d("input"),b(e,"for","members-input"),b(l,"id","members-input"),b(l,"type","number"),l.value=1,b(r,"class","input-wrapper"),b(n,"id","members-input-wrapper"),b(n,"class","input-label-wrapper")},m(a,s){i(a,n,s),h(n,e),h(n,o),h(n,r),h(r,l),t[35](l),u||(c=g(l,"input",t[36]),u=!0)},p:a,d(e){e&&s(n),t[35](null),u=!1,c()}}}function H(t){let n,e,o,r,l,u,c,m,p;return{c(){n=d("div"),e=d("label"),e.textContent="Contact:",o=f(),r=d("div"),l=d("input"),u=f(),c=d("div"),b(e,"for","contact-input"),b(l,"id","contact-input"),b(l,"type","text"),b(c,"class","ghost-input"),b(r,"class","input-wrapper"),b(n,"class","input-label-wrapper")},m(a,s){i(a,n,s),h(n,e),h(n,o),h(n,r),h(r,l),t[37](l),h(r,u),h(r,c),m||(p=g(l,"input",t[38]),m=!0)},p:a,d(e){e&&s(n),t[37](null),m=!1,p()}}}function G(t){let n,e,o=0==t[7]&&A(t),r=(0==t[7]||1==t[7])&&H(t);return{c(){o&&o.c(),n=f(),r&&r.c(),e=l()},m(t,l){o&&o.m(t,l),i(t,n,l),r&&r.m(t,l),i(t,e,l)},p(t,i){0==t[7]?o?o.p(t,i):(o=A(t),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null),0==t[7]||1==t[7]?r?r.p(t,i):(r=H(t),r.c(),r.m(e.parentNode,e)):r&&(r.d(1),r=null)},d(t){o&&o.d(t),t&&s(n),r&&r.d(t),t&&s(e)}}}function J(t){let n,e;return{c(){n=d("map-component"),v(n,"id","map"),v(n,"callback",e=t[40])},m(t,e){i(t,n,e)},p(t,i){1024&i[0]&&e!==(e=t[40])&&v(n,"callback",e)},d(t){t&&s(n)}}}function U(t){let n,e=3==t[9]&&z(t);return{c(){e&&e.c(),n=l()},m(t,o){e&&e.m(t,o),i(t,n,o)},p(t,i){3==t[9]?e?e.p(t,i):(e=z(t),e.c(),e.m(n.parentNode,n)):e&&(e.d(1),e=null)},d(t){e&&e.d(t),t&&s(n)}}}function E(t){let n,e=t[9],o=U(t);return{c(){o.c(),n=l(),this.c=a},m(t,e){o.m(t,e),i(t,n,e)},p(t,i){512&i[0]&&r(e,e=t[9])?(o.d(1),o=U(t),o.c(),o.m(n.parentNode,n)):o.p(t,i)},i:a,o:a,d(t){t&&s(n),o.d(t)}}}function I(t,n,e){let i=L.latLng(n,e);t.setLatLng(i)}function R(t){t.nextElementSibling.innerHTML=t.value}function _(t,n,e){let i,o,{map:r=null}=n,l=k(0);u(t,l,(t=>e(9,i=t)));let a,s,d,f,b,h=k({});u(t,h,(t=>e(10,o=t)));let g,w,v,y;x("/assets/trade-unions.json",(t=>{a=JSON.parse(t),s={};for(let t of a){let n=t.country;null==t.contact&&(t.contact="https://discord.gg/Qk8KUk787z"),n in s?s[n].push(t):s[n]=[t]}l.update((t=>t+1))}));let z=["","",""],N={},M=function(t,n){let e=new L.Icon({iconUrl:"/img/common/markers/marker-black.png",shadowUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",iconSize:[25,41],iconAnchor:[12,41],popupAnchor:[1,-34],shadowSize:[41,41]});return L.marker([t,n],{icon:e})}(0,0);M.setOpacity(0);let O,A=[],H=c("profile-component"),G=H.closeGroupsAdd,J=H.maps,U=H.onLoadedGroups,E=H.userGroups,_=H.user,D=0!=E.length,K=D?2:0;D&&(O=null!=E[0].status,O&&(K=3));let Q=j(h,"trade-unions-component",l);function Y(t,n){x(`https://nominatim.openstreetmap.org/reverse?lat=${t}&lon=${n}&format=jsonv2`,(t=>{let n=(t=JSON.parse(t)).address,i=n.city||n.town||n.village||n.hamlet,o=n.state,r=n.country;null!=o?r+=", "+o:o="",null!=i?r+=", "+i:i="",e(3,w.value=r,w),R(w)}))}function q(t,n){x(`https://nominatim.openstreetmap.org/reverse?lat=${t}&lon=${n}&format=jsonv2&accept-language=en`,(t=>{let n=(t=JSON.parse(t)).address;if(null!=n){let t=n.city||n.town||n.village||n.hamlet,e=n.state,i=n.country;null!=e||(e=""),null!=t||(t=""),z=[i,e,t]}}))}function B(t,n,e){let i,o="<b>"+n.TradeUnion+"</b><br>";for(let r of["location","members","contact"]){let l=n[r]+": ";if("contact"==r)o+=l+"<a href='"+t.contact+"' target='_blank' rel=noreferrer>"+t.contact+"</a>";else if("location"==r){let r,a=[t.country,t.state,t.town].filter((t=>null!=t&&null!=t));r="en"==e?a.map((t=>t)).join(", "):a.map((t=>$(n,t))).join(", "),o+=l+r+"<br>",i=[t.latitude,t.longitude]}else o+=l+t[r]+"<br>"}return{text:o,coordinates:i}}function F(t,n,i){e(19,r=t([22,0],2)),J.groupsAdd=r,T(a,s,r,n,i,B,"green",{enableCountryGrouping:!1,pinCallback:V}),M.addTo(r),r.on("click",(function(t){if(0==K){let n=t.latlng.lat,e=t.latlng.lng;N.latitude=n,N.longitude=e,N.id=null,I(M,n,e),M.setOpacity(1),Y(n,e),q(n,e)}}))}function P(t){!1!==t?(0!=K||_.verified?e(2,g.innerHTML="Success!",g):e(2,g.innerHTML="You have been added to our database! Now go to our Discord to verify yourself.",g),e(2,g.style.color="green",g),0!=K&&1!=K||(E[0]={}),E[0].country=""==z[0]?null:z[0],E[0].state=""==z[1]?null:z[1],E[0].town=""==z[2]?null:z[2],E[0].members=N.members,U()):(e(2,g.innerHTML="Something went wrong.",g),e(2,g.style.color="red",g))}function V(t,n){if(1==K){let e=n.latlng.lat,i=n.latlng.lng;N.latitude=e,N.longitude=i,N.id=t.id,N.members=t.members,I(M,e,i),M.setOpacity(1),Y(e,i),q(e,i)}}function W(t){for(let t of A)null!=t&&(t.style.background="rgba(197, 43, 40, 0.319)",t.style.color="black");e(6,A[t].style.background="rgb(197, 43, 40)",A),e(6,A[t].style.color="white",A),e(7,K=t)}function X(){if(3==i)W(K),2!=K&&3!=K||e(3,w.value=function(t){if(null!=t)return[t.country,t.state,t.town].filter((t=>null!=t)).map((t=>"en"==Q?t:$(o,t))).join(", ");return"Create or join trade-union"}(E[0]),w);else{setTimeout((()=>X()),100)}}j(h,"countries",l),m((()=>{X()}));return t.$$set=t=>{"map"in t&&e(19,r=t.map)},[f,b,g,w,v,y,A,K,O,i,o,l,h,G,D,Q,F,function(){if(""!=z[0]||3==K){let t,n;0==K?(t=y.value,n=v.value):1==K?n=v.value:2==K||3==K?(t="",n=""):3==K&&(t="",n="",z=[null,null,null],N.latitude=null,N.longitude=null),d={country:z[0],state:z[1],town:z[2],latitude:N.latitude,longitude:N.longitude,contact:""==n?null:n,members:""==t?null:parseInt(t),group_id:N.id,mode:K},""==d.state&&(d.state=null),""==d.town&&(d.town=null),C("/"+Q+"/trade-unions-add-post/",d,P)}},W,r,function(t){p[t?"unshift":"push"]((()=>{A[0]=t,e(6,A)}))},()=>W(0),function(t){p[t?"unshift":"push"]((()=>{A[1]=t,e(6,A)}))},()=>W(1),function(t){p[t?"unshift":"push"]((()=>{b=t,e(1,b)}))},function(t){p[t?"unshift":"push"]((()=>{A[2]=t,e(6,A)}))},()=>W(2),function(t){p[t?"unshift":"push"]((()=>{A[3]=t,e(6,A)}))},()=>W(3),function(t){p[t?"unshift":"push"]((()=>{f=t,e(0,f)}))},function(t){p[t?"unshift":"push"]((()=>{A[3]=t,e(6,A)}))},()=>W(3),function(t){p[t?"unshift":"push"]((()=>{f=t,e(0,f)}))},function(t){p[t?"unshift":"push"]((()=>{w=t,e(3,w)}))},()=>R(w),function(t){p[t?"unshift":"push"]((()=>{y=t,e(5,y)}))},t=>S(t,y,1e4),function(t){p[t?"unshift":"push"]((()=>{v=t,e(4,v)}))},()=>R(v),function(t){p[t?"unshift":"push"]((()=>{g=t,e(2,g)}))},t=>F(t,o,Q)]}class D extends t{constructor(t){super(),this.shadowRoot.innerHTML="<style>@import '/css/common.css';#button-line{position:relative;width:fit-content;margin:auto;margin-top:1.5rem}#button-line button{font-family:var(--sans-serif,sans-serif);font-size:1.15rem;padding:1rem 0;width:7rem}#button-line :first-child{border-top-left-radius:1rem;border-bottom-left-radius:1rem;margin-right:0.1rem}#button-line :last-child{margin-left:0.1rem;border-top-right-radius:1rem;border-bottom-right-radius:1rem}.close-button{position:absolute;top:2rem;right:0rem;width:2rem;height:2rem;border:none;cursor:pointer;z-index:2}.close-button:hover{opacity:0.7}.close-button::before,.close-button::after{content:\"\";position:absolute;top:50%;left:50%;width:0.2rem;height:2rem;background-color:#000;border-radius:1rem}.close-button::before{transform:translate(-50%, -50%) rotate(45deg)}.close-button::after{transform:translate(-50%, -50%) rotate(-45deg)}#confirmation-msg{margin-top:0.5rem;margin-bottom:2rem}label{display:inline-block;font-family:var(--serif,serif);font-size:1.15rem;line-height:160%;color:#222222;width:6rem}input,.ghost-input{font-size:1.15rem;font-family:var(--serif,serif)}input{height:2.5rem;display:inline-block;position:relative}#address-input,#contact-input{width:100%}#address-input-wrapper{margin-top:2rem;margin-bottom:1rem}#members-input-wrapper{margin-bottom:1rem}#members-input{width:5rem}.ghost-input{display:block;visibility:hidden;height:0;padding-left:0.5rem;padding-right:0.5rem}.input-wrapper{display:inline-block;max-width:calc(100% - 5.5rem);min-width:min(20rem, calc(100% - 5.5rem));height:2.5rem}.input-label-wrapper{display:flex;justify-content:start}.input-label-wrapper label{position:relative;top:0.3rem}#submit-button{display:block;margin:auto;margin-top:2rem;padding:1rem 2rem;font-size:1.4rem;font-family:var(--sans-serif,sans-serif);border:0rem solid black;border-radius:0.5rem;background:#cb1816;color:white}#map{--height:30rem;--width:100%;--margin-top:2rem;--margin-bottom:0.5rem}#text-container{position:relative;max-width:calc(100vw - 4rem);margin:auto}#container{margin:auto;max-width:800px;margin-top:1rem;margin-bottom:4rem}#container p{text-align:justify}</style>",n(this,{target:this.shadowRoot,props:e(this.attributes),customElement:!0},_,E,r,{map:19},null,[-1,-1]),t&&(t.target&&i(t.target,this,t.anchor),t.props&&(this.$set(t.props),o()))}static get observedAttributes(){return["map"]}get map(){return this.$$.ctx[19]}set map(t){this.$$set({map:t}),o()}}customElements.define("trade-unions-add-component",D);export{D as default};