mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
2 lines
8.2 KiB
JavaScript
2 lines
8.2 KiB
JavaScript
import{b,d as V,f as u}from"./format-money-db0e5105.js";import{M as E,I as j,f as m,i as d,o as T}from"./vendor-0a0b4763.js";import{P as c}from"./put-ade65e7d.js";/* empty css */import{G as C}from"./get-04515a82.js";class R{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 x{constructor(){this.type="all",this.rowCount=null,this.sortModel=null}rowCount(){return this.rowCount}getRows(t){console.log("The sort model used is: ",t.sortModel);let i=[];for(let a in t.sortModel)if(t.sortModel.hasOwnProperty(a)){let o=t.sortModel[a];i.push({column:o.colId,direction:o.sort})}new C().infiniteList({start_row:t.startRow,end_row:t.endRow,type:this.type,sorting:i}).then(a=>{this.parseTransactions(a.data.data,t.successCallback),this.rowCount=a.data.meta.pagination.total}).catch(a=>{console.log(a)})}parseTransactions(t,i){let n=[];for(let a in t)if(t.hasOwnProperty(a)){let o=t[a],l=o.attributes.transactions.length>1,f=!0;for(let g in o.attributes.transactions)if(o.attributes.transactions.hasOwnProperty(g)){let r=o.attributes.transactions[g],s={};s.split=l,s.firstSplit=f,s.group_title=o.attributes.group_title,s.created_at=o.attributes.created_at,s.updated_at=o.attributes.updated_at,s.user=o.attributes.user,s.user_group=o.attributes.user_group,s.id=parseInt(o.id),s.transaction_journal_id=parseInt(r.transaction_journal_id),s.description=r.description,s.date=new Date(r.date),s.from={name:r.source_name,id:r.source_id,type:r.source_type},s.to={name:r.destination_name,id:r.destination_id,type:r.destination_type},s.category={name:r.category_name,id:r.category_id},s.budget={name:r.budget_name,id:r.budget_id},s.amount={id:parseInt(o.id),transaction_journal_id:parseInt(r.transaction_journal_id),type:r.type,amount:r.amount,currency_code:r.currency_code,decimal_places:r.currency_decimal_places,foreign_amount:r.foreign_amount,foreign_currency_code:r.foreign_currency_code,foreign_decimal_places:r.foreign_currency_decimal_places},s.icon={classes:"fa fa-solid fa-arrow-left",id:s.id},f=!1,n.push(s)}}return i(n,!1),n}setType(t){this.type=t}}class A{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 x,p=window.location.href.split("/"),M=p[p.length-1];_.setType(M);let w;const D=["description","amount","date"],G=e=>{console.log("onCellEditRequestMethod");const t=e.data,i=e.colDef.field;let n=e.newValue;if(!D.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 o={transactions:[{transaction_journal_id:t.transaction_journal_id}]};o.transactions[0][i]=n,new c().put(o,{id:t.id})},P={rowModelType:"infinite",datasource:_,cacheOverflowSize:1,cacheBlockSize:20,onCellEditRequest:G,readOnlyEdit:!0,getRowId:function(e){return console.log("getRowId",e.data.id),e.data.id},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:R,cellRenderer(e){if(e.getValue()){let t="",i=parseFloat(e.getValue().amount),n=e.getValue(),a="text-danger";if(n.type==="withdrawal"&&(i=i*-1),n.type==="deposit"&&(a="text-success"),n.type==="transfer"&&(a="text-info"),t+='<span class="'+a+'">'+u(i,e.getValue().currency_code)+"</span>",n.foreign_amount){let o=parseFloat(e.getValue().foreign_amount);n.type==="withdrawal"&&(o=o*-1),t+=' (<span class="'+a+'">'+u(o,n.foreign_currency_code)+"</span>)"}return t}return""}},{field:"date",editable:!0,cellDataType:"date",cellEditor:A,cellEditorPopup:!0,cellEditorPopupPosition:"under",cellRenderer(e){return e.getValue()?m(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 v=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 m(e,d.t("config.date_time_fns"))},init(){this.notifications.wait.show=!0,this.notifications.wait.text=d.t("firefly.wait_loading_data"),w=T(document.querySelector("#grid"),P)},parseTransactions(e){for(let t in e)if(e.hasOwnProperty(t)){let i=e[t],n=i.attributes.transactions.length>1,a=!0;for(let o in i.attributes.transactions)if(i.attributes.transactions.hasOwnProperty(o)){let l=i.attributes.transactions[o];l.split=n,tranaction.icon="fa fa-solid fa-arrow-left",l.firstSplit=a,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,a=!1,this.transactions.push(l)}}this.notifications.wait.show=!1,console.log("refresh!")}}},h={index:v,dates:V};function y(){Object.keys(h).forEach(e=>{console.log(`Loading page component "${e}"`);let t=h[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());
|