Browse Source

New error modals

master
Igor Zhukov 11 years ago
parent
commit
be608d1c5a
  1. 6
      app/css/app.css
  2. 17
      app/js/controllers.js
  3. 3
      app/js/filters.js
  4. 35
      app/js/lib/mtproto.js
  5. 18
      app/js/services.js
  6. 54
      app/partials/error_modal.html
  7. 2
      app/partials/login.html

6
app/css/app.css

@ -2031,11 +2031,13 @@ img.img_fullsize {
.error_modal_window .modal-dialog { .error_modal_window .modal-dialog {
max-width: 400px; max-width: 350px;
} }
.error_modal_description { .error_modal_description {
text-align: center; text-align: center;
padding: 40px 20px; padding: 20px 20px;
font-size: 14px;
line-height: 160%;
} }

17
app/js/controllers.js

@ -28,7 +28,7 @@ angular.module('myApp.controllers', [])
return; return;
} }
}); });
var options = {dcID: 1}; var options = {dcID: 1, createNetworker: true};
$scope.credentials = {}; $scope.credentials = {};
$scope.progress = {}; $scope.progress = {};
@ -69,7 +69,10 @@ angular.module('myApp.controllers', [])
}, options).then(function (result) { }, options).then(function (result) {
$scope.progress.enabled = false; $scope.progress.enabled = false;
if (!result.phone_registered) { 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; return false;
} }
@ -106,7 +109,7 @@ angular.module('myApp.controllers', [])
break; break;
default: 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) { }, function (error) {
switch (error.code) { switch (error.code) {
case 400: 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; break;
} }
}); });
@ -1128,12 +1131,6 @@ angular.module('myApp.controllers', [])
}); });
$scope.profile.photo = AppUsersManager.getUserPhoto(id, 'User'); $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 () { })['finally'](function () {
$scope.photo.updating = false; $scope.photo.updating = false;

3
app/js/filters.js

@ -89,9 +89,10 @@ angular.module('myApp.filters', [])
.filter('phoneNumber', [function() { .filter('phoneNumber', [function() {
return function (phoneRaw) { return function (phoneRaw) {
var nbsp = ' ';
phoneRaw = (phoneRaw || '').replace(/\D/g, ''); phoneRaw = (phoneRaw || '').replace(/\D/g, '');
if (phoneRaw.charAt(0) == '7' && phoneRaw.length == 11) { 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; return '+' + phoneRaw;
} }

35
app/js/lib/mtproto.js

@ -1525,7 +1525,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
this.serverSalt = serverSalt; this.serverSalt = serverSalt;
this.upload = options.upload || false; this.upload = options.fileUpload || options.fileDownload || false;
this.updateSession(); this.updateSession();
@ -2356,8 +2356,12 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
}); });
} }
function mtpGetNetworker (dcID, upload) { function mtpGetNetworker (dcID, options) {
var cache = upload ? cachedUploadNetworkers : cachedNetworkers; options = options || {};
var cache = (options.fileUpload || options.fileDownload)
? cachedUploadNetworkers
: cachedNetworkers;
if (!dcID) { if (!dcID) {
throw new Exception('get Networker without dcID'); throw new Exception('get Networker without dcID');
} }
@ -2382,7 +2386,11 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
var authKey = bytesFromHex(authKeyHex); var authKey = bytesFromHex(authKeyHex);
var serverSalt = bytesFromHex(serverSaltHex); 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) { return MtpAuthorizer.auth(dcID).then(function (auth) {
@ -2391,7 +2399,7 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
storeObj[ssk] = bytesToHex(auth.serverSalt); storeObj[ssk] = bytesToHex(auth.serverSalt);
AppConfigManager.set(storeObj); 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) { }, function (error) {
console.log('Get networker error', error, error.stack); console.log('Get networker error', error, error.stack);
return $q.reject(error); return $q.reject(error);
@ -2404,14 +2412,13 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
var deferred = $q.defer(), var deferred = $q.defer(),
dcID, dcID,
upload = options.fileDownload || options.fileUpload,
networkerPromise; networkerPromise;
if (dcID = options.dcID) { if (dcID = options.dcID) {
networkerPromise = mtpGetNetworker(dcID, upload); networkerPromise = mtpGetNetworker(dcID, options);
} else { } else {
networkerPromise = AppConfigManager.get('dc').then(function (baseDcID) { 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 limit: 0
}, { }, {
dcID: location.dc_id, dcID: location.dc_id,
fileDownload: true fileDownload: true,
createNetworker: true
}); });
}); });
@ -2734,7 +2742,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit: 0 limit: 0
}, { }, {
dcID: location.dc_id, dcID: location.dc_id,
fileDownload: true fileDownload: true,
createNetworker: true
}); });
}).then(function (result) { }).then(function (result) {
deferred.resolve(cachedDownloads[fileName] = 'data:image/jpeg;base64,' + bytesToBase64(result.bytes)) deferred.resolve(cachedDownloads[fileName] = 'data:image/jpeg;base64,' + bytesToBase64(result.bytes))
@ -2784,7 +2793,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit: limit limit: limit
}, { }, {
dcID: dcID, dcID: dcID,
fileDownload: true fileDownload: true,
createNetworker: true
}); });
}, 6).then(function (result) { }, 6).then(function (result) {
@ -2855,7 +2865,8 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) {
limit: limit limit: limit
}, { }, {
dcID: dcID, dcID: dcID,
fileDownload: true fileDownload: true,
createNetworker: true
}); });
}, 6).then(function (result) { }, 6).then(function (result) {
writeBlobPromise.then(function () { writeBlobPromise.then(function () {

18
app/js/services.js

@ -2964,30 +2964,28 @@ angular.module('myApp.services', [])
.service('ErrorService', function ($rootScope, $modal) { .service('ErrorService', function ($rootScope, $modal) {
function showError (templateUrl, params, options) { function show (params, options) {
options = options || {};
var scope = $rootScope.$new(); var scope = $rootScope.$new();
angular.extend(scope, params); angular.extend(scope, params);
return $modal.open({ return $modal.open({
templateUrl: templateUrl, templateUrl: 'partials/error_modal.html',
// controller: 'ErrorModalController',
scope: scope, scope: scope,
windowClass: options.windowClass || '' windowClass: options.windowClass || 'error_modal_window'
}); });
} }
function showSimpleError (title, description) { function alert (title, description) {
return showError ('partials/error_modal.html', { return show ({
title: title, title: title,
description: description description: description
}, {
windowClass: 'error_modal_window'
}); });
}; };
return { return {
showError: showError, show: show,
showSimpleError: showSimpleError alert: alert
} }
}) })

54
app/partials/error_modal.html

@ -2,16 +2,62 @@
<div class="modal-header"> <div class="modal-header">
<a class="modal-close-link" ng-click="$close()">Close</a> <a class="modal-close-link" ng-click="$close()">Close</a>
<h4 class="modal-title">{{title}}</h4> <h4 ng-if="error" class="modal-title" ng-switch="error.type">
<span ng-switch-when="ACCOUNT_REQUIRED">No account</span>
<span ng-switch-default ng-switch="error.code">
<span ng-switch-when="400">Error</span>
<span ng-switch-when="401">Unauthorized</span>
<span ng-switch-when="403">Access denied</span>
<span ng-switch-when="404">Not found</span>
<span ng-switch-when="420">Too fast</span>
<span ng-switch-default>Server error</span>
</span>
</h4>
<h4 ng-if="!error" class="modal-title" ng-bind="title || 'Alert'"></h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="error_modal_description"> <div ng-if="error" class="error_modal_description" ng-switch="error.type">
{{description}} <span ng-switch-when="FIRSTNAME_INVALID">
The first name you entered is invalid.
</span>
<span ng-switch-when="LASTNAME_INVALID">
The last name you entered is invalid.
</span>
<span ng-switch-when="PHONE_NUMBER_INVALID">
The phone number you entered is invalid.
</span>
<span ng-switch-when="USERS_TOO_MUCH">
You have selected too much users.
</span>
<span ng-switch-when="PHOTO_INVALID_DIMENSIONS">
The photo dimensions are invalid, please select another file.
</span>
<span ng-switch-when="ACCOUNT_REQUIRED">
Sorry, there is no <strong>Telegram</strong> account for {{phone | phoneNumber}}<br/><br/>
Please <strong>sign up</strong> using our mobile apps for <a href="https://telegram.org/" target="_blank">iOS</a> or <a href="https://telegram.org/" target="_blank">Android</a>.
</span>
<div ng-switch-default ng-switch="error.code">
<span ng-switch-when="400">One of the params is missing or invalid.</span>
<span ng-switch-when="401">This action requires authorization access. Please <a href="#/auth">log in</a>.</span>
<span ng-switch-when="403">You are not allowed for this action.</span>
<span ng-switch-when="404">The page was not found.</span>
<span ng-switch-when="420">You are performing too many actions. Please try again later.</span>
<span ng-switch-default>Internal server error occured. Please try again later.</span>
<div ng-if="error.originalError" ng-switch="showErrorDetails">
<pre ng-switch-when="true"><code>{{error.originalError}}</code></pre>
<a ng-switch-default href="" ng-click="showErrorDetails = true">Click here</a> for technical details.
</div>
</div>
</div> </div>
<div ng-if="!error" class="error_modal_description" ng-bind="description"></div>
</div> </div>
</div> </div>

2
app/partials/login.html

@ -17,7 +17,7 @@
</form> </form>
<form name="myLoginForm" ng-if="credentials.phone_code_hash" ng-submit="logIn()"> <form name="myLoginForm" ng-if="credentials.phone_code_hash" ng-submit="logIn()">
<h3 class="login_form_head">{{ credentials.phone_number | phoneNumber }} <small>(<a href="#/auth">edit</a>)</small></h3> <h3 class="login_form_head">{{ credentials.phone_number | phoneNumber }} <small>(<a href="#/login">edit</a>)</small></h3>
<p class="login_form_lead">We have sent you a code via SMS.<br/>Please enter it below.</p> <p class="login_form_lead">We have sent you a code via SMS.<br/>Please enter it below.</p>
<p class="login_form_lead"> <p class="login_form_lead">

Loading…
Cancel
Save