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.

4 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 p