From 9c5523252d95b4d53ca612dd6744338ea74ef90a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 28 Apr 2018 05:40:08 +0200 Subject: [PATCH] Clean up old JS. --- app/Http/Controllers/AccountController.php | 24 ++++++--------- app/Support/ExpandedForm.php | 36 ++++++++++++++++++++++ config/twigbridge.php | 2 +- public/js/ff/accounts/create.js | 10 ------ public/js/ff/accounts/edit.js | 9 ------ resources/views/accounts/create.twig | 14 ++------- resources/views/accounts/edit.twig | 18 +++-------- 7 files changed, 53 insertions(+), 60 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 6e92d75b4e..b46adfdf38 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -87,12 +87,10 @@ class AccountController extends Controller */ public function create(Request $request, string $what = 'asset') { - $allCurrencies = $this->currencyRepos->get(); - $currencySelectList = ExpandedForm::makeSelectList($allCurrencies); - $defaultCurrency = app('amount')->getDefaultCurrency(); - $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); - $subTitle = trans('firefly.make_new_' . $what . '_account'); - $roles = []; + $defaultCurrency = app('amount')->getDefaultCurrency(); + $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); + $subTitle = trans('firefly.make_new_' . $what . '_account'); + $roles = []; foreach (config('firefly.accountRoles') as $role) { $roles[$role] = (string)trans('firefly.account_role_' . $role); } @@ -106,7 +104,7 @@ class AccountController extends Controller } $request->session()->forget('accounts.create.fromStore'); - return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencySelectList', 'allCurrencies', 'roles')); + return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'roles')); } /** @@ -165,12 +163,10 @@ class AccountController extends Controller */ public function edit(Request $request, Account $account, AccountRepositoryInterface $repository) { - $what = config('firefly.shortNamesByFullName')[$account->accountType->type]; - $subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]); - $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); - $allCurrencies = $this->currencyRepos->get(); - $currencySelectList = ExpandedForm::makeSelectList($allCurrencies); - $roles = []; + $what = config('firefly.shortNamesByFullName')[$account->accountType->type]; + $subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]); + $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); + $roles = []; foreach (config('firefly.accountRoles') as $role) { $roles[$role] = (string)trans('firefly.account_role_' . $role); } @@ -217,8 +213,6 @@ class AccountController extends Controller return view( 'accounts.edit', compact( - 'allCurrencies', - 'currencySelectList', 'account', 'currency', 'subTitle', diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index 08fbd72e8c..5dabfcdee2 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -27,6 +27,7 @@ use Carbon\Carbon; use Eloquent; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Support\Collection; @@ -188,6 +189,41 @@ class ExpandedForm return $html; } + /** + * @param string $name + * @param null $value + * @param array $options + * + * @return string + */ + public function currencyList(string $name, $value = null, array $options = []): string + { + // properties for cache + $cache = new CacheProperties; + $cache->addProperty('exp-form-currency-list'); + $cache->addProperty($name); + $cache->addProperty($value); + $cache->addProperty($options); + + if ($cache->has()) { + return $cache->get(); + } + /** @var CurrencyRepositoryInterface $currencyRepos */ + $currencyRepos = app(CurrencyRepositoryInterface::class); + + // get all currencies: + $list = $currencyRepos->get(); + $array = []; + /** @var TransactionCurrency $currency */ + foreach ($list as $currency) { + $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')'; + } + $res = $this->select($name, $array, $value, $options); + $cache->store($res); + + return $res; + } + /** * @param $name * @param null $value diff --git a/config/twigbridge.php b/config/twigbridge.php index 2ae6c1ddab..63b6398f22 100644 --- a/config/twigbridge.php +++ b/config/twigbridge.php @@ -188,7 +188,7 @@ return [ 'is_safe' => [ 'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount', - 'number', 'assetAccountList','amountNoCurrency' + 'number', 'assetAccountList','amountNoCurrency','currencyList' ], ], 'Form' => [ diff --git a/public/js/ff/accounts/create.js b/public/js/ff/accounts/create.js index ddf5207587..bff8a0c275 100644 --- a/public/js/ff/accounts/create.js +++ b/public/js/ff/accounts/create.js @@ -29,14 +29,4 @@ $(document).ready(function () { } ); } - // on change currency drop down list: - $('#ffInput_currency_id').change(updateCurrencyItems); - updateCurrencyItems(); - }); - -function updateCurrencyItems() { - var value = $('#ffInput_currency_id').val(); - var symbol = currencies[value]; - $('.non-selectable-currency-symbol').text(symbol); -} diff --git a/public/js/ff/accounts/edit.js b/public/js/ff/accounts/edit.js index 0f8d1922be..fbd367bf18 100644 --- a/public/js/ff/accounts/edit.js +++ b/public/js/ff/accounts/edit.js @@ -30,13 +30,4 @@ $(document).ready(function () { ); } - // on change currency drop down list: - $('#ffInput_currency_id').change(updateCurrencyItems); - }); - -function updateCurrencyItems() { - var value = $('#ffInput_currency_id').val(); - var symbol = currencies[value]; - $('.non-selectable-currency-symbol').text(symbol); -} diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig index 3ad8c7dbc5..0fe42b070c 100644 --- a/resources/views/accounts/create.twig +++ b/resources/views/accounts/create.twig @@ -18,8 +18,7 @@
{{ ExpandedForm.text('name') }} {% if what == 'asset' %} - {# Not really mandatory but OK #} - {{ ExpandedForm.select('currency_id', currencySelectList, null, {helpText:'account_default_currency'|_}) }} + {{ ExpandedForm.currencyList('currency_id', null, {helpText:'account_default_currency'|_}) }} {% endif %}
@@ -39,10 +38,10 @@ {% if what == 'asset' %} - {{ ExpandedForm.nonSelectableBalance('openingBalance') }} + {{ ExpandedForm.amountNoCurrency('openingBalance') }} {{ ExpandedForm.date('openingBalanceDate') }} {{ ExpandedForm.select('accountRole', roles,null,{'helpText' : 'asset_account_role_help'|_}) }} - {{ ExpandedForm.nonSelectableBalance('virtualBalance') }} + {{ ExpandedForm.amountNoCurrency('virtualBalance') }} {% endif %} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} @@ -71,13 +70,6 @@ {% block scripts %} - {# JS currency list for update thing #} - {% endblock %} diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig index d1a14908cb..feaba02711 100644 --- a/resources/views/accounts/edit.twig +++ b/resources/views/accounts/edit.twig @@ -17,9 +17,8 @@
{{ ExpandedForm.text('name') }} - {% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %} - {# Not really mandatory but OK #} - {{ ExpandedForm.select('currency_id', currencySelectList) }} + {% if account.accountType.type == 'Default account' or account.accountType.type == 'Asset account' %} + {{ ExpandedForm.currencyList('currency_id', null, {helpText:'account_default_currency'|_}) }} {% endif %}
@@ -42,10 +41,10 @@ {% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %} {# get opening balance entry for this thing! #} - {{ ExpandedForm.nonSelectableBalance('openingBalance',null, {'currency' : currency }) }} + {{ ExpandedForm.amountNoCurrency('openingBalance',null) }} {{ ExpandedForm.date('openingBalanceDate') }} {{ ExpandedForm.select('accountRole', roles) }} - {{ ExpandedForm.nonSelectableBalance('virtualBalance',null, {'currency' : currency }) }} + {{ ExpandedForm.amountNoCurrency('virtualBalance',null) }} {% endif %} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} @@ -87,15 +86,6 @@ {% block scripts %} - - {# JS currency list for update thing #} - - {% endblock %}