mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
2 lines
8.5 KiB
JavaScript
2 lines
8.5 KiB
JavaScript
import{b,d as V,f as u}from"./format-money-62afb78b.js";import{M as E,I as j,f as h,i as d,o as C}from"./vendor-2609b2c9.js";import{G as m}from"./get-ea675e30.js";import{P as c}from"./put-c9d3942f.js";class T{init(t){document.addEventListener("cellValueChanged",()=>{console.log("I just realized a cell value has changed.")}),console.log("AmountEditor.init"),this.params=t,this.originalValue=t.value,this.eGui=document.createElement("div"),this.input=document.createElement("input"),this.input.type="number",this.input.min="0",this.input.step="any",this.input.style.overflow="hidden",this.input.style.textOverflow="ellipsis",this.input.autofocus=!0,this.input.value=parseFloat(t.value.amount).toFixed(t.value.decimal_places)}onChange(t){console.log("AmountEditor.onChange"),this.params.onValueChange(t),this.params.stopEditing(t)}afterGuiAttached(){this.input.focus(),this.input.select()}getGui(){return console.log("AmountEditor.getGui"),this.eGui.appendChild(this.input),this.eGui}getValue(){return console.log("AmountEditor.getValue"),this.originalValue.amount=parseFloat(this.input.value),this.submitAmount(this.originalValue),this.originalValue}submitAmount(t){console.log("AmountEditor.submitAmount"),console.log(t);const i=t.amount;console.log('New value for field "amount" in transaction journal #'+t.transaction_journal_id+" of group #"+t.id+' is "'+i+'"');let n={transactions:[{transaction_journal_id:t.transaction_journal_id,amount:i}]};new c().put(n,{id:t.id})}}class v{constructor(){this.type="all",this.rowCount=null}rowCount(){return this.rowCount}getRows(t){new m().listByCount({start_row:t.startRow,end_row:t.endRow,type:this.type}).then(n=>{this.parseTransactions(n.data.data,t.successCallback),this.rowCount=n.data.meta.pagination.total}).catch(n=>{console.log(n)})}parseTransactions(t,i){let n=[];for(let r in t)if(t.hasOwnProperty(r)){let a=t[r],l=a.attributes.transactions.length>1,g=!0;for(let p in a.attributes.transactions)if(a.attributes.transactions.hasOwnProperty(p)){let o=a.attributes.transactions[p],s={};s.split=l,s.firstSplit=g,s.group_title=a.attributes.group_title,s.created_at=a.attributes.created_at,s.updated_at=a.attributes.updated_at,s.user=a.attributes.user,s.user_group=a.attributes.user_group,s.id=parseInt(a.id),s.transaction_journal_id=parseInt(o.transaction_journal_id),s.description=o.description,s.date=new Date(o.date),s.from={name:o.source_name,id:o.source_id,type:o.source_type},s.to={name:o.destination_name,id:o.destination_id,type:o.destination_type},s.category={name:o.category_name,id:o.category_id},s.budget={name:o.budget_name,id:o.budget_id},s.amount={id:parseInt(a.id),transaction_journal_id:parseInt(o.transaction_journal_id),type:o.type,amount:o.amount,currency_code:o.currency_code,decimal_places:o.currency_decimal_places,foreign_amount:o.foreign_amount,foreign_currency_code:o.foreign_currency_code,foreign_decimal_places:o.foreign_currency_decimal_places},s.icon={classes:"fa fa-solid fa-arrow-left",id:s.id},g=!1,n.push(s)}}return i(n,!1),n}setType(t){this.type=t}}class x{init(t){console.log("DateTimeEditor.init"),this.params=t,this.originalValue=t.value,this.eGui=document.createElement("div"),this.input=document.createElement("input"),this.input.type="datetime-local",this.input.style.overflow="hidden",this.input.style.textOverflow="ellipsis",this.input.value=b(t.value,"yyyy-MM-dd HH:mm")}onChange(t){console.log("DateTimeEditor.onChange"),this.params.onValueChange(t),this.params.stopEditing(t)}afterGuiAttached(){this.input.focus()}getGui(){return console.log("DateTimeEditor.getGui"),this.eGui.appendChild(this.input),this.eGui}getValue(){return console.log("DateTimeEditor.getValue"),this.originalValue=this.input.value,this.originalValue}submitAmount(t){console.log("AmountEditor.submitAmount"),console.log(t);const i=t.amount;console.log('New value for field "amount" in transaction journal #'+t.transaction_journal_id+" of group #"+t.id+' is "'+i+'"');let n={transactions:[{transaction_journal_id:t.transaction_journal_id,amount:i}]};new c().put(n,{id:t.id})}}const _=new v;_.setType("withdrawal");document.addEventListener("cellEditRequest",()=>{console.log("Loaded through event listener.")});let w;const A=["description","amount","date"],R=e=>{console.log("onCellEditRequestMethod");const t=e.data,i=e.colDef.field;let n=e.newValue;if(!A.includes(i)){console.log("Field "+i+" is not editable.");return}i==="amount"&&(n=e.newValue.amount,console.log("New value is now"+n)),console.log('New value for field "'+i+'" in transaction journal #'+t.transaction_journal_id+" of group #"+t.id+' is "'+n+'"'),t[i]=n,w.getRowNode(String(e.rowIndex)).updateData(t);let a={transactions:[{transaction_journal_id:t.transaction_journal_id}]};a.transactions[0][i]=n,new c().put(a,{id:t.id})};document.addEventListener("cellValueChanged",()=>{console.log("I just realized a cell value has changed.")});document.addEventListener("onCellValueChanged",()=>{console.log("I just realized a cell value has changed.")});const D={rowModelType:"infinite",datasource:_,onCellEditRequest:R,readOnlyEdit:!0,columnDefs:[{field:"icon",editable:!1,headerName:"",sortable:!1,width:40,cellRenderer:function(e){return e.getValue()?'<a href="./transactions/show/'+parseInt(e.value.id)+'"><em class="'+e.value.classes+'"></em></a>':""}},{field:"description",cellDataType:"text",editable:!0},{field:"amount",editable:function(e){return e.data.amount.foreign_amount===null&&e.data.amount.foreign_currency_code===null},cellEditor:T,cellRenderer(e){if(e.getValue()){let t="",i=parseFloat(e.getValue().amount),n=e.getValue(),r="text-danger";if(n.type==="withdrawal"&&(i=i*-1),n.type==="deposit"&&(r="text-success"),n.type==="transfer"&&(r="text-info"),t+='<span class="'+r+'">'+u(i,e.getValue().currency_code)+"</span>",n.foreign_amount){let a=parseFloat(e.getValue().foreign_amount);n.type==="withdrawal"&&(a=a*-1),t+=' (<span class="'+r+'">'+u(a,n.foreign_currency_code)+"</span>)"}return t}return""}},{field:"date",editable:!0,cellDataType:"date",cellEditor:x,cellEditorPopup:!0,cellEditorPopupPosition:"under",cellRenderer(e){return e.getValue()?h(e.getValue(),d.t("config.date_time_fns_short")):""}},{field:"from",cellDataType:"text",cellRenderer:function(e){if(e.getValue()){let t=e.getValue();return'<a href="./accounts/show/'+t.id+'">'+t.name+"</a>"}return""}},{field:"to",cellDataType:"text",cellRenderer:function(e){if(e.getValue()){let t=e.getValue();return'<a href="./accounts/show/'+t.id+'">'+t.name+"</a>"}return""}},{field:"category",cellDataType:"text",cellRenderer:function(e){if(e.getValue()){let t=e.getValue();if(t.id!==null)return'<a href="./categories/show/'+t.id+'">'+t.name+"</a>"}return""}},{field:"budget",cellDataType:"text",cellRenderer:function(e){if(e.getValue()){let t=e.getValue();if(t.id!==null)return'<a href="./budgets/show/'+t.id+'">'+t.name+"</a>"}return""}}]};E.registerModules([j]);let G=function(){return{notifications:{error:{show:!1,text:"",url:""},success:{show:!1,text:"",url:""},wait:{show:!1,text:""}},transactions:[],totalPages:1,perPage:50,page:1,tableColumns:{description:{enabled:!0},source:{enabled:!0},destination:{enabled:!0},amount:{enabled:!0}},table:null,formatMoney(e,t){return u(e,t)},format(e){return h(e,d.t("config.date_time_fns"))},init(){this.notifications.wait.show=!0,this.notifications.wait.text=d.t("firefly.wait_loading_data"),w=C(document.querySelector("#grid"),D)},getTransactions(e){const t=window.location.href.split("/"),i=t[t.length-1];new m().list({page:e,type:i}).then(r=>{this.parseTransactions(r.data.data),this.totalPages=r.data.meta.pagination.total_pages,this.perPage=r.data.meta.pagination.per_page,this.page=r.data.meta.pagination.current_page}).catch(r=>{this.notifications.wait.show=!1,this.notifications.error.show=!0,this.notifications.error.text=r.response.data.message})},parseTransactions(e){for(let t in e)if(e.hasOwnProperty(t)){let i=e[t],n=i.attributes.transactions.length>1,r=!0;for(let a in i.attributes.transactions)if(i.attributes.transactions.hasOwnProperty(a)){let l=i.attributes.transactions[a];l.split=n,tranaction.icon="fa fa-solid fa-arrow-left",l.firstSplit=r,l.group_title=i.attributes.group_title,l.id=i.id,l.created_at=i.attributes.created_at,l.updated_at=i.attributes.updated_at,l.user=i.attributes.user,l.user_group=i.attributes.user_group,r=!1,this.transactions.push(l)}}this.notifications.wait.show=!1,console.log("refresh!")}}},f={index:G,dates:V};function y(){Object.keys(f).forEach(e=>{console.log(`Loading page component "${e}"`);let t=f[e]();Alpine.data(e,()=>t)}),Alpine.start()}document.addEventListener("firefly-iii-bootstrapped",()=>{console.log("Loaded through event listener."),y()});window.bootstrapped&&(console.log("Loaded through window variable."),y());
|