From be608d1c5abf6fd90dbd12f479ae5d7ee408abec Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 26 Mar 2014 10:47:01 +0400 Subject: [PATCH] New error modals --- app/css/app.css | 6 ++-- app/js/controllers.js | 17 +++++------ app/js/filters.js | 3 +- app/js/lib/mtproto.js | 35 +++++++++++++++-------- app/js/services.js | 18 ++++++------ app/partials/error_modal.html | 54 ++++++++++++++++++++++++++++++++--- app/partials/login.html | 2 +- 7 files changed, 95 insertions(+), 40 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 42c61ad8..76106efd 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -2031,11 +2031,13 @@ img.img_fullsize { .error_modal_window .modal-dialog { - max-width: 400px; + max-width: 350px; } .error_modal_description { text-align: center; - padding: 40px 20px; + padding: 20px 20px; + font-size: 14px; + line-height: 160%; } diff --git a/app/js/controllers.js b/app/js/controllers.js index 2274e4b7..de5c2849 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -28,7 +28,7 @@ angular.module('myApp.controllers', []) return; } }); - var options = {dcID: 1}; + var options = {dcID: 1, createNetworker: true}; $scope.credentials = {}; $scope.progress = {}; @@ -69,7 +69,10 @@ angular.module('myApp.controllers', []) }, options).then(function (result) { $scope.progress.enabled = false; if (!result.phone_registered) { - ErrorService.showSimpleError('No account', 'Sorry, there is no Telegram account for ' + $scope.credentials.phone_number + '. Please sign up using our mobile apps.'); + ErrorService.show({ + error: {code: 400, type: 'ACCOUNT_REQUIRED'}, + phone: $scope.credentials.phone_number + }); return false; } @@ -106,7 +109,7 @@ angular.module('myApp.controllers', []) break; default: - ErrorService.showSimpleError('Unknown error occured', 'Please check your internet connection or install the latest version of Google Chrome browser.'); + ErrorService.alert('Unknown error occured', 'Please check your internet connection or install the latest version of Google Chrome browser.'); } }); } @@ -1050,7 +1053,7 @@ angular.module('myApp.controllers', []) }, function (error) { switch (error.code) { case 400: - ErrorService.showSimpleError('Bad photo', 'The photo is invalid, please select another file.'); + ErrorService.alert('Bad photo', 'The photo is invalid, please select another file.'); break; } }); @@ -1128,12 +1131,6 @@ angular.module('myApp.controllers', []) }); $scope.profile.photo = AppUsersManager.getUserPhoto(id, 'User'); }); - }, function (error) { - switch (error.code) { - case 400: - ErrorService.showSimpleError('Bad photo', 'The photo is invalid, please select another file.'); - break; - } }); })['finally'](function () { $scope.photo.updating = false; diff --git a/app/js/filters.js b/app/js/filters.js index b45f7bf8..25ed89b7 100644 --- a/app/js/filters.js +++ b/app/js/filters.js @@ -89,9 +89,10 @@ angular.module('myApp.filters', []) .filter('phoneNumber', [function() { return function (phoneRaw) { + var nbsp = ' '; phoneRaw = (phoneRaw || '').replace(/\D/g, ''); if (phoneRaw.charAt(0) == '7' && phoneRaw.length == 11) { - return '+' + phoneRaw.charAt(0) + ' (' + phoneRaw.substr(1, 3) + ') ' + phoneRaw.substr(4, 3) + '-' + phoneRaw.substr(7, 2) + '-' + phoneRaw.substr(9, 2); + return '+' + phoneRaw.charAt(0) + nbsp + '(' + phoneRaw.substr(1, 3) + ')' + nbsp + phoneRaw.substr(4, 3) + '-' + phoneRaw.substr(7, 2) + '-' + phoneRaw.substr(9, 2); } return '+' + phoneRaw; } diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index b4a7d716..3a640a8e 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -1525,7 +1525,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato this.serverSalt = serverSalt; - this.upload = options.upload || false; + this.upload = options.fileUpload || options.fileDownload || false; this.updateSession(); @@ -2356,8 +2356,12 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker }); } - function mtpGetNetworker (dcID, upload) { - var cache = upload ? cachedUploadNetworkers : cachedNetworkers; + function mtpGetNetworker (dcID, options) { + options = options || {}; + + var cache = (options.fileUpload || options.fileDownload) + ? cachedUploadNetworkers + : cachedNetworkers; if (!dcID) { throw new Exception('get Networker without dcID'); } @@ -2382,7 +2386,11 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker var authKey = bytesFromHex(authKeyHex); var serverSalt = bytesFromHex(serverSaltHex); - return cache[dcID] = MtpNetworkerFactory.getNetworker(dcID, authKey, serverSalt, {upload: upload}); + return cache[dcID] = MtpNetworkerFactory.getNetworker(dcID, authKey, serverSalt, options); + } + + if (!options.createNetworker) { + return $q.reject({type: 'AUTH_KEY_EMPTY', code: 500}); } return MtpAuthorizer.auth(dcID).then(function (auth) { @@ -2391,7 +2399,7 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker storeObj[ssk] = bytesToHex(auth.serverSalt); AppConfigManager.set(storeObj); - return cache[dcID] = MtpNetworkerFactory.getNetworker(dcID, auth.authKey, auth.serverSalt, {upload: upload}); + return cache[dcID] = MtpNetworkerFactory.getNetworker(dcID, auth.authKey, auth.serverSalt, options); }, function (error) { console.log('Get networker error', error, error.stack); return $q.reject(error); @@ -2404,14 +2412,13 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker var deferred = $q.defer(), dcID, - upload = options.fileDownload || options.fileUpload, networkerPromise; if (dcID = options.dcID) { - networkerPromise = mtpGetNetworker(dcID, upload); + networkerPromise = mtpGetNetworker(dcID, options); } else { networkerPromise = AppConfigManager.get('dc').then(function (baseDcID) { - return mtpGetNetworker(dcID = baseDcID || 1, upload); + return mtpGetNetworker(dcID = baseDcID || 1, options); }); } @@ -2697,7 +2704,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { limit: 0 }, { dcID: location.dc_id, - fileDownload: true + fileDownload: true, + createNetworker: true }); }); @@ -2734,7 +2742,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { limit: 0 }, { dcID: location.dc_id, - fileDownload: true + fileDownload: true, + createNetworker: true }); }).then(function (result) { deferred.resolve(cachedDownloads[fileName] = 'data:image/jpeg;base64,' + bytesToBase64(result.bytes)) @@ -2784,7 +2793,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { limit: limit }, { dcID: dcID, - fileDownload: true + fileDownload: true, + createNetworker: true }); }, 6).then(function (result) { @@ -2855,7 +2865,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { limit: limit }, { dcID: dcID, - fileDownload: true + fileDownload: true, + createNetworker: true }); }, 6).then(function (result) { writeBlobPromise.then(function () { diff --git a/app/js/services.js b/app/js/services.js index a952dcb4..a77e8547 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -2964,30 +2964,28 @@ angular.module('myApp.services', []) .service('ErrorService', function ($rootScope, $modal) { - function showError (templateUrl, params, options) { + function show (params, options) { + options = options || {}; var scope = $rootScope.$new(); angular.extend(scope, params); return $modal.open({ - templateUrl: templateUrl, - // controller: 'ErrorModalController', + templateUrl: 'partials/error_modal.html', scope: scope, - windowClass: options.windowClass || '' + windowClass: options.windowClass || 'error_modal_window' }); } - function showSimpleError (title, description) { - return showError ('partials/error_modal.html', { + function alert (title, description) { + return show ({ title: title, description: description - }, { - windowClass: 'error_modal_window' }); }; return { - showError: showError, - showSimpleError: showSimpleError + show: show, + alert: alert } }) diff --git a/app/partials/error_modal.html b/app/partials/error_modal.html index ee906606..f492053c 100644 --- a/app/partials/error_modal.html +++ b/app/partials/error_modal.html @@ -2,16 +2,62 @@ - \ No newline at end of file diff --git a/app/partials/login.html b/app/partials/login.html index 6743857f..68981645 100644 --- a/app/partials/login.html +++ b/app/partials/login.html @@ -17,7 +17,7 @@
- +