mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
2 lines
8.3 KiB
JavaScript
2 lines
8.3 KiB
JavaScript
import{b,d as V,f as u}from"./format-money-2e5851ad.js";import{M as E,I as j,f as m,i as d,o as C}from"./vendor-50e42c6c.js";import{P as c}from"./put-bb9ad93a.js";import{G as T}from"./get-e0a81c64.js";class v{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 o={transactions:[{transaction_journal_id:t.transaction_journal_id,amount:i}]};new c().put(o,{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 n=t.sortModel[a];i.push({column:n.colId,direction:n.sort})}new T().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 o=[];for(let a in t)if(t.hasOwnProperty(a)){let n=t[a],s=n.attributes.transactions.length>1,f=!0;for(let g in n.attributes.transactions)if(n.attributes.transactions.hasOwnProperty(g)){let r=n.attributes.transactions[g],l={};l.split=s,l.firstSplit=f,l.group_title=n.attributes.group_title,l.created_at=n.attributes.created_at,l.updated_at=n.attributes.updated_at,l.user=n.attributes.user,l.user_group=n.attributes.user_group,l.id=parseInt(n.id),l.transaction_journal_id=parseInt(r.transaction_journal_id),l.description=r.description,l.date=new Date(r.date),l.from={name:r.source_name,id:r.source_id,type:r.source_type},l.to={name:r.destination_name,id:r.destination_id,type:r.destination_type},l.category={name:r.category_name,id:r.category_id},l.budget={name:r.budget_name,id:r.budget_id},l.amount={id:parseInt(n.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},l.icon={classes:"fa fa-solid fa-arrow-left",id:l.id},f=!1,o.push(l)}}return i(o,!1),o}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 o={transactions:[{transaction_journal_id:t.transaction_journal_id,amount:i}]};new c().put(o,{id:t.id})}}const _=new x,p=window.location.href.split("/"),M=p[p.length-1];_.setType(M);document.addEventListener("cellEditRequest",()=>{console.log("Loaded through event listener.")});let w;const R=["description","amount","date"],D=e=>{console.log("onCellEditRequestMethod");const t=e.data,i=e.colDef.field;let o=e.newValue;if(!R.includes(i)){console.log("Field "+i+" is not editable.");return}i==="amount"&&(o=e.newValue.amount,console.log("New value is now"+o)),console.log('New value for field "'+i+'" in transaction journal #'+t.transaction_journal_id+" of group #"+t.id+' is "'+o+'"'),t[i]=o,w.getRowNode(String(e.rowIndex)).updateData(t);let n={transactions:[{transaction_journal_id:t.transaction_journal_id}]};n.transactions[0][i]=o,new c().put(n,{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 G={rowModelType:"infinite",datasource:_,onCellEditRequest:D,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:v,cellRenderer(e){if(e.getValue()){let t="",i=parseFloat(e.getValue().amount),o=e.getValue(),a="text-danger";if(o.type==="withdrawal"&&(i=i*-1),o.type==="deposit"&&(a="text-success"),o.type==="transfer"&&(a="text-info"),t+='<span class="'+a+'">'+u(i,e.getValue().currency_code)+"</span>",o.foreign_amount){let n=parseFloat(e.getValue().foreign_amount);o.type==="withdrawal"&&(n=n*-1),t+=' (<span class="'+a+'">'+u(n,o.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 P=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=C(document.querySelector("#grid"),G)},parseTransactions(e){for(let t in e)if(e.hasOwnProperty(t)){let i=e[t],o=i.attributes.transactions.length>1,a=!0;for(let n in i.attributes.transactions)if(i.attributes.transactions.hasOwnProperty(n)){let s=i.attributes.transactions[n];s.split=o,tranaction.icon="fa fa-solid fa-arrow-left",s.firstSplit=a,s.group_title=i.attributes.group_title,s.id=i.id,s.created_at=i.attributes.created_at,s.updated_at=i.attributes.updated_at,s.user=i.attributes.user,s.user_group=i.attributes.user_group,a=!1,this.transactions.push(s)}}this.notifications.wait.show=!1,console.log("refresh!")}}},h={index:P,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());
|