Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix edit/create JS for accounts.
James Cole029cbe7ca206
diff --git a/config/translations.php b/config/translations.phpindex cd5cdbfe04..45495a9491 100644--- a/config/translations.php+++ b/config/translations.php@@ -66,6 +66,8 @@ return ['you_create_deposit','wait_loading_page','withdrawal',+ 'i_owe_amount',+ 'i_am_owed_amount','deposit','transfer','inactive',diff --git a/resources/assets/v3/js/pages/accounts/create.js b/resources/assets/v3/js/pages/accounts/create.jsnew file mode 100644index 0000000000..5952d23554--- /dev/null+++ b/resources/assets/v3/js/pages/accounts/create.js@@ -0,0 +1,83 @@+/*+ * dashboard.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import '../../boot/bootstrap.js';+import sidebar from '../../pages/shared/sidebar.js';+import dates from '../shared/dates.js';+import i18next from "i18next";++let create = function () {+ return {+ init() {+ let list = document.querySelectorAll('div.app-content form input[type="text"]:enabled');+ if(list.length > 0) {+ list[0].focus();+ }+ let el = document.getElementById('ffInput_liability_direction');+ if(null !== el) {+ el.addEventListener('change', (event) => {+ let direction = event.target.value;+ if ('credit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_am_owed_amount');+ }+ if ('debit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_owe_amount');+ }+ });+ // also change it the first time around+ let direction = el.value;+ if ('credit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_am_owed_amount');+ }+ if ('debit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_owe_amount');+ }+ }+ }+ }+};+++const comps = {+ create,+ sidebar,+ dates+};++function loadPage(comps) {+ // console.log('loadPage');+ Object.keys(comps).forEach(comp => {+ let data = comps[comp]();+ Alpine.data(comp, () => data);+ // console.log(comp);+ });+ Alpine.start();+}++// wait for load until bootstrapped event is received.+document.addEventListener('firefly-iii-bootstrapped', () => {+ // console.log('Loaded through event listener.');+ loadPage(comps);+});+// or is bootstrapped before event is triggered.+if (window.bootstrapped) {+ // console.log('Loaded through window variable.');+ loadPage(comps);+}diff --git a/resources/assets/v3/js/pages/accounts/edit.js b/resources/assets/v3/js/pages/accounts/edit.jsnew file mode 100644index 0000000000..5c1087f7c1--- /dev/null+++ b/resources/assets/v3/js/pages/accounts/edit.js@@ -0,0 +1,83 @@+/*+ * dashboard.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import '../../boot/bootstrap.js';+import sidebar from '../../pages/shared/sidebar.js';+import dates from '../shared/dates.js';+import i18next from "i18next";++let edit = function () {+ return {+ init() {+ let list = document.querySelectorAll('div.app-content form input[type="text"]:enabled');+ if(list.length > 0) {+ list[0].focus();+ }+ let el = document.getElementById('ffInput_liability_direction');+ if(null !== el) {+ el.addEventListener('change', (event) => {+ let direction = event.target.value;+ if ('credit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_am_owed_amount');+ }+ if ('debit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_owe_amount');+ }+ });+ // also change it the first time around+ let direction = el.value;+ if ('credit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_am_owed_amount');+ }+ if ('debit' === direction) {+ document.querySelector('label[for="ffInput_opening_balance"]').textContent = i18next.t('firefly.i_owe_amount');+ }+ }+ }+ }+};+++const comps = {+ edit,+ sidebar,+ dates+};++function loadPage(comps) {+ // console.log('loadPage');+ Object.keys(comps).forEach(comp => {+ let data = comps[comp]();+ Alpine.data(comp, () => data);+ // console.log(comp);+ });+ Alpine.start();+}++// wait for load until bootstrapped event is received.+document.addEventListener('firefly-iii-bootstrapped', () => {+ // console.log('Loaded through event listener.');+ loadPage(comps);+});+// or is bootstrapped before event is triggered.+if (window.bootstrapped) {+ // console.log('Loaded through window variable.');+ loadPage(comps);+}diff --git a/resources/assets/v3/vite.config.js b/resources/assets/v3/vite.config.jsindex 38506dd80e..bd371ffa07 100644--- a/resources/assets/v3/vite.config.js+++ b/resources/assets/v3/vite.config.js@@ -40,6 +40,10 @@ export default defineConfig(({command, mode, isSsrBuild, isPreview}) => {// CSS for entire app'sass/app.scss',+ // accounts+ 'js/pages/accounts/create.js',+ 'js/pages/accounts/edit.js',+// dashboard'js/pages/dashboard/boxes.js','js/pages/dashboard/dashboard.js',diff --git a/resources/views/accounts/create.blade.php b/resources/views/accounts/create.blade.phpindex f4fd26d68b..8369c3d1c0 100644--- a/resources/views/accounts/create.blade.php+++ b/resources/views/accounts/create.blade.php@@ -7,7 +7,7 @@</script><form action="{{ route('accounts.store') }}" method="post" id="store" class="form-horizontal"- enctype="multipart/form-data">+ enctype="multipart/form-data" x-data="create"><input type="hidden" name="_token" value="{{ csrf_token() }}"/><input type="hidden" name="objectType" value="{{ $objectType }}"/><input type="hidden" name="active" value="1"/>@@ -83,16 +83,7 @@</form>@endsection@section('scripts')- <script type="text/javascript" nonce="{{ $JS_NONCE }}">- var iAmOwed = '{{ __('firefly.i_am_owed_amount') }}';- var iOwe = '{{ __('firefly.i_owe_amount') }}';- </script>- <script type="text/javascript" src="v1/js/ff/accounts/create.js?v={{ $FF_BUILD_TIME }}" nonce="{{ $JS_NONCE }}"></script>+ @vite(['js/pages/accounts/create.js'])@endsection-@section('styles')- <link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ $FF_BUILD_TIME }}" type="text/css" rel="stylesheet"- media="all" nonce="{{ $JS_NONCE }}">- <link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ $FF_BUILD_TIME }}" type="text/css" rel="stylesheet"- media="all" nonce="{{ $JS_NONCE }}">@endsectiondiff --git a/resources/views/accounts/delete.blade.php b/resources/views/accounts/delete.blade.phpindex 29887d54dc..b06630d112 100644--- a/resources/views/accounts/delete.blade.php+++ b/resources/views/accounts/delete.blade.php@@ -53,3 +53,6 @@</form>@endsection+@section('scripts')+ @vite(['js/pages/generic.js'])+@endsectiondiff --git a/resources/views/accounts/edit.blade.php b/resources/views/accounts/edit.blade.phpindex 1e6253c6c0..2b39111516 100644--- a/resources/views/accounts/edit.blade.php+++ b/resources/views/accounts/edit.blade.php@@ -2,11 +2,11 @@@section('content')<!-- set location data high up --><script type="text/javascript" nonce="{{ $JS_NONCE }}">- var locations = {{ json_encode($locations) }};+ var locations = {!! json_encode($locations) !!};var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";</script>- <form method="post" action="{{ route('accounts.update',$account->id) }}" class="form-horizontal"+ <form method="post" action="{{ route('accounts.update',$account->id) }}" class="form-horizontal" x-data="edit"accept-charset="UTF-8"enctype="multipart/form-data"><input type="hidden" name="_token" value="{{ csrf_token() }}"/>@@ -105,16 +105,5 @@</form>@endsection@section('scripts')- <script type="text/javascript" nonce="{{ $JS_NONCE }}">- var iAmOwed = '{{ __('firefly.i_am_owed_amount') }}';- var iOwe = '{{ __('firefly.i_owe_amount') }}';- </script>- <script type="text/javascript" src="v1/js/ff/accounts/edit.js?v={{ $FF_BUILD_TIME }}" nonce="{{ $JS_NONCE }}"></script>-@endsection--@section('styles')- <link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ $FF_BUILD_TIME }}" type="text/css" rel="stylesheet"- media="all" nonce="{{ $JS_NONCE }}">- <link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ $FF_BUILD_TIME }}" type="text/css" rel="stylesheet"- media="all" nonce="{{ $JS_NONCE }}">+ @vite(['js/pages/accounts/edit.js'])@endsectiondiff --git a/resources/views/tags/edit.blade.php b/resources/views/tags/edit.blade.phpindex ffe5265620..e2cd6bf289 100644--- a/resources/views/tags/edit.blade.php+++ b/resources/views/tags/edit.blade.php@@ -2,7 +2,7 @@@section('content')<!-- set location data high up --><script type="text/javascript" nonce="{{ $JS_NONCE }}">- var locations = {{ json_encode($locations) }};+ var locations = {!! json_encode($locations) !!};var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";</script>