diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json index 74f25ba537a8763882a2a2005e1c418499c5a772..e565aa579187cdf741b41ad158841fc925b951dc 100644 --- a/www/i18n/locale-en.json +++ b/www/i18n/locale-en.json @@ -12,6 +12,7 @@ "BTN_SEND_MONEY": "Transfer money", "BTN_SEND_MONEY_SHORT": "Transfer", "BTN_SAVE": "Save", + "BTN_YES_SAVE": "Oui, Enregistrer", "BTN_SHOW": "Show", "BTN_SHOW_PUBKEY": "Show key", "BTN_RELATIVE_UNIT": "Use relative unit", @@ -375,7 +376,9 @@ "FIX_IDENTITY": "The pseudonym <b>{{uid}}</b> will be published again, replacing the old publication that has expired.<br/></br/><b>Are you sure</b> you want to continue ?", "FIX_MEMBERSHIP": "Your application for membership will be sent.<br/></br/><b>Are you sure ?</b>", "RENEW_MEMBERSHIP": "Your membership will be renewed.<br/></br/><b>Are you sure ?</b>", - "NOT_NEED_RENEW_MEMBERSHIP": "Your membership does not need to be renewed (it will only expire in {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Are you sure you</b> want to renew your membership?" + "NOT_NEED_RENEW_MEMBERSHIP": "Your membership does not need to be renewed (it will only expire in {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Are you sure you</b> want to renew your membership?", + "SAVE_BEFORE_LEAVE": "Do you want to <b>save your changes</b> before leaving the page?", + "SAVE_BEFORE_LEAVE_TITLE": "Changes not saved" }, "HELP": { "TITLE": "Online help", diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index ef7bc8ef9fe711188fd447adc6ba2d31eae5b6b7..1288c9f51615a1b820705766ee9040d5eae5ea45 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -12,6 +12,7 @@ "BTN_SEND_MONEY": "Faire un virement", "BTN_SEND_MONEY_SHORT": "Virement", "BTN_SAVE": "Enregistrer", + "BTN_YES_SAVE": "Oui, Enregistrer", "BTN_SHOW": "Voir", "BTN_SHOW_PUBKEY": "Voir la clé", "BTN_RELATIVE_UNIT": "Afficher en unité relative ?", @@ -375,7 +376,9 @@ "FIX_IDENTITY": "Le pseudonyme <b>{{uid}}</b> va être publiée à nouveau, en remplacement de l'ancienne publication qui a expirée.<br/></br/><b>Etes-vous sûr</b> de vouloir continuer ?", "FIX_MEMBERSHIP": "Votre demande d'adhésion comme membre va être renvoyée.<br/></br/><b>Etes-vous sûr ?</b>", "RENEW_MEMBERSHIP": "Votre adhésion comme membre va être renouvellée.<br/></br/><b>Etes-vous sûr ?</b>", - "NOT_NEED_RENEW_MEMBERSHIP": "Votre adhésion n'a pas besoin d'être renouvellée (elle n'expirera que dans {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Etes-vous sûr</b> de vouloir renouveller votre adhésion ?" + "NOT_NEED_RENEW_MEMBERSHIP": "Votre adhésion n'a pas besoin d'être renouvellée (elle n'expirera que dans {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Etes-vous sûr</b> de vouloir renouveller votre adhésion ?", + "SAVE_BEFORE_LEAVE": "Voulez-vous <b>sauvegarder vos modifications</b> avant de quitter la page ?", + "SAVE_BEFORE_LEAVE_TITLE": "Modifications non enregistrées" }, "HELP": { "TITLE": "Aide en ligne", diff --git a/www/js/app.js b/www/js/app.js index 94c02a2d11ace542724fae1554ee4525083ee1b4..7edaa46541525b81f2b182816bf55bd864f6e77b 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -236,9 +236,12 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht // removeIf(device) // Automatic redirection to large state (if exists) $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if (!UIUtils.screen.isSmall() && next.data.large) { - event.preventDefault(); - $state.go(next.data.large, nextParams); + if (next.data.large && !UIUtils.screen.isSmall()) { + var redirect = !$rootScope.tour && !event.currentScope.tour; // disabled for help tour + if (redirect) { + event.preventDefault(); + $state.go(next.data.large, nextParams); + } } }); // endRemoveIf(device) diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index 8e21927eeae77e16e717f998b6c7f2d7a464a15e..22391db6cdc1f5b7ea2e79f3386df35c34256492 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -78,7 +78,11 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ $scope.login = csWallet.isLogin(); $scope.showHome = function() { - $state.go('app.home'); + $ionicHistory.nextViewOptions({ + historyRoot: true + }); + return $state.go('app.home') + .then(UIUtils.loading.hide) }; //////////////////////////////////////// @@ -169,38 +173,39 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ // Load wallet data (after login) $scope.loadWalletData = function(options) { - if (options && options.loadMinData) { - return csWallet.loadMinData() - .catch(UIUtils.onError('ERROR.LOAD_WALLET_DATA_ERROR')); - } - return csWallet.loadData() - .catch(UIUtils.onError('ERROR.LOAD_WALLET_DATA_ERROR')) + return csWallet.loadData(options) + /*.catch(UIUtils.onError('ERROR.LOAD_WALLET_DATA_ERROR'))*/ + .then(function(walletData) { // Warn if wallet has been never used - see #167 var showAlert = !csConfig.initPhase && csWallet.isNeverUsed() && (!csSettings.data.wallet || csSettings.data.wallet.alertIfUnusedWallet); if (!showAlert) return walletData; - return UIUtils.alert.confirm('CONFIRM.LOGIN_UNUSED_WALLET', - 'CONFIRM.LOGIN_UNUSED_WALLET_TITLE', { - okText: 'COMMON.BTN_CONTINUE' + return UIUtils.loading.hide() + .then(function(){ + return UIUtils.alert.confirm('CONFIRM.LOGIN_UNUSED_WALLET', 'CONFIRM.LOGIN_UNUSED_WALLET_TITLE', + { + okText: 'COMMON.BTN_CONTINUE' + }); }) .then(function(confirm) { if (confirm) return walletData; + return csWallet.logout(); }); }) + .then(function(walletData) { if (walletData) { $rootScope.walletData = walletData; return walletData; } - else { // failed to login - throw new Error('CANCELLED'); + else { // cancel login + throw 'CANCELLED'; } }); }; // Login and load wallet $scope.loadWallet = function(options) { - options = options || {}; if (!csWallet.isLogin()) { return $scope.showLoginModal() .then(function (walletData) { @@ -209,7 +214,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ return $scope.loadWalletData(options); } else { // failed to login - throw new Error('CANCELLED'); + throw 'CANCELLED'; } }); } @@ -217,9 +222,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ return $scope.loadWalletData(options); } else { - var deferred = $q.defer(); - deferred.resolve(csWallet.data); - return deferred.promise; + return $q.when(csWallet.data); } }; @@ -231,12 +234,12 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ if (!csWallet.isLogin()) { return $scope.showLoginModal() - .then(function(walletData){ - UIUtils.loading.hide(10); - if (walletData) { - $state.go(state ? state : 'app.view_wallet'); - } - }); + .then(function(walletData){ + if (walletData) { + return $state.go(state ? state : 'app.view_wallet') + .then(UIUtils.loading.hide); + } + }); } else { return $state.go(state); @@ -291,10 +294,8 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ // add listener on wallet event csWallet.api.data.on.login($scope, function(walletData, deferred) { - deferred = deferred || $q.defer(); $scope.login = true; - deferred.resolve(); - return deferred.promise; + return deferred ? deferred.resolve() : $q.when(); }); csWallet.api.data.on.logout($scope, function() { $scope.login = false; diff --git a/www/js/controllers/help-controllers.js b/www/js/controllers/help-controllers.js index 0339a08db9744970ba02d6ae3e770e6918819861..9c01e4e2916828f1111ec96f966ba9b2978344ff 100644 --- a/www/js/controllers/help-controllers.js +++ b/www/js/controllers/help-controllers.js @@ -83,20 +83,13 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe UIUtils, csConfig, csSettings, csCurrency, Device, csWallet) { $scope.tour = false; // Is a tour or a helptip ? - - $scope.emptyPromise = function(result) { - var defer = $q.defer(); - $timeout(function() { - defer.resolve(result); - }); - return defer.promise; - }; + $scope.continue = true; $scope.executeStep = function(partName, steps, index) { index = angular.isDefined(index) ? index : 0; if (index >= steps.length) { - return $scope.emptyPromise(true); // end + return $q.when(true); // end } var step = steps[index]; @@ -105,11 +98,12 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe } var promise = step(); if (typeof promise === 'boolean') { - promise = $scope.emptyPromise(promise); + promise = $q.when(promise); } return promise .then(function(next) { if (angular.isUndefined(next)) { + $scope.continue = false; return index; // keep same index (no button press: popover just closed) } if (!next || index === steps.length - 1) { @@ -118,7 +112,14 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe return $scope.executeStep(partName, steps, index+1); }) .catch(function(err) { - console.error(err); + if (err && err.message == 'transition prevented') { + console.error('ERROR: in help tour [{0}], in step [{1}] -> use large if exists, to prevent [transition prevented] error'.format(partName, index)); + } + else { + console.error('ERROR: in help tour [{0}], in step [{1}] : {2}'.format(partName, index, err)); + } + $scope.continue = false; + return index; }); }; @@ -140,14 +141,15 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe $scope.startHelpTour = function() { $scope.tour = true; + $scope.continue = true; // Currency tour return $scope.startCurrencyTour(0, true) .then(function(endIndex){ - if (!endIndex) return false; + if (!endIndex || $scope.cancelled) return false; csSettings.data.helptip.currency=endIndex; csSettings.store(); - return true; + return $scope.continue; }) // Wot tour @@ -155,10 +157,10 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe if (!next) return false; return $scope.startWotTour(0, true) .then(function(endIndex){ - if (!endIndex) return false; + if (!endIndex || $scope.cancelled) return false; csSettings.data.helptip.wot=endIndex; csSettings.store(); - return true; + return $scope.continue; }); }) @@ -170,7 +172,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe if (!endIndex) return false; csSettings.data.helptip.wotCerts=endIndex; csSettings.store(); - return true; + return $scope.continue; }); }) @@ -189,7 +191,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe if (!endIndex) return false; csSettings.data.helptip.wallet=endIndex; csSettings.store(); - return true; + return $scope.continue; }); }) @@ -202,7 +204,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe if (!endIndex) return false; csSettings.data.helptip.walletCerts=endIndex; csSettings.store(); - return true; + return $scope.continue; }); }) @@ -263,7 +265,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe if ($ionicSideMenuDelegate.isOpen()) { $ionicSideMenuDelegate.toggleLeft(false); } - return $state.go('app.currency_view') + return $state.go(UIUtils.screen.isSmall() ? 'app.currency_view' : 'app.currency_view_lg') .then(function () { return $scope.showHelpTip('helptip-currency-newcomers', { bindings: { @@ -562,7 +564,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe * @returns {*} */ $scope.startWalletNoLoginTour = function(startIndex, hasNext) { - if (csWallet.isLogin()) return $scope.emptyPromise(true); // skip if login + if (csWallet.isLogin()) return $q.when(true); // skip if login var steps = [ function () { @@ -587,7 +589,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe * @returns {*} */ $scope.startWalletTour = function(startIndex, hasNext) { - if (!csWallet.isLogin()) return $scope.emptyPromise(true); // skip if not login + if (!csWallet.isLogin()) return $q.when(true); // skip if not login var contentParams; @@ -678,7 +680,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe * @returns {*} */ $scope.startWalletCertTour = function(startIndex, hasNext) { - if (!csWallet.isLogin()) return $scope.emptyPromise(true); + if (!csWallet.isLogin()) return $q.when(true); var contentParams; var skipAll = false; @@ -769,7 +771,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe * @returns {*} */ $scope.startHeaderTour = function(startIndex, hasNext) { - if (UIUtils.screen.isSmall()) return $scope.emptyPromise(true); + if (UIUtils.screen.isSmall()) return $q.when(true); function _getProfilBtnElement() { var elements = $window.document.querySelectorAll('#helptip-header-bar-btn-profile'); @@ -916,7 +918,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe else { var contentParams; return $q.all([ - $state.go('app.home'), + $scope.showHome(), csCurrency.default() .then(function(parameters) { diff --git a/www/js/controllers/settings-controllers.js b/www/js/controllers/settings-controllers.js index c0a070d3c57d73429f7d7c81eda2a0686b0ede2e..a653c3e60ccba3db2aae48b0957a4134e41b59c3 100644 --- a/www/js/controllers/settings-controllers.js +++ b/www/js/controllers/settings-controllers.js @@ -140,20 +140,26 @@ function SettingsController($scope, $q, $ionicPopup, $timeout, $translate, csHtt }); }; - $scope.onSettingsChanged = function() { - if (!$scope.loading) { - $scope.loading = true; + $scope.save = function() { + if ($scope.loading) return $q.when(); + if ($scope.saving) { + // Retry later + return $timeout(function() { + return $scope.save(); + }, 500); + } + $scope.saving = true; + // Async - to avoid UI lock + $timeout(function() { // Make sure to format helptip $scope.cleanupHelpTip(); - angular.merge(csSettings.data, $scope.formData); csSettings.store(); - $scope.loading = false; - } + $scope.saving = false; + }, 100); }; - $scope.$watch('formData', $scope.onSettingsChanged, true); - //$scope.$watch('formData.helptip', $scope.onSettingsChanged, true); + $scope.$watch('formData', $scope.save, true); $scope.getServer = function() { diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index 77efa05e4cfb84602cb709ef7594f788add90915..da98b9fcea50059ecdfeb90a31676797a381a797 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -54,11 +54,8 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, UIUtils.loading.hide(); // loading could have be open (e.g. new account) }) .catch(function(err){ - if ('CANCELLED' === err) { - $ionicHistory.nextViewOptions({ - historyRoot: true - }); - $state.go('app.home'); + if (err == 'CANCELLED') { + $scope.showHome(); } }); }); @@ -291,9 +288,8 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, .catch(function(err){ UIUtils.loading.hide(); UIUtils.alert.error(err) - .then(function(){ - $scope.renewMembership(); // loop - }); + // loop + .then($scope.renewMembership); }); }; @@ -305,7 +301,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, return $translate('CONFIRM.FIX_IDENTITY', {uid: $rootScope.walletData.uid}) .then(function(message) { - return UIUtils.alert.confirm(message) + return UIUtils.alert.confirm(message); }) .then(function(confirm) { if (!confirm) return; @@ -385,17 +381,23 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, // Change QRcode visibility var qrcode = document.getElementById('qrcode'); - qrcode.classList.toggle('visible-xs', !show); - qrcode.classList.toggle('visible-sm', !show); + if (qrcode) { + qrcode.classList.toggle('visible-xs', !show); + qrcode.classList.toggle('visible-sm', !show); + } if (show && !$scope.loading) { $timeout(function (){ var pubkeyElement = document.getElementById('wallet-pubkey'); - pubkeyElement.classList.toggle('done', true); - pubkeyElement.classList.toggle('in', true); - var pubkeyElement = document.getElementById('wallet-uid'); - pubkeyElement.classList.toggle('done', true); - pubkeyElement.classList.toggle('in', true); + if (pubkeyElement) { + pubkeyElement.classList.toggle('done', true); + pubkeyElement.classList.toggle('in', true); + } + var uidElement = document.getElementById('wallet-uid'); + if (uidElement) { + uidElement.classList.toggle('done', true); + uidElement.classList.toggle('in', true); + } }, 500); } }; @@ -471,7 +473,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, }; $scope.showCertifications = function() { - $state.go('app.wallet_view_cert', { + $state.go(UIUtils.screen.isSmall() ? 'app.wallet_view_cert' : 'app.wallet_view_cert_lg', { pubkey: $rootScope.walletData.pubkey, uid: $rootScope.walletData.name || $rootScope.walletData.uid }); diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index 37c1399560e281ca806fb2193b960ef3820a2f7d..4f17fbaf11d81451993259b840d63a77b3465b60 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -205,7 +205,7 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, csConfig, c }); }; - $scope.showMore= function() { + $scope.showMore = function() { var offset = $scope.search.results ? $scope.search.results.length : 0; $scope.search.loadingMore = true; @@ -225,7 +225,7 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, csConfig, c $scope.search.loadingMore = false; $scope.search.hasMore = false; $scope.$broadcast('scroll.infiniteScrollComplete'); - }) + }); }; $scope.select = function(identity) { @@ -411,6 +411,14 @@ function WotIdentityViewController($scope, $state, $timeout, UIUtils, csWot) { }); }; + $scope.showCertifications = function() { + // Warn: do not use a simple link here (a ng-click is need for help tour) + $state.go(UIUtils.screen.isSmall() ? 'app.wot_view_cert' : 'app.wot_view_cert_lg', { + pubkey: $scope.formData.pubkey, + uid: $scope.formData.name || $scope.formData.uid + }); + }; + $scope.showSharePopover = function(event) { var title = $scope.formData.name || $scope.formData.uid || $scope.formData.pubkey; var url = $state.href('app.wot_view_identity', {pubkey: $scope.formData.pubkey, uid: $scope.formData.uid}, {absolute: true}); diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js index f2c42572673214a60561c4aee5c7335f488148c2..cd289d93d60b16d628c5038df8417cea02e0a870 100644 --- a/www/js/services/bma-services.js +++ b/www/js/services/bma-services.js @@ -195,7 +195,7 @@ angular.module('cesium.bma.services', ['ngResource', 'cesium.http.services', 'ce }); }; - exports.blockchain.stats.lastUd = function() { + exports.blockchain.lastUd = function() { return exports.blockchain.stats.ud() .then(function(res) { if (!res.result.blocks || !res.result.blocks.length) { diff --git a/www/js/services/currency-services.js b/www/js/services/currency-services.js index e8e27adc270201ac9b141164c18995cfae089188..1cf4c1a3f0a82dd2887bd68bd6a291791f890369 100644 --- a/www/js/services/currency-services.js +++ b/www/js/services/currency-services.js @@ -14,15 +14,14 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s api = new Api(this, "csCurrency-" + id), loadData = function() { - return $q(function (resolve, reject){ - if (data.loaded) { // load only once - resolve(data); - return; - } + if (data.loaded) { // load only once + return $q.when(data); + } - data.currencies = []; - // Load currency from default node - BMA.blockchain.parameters() + data.currencies = []; + + // Load currency from default node + return BMA.blockchain.parameters() .then(function(res){ data.currencies.push({ name: res.currency, @@ -35,14 +34,13 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s }) .then(function() { data.loaded = true; - resolve(data); + return data; }) .catch(function(err) { data.loaded = false; data.currencies = []; - reject(err); + throw err; }); - }); }, getAll = function() { diff --git a/www/js/services/http-services.js b/www/js/services/http-services.js index 217f24b6a50e9c22fbb291fb0bb2830b3ff628a8..d267c775a56bada8a69966d7297b256351fa477b 100644 --- a/www/js/services/http-services.js +++ b/www/js/services/http-services.js @@ -144,9 +144,7 @@ angular.module('cesium.http.services', ['ngResource', 'cesium.cache.services']) function _waitOpen() { if (!sock) throw new Error('Websocket not opened'); if (sock && sock.readyState === 1) { - var deferred = $q.defer(); - deferred.resolve(sock); - return deferred.promise; + return $q.when(sock); } return $timeout(_waitOpen, 100); } diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js index 211ff59111d9fccf1a147aeba9b929a65864f58d..3beece60c9a27d4612499c572e9fd8255902bab9 100644 --- a/www/js/services/utils-services.js +++ b/www/js/services/utils-services.js @@ -78,21 +78,16 @@ angular.module('cesium.utils.services', ['ngResource']) options = options ? angular.merge(defaultOptions, options) : defaultOptions; - return $q(function(resolve, reject) { - $translate([message, title, options.cancelText, options.okText]) + return $translate([message, title, options.cancelText, options.okText]) .then(function (translations) { - $ionicPopup.confirm({ + return $ionicPopup.confirm({ template: translations[message], cssClass: options.cssClass, title: translations[title], cancelText: translations[options.cancelText], okText: translations[options.okText] - }) - .then(function(res) { - resolve(res); }); }); - }); } function hideLoading(timeout){ @@ -112,7 +107,7 @@ angular.module('cesium.utils.services', ['ngResource']) .then(function(translations){ return $ionicLoading.show({ template: translations['COMMON.LOADING'] - }) + }); }); } diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index a68289ef4e32e9d3658505be390f0543ca28f8a0..b0819f1eb97c79c034fa042490fcd778bee6e4bd 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -196,6 +196,7 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser }, isNeverUsed = function() { + if (!data.loaded) return undefined; // undefined if not full loaded return !data.pubkey || (!data.isMember && (!data.requirements || !data.requirements.pendingMembership) && @@ -705,10 +706,19 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser }, loadData = function(options) { + + if (options && options.minData) { + return loadMinData(options); + } + if (options || data.loaded) { return refreshData(options); } + return loadFullData(); + }, + + loadFullData = function() { data.loaded = false; return $q.all([ @@ -760,15 +770,13 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser }); }, - loadMinData = function() { - var options = { - parameters: !data.parameters, // do not load if already done - requirements: !data.requirements || angular.isUndefined(data.requirements.needSelf) - }; + loadMinData = function(options) { + options = options || {}; + options.parameters = angular.isDefined(options.parameters) ? options.parameters : !data.parameters; // do not load if already done + options.requirements = angular.isDefined(options.requirements) ? options.requirements : + (!data.requirements || angular.isUndefined(data.requirements.needSelf)); if (!options.parameters && !options.requirements) { - var deferred = $q.defer(); - deferred.resolve(data); - return deferred.promise; + return $q.when(data); } return refreshData(options); }, @@ -1495,7 +1503,6 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser isUserPubkey: isUserPubkey, getData: getData, loadData: loadData, - loadMinData: loadMinData, refreshData: refreshData, // operations transfer: transfer, diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js index f8b4801896672f92f2a203b4e8d208d06fc521d3..8f210b09c5874593b133838a67b71f2a6ea803e5 100644 --- a/www/js/services/wot-services.js +++ b/www/js/services/wot-services.js @@ -452,9 +452,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic var data = withCache ? identityCache.get(pubkey) : null; if (data && (!uid || data.uid == uid)) { console.debug("[wot] Found cached identity " + pubkey.substring(0, 8)); - var deferred = $q.defer(); - deferred.resolve(data); - return deferred.promise; + return $q.when(data); } console.debug("[wot] Loading identity " + pubkey.substring(0, 8)); @@ -555,7 +553,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic .catch(function(err) { console.debug('Error while loading identity data, on extension point.'); console.error(err); - }) + }); }) .then(function() { delete data.lookup; // not need anymore @@ -567,9 +565,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic search = function(text) { if (!text || text.trim() !== text) { - var deferred = $q.defer(); - deferred.resolve(); - return deferred.promise; + return $q.when(undefined); } return BMA.wot.lookup({ search: text }) diff --git a/www/plugins/es/i18n/locale-en.json b/www/plugins/es/i18n/locale-en.json index f4b97062c906354a7dc27393dd8a81cc6bb7d80c..16b0c05e74d48195d1b3c1e2583339678cac1944 100644 --- a/www/plugins/es/i18n/locale-en.json +++ b/www/plugins/es/i18n/locale-en.json @@ -83,6 +83,7 @@ "VIEW": { "TITLE": "Message", "SENDER": "Sent by", + "RECIPIENT": "Sent to", "NO_CONTENT": "Empty message" }, "CONFIRM": { @@ -135,7 +136,7 @@ "TITLE": "Ad", "MENU_TITLE": "Options", "POPOVER_SHARE_TITLE": "Ad {{title}}", - "REMOVE_CONFIRMATION" : "Are you sure you want to delete this ad ?<br/><br/> This is irreversible." + "REMOVE_CONFIRMATION" : "Are you sure you want to delete this ad?<br/><br/> This is irreversible." }, "TYPE": { "TITLE": "New ad", @@ -196,7 +197,7 @@ "LOCATION": "Address:", "MENU_TITLE": "Options", "POPOVER_SHARE_TITLE": "{{title}}", - "REMOVE_CONFIRMATION" : "Are you sure you want to delete this record ?<br/><br/>This is irreversible." + "REMOVE_CONFIRMATION" : "Are you sure you want to delete this record?<br/><br/>This is irreversible." }, "TYPE": { "TITLE": "New", @@ -254,7 +255,8 @@ "ERROR": { "LOAD_PROFILE_FAILED": "Could not load user profile.", "SAVE_PROFILE_FAILED": "Saving profile failed", - "INVALID_SOCIAL_NETWORK_FORMAT": "Invalid format: please fill a valid Internet address.<br/><br/>Examples :<ul><li>- A Facebook page (https://www.facebook.com/user)</li><li>- A web page (http://www.domain.com)</li><li>- An email address (joe@dalton.com)</li></ul>" + "INVALID_SOCIAL_NETWORK_FORMAT": "Invalid format: please fill a valid Internet address.<br/><br/>Examples :<ul><li>- A Facebook page (https://www.facebook.com/user)</li><li>- A web page (http://www.domain.com)</li><li>- An email address (joe@dalton.com)</li></ul>", + "IMAGE_RESIZE_FAILED": "Error while resizing picture" }, "INFO": { "PROFILE_SAVED": "Profile saved" @@ -280,11 +282,13 @@ "DIVIDER": "Notifications", "HELP_TEXT": "Enable the types of notifications you want to receive:", "ENABLE_TX_SENT": "Notify the validation of <b>sent payments</b>?", - "ENABLE_TX_RECEIVED": "Notify the validation of <b>received payments</b>?" + "ENABLE_TX_RECEIVED": "Notify the validation of <b>received payments</b>?", + "ENABLE_CERT_SENT": "Notify the validation of <b>sent certifications</b>?", + "ENABLE_CERT_RECEIVED": "Notify the validation des <b>received certifications</b>?" }, "CONFIRM": { "ASK_ENABLE_TITLE": "New features", - "ASK_ENABLE": "Some new features are available: <ul><li> <b><i class=\"icon ion-speakerphone\"></i> Ad</b>;<li> <b><i class=\"icon ion-ios-book\"></i> companies registry</b>;<li> <b><i class=\"icon ion-email\"></i> Private messages</b>.</ul><br/>There have been <b>disabled</b> in your settings.<br/><br/><b>Do you want to enable</b> this features (recommended) ?" + "ASK_ENABLE": "Some new features are available: <ul><li> <b><i class=\"icon ion-speakerphone\"></i> Ad</b>;<li> <b><i class=\"icon ion-ios-book\"></i> companies registry</b>;<li> <b><i class=\"icon ion-email\"></i> Private messages</b>.</ul><br/>There have been <b>disabled</b> in your settings.<br/><br/><b>Do you want to enable</b> this features (recommended)?" } }, "EVENT": { diff --git a/www/plugins/es/i18n/locale-fr-FR.json b/www/plugins/es/i18n/locale-fr-FR.json index 0f4342cb83d297a31a8d69b92164e002f4bfb3ba..ff63feb6083f236c85aaa87a0090e943f13d1d62 100644 --- a/www/plugins/es/i18n/locale-fr-FR.json +++ b/www/plugins/es/i18n/locale-fr-FR.json @@ -255,13 +255,14 @@ "ERROR": { "LOAD_PROFILE_FAILED": "Erreur de chargement du profil utilisateur.", "SAVE_PROFILE_FAILED": "Erreur lors de la sauvegarde", - "INVALID_SOCIAL_NETWORK_FORMAT": "Format non pris en compte : veuillez indiquer une adresse valide.<br/><br/>Exemples :<ul><li>- Une page Facebook (https://www.facebook.com/user)</li><li>- Une page web (http://www.monsite.fr)</li><li>- Une adresse email (joe@dalton.com)</li></ul>" + "INVALID_SOCIAL_NETWORK_FORMAT": "Format non pris en compte : veuillez indiquer une adresse valide.<br/><br/>Exemples :<ul><li>- Une page Facebook (https://www.facebook.com/user)</li><li>- Une page web (http://www.monsite.fr)</li><li>- Une adresse email (joe@dalton.com)</li></ul>", + "IMAGE_RESIZE_FAILED": "Erreur lors du redimensionnement de l'image" }, "INFO": { "PROFILE_SAVED": "Profil sauvegardé", }, "HELP": { - "WARNING_PUBLIC_DATA": "Veuillez noter que les informations publiées ici <b>sont publiques</b> : visibles y compris par des personnes <b>non connectées</b>." + "WARNING_PUBLIC_DATA": "Les informations renseignées dans votre profil <b>sont publiques</b> : visibles y compris par des personnes <b>non connectées</b>." } }, "ES_SETTINGS": { diff --git a/www/plugins/es/js/controllers/common-controllers.js b/www/plugins/es/js/controllers/common-controllers.js index 5a1e02b39c90ad92239cc717fb8441a643af6637..77b9adbec7058c4f9365ed7919a0b852f05464bf 100644 --- a/www/plugins/es/js/controllers/common-controllers.js +++ b/www/plugins/es/js/controllers/common-controllers.js @@ -194,7 +194,7 @@ function ESCommentsController($scope, $timeout, $filter, $state, $focus, UIUtils $scope.save = function() { if (!$scope.formData.message || !$scope.formData.message.length) return; - $scope.loadWallet({loadMinData: true}) + $scope.loadWallet({minData: true}) .then(function() { UIUtils.loading.hide(); var comment = $scope.formData; diff --git a/www/plugins/es/js/controllers/market-controllers.js b/www/plugins/es/js/controllers/market-controllers.js index fb270588eb78e63a31a23fc6c942af13cdbcf851..92d69e9657eaad629aa39bf2d1c4e9da9dd7098f 100644 --- a/www/plugins/es/js/controllers/market-controllers.js +++ b/www/plugins/es/js/controllers/market-controllers.js @@ -372,7 +372,7 @@ function ESMarketLookupController($scope, $state, $focus, $timeout, $filter, $q, }; $scope.showNewRecordModal = function() { - return $scope.loadWallet() + return $scope.loadWallet({minData: true}) .then(function() { return UIUtils.loading.hide(); }).then(function() { @@ -588,11 +588,10 @@ function ESMarketRecordViewController($scope, $anchorScroll, $ionicPopover, $sta }; } -function ESMarketRecordEditController($scope, esMarket, UIUtils, $state, $ionicPopover, - $timeout, ModalUtils, esHttp, $ionicHistory, $focus, csSettings, csCurrency) { +function ESMarketRecordEditController($scope, $q, $timeout, $state, $ionicPopover, esMarket, $ionicHistory, $focus, + UIUtils, ModalUtils, esHttp, csSettings, csCurrency) { 'ngInject'; - $scope.walletData = {}; $scope.formData = { price: null, category: {} @@ -606,30 +605,28 @@ function ESMarketRecordEditController($scope, esMarket, UIUtils, $state, $ionicP }; $scope.$on('$ionicView.enter', function(e, state) { - // Load currencies list - csCurrency.all() - .then(function(currencies){ - if (currencies.length == 1) { - $scope.currency = currencies[0].name; - } - // Load wallet - return $scope.loadWallet(); - }) - .then(function(walletData) { + // Load wallet + $scope.loadWallet({minData: true}) + .then(function() { $scope.useRelative = csSettings.data.useRelative; - $scope.walletData = walletData; if (state.stateParams && state.stateParams.id) { // Load by id $scope.load(state.stateParams.id); } else { - if (state.stateParams && state.stateParams.type) { // New record + // New record + if (state.stateParams && state.stateParams.type) { $scope.formData.type=state.stateParams.type; } - $scope.loading = false; - UIUtils.loading.hide(); - $timeout(function(){ - UIUtils.motion.ripple(); - }, 100); + // Set the default currency + csCurrency.default() + .then(function(currency){ + $scope.formData.currency = currency.name; + $scope.loading = false; + UIUtils.loading.hide(); + $timeout(function(){ + UIUtils.motion.ripple(); + }, 100); + }); } $focus('market-record-title'); }); @@ -653,7 +650,7 @@ function ESMarketRecordEditController($scope, esMarket, UIUtils, $state, $ionicP $scope.load = function(id) { return esMarket.record.load(id, {fetchPictures: true}) - .then(function (data) { + .then(function(data) { $scope.formData = data.record; $scope.id = data.id; $scope.pictures = data.record.pictures || []; diff --git a/www/plugins/es/js/controllers/message-controllers.js b/www/plugins/es/js/controllers/message-controllers.js index d170f331447d2599c5dffcfc99ae21c883a8065c..ce61c26d5c67d452b854b8ec95b2b01df30a313f 100644 --- a/www/plugins/es/js/controllers/message-controllers.js +++ b/www/plugins/es/js/controllers/message-controllers.js @@ -61,7 +61,7 @@ function ESMessageListController($scope, $rootScope, $state, $timeout, $translat $scope.$on('$ionicView.enter', function(e, state) { - $scope.loadWallet() + $scope.loadWallet({minData: true}) .then(function() { if (!$scope.entered) { $scope.entered = true; @@ -173,7 +173,7 @@ function ESMessageListController($scope, $rootScope, $state, $timeout, $translat /* -- Modals -- */ $scope.showNewMessageModal = function(parameters) { - return $scope.loadWallet() + return $scope.loadWallet({minData: true}) .then(function() { UIUtils.loading.hide(); return esModals.showMessageCompose(parameters) @@ -258,7 +258,7 @@ function ESMessageComposeController($scope, $ionicHistory, Modals, UIUtils, Cry } } - $scope.loadWallet() + $scope.loadWallet({minData: true}) .then(function() { UIUtils.loading.hide(); }) @@ -423,7 +423,7 @@ function ESMessageViewController($scope, $state, $timeout, $translate, $ionicHis $scope.load = function(id, type) { type = type || 'inbox'; - return $scope.loadWallet() + return $scope.loadWallet({minData: true}) .then(function() { return esMessage.get({type: type, id: id}); }) diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 9d9df692f22a52801e69b749fc72324912317ada..0d1802846cca607a5c215d946eda485a44fd8498 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -350,7 +350,7 @@ function ESRegistryLookupController($scope, $state, $focus, $timeout, esRegistry }; $scope.showNewRecordModal = function() { - $scope.loadWallet() + $scope.loadWallet({minData: true}) .then(function(walletData) { UIUtils.loading.hide(); $scope.walletData = walletData; @@ -560,7 +560,7 @@ function ESRegistryRecordEditController($scope, esRegistry, UIUtils, $state, $q, }; $scope.$on('$ionicView.enter', function(e, state) { - $scope.loadWallet() + $scope.loadWallet({minData: true}) .then(function(walletData) { $scope.walletData = walletData; if (state.stateParams && state.stateParams.id) { // Load by id @@ -660,7 +660,7 @@ function ESRegistryRecordEditController($scope, esRegistry, UIUtils, $state, $q, return esRegistry.record.add(json); } // Update - return esRegistry.record.update(json, {id: $scope.id}) + return esRegistry.record.update(json, {id: $scope.id}); }) .then(function(id) { diff --git a/www/plugins/es/js/controllers/user-controllers.js b/www/plugins/es/js/controllers/user-controllers.js index 580fce4e961e6c8827b00e6baff97dc28173be67..92cb73f0cfd9af93a1cd72369d6b2bfc319ad410 100644 --- a/www/plugins/es/js/controllers/user-controllers.js +++ b/www/plugins/es/js/controllers/user-controllers.js @@ -3,6 +3,7 @@ angular.module('cesium.es.user.controllers', ['cesium.es.services']) .config(function($stateProvider) { $stateProvider.state('app.user_edit_profile', { + cache: false, url: "/user/profile/edit", views: { 'menuContent': { @@ -18,10 +19,12 @@ angular.module('cesium.es.user.controllers', ['cesium.es.services']) ; -function ProfileController($scope, $rootScope, UIUtils, $timeout, esUser, $state, $focus, $q, SocialUtils, $translate, $ionicHistory) { +function ProfileController($scope, $rootScope, $timeout, $state, $focus, $translate, $ionicHistory, + esUser, SocialUtils, UIUtils, esHttp) { 'ngInject'; $scope.loading = true; + $scope.dirty = false; $scope.walletData = null; $scope.formData = { title: null, @@ -35,43 +38,79 @@ function ProfileController($scope, $rootScope, UIUtils, $timeout, esUser, $state }; $scope.$on('$ionicView.enter', function(e) { - $scope.loading = true; // to avoid the call of doSave() $scope.loadWallet() .then(function(walletData) { - esUser.profile.get({id: walletData.pubkey}) - .then(function(res) { - if (res && res.found && res._source) { - var profile = res._source; - $scope.avatar = profile.avatar ? UIUtils.image.fromAttachment(profile.avatar) : null; - profile.socials = profile.socials ? SocialUtils.reduce(profile.socials) : []; - $scope.existing = true; - $scope.updateView(walletData, profile); - } - UIUtils.loading.hide(); - $scope.loading = false; - }) - .catch(function(err){ - if (err && err.ucode == 404) { - $scope.updateView(walletData, {}); - UIUtils.loading.hide(); + return $scope.load(walletData); + }) + .catch(function(err){ + if (err == 'CANCELLED') { + return $scope.close() + .then(UIUtils.loading.hide); + } + UIUtils.onError('PROFILE.ERROR.LOAD_PROFILE_FAILED')(err); + }); + }); + + $scope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { + /*if ($scope.dirty && !$scope.saving) { + + // stop the change state action + event.preventDefault(); + + if (!$scope.loading) { + $scope.loading = true; + return UIUtils.alert.confirm('CONFIRM.SAVE_BEFORE_LEAVE', + 'CONFIRM.SAVE_BEFORE_LEAVE_TITLE', { + cancelText: 'COMMON.BTN_NO', + okText: 'COMMON.BTN_YES_SAVE' + }) + .then(function(confirmSave) { $scope.loading = false; - $scope.existing = false; - } - else { - UIUtils.onError('PROFILE.ERROR.LOAD_PROFILE_FAILED')(err); - } - }); + if (confirmSave) { + return $scope.save(); + } + }) + .then(function() { + $scope.dirty = false; + $ionicHistory.nextViewOptions({ + historyRoot: true + }); + $state.go(next.name, nextParams); + }); + } + }*/ + }); + + $scope.load = function(walletData) { + $scope.loading = true; // to avoid the call of doSave() + return esUser.profile.get({id: walletData.pubkey}) + .then(function(res) { + if (res && res.found && res._source) { + var profile = res._source; + $scope.avatar = profile.avatar ? esHttp.image.fromAttachment(profile.avatar) : null; + profile.socials = profile.socials ? SocialUtils.reduce(profile.socials) : []; + $scope.existing = true; + $scope.updateView(walletData, profile); + } + UIUtils.loading.hide(); + $scope.loading = false; // removeIf(device) $focus('profile-name'); // endRemoveIf(device) }) .catch(function(err){ - if (err === 'CANCELLED') { - $state.go('app.home'); + UIUtils.loading.hide(10); + if (err && err.ucode == 404) { + $scope.updateView(walletData, {}); + $scope.loading = false; + $scope.existing = false; + } + else { + UIUtils.onError('PROFILE.ERROR.LOAD_PROFILE_FAILED')(err); } }); - }); + }; $scope.setForm = function(form) { $scope.form = form; @@ -92,32 +131,25 @@ function ProfileController($scope, $rootScope, UIUtils, $timeout, esUser, $state }; $scope.onFormDataChanged = function() { - if (!$scope.loading && !$scope.saving) { - $scope.save(true); - } + if ($scope.loading) return; + $scope.dirty = true; }; $scope.$watch('formData', $scope.onFormDataChanged, true); $scope.fileChanged = function(event) { - UIUtils.loading.show(); - var file = event.target.files[0]; - return $q(function(resolve, reject) { - UIUtils.image.resizeFile(file, true) - .then(function(imageData) { - $scope.avatar = {src: imageData}; - $scope.avatarStyle={'background-image':'url("'+imageData+'")'}; - UIUtils.loading.hide(10); - resolve(); - }) - .catch(UIUtils.onError('Failed to resize image')); - }); + return UIUtils.loading.show() + .then(function() { + var file = event.target.files[0]; + return UIUtils.image.resizeFile(file, true); + }) + .then(function(imageData) { + $scope.avatar = {src: imageData}; + $scope.dirty = true; + return UIUtils.loading.hide(10); + }) + .catch(UIUtils.onError('PROFILE.ERROR.IMAGE_RESIZE_FAILED')); }; - $scope.submitAndSave = function() { - $scope.form.$submitted=true; - $scope.save(); - }; - $scope.save = function(silent) { if(!$scope.form.$valid || !$rootScope.walletData) { return; @@ -135,65 +167,87 @@ function ProfileController($scope, $rootScope, UIUtils, $timeout, esUser, $state var updateWallet = function(formData) { if (formData) { $scope.walletData.name = formData.title; - if (formData.avatar) { - $scope.walletData.avatar = formData.avatar; - $scope.walletData.avatarStyle = $scope.avatarStyle; + if ($scope.avatar) { + $scope.walletData.avatar = $scope.avatar; } else { delete $scope.walletData.avatar; - delete $scope.walletData.avatarStyle; } } }; var showSuccessToast = function() { if (!silent) { - $translate('PROFILE.INFO.PROFILE_SAVED') - .then(function(message){ - UIUtils.toast.show(message); - }); + return $translate('PROFILE.INFO.PROFILE_SAVED') + .then(function(message){ + UIUtils.toast.show(message); + }); } }; var doFinishSave = function(formData) { if (!$scope.existing) { - esUser.profile.add(formData) - .then(function() { - console.log("User profile successfully created."); - $scope.existing = true; - $scope.saving = false; - updateWallet(formData); - showSuccessToast(); - }) - .catch(onError('PROFILE.ERROR.SAVE_PROFILE_FAILED')); + return esUser.profile.add(formData) + .then(function() { + console.log("User profile successfully created."); + $scope.existing = true; + $scope.saving = false; + $scope.dirty = false; + updateWallet(formData); + showSuccessToast(); + }) + .catch(onError('PROFILE.ERROR.SAVE_PROFILE_FAILED')); } else { - esUser.profile.update(formData, {id: $rootScope.walletData.pubkey}) - .then(function() { - console.log("User profile successfully updated."); - $scope.saving = false; - updateWallet(formData); - showSuccessToast(); - }) - .catch(onError('PROFILE.ERROR.SAVE_PROFILE_FAILED')); + return esUser.profile.update(formData, {id: $rootScope.walletData.pubkey}) + .then(function() { + console.log("User profile successfully updated."); + $scope.saving = false; + $scope.dirty = false; + updateWallet(formData); + showSuccessToast(); + }) + .catch(onError('PROFILE.ERROR.SAVE_PROFILE_FAILED')); } }; if ($scope.avatar && $scope.avatar.src) { - UIUtils.image.resizeSrc($scope.avatar.src, true) // resize to thumbnail - .then(function(imageSrc) { - $scope.formData.avatar = esHttp.image.toAttachment({src: imageSrc}); - doFinishSave($scope.formData); - }); + return UIUtils.image.resizeSrc($scope.avatar.src, true) // resize to thumbnail + .then(function(imageSrc) { + $scope.formData.avatar = esHttp.image.toAttachment({src: imageSrc}); + doFinishSave($scope.formData); + }); } else { delete $scope.formData.avatar; - doFinishSave($scope.formData); + return doFinishSave($scope.formData); } }; + $scope.saveAndClose = function() { + $scope.save() + .then(function() { + $scope.close(); + }); + }; + + $scope.submitAndSaveAndClose = function() { + $scope.form.$submitted=true; + $scope.saveAndClose(); + }; + $scope.cancel = function() { - $ionicHistory.goBack(); + $scope.dirty = false; // force not saved + $scope.close(); + }; + + $scope.close = function() { + if ($ionicHistory.backView()) { + return $ionicHistory.goBack(); + } + else { + return $scope.showHome(); + } }; } diff --git a/www/plugins/es/js/controllers/wot-controllers.js b/www/plugins/es/js/controllers/wot-controllers.js index de681fe99847460d3e13d63db64e84975f8e9197..badaedd38df1986eb75ff16f1855781e040f34af 100644 --- a/www/plugins/es/js/controllers/wot-controllers.js +++ b/www/plugins/es/js/controllers/wot-controllers.js @@ -46,7 +46,7 @@ function ESWotIdentityViewController($scope, csSettings, PluginService, esModals /* -- modals -- */ $scope.showNewMessageModal = function() { - return $scope.loadWallet() + return $scope.loadWallet({minData: true}) .then(function() { UIUtils.loading.hide(); return esModals.showMessageCompose({ diff --git a/www/plugins/es/js/services/comment-services.js b/www/plugins/es/js/services/comment-services.js index 81845ac081d218858644773aa7055f1ad79f2ace..8c46b3f329c80a39e6dc6a750ac6b25fbae512a9 100644 --- a/www/plugins/es/js/services/comment-services.js +++ b/www/plugins/es/js/services/comment-services.js @@ -10,19 +10,25 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services fields = { commons: ["issuer", "time", "message", "reply_to"], }, - that, - pendings = {}; - searchRequest = esHttp.post(host, port, '/'+index+'/comment/_search'), - deleteRequest = esHttp.record.remove(host, port, index, 'comment'), - wsChanges = esHttp.ws('ws://' + esHttp.getServer(host, wsPort) + '/ws/_changes'); - - console.log("Creating JS comment service for index: " + index); + exports = { + index: index, + fields: { + commons: fields.commons + }, + raw: { + search: esHttp.post(host, port, '/'+index+'/comment/_search'), + remove: esHttp.record.remove(host, port, index, 'comment'), + wsChanges: esHttp.ws('ws://' + esHttp.getServer(host, wsPort) + '/ws/_changes'), + add: new esHttp.record.post(host, port, '/'+index+'/comment'), + update: new esHttp.record.post(host, port, '/'+index+'/comment/:id/_update') + } + }; - function refreshTreeLinks(data) { - return addTreeLinks(data, true); - } + exports.raw.refreshTreeLinks = function(data) { + return exports.raw.addTreeLinks(data, true); + }; - function addTreeLinks(data, refresh) { + exports.raw.addTreeLinks = function(data, refresh) { data = data || {}; data.result = data.result || []; data.mapById = data.mapById || {}; @@ -63,7 +69,7 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services }; console.debug("[ES] [comment] Getting missing comments in tree"); - return searchRequest(request) + return exports.raw.search(request) .then(function(res){ if (!res.hits.total) { console.error("[ES] [comment] Comments has invalid [reply_to]: " + _.values(incompleteCommentIdByParentIds).join(',')); @@ -80,11 +86,11 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services console.error("Comments has invalid [reply_to]: " + _.values(incompleteCommentIdByParentIds).join(',')); } - return addTreeLinks(data); // recursive call + return exports.raw.addTreeLinks(data); // recursive call }); - } + }; - function loadDataByRecordId(recordId, options) { + exports.raw.loadDataByRecordId = function(recordId, options) { options = options || {}; options.from = options.from || 0; options.size = options.size || DEFAULT_SIZE; @@ -111,7 +117,7 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services }; // Search comments - return searchRequest(request) + return exports.raw.search(request) .then(function(res){ if (!res.hits.total) return data; @@ -122,7 +128,7 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services }, data.result); // Add tree (parent/child) link - return addTreeLinks(data); + return exports.raw.addTreeLinks(data); }) // Fill avatars (and uid) @@ -141,10 +147,10 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services }); return data; }); - } + }; // Add listener to send deletion - function createOnDeleteListener(data) { + exports.raw.createOnDeleteListener = function(data) { return function(comment) { var index = _.findIndex(data.result, {id: comment.id}); if (index === -1) return; @@ -152,23 +158,23 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services delete data.mapById[comment.id]; // Send deletion request if (comment.issuer === csWallet.data.pubkey) { - deleteRequest(comment.id, csWallet.data.keypair) + exports.raw.remove(comment.id, csWallet.data.keypair) .catch(function(err){ console.error(err); throw new Error('MARKET.ERROR.FAILED_REMOVE_COMMENT'); }); } }; - } + }; - function startListenChanges(recordId, data) { + exports.raw.startListenChanges = function(recordId, data) { data = data || {}; data.result = data.result || []; data.mapById = data.mapById || {}; data.pendings = data.pendings || {}; // Add listener to send deletion - var onRemoveListener = createOnDeleteListener(data); + var onRemoveListener = exports.raw.createOnDeleteListener(data); _.forEach(data.result, function(comment) { comment.addOnRemoveListener(onRemoveListener); }); @@ -176,7 +182,7 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services // Open websocket var time = new Date().getTime(); console.info("[ES] [comment] Starting websocket to listen comments on [{0}/record/{1}]".format(index, recordId.substr(0,8))); - return wsChanges.open() + return exports.raw.wsChanges.open() // Define source filter .then(function(sock) { @@ -186,46 +192,40 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services // Listen changes .then(function(){ console.debug("[ES] [comment] Websocket opened in {0} ms".format(new Date().getTime() - time)); - wsChanges.on(function(change) { + exports.raw.wsChanges.on(function(change) { if (!change) return; - if (change._operation === 'DELETE') { - var comment = data.mapById[change._id]; - if (comment) { - $rootScope.$apply(function() { - comment.remove(); - }); - } + var comment = data.mapById[change._id]; + if (comment && change._operation === 'DELETE') { + $rootScope.$apply(comment.remove); } else if (change._source && change._source.record === recordId) { - console.debug("Received new: " + change._id); - var comment = data.mapById[change._id]; - if (!comment) { // new comment - // Check if not in pending comment - if (data.pendings && data.pendings[change._source.time] && change._source.issuer === csWallet.data.pubkey) { - console.debug("Skip comment received by WS (already in pending)"); - return; - } + // update + if (comment) { + comment.copyFromJson(change._source); + exports.raw.refreshTreeLinks(data); + } + // create (if not in pending comment) + else if (data.pendings && data.pendings[change._source.time] && change._source.issuer === csWallet.data.pubkey) { comment = new Comment(change._id, change._source); comment.addOnRemoveListener(onRemoveListener); comment.isnew = true; data.mapById[change._id] = comment; - refreshTreeLinks(data) + exports.raw.refreshTreeLinks(data) // fill avatars (and uid) .then(function() { return esUser.profile.fillAvatars([comment], 'issuer'); }) .then(function() { data.result.push(comment); - }) + }); } else { - comment.copyFromJson(change._source); - refreshTreeLinks(data); + console.debug("Skip comment received by WS (already in pending)"); } } - }) + }); }); - } + }; /** * Save a comment (add or update) @@ -234,14 +234,16 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services * @param comment * @returns {*} */ - function save(recordId, data, comment) { + exports.raw.save = function(recordId, data, comment) { data = data || {}; data.result = data.result || []; data.mapById = data.mapById || {}; data.pendings = data.pendings || {}; + // Preparing JSON to sent + var id = comment.id; var json = { - time: comment.time, + time: id ? comment.time : esHttp.date.now(), message: comment.message, record: recordId, issuer: csWallet.data.pubkey @@ -253,69 +255,63 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.bma.services json.reply_to = null; // force to null because ES ignore missing field, when updating } - if (!comment.id) { - json.time = esHttp.date.now(); - - data.pendings = data.pendings || {}; - data.pendings[json.time] = json; - - var commentObj = new Comment(null, json); - commentObj.addOnRemoveListener(createOnDeleteListener(data)); + // Create or update the entity + var entity; + if (!id) { + entity = new Comment(null, json); + entity.addOnRemoveListener(exports.raw.createOnDeleteListener(data)); // copy additional wallet data - commentObj.uid = csWallet.data.uid; - commentObj.name = csWallet.data.name; - commentObj.avatar = csWallet.data.avatar; + entity.uid = csWallet.data.uid; + entity.name = csWallet.data.name; + entity.avatar = csWallet.data.avatar; - commentObj.isnew = true; + entity.isnew = true; if (comment.parent) { - comment.parent.addReply(commentObj); + comment.parent.addReply(entity); } - data.result.push(commentObj); + data.result.push(entity); + } + else { + entity = data.mapById[id]; + entity.copy(comment); + } + + // Send add request + if (!id) { + data.pendings = data.pendings || {}; + data.pendings[json.time] = json; - return that.raw.add(json) - .then(function(id) { - commentObj.id = id; - data.mapById[id] = commentObj; + return exports.raw.add(json) + .then(function (id) { + entity.id = id; + data.mapById[id] = entity; delete data.pendings[json.time]; - return commentObj; + return entity; }); } - // Update + // Send update request else { - var commentObj = data.mapById[comment.id]; - commentObj.copy(comment); - return that.raw.update(json, {id: comment.id}); + return exports.raw.update(json, {id: id}); } - } + }; - function stopListenChanges(data) { + exports.raw.stopListenChanges = function(data) { console.debug("[ES] [comment] Stopping websocket on comments"); _.forEach(data.result, function(comment) { comment.cleanAllListeners(); }); // Close previous - wsChanges.close(); - } - - that = { - id: index, - search: searchRequest, - load: loadDataByRecordId, - save: save, - remove: deleteRequest, - raw: { - add: new esHttp.record.post(host, port, '/'+index+'/comment'), - update: new esHttp.record.post(host, port, '/'+index+'/comment/:id/_update') - }, - changes: { - start: startListenChanges, - stop: stopListenChanges - }, - fields: { - commons: fields.commons - } + exports.raw.wsChanges.close(); + }; + + // Expose functions + exports.load = exports.raw.loadDataByRecordId; + exports.save = exports.raw.save; + exports.changes = { + start: exports.raw.startListenChanges, + stop: exports.raw.stopListenChanges }; - return that; + return exports; } return { diff --git a/www/plugins/es/js/services/market-services.js b/www/plugins/es/js/services/market-services.js index 7ad79499e99006c3bd891d73fbfef11ff79e38d2..3d5b64bd34009485d9c5adbf1f164cc0a67229fd 100644 --- a/www/plugins/es/js/services/market-services.js +++ b/www/plugins/es/js/services/market-services.js @@ -154,7 +154,7 @@ angular.module('cesium.es.market.services', ['ngResource', 'cesium.services', 'c .then(function(res) { var categories = res[0]; var currentUD = res[1]; - var res = res[2]; + res = res[2]; if (!res || !res.hits || !res.hits.total) { return []; @@ -204,8 +204,18 @@ angular.module('cesium.es.market.services', ['ngResource', 'cesium.services', 'c issuer: idties[0], record: record }; + + // Make sure currency if present (fix old data) + if (!record.currency) { + return csCurrency.default() + .then(function (currency) { + record.currency = currency.name; + return data; + }); + } + return data; - }) + }); }); } diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index bf38064a9383483f2e75e3a530660b511f5e723e..ede5da1d7558f5daf8bfe3e91abe696f14e918fc 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -173,7 +173,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' function loadMessageNotifications(options) { if (!csWallet.isLogin()) { - return $timeout(function(){return []}); + return $q.when([]); } options = options || {}; options.from = options.from || 0; @@ -211,7 +211,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' function searchMessages(options) { if (!csWallet.isLogin()) { - return $timeout(function(){return []}); + return $q.when([]); } options = options || {}; @@ -256,7 +256,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' function loadMessages(keypair, options) { if (!csWallet.isLogin()) { - return $timeout(function(){return []}); + return $q.when([]); } options = options || {}; @@ -268,7 +268,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' // Encrypt content .then(function(messages) { - return decryptMessages(messages, keypair, options.type) + return decryptMessages(messages, keypair, options.type); }) // Add avatar @@ -407,7 +407,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' // Send read request .then(function(signature){ - return esHttp.post(host, port, '/message/inbox/:id/_read')(signature, {id:message.id}) + return esHttp.post(host, port, '/message/inbox/:id/_read')(signature, {id:message.id}); }) // Update message count @@ -437,7 +437,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' CryptoUtils.sign(message.hash, csWallet.data.keypair) // then send read request .then(function(signature){ - return esHttp.post(host, port, '/message/inbox/:id/_read')(signature, {id:message.id}) + return esHttp.post(host, port, '/message/inbox/:id/_read')(signature, {id:message.id}); })); }, [])); }) diff --git a/www/plugins/es/js/services/notification-services.js b/www/plugins/es/js/services/notification-services.js index 966f5c93b259323cd99d539b804eeb899ef76d72..613081f81e55ca917759a5b2fad853af551618b3 100644 --- a/www/plugins/es/js/services/notification-services.js +++ b/www/plugins/es/js/services/notification-services.js @@ -104,7 +104,7 @@ angular.module('cesium.es.notification.services', ['cesium.services', 'cesium.es var notifications = res.hits.hits.reduce(function(res, hit) { var item = new Notification(hit._source, markNotificationAsRead); item.id = hit._id; - return res.concat(item) + return res.concat(item); }, []); return esUser.profile.fillAvatars(notifications); @@ -142,7 +142,7 @@ angular.module('cesium.es.notification.services', ['cesium.services', 'cesium.es notification.read = true; CryptoUtils.sign(notification.hash, csWallet.data.keypair) .then(function(signature){ - return esHttp.post(host, port, '/user/event/:id/_read')(signature, {id:notification.id}) + return esHttp.post(host, port, '/user/event/:id/_read')(signature, {id:notification.id}); }) .catch(function(err) { console.error('Error while trying to mark event as read:' + (err.message ? err.message : err)); diff --git a/www/plugins/es/js/services/registry-services.js b/www/plugins/es/js/services/registry-services.js index d3c5027e3b44a58990338f46ce38361351207864..1986b9e8902509c29fa68247fc3eaf012f64bdbe 100644 --- a/www/plugins/es/js/services/registry-services.js +++ b/www/plugins/es/js/services/registry-services.js @@ -129,7 +129,7 @@ angular.module('cesium.es.registry.services', ['ngResource', 'cesium.services', ]) .then(function(res) { var categories = res[0]; - var res = res[1]; + res = res[1]; if (!res || !res.hits || !res.hits.total) { return []; @@ -170,7 +170,7 @@ angular.module('cesium.es.registry.services', ['ngResource', 'cesium.services', record: record }; return data; - }) + }); }); } diff --git a/www/plugins/es/js/services/user-services.js b/www/plugins/es/js/services/user-services.js index 1152cc3aaf4d39b17a8980acc73c6cf22c3e6c37..333048e7b51af9be7e083a77874c599322bfb842 100644 --- a/www/plugins/es/js/services/user-services.js +++ b/www/plugins/es/js/services/user-services.js @@ -15,7 +15,7 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se function factory(id, host, port, wsPort) { - const + var CONSTANTS = { contentTypeImagePrefix: "image/" }, @@ -166,7 +166,7 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se .then(function(json) { var settings = JSON.parse(json || '{}'); settings.time = record.time; - return settings + return settings; }); }) .catch(function(err){ @@ -460,13 +460,12 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se .catch(function(err) { console.error(err); deferred.resolve(); // silent - }) + }); } function removeListeners() { console.debug("[ES] [user] Disable"); - _.forEach(listeners, function(remove){ remove(); }); diff --git a/www/plugins/es/templates/market/edit_record.html b/www/plugins/es/templates/market/edit_record.html index 6121f64eae388a1930b4e8b5774ece3f75033965..6e54f2742d00f1dc5c7a5ac7a8f7e4f6d631b158 100644 --- a/www/plugins/es/templates/market/edit_record.html +++ b/www/plugins/es/templates/market/edit_record.html @@ -94,15 +94,15 @@ > <div class="input-label" ng-class="{'has-input': formData.price != undefined || form.price.$invalid}">{{'MARKET.EDIT.RECORD_PRICE' | translate}} - <ng-if ng-if="useRelative">({{'COMMON.UD' | translate}}<sub>{{currency | abbreviate}}</sub>)</ng-if> - <ng-if ng-if="!useRelative">({{currency | abbreviate}})</ng-if> + <ng-if ng-if="useRelative">({{'COMMON.UD' | translate}}<sub>{{formData.currency | abbreviate}}</sub>)</ng-if> + <ng-if ng-if="!useRelative">({{formData.currency | abbreviate}})</ng-if> </div> <input ng-if="!useRelative" - type="number" name="price" placeholder="{{'MARKET.EDIT.RECORD_PRICE_HELP' | translate}} ({{currency | abbreviate}})" + type="number" name="price" placeholder="{{'MARKET.EDIT.RECORD_PRICE_HELP' | translate}} ({{formData.currency | abbreviate}})" ng-model="formData.price" number-int> <input ng-if="useRelative" - type="number" name="price" placeholder="{{'MARKET.EDIT.RECORD_PRICE_HELP' | translate}} ({{'COMMON.UD' | translate}} {{currency | abbreviate}})" + type="number" name="price" placeholder="{{'MARKET.EDIT.RECORD_PRICE_HELP' | translate}} ({{'COMMON.UD' | translate}} {{formData.currency | abbreviate}})" ng-model="formData.price" number-float> <span class="gray button button-block icon ion-arrow-swap hidden-xs hidden-sm" ng-click="unitPopover.show($event)"> @@ -126,7 +126,7 @@ ng-show="formData.price" ng-click="openCurrencyLookup()" > <span class="item-label gray" translate>MARKET.EDIT.RECORD_CURRENCY</span> - <span class="badge badge-royal">{{currency}}</span> + <span class="badge badge-royal">{{formData.currency}}</span> <i class="gray icon ion-ios-arrow-right"></i> </dev--> diff --git a/www/plugins/es/templates/user/edit_profile.html b/www/plugins/es/templates/user/edit_profile.html index 029b15e4c1b0c2b1cd668a4214a8aaa7cbc0ceb3..85ab1c3b357dab0ee0cda8ccb552c4ea5493e17c 100644 --- a/www/plugins/es/templates/user/edit_profile.html +++ b/www/plugins/es/templates/user/edit_profile.html @@ -4,7 +4,7 @@ </ion-nav-title> <ion-nav-buttons side="secondary"> - <button class="button button-icon button-clear ion-android-done visible-xs visible-sm" ng-click="submitAndSave()"> + <button class="button button-icon button-clear ion-android-done visible-xs visible-sm" ng-click="submitAndSaveAndClose()"> </button> </ion-nav-buttons> @@ -13,8 +13,8 @@ <div class="positive-900-bg hero"> <div class="content"> <i class="avatar" - ng-style="avatarStyle" - ng-class="{'avatar-wallet': !loading && !avatarStyle && walletData && !walletData.isMember, 'avatar-member': !loading && !avatarStyle && walletData.isMember}"> + style="background-image: url('{{avatar.src}}')" + ng-class="{'avatar-wallet': !loading && !avatar && walletData && !walletData.isMember, 'avatar-member': !loading && !avatar && walletData.isMember}"> <button class="button button-positive button-avatar button-large button-clear flat icon ion-camera hidden-no-device" ng-click="openPicturePopup()"></button> <button class="button button-positive button-avatar button-large button-clear flat icon ion-camera hidden-device" onclick="angular.element(document.querySelector('form #avatarFile'))[0].click();"></button> @@ -39,7 +39,7 @@ </div> <div class="col"> - <form name="profileForm" novalidate="" ng-submit="save()"> + <form name="profileForm" novalidate="" ng-submit="saveAndClose()"> <input type="file" id="avatarFile" accept=".png,.jpeg,.jpg" onchange="angular.element(this).scope().fileChanged(event)" style="visibility:hidden; position:absolute;"/> diff --git a/www/templates/common/popover_profile.html b/www/templates/common/popover_profile.html index 4c0509b861f1db01631ae72fbcd206b9c7750a71..cfa07bc1e4f208652b4a88a8f5c760954e3315d3 100644 --- a/www/templates/common/popover_profile.html +++ b/www/templates/common/popover_profile.html @@ -3,7 +3,7 @@ <div class="row"> <div class="col col-33"> <i class="avatar avatar-member" ng-if="!$root.walletData.avatar" ng-class="{'royal-bg': login, 'stable-bg': !login}"></i> - <i class="avatar" ng-if="$root.walletData.avatar" style="background-image: url({{$root.walletData.avatar.src}})"></i> + <i class="avatar" ng-if="$root.walletData.avatar" style="background-image: url('{{$root.walletData.avatar.src}}')"></i> </div> <div class="col col-66" ng-if="login"> <h4>{{$root.walletData.name||$root.walletData.uid}}</h4> diff --git a/www/templates/wot/view_identity.html b/www/templates/wot/view_identity.html index 9af975cf8dcee9409c4fbda3f60db65088347109..879edb154052148dc1b07d2b493a155086e8fad1 100644 --- a/www/templates/wot/view_identity.html +++ b/www/templates/wot/view_identity.html @@ -52,7 +52,7 @@ <a id="helptip-wot-view-certifications" class="item item-icon-left item-text-wrap item-icon-right ink" ng-if="formData.hasSelf" - ui-sref="app.wot_view_cert({pubkey: formData.pubkey, uid: formData.name || formData.uid})"> + ng-click="showCertifications()"> <i class="icon ion-ribbon-b"></i> <span translate>ACCOUNT.CERTIFICATION_COUNT</span> <span id="helptip-wot-view-certifications-count"