From b965bb4c7677ebe2220b08ac5b903b041fbd731e Mon Sep 17 00:00:00 2001 From: Benoit Lavenierblavenie <benoit.lavenier@e-is.pro> Date: Sat, 20 Jul 2019 17:22:30 +0200 Subject: [PATCH] [enh] Home: Allow to change locale --- www/js/controllers/app-controllers.js | 29 +++++++++++++++++++++++++- www/templates/api/home.html | 12 ++++------- www/templates/api/locales_popover.html | 2 +- www/templates/api/transfer.html | 12 ++++------- www/templates/home/home.html | 11 ++++++++++ 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index df0a751d9..b7308055b 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -503,10 +503,11 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ } -function HomeController($scope, $state, $timeout, $ionicHistory, csPlatform, csCurrency) { +function HomeController($scope, $state, $timeout, $ionicHistory, $translate, UIUtils, csPlatform, csCurrency, csSettings) { 'ngInject'; $scope.loading = true; + $scope.locales = angular.copy(csSettings.locales); $scope.enter = function(e, state) { if (state && state.stateParams && state.stateParams.error) { // Error query parameter @@ -558,6 +559,32 @@ function HomeController($scope, $state, $timeout, $ionicHistory, csPlatform, csC } }; + $scope.changeLanguage = function(langKey) { + $translate.use(langKey); + $scope.hideLocalesPopover(); + csSettings.data.locale = _.findWhere($scope.locales, {id: langKey}); + }; + + /* -- show/hide locales popup -- */ + + $scope.showLocalesPopover = function(event) { + UIUtils.popover.show(event, { + templateUrl: 'templates/api/locales_popover.html', + scope: $scope, + autoremove: true, + afterShow: function(popover) { + $scope.localesPopover = popover; + } + }); + }; + + $scope.hideLocalesPopover = function() { + if ($scope.localesPopover) { + $scope.localesPopover.hide(); + $scope.localesPopover = null; + } + }; + // For DEV ONLY /*$timeout(function() { $scope.loginAndGo(); diff --git a/www/templates/api/home.html b/www/templates/api/home.html index db9604dc5..d669e13ec 100644 --- a/www/templates/api/home.html +++ b/www/templates/api/home.html @@ -5,15 +5,11 @@ <ion-nav-buttons side="right"> <!-- locales --> - <img ng-if="$root.settings.locale.country" - ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png" - style="padding: 5px 0" - ng-click="showLocalesPopover($event)"> - <button class="button button-clear hidden-xs hidden-sm gray" - style="max-width: 450px !important" - ng-click="showLocalesPopover($event)"> - {{$root.settings.locale.label}} + ng-click="showLocalesPopover($event)" style="align-content: center"> + <img ng-if="$root.settings.locale.country" + ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png"> + <span ng-if="!$root.settings.locale.country">{{$root.settings.locale.label}} </span> <small class="ion-arrow-down-b"></small> </button> </ion-nav-buttons> diff --git a/www/templates/api/locales_popover.html b/www/templates/api/locales_popover.html index e71190c63..db706efc4 100644 --- a/www/templates/api/locales_popover.html +++ b/www/templates/api/locales_popover.html @@ -6,7 +6,7 @@ class="item item-icon-left ink" ng-click="changeLanguage(l.id)"> <i class="item-image avatar" - style="background-image: url(https://www.countryflags.io/{{l.country}}/flat/32.png)"></i> + style="border-radius: 0; background-image: url(https://www.countryflags.io/{{l.country}}/shiny/64.png)"></i> {{l.label | translate}} </a> diff --git a/www/templates/api/transfer.html b/www/templates/api/transfer.html index cd774b6cd..efb9ced6d 100644 --- a/www/templates/api/transfer.html +++ b/www/templates/api/transfer.html @@ -12,15 +12,11 @@ <ion-nav-buttons side="right"> <!-- locales --> - <img ng-if="$root.settings.locale.country" - ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png" - style="padding: 5px 0" - ng-click="showLocalesPopover($event)"> - <button class="button button-clear hidden-xs hidden-sm gray" - style="max-width: 450px !important" - ng-click="showLocalesPopover($event)"> - {{$root.settings.locale.label}} + ng-click="showLocalesPopover($event)" style="align-content: center"> + <img ng-hide="!$root.settings.locale.country" + ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png"> + <span ng-hide="$root.settings.locale.country">{{$root.settings.locale.label}} </span> <small class="ion-arrow-down-b"></small> </button> diff --git a/www/templates/home/home.html b/www/templates/home/home.html index 305ac7c1b..f1708265d 100644 --- a/www/templates/home/home.html +++ b/www/templates/home/home.html @@ -2,6 +2,17 @@ <!-- no title --> <ion-nav-title></ion-nav-title> + <ion-nav-buttons side="secondary" > + <!-- locales --> + <button class="button button-clear hidden-xs hidden-sm gray" + ng-click="showLocalesPopover($event)" style="align-content: center"> + <img ng-if=":locale:$root.settings.locale.country" + ng-src="https://www.countryflags.io/{{:locale:$root.settings.locale.country}}/shiny/32.png"> + <span ng-if=":locale:!$root.settings.locale.country">{{:locale:$root.settings.locale.label}} </span> + <small class="ion-arrow-down-b"></small> + </button> + </ion-nav-buttons> + <ion-content class="has-header text-center no-padding-xs positive-900-bg circle-bg-dark"> -- GitLab