You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
17 KiB
3 lines
17 KiB
var L=Object.defineProperty;var z=(t,e,r)=>e in t?L(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e,r)=>z(t,typeof e!="symbol"?e+"":e,r);import{V as K,f as X,e as Z,b as _,C as ee,_ as te,g as j,h as m,i as g,j as i,l as b,t as v,m as y,s as H,o as T,p as f,w as ie,k as Q,F as re,x as h}from"./index-BLqts8WY.js";import{I as oe}from"./ImageMethodDialog-B6b8zZ7c.js";import{Q as se}from"./QuickNav-DgCyvgDx.js";import{T as ne}from"./TopMessage-BE0GBIgW.js";import{l as ae,e as le,h as W,ap as J,g as de,aq as pe,ar as he,as as ce,at as ue}from"./index-MyY_xqVN.js";import"./PhotoDialog-Dn3GjI9b.js";import"./index-CsfPLOYu.js";var ge=Object.defineProperty,me=Object.getOwnPropertyDescriptor,fe=(t,e,r,c)=>{for(var n=c>1?void 0:c?me(e,r):e,p=t.length-1,l;p>=0;p--)(l=t[p])&&(n=(c?l(e,r,n):l(n))||n);return c&&n&&ge(e,r,n),n};let I=class extends K{constructor(){super(...arguments);s(this,"$notify");s(this,"activeDid","");s(this,"apiServer","");s(this,"amountInput","0");s(this,"description","");s(this,"destinationPathAfter","");s(this,"fulfillsProjectId","");s(this,"fulfillsProjectName","a project");s(this,"givenToProject",!1);s(this,"givenToRecipient",!1);s(this,"giverDid","");s(this,"giverName","");s(this,"hideBackButton",!1);s(this,"imageUrl","");s(this,"isTrade",!1);s(this,"message","");s(this,"offerId","");s(this,"prevCredToEdit");s(this,"providerProjectId","");s(this,"providerProjectName","a project");s(this,"providedByProject",!1);s(this,"providedByGiver",!1);s(this,"recipientDid","");s(this,"recipientName","");s(this,"showGeneralAdvanced",!1);s(this,"unitCode","HUR");s(this,"libsUtil",ae)}async mounted(){var P,o,$,C,D,k,x,U,N,E,G,A,B,S,q,R,O,M,V,F;try{this.prevCredToEdit=this.$route.query.prevCredToEdit?JSON.parse(this.$route.query.prevCredToEdit):void 0}catch{this.$notify({group:"alert",type:"danger",title:"Retrieval Error",text:"The previous record isn't available for editing. If you submit, you'll create a new record."},6e3)}const e=($=(o=(P=this.prevCredToEdit)==null?void 0:P.claim)==null?void 0:o.object)==null?void 0:$.amountOfThisGood;this.amountInput=this.$route.query.amountInput||(e?String(e):"")||this.amountInput,this.description=this.$route.query.description||((D=(C=this.prevCredToEdit)==null?void 0:C.claim)==null?void 0:D.description)||this.description,this.destinationPathAfter=this.$route.query.destinationPathAfter,this.giverDid=this.$route.query.giverDid||((U=(x=(k=this.prevCredToEdit)==null?void 0:k.claim)==null?void 0:x.agent)==null?void 0:U.identifier)||this.giverDid,this.giverName=this.$route.query.giverName||"",this.hideBackButton=this.$route.query.hideBackButton==="true",this.message=this.$route.query.message||"";const r=(E=(N=this.prevCredToEdit)==null?void 0:N.claim)==null?void 0:E.fulfills,c=Array.isArray(r)?r:r?[r]:[],n=c.find(d=>d["@type"]==="Offer");this.offerId=this.$route.query.offerId||(n==null?void 0:n.identifier)||this.offerId;const p=c.find(d=>d["@type"]==="PlanAction");this.fulfillsProjectId=this.$route.query.fulfillsProjectId||(p==null?void 0:p.identifier)||this.fulfillsProjectId;const l=(A=(G=this.prevCredToEdit)==null?void 0:G.claim)==null?void 0:A.provider,a=(Array.isArray(l)?l:l?[l]:[]).find(d=>d["@type"]==="PlanAction");this.providerProjectId=this.$route.query.providerProjectId||(a==null?void 0:a.identifier)||this.providerProjectId,this.recipientDid=this.$route.query.recipientDid||((q=(S=(B=this.prevCredToEdit)==null?void 0:B.claim)==null?void 0:S.recipient)==null?void 0:q.identifier),this.recipientName=this.$route.query.recipientName||"",this.unitCode=this.$route.query.unitCode||((M=(O=(R=this.prevCredToEdit)==null?void 0:R.claim)==null?void 0:O.object)==null?void 0:M.unitCode)||this.unitCode,this.imageUrl=this.$route.query.imageUrl||((F=(V=this.prevCredToEdit)==null?void 0:V.claim)==null?void 0:F.image)||localStorage.getItem("imageUrl")||this.imageUrl,this.$route.query.shareTitle&&(this.description=this.$route.query.shareTitle+(this.description?`
|
|
`+this.description:"")),this.$route.query.shareText&&(this.description=(this.description?this.description+`
|
|
`:"")+this.$route.query.shareText),this.$route.query.shareUrl&&(this.imageUrl=this.$route.query.shareUrl);const w=await X();if(this.apiServer=w.apiServer||"",this.activeDid=w.activeDid||"",this.giverDid&&!this.giverName||this.recipientDid&&!this.recipientName){const d=await Z.contacts.toArray(),Y=await le();this.giverDid&&!this.giverName&&(this.giverName=W(this.giverDid,this.activeDid,Y,d)),this.recipientDid&&!this.recipientName&&(this.recipientName=W(this.recipientDid,this.activeDid,Y,d))}if(this.givenToProject=!!this.fulfillsProjectId,this.givenToRecipient=!this.givenToProject&&!!this.recipientDid,this.providedByProject=!!this.providerProjectId,this.providedByGiver=!this.providedByProject&&!!this.giverDid,this.showGeneralAdvanced=!!w.showGeneralAdvanced,this.fulfillsProjectId){const d=await J(this.fulfillsProjectId,this.axios,this.apiServer,this.activeDid);this.fulfillsProjectName=d!=null&&d.name?`the project "${d.name}"`:"a project"}if(this.providerProjectId){const d=await J(this.providerProjectId,this.axios,this.apiServer,this.activeDid);this.providerProjectName=d!=null&&d.name?`the project "${d.name}"`:"a project"}}changeUnitCode(){const e=Object.keys(this.libsUtil.UNIT_SHORT),r=e.indexOf(this.unitCode);this.unitCode=e[(r+1)%e.length]}increment(){this.amountInput=`${(parseFloat(this.amountInput)||0)+1}`}decrement(){this.amountInput=`${Math.max(0,(parseFloat(this.amountInput)||1)-1)}`}cancel(){this.deleteImage(),this.destinationPathAfter?this.$router.push({path:this.destinationPathAfter}):this.$router.back()}cancelBack(){this.deleteImage(),this.$router.back()}openImageDialog(){this.$refs.imageDialog.open(e=>{this.imageUrl=e},"GiveAction")}confirmDeleteImage(){this.$notify({group:"modal",type:"confirm",title:"Are you sure you want to delete the image?",text:"",onYes:this.deleteImage},-1)}async deleteImage(){if(this.imageUrl)try{const e=await de(this.activeDid),r=await this.axios.delete(_+"/image/"+encodeURIComponent(this.imageUrl),{headers:e});if(r.status!==204){console.error("Problem deleting image:",r),this.$notify({group:"alert",type:"danger",title:"Error",text:"There was a problem deleting the image."},5e3);return}localStorage.removeItem("imageUrl"),this.imageUrl=""}catch(e){console.error("Error deleting image:",e),e.response.status===404?(console.log("Weird: the image was already deleted.",e),localStorage.removeItem("imageUrl"),this.imageUrl=""):this.$notify({group:"alert",type:"danger",title:"Error",text:"There was an error deleting the image."},5e3)}}async confirm(){if(!this.activeDid){this.$notify({group:"alert",type:"danger",title:"Error",text:"You must select an identifier before you can record a give."},2e3);return}if(parseFloat(this.amountInput)<0){this.$notify({group:"alert",type:"danger",text:"You may not send a negative number.",title:""},2e3);return}if(!this.description&&!parseFloat(this.amountInput)){this.$notify({group:"alert",type:"danger",title:"Error",text:`You must enter a description or some number of ${this.libsUtil.UNIT_LONG[this.unitCode]}.`},2e3);return}this.$notify({group:"alert",type:"toast",text:"Recording the give...",title:""},1e3),await this.recordGive()}notifyUserOfGiver(){this.giverDid?this.$notify({group:"alert",type:"warning",title:"Unavailable",text:"You cannot assign both a giver and a project."},3e3):this.$notify({group:"alert",type:"warning",title:"Go To The Contacts Page",text:"To assign a giver, you must open this page from a contact."},3e3)}notifyUserOfRecipient(){this.recipientDid?this.$notify({group:"alert",type:"warning",title:"Unavailable",text:"You cannot assign both to a recipient and to a project."},3e3):this.$notify({group:"alert",type:"warning",title:"Go To The Contacts Page",text:"To assign to a recipient, you must open this page from a contact."},3e3)}notifyUserOfProvidingProject(){this.providerProjectId?this.$notify({group:"alert",type:"warning",title:"Unavailable",text:"You cannot select both a giving project and person."},3e3):this.$notify({group:"alert",type:"warning",title:"Go To The Project Page",text:"To select a project as a provider, you must open this page through a project."},3e3)}notifyUserFulfillsProject(){this.fulfillsProjectId?this.$notify({group:"alert",type:"warning",title:"Unavailable",text:"You cannot assign both to a project and to a recipient."},3e3):this.$notify({group:"alert",type:"warning",title:"Go To The Project Page",text:"To assign to a project, you must open this page through a project."},3e3)}async recordGive(){var e,r,c;try{const n=this.providedByGiver?this.giverDid:void 0,p=this.givenToRecipient?this.recipientDid:void 0,l=this.givenToProject?this.fulfillsProjectId:void 0;let u;if(this.prevCredToEdit?u=await pe(this.axios,this.apiServer,this.prevCredToEdit,this.activeDid,n,p,this.description,parseFloat(this.amountInput),this.unitCode,l,this.offerId,this.isTrade,this.imageUrl,this.providerProjectId):u=await he(this.axios,this.apiServer,this.activeDid,n,p,this.description,parseFloat(this.amountInput),this.unitCode,l,this.offerId,this.isTrade,this.imageUrl,this.providerProjectId),u.type==="error"||this.isGiveCreationError(u.response)){const a=this.getGiveCreationErrorMessage(u);console.error("Error with give creation result:",u),this.$notify({group:"alert",type:"danger",title:"Error",text:a||"There was an error creating the give."},-1)}else this.$notify({group:"alert",type:"success",title:"Success",text:`That ${this.isTrade?"trade":"gift"} was recorded.`},5e3),localStorage.removeItem("imageUrl"),this.destinationPathAfter?this.$router.push({path:this.destinationPathAfter}):this.$router.back()}catch(n){console.error("Error with give recordation caught:",n);const p=n.userMessage||((c=(r=(e=n.response)==null?void 0:e.data)==null?void 0:r.error)==null?void 0:c.message)||"There was an error recording the give.";this.$notify({group:"alert",type:"danger",title:"Error",text:p},-1)}}constructGiveParam(){var l,u;const e=this.providedByGiver?this.giverDid:void 0,r=this.givenToRecipient?this.recipientDid:void 0,c=this.givenToProject?this.fulfillsProjectId:void 0,n=ce((l=this.prevCredToEdit)==null?void 0:l.claim,e,r,this.description,parseFloat(this.amountInput),this.unitCode,c,this.offerId,this.isTrade,this.imageUrl,this.providerProjectId,(u=this.prevCredToEdit)==null?void 0:u.id);return JSON.stringify(n)}isGiveCreationError(e){var r;return e.status!==201||((r=e.data)==null?void 0:r.error)}getGiveCreationErrorMessage(e){var r,c,n,p,l;return((r=e.error)==null?void 0:r.userMessage)||((c=e.error)==null?void 0:c.error)||((l=(p=(n=e.response)==null?void 0:n.data)==null?void 0:p.error)==null?void 0:l.message)}explainData(){this.$notify({group:"alert",type:"success",title:"Data Sharing",text:ue},-1)}};I=fe([ee({components:{ImageMethodDialog:oe,QuickNav:se,TopMessage:ne}})],I);const ve={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},ye={key:0,class:"text-lg text-center font-light relative px-7"},be={class:"text-xl font-bold text-center mb-4"},we={class:"flex flex-row justify-center"},je={class:"flex justify-center mt-4","data-testId":"imagery"},Te={key:0,class:"flex justify-between"},Pe=["href"],Ie=["src"],$e={key:1},Ce={class:"mt-4 flex justify-between gap-2"},De={class:"flex-grow border border-slate-400 p-2 rounded-md"},ke={class:"flex"},xe={class:"text-sm mt-1"},Ue={class:"flex"},Ne={class:"text-sm mt-1"},Ee={class:"flex-shrink flex justify-center items-center"},Ge={class:"flex-grow border border-slate-400 p-2 rounded-md"},Ae={class:"flex"},Be={class:"text-sm mt-1"},Se={class:"flex"},qe={class:"text-sm mt-1"},Re={class:"mt-8 flex"},Oe={key:1,class:"mt-4 flex"},Me={class:"text-center mb-2 mt-6 italic"},Ve={class:"grid grid-cols-1 sm:grid-cols-2 gap-2"};function Fe(t,e,r,c,n,p){const l=j("QuickNav"),u=j("TopMessage"),a=j("fa"),w=j("ImageMethodDialog"),P=j("router-link");return h(),m(re,null,[g(l),g(u),i("section",ve,[t.hideBackButton?b("",!0):(h(),m("div",ye,[i("h1",{class:"text-lg text-center px-2 py-1 absolute -left-2 -top-1",onClick:e[0]||(e[0]=o=>t.cancelBack())},[g(a,{icon:"chevron-left",class:"fa-fw"})])])),e[22]||(e[22]=i("h1",{class:"text-4xl text-center font-light px-4 mb-4"},"What Was Given",-1)),i("h1",be,[i("span",null," From "+v(t.providedByProject?t.providerProjectName:t.providedByGiver?t.giverName:"someone not named"),1),e[18]||(e[18]=i("br",null,null,-1)),i("span",null," to "+v(t.givenToProject?t.fulfillsProjectName:t.givenToRecipient?t.recipientName:"someone not named"),1)]),y(i("textarea",{class:"block w-full rounded border border-slate-400 mb-2 px-3 py-2",placeholder:"What was received","onUpdate:modelValue":e[1]||(e[1]=o=>t.description=o)},null,512),[[H,t.description]]),i("div",we,[i("span",{class:"rounded-l border border-r-0 border-slate-400 bg-slate-200 text-center text-blue-500 px-2 py-2 w-20",onClick:e[2]||(e[2]=o=>t.changeUnitCode())},v(t.libsUtil.UNIT_SHORT[t.unitCode]||t.unitCode),1),i("div",{class:"border border-r-0 border-slate-400 bg-slate-200 px-4 py-2",onClick:e[3]||(e[3]=o=>t.amountInput==="0"?null:t.decrement())},[g(a,{icon:"chevron-left"})]),y(i("input",{type:"number",class:"border border-r-0 border-slate-400 px-2 py-2 text-center w-20","onUpdate:modelValue":e[4]||(e[4]=o=>t.amountInput=o)},null,512),[[H,t.amountInput]]),i("div",{class:"rounded-r border border-slate-400 bg-slate-200 px-4 py-2",onClick:e[5]||(e[5]=o=>t.increment())},[g(a,{icon:"chevron-right"})])]),i("div",je,[t.imageUrl?(h(),m("span",Te,[i("a",{href:t.imageUrl,target:"_blank"},[i("img",{src:t.imageUrl,class:"h-24 rounded-xl"},null,8,Ie)],8,Pe),g(a,{icon:"trash-can",onClick:t.confirmDeleteImage,class:"text-red-500 fa-fw ml-8 mt-10"},null,8,["onClick"])])):(h(),m("span",$e,[g(a,{icon:"camera",class:"bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-2 rounded-md",onClick:t.openImageDialog},null,8,["onClick"])]))]),g(w,{ref:"imageDialog"},null,512),i("div",Ce,[i("div",De,[i("div",ke,[t.giverDid&&!t.providedByProject?y((h(),m("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":e[6]||(e[6]=o=>t.providedByGiver=o)},null,512)),[[T,t.providedByGiver]]):(h(),f(a,{key:1,icon:"square",class:"mr-2 bg-white text-white h-5 w-5 px-0.5 py-0.5 rounded-sm"})),i("label",xe,v(t.giverDid?"This was provided by "+t.giverName+".":"No named individual gave."),1),!t.giverDid||t.providedByProject?(h(),f(a,{key:2,icon:"info-circle",class:"-mt-1 bg-white text-slate-500 h-5 w-5 px-0.5 py-0.5 rounded-sm",onClick:e[7]||(e[7]=o=>t.notifyUserOfGiver())})):b("",!0)]),i("div",Ue,[t.providerProjectId&&!t.providedByGiver?y((h(),m("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":e[8]||(e[8]=o=>t.providedByProject=o)},null,512)),[[T,t.providedByProject]]):(h(),f(a,{key:1,icon:"square",class:"mr-2 bg-white text-white h-5 w-5 px-0.5 py-0.5 rounded-sm"})),i("label",Ne,v(t.providerProjectId?"This was provided by "+t.providerProjectName+".":"This was not provided by a project."),1),!t.providerProjectId||t.providedByGiver?(h(),f(a,{key:2,icon:"info-circle",class:"-mt-1 bg-white text-slate-500 h-5 w-5 px-0.5 py-0.5 rounded-sm",onClick:e[9]||(e[9]=o=>t.notifyUserOfProvidingProject())})):b("",!0)])]),i("div",Ee,[g(a,{icon:"arrow-right",class:"fa-fw h-7"})]),i("div",Ge,[i("div",Ae,[t.recipientDid&&!t.givenToProject?y((h(),m("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":e[10]||(e[10]=o=>t.givenToRecipient=o)},null,512)),[[T,t.givenToRecipient]]):(h(),f(a,{key:1,icon:"square",class:"mr-2 bg-white text-white h-5 w-5 px-0.5 py-0.5 rounded-sm"})),i("label",Be,v(t.recipientDid?"This was given to "+t.recipientName+".":"No individual benefitted."),1),!t.recipientDid||t.givenToProject?(h(),f(a,{key:2,icon:"info-circle",class:"-mt-1 bg-white text-slate-500 h-5 w-5 px-0.5 py-0.5 rounded-sm",onClick:e[11]||(e[11]=o=>t.notifyUserOfRecipient())})):b("",!0)]),i("div",Se,[t.fulfillsProjectId&&!t.givenToRecipient?y((h(),m("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":e[12]||(e[12]=o=>t.givenToProject=o)},null,512)),[[T,t.givenToProject]]):(h(),f(a,{key:1,icon:"square",class:"mr-2 bg-white text-white h-5 w-5 px-0.5 py-0.5 rounded-sm"})),i("label",qe,v(t.fulfillsProjectId?"This was given to "+t.fulfillsProjectName+". ":"No project benefitted."),1),!t.fulfillsProjectId||t.givenToRecipient?(h(),f(a,{key:2,icon:"info-circle",class:"-mt-1 bg-white text-slate-500 h-5 w-5 px-0.5 py-0.5 rounded-sm",onClick:e[13]||(e[13]=o=>t.notifyUserFulfillsProject())})):b("",!0)])])]),i("div",Re,[y(i("input",{type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":e[14]||(e[14]=o=>t.isTrade=o)},null,512),[[T,t.isTrade]]),e[19]||(e[19]=i("label",{class:"text-sm mt-1"},"This was a trade (not a gift)",-1))]),t.showGeneralAdvanced?(h(),m("div",Oe,[g(P,{to:{name:"claim-add-raw",query:{claim:t.constructGiveParam()}},class:"text-blue-500"},{default:ie(()=>e[20]||(e[20]=[Q(" Edit Raw Data ")])),_:1},8,["to"])])):b("",!0),i("p",Me,[e[21]||(e[21]=Q(" Sign & Send to publish to the world ")),g(a,{icon:"circle-info",class:"pl-2 text-blue-500 cursor-pointer",onClick:e[15]||(e[15]=o=>t.explainData())})]),i("div",Ve,[i("button",{class:"block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md",onClick:e[16]||(e[16]=(...o)=>t.confirm&&t.confirm(...o))}," Sign & Send "),i("button",{class:"block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md",onClick:e[17]||(e[17]=(...o)=>t.cancel&&t.cancel(...o))}," Cancel ")])])],64)}const Xe=te(I,[["render",Fe]]);export{Xe as default};
|
|
|