From 2eaf7ca17230bb3d9fbc12461827edd1ed7de7b2 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 13 Jan 2014 23:54:53 +0100 Subject: [PATCH] check valid send states in editor --- src/js/controller/write.js | 44 +++++++++++++++++++++++++++++++------- src/sass/views/_read.scss | 2 +- src/sass/views/_write.scss | 6 ++++++ src/tpl/write.html | 2 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/js/controller/write.js b/src/js/controller/write.js index 691afc4..96236e9 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -108,6 +108,7 @@ define(function(require) { // verify email address if (!util.validateEmailAddress(recipient.address)) { recipient.secure = undefined; + checkSendStatus(); return; } @@ -122,21 +123,48 @@ define(function(require) { if (key && key.userId === recipient.address) { recipient.key = key; recipient.secure = true; - $scope.$apply(); } + + checkSendStatus(); + $scope.$apply(); }); } - function resetDisplay() { + function checkSendStatus() { + $scope.okToSend = false; $scope.sendBtnText = undefined; - } + $scope.sendBtnSecure = undefined; - function displaySecure() { - $scope.sendBtnText = 'Send securely'; - } + var allSecure = true; + var numReceivers = 0; - function displayInsecure() { - $scope.sendBtnText = 'Invite & send securely'; + // count number of receivers and check security + $scope.to.forEach(check); + $scope.cc.forEach(check); + $scope.bcc.forEach(check); + + function check(recipient) { + // validate address + if (!util.validateEmailAddress(recipient.address)) { + return; + } + numReceivers++; + if (!recipient.secure) { + allSecure = false; + } + } + + // sender can invite only one use at a time + if (!allSecure && numReceivers === 1) { + $scope.sendBtnText = 'Invite & send securely'; + $scope.okToSend = true; + $scope.sendBtnSecure = false; + } else if (allSecure && numReceivers > 0) { + // all recipients are secure + $scope.sendBtnText = 'Send securely'; + $scope.okToSend = true; + $scope.sendBtnSecure = true; + } } // diff --git a/src/sass/views/_read.scss b/src/sass/views/_read.scss index 00f6ef7..535488b 100644 --- a/src/sass/views/_read.scss +++ b/src/sass/views/_read.scss @@ -7,7 +7,7 @@ .headers { p { margin: 0px; - padding: 0px; + padding: 0px; } .subject { diff --git a/src/sass/views/_write.scss b/src/sass/views/_write.scss index a7c3780..bb309d4 100644 --- a/src/sass/views/_write.scss +++ b/src/sass/views/_write.scss @@ -20,6 +20,12 @@ .headers { margin-top: 10px; + + p { + margin: 0.2em 0; + padding: 0.2em 0; + } + span { color: $color-grey; } diff --git a/src/tpl/write.html b/src/tpl/write.html index 9f76f5f..c3ddf1c 100644 --- a/src/tpl/write.html +++ b/src/tpl/write.html @@ -39,7 +39,7 @@
- +