work in progress

This commit is contained in:
Tankred Hase 2014-01-10 21:35:34 +01:00
parent e62e085771
commit 60342b3902
2 changed files with 78 additions and 23 deletions

View File

@ -39,7 +39,9 @@ define(function(require) {
function resetFields() {
$scope.writerTitle = 'New email';
$scope.to = '';
$scope.to = [{
address: ''
}];
$scope.subject = '';
$scope.body = '';
$scope.ciphertextPreview = '';
@ -73,43 +75,59 @@ define(function(require) {
// Editing headers
//
$scope.verifyTo = function() {
if (!$scope.to) {
resetDisplay();
$scope.onAddressUpdate = function(recipient) {
var to = $scope.to,
address = recipient.address;
// handle number of email inputs for multiple recipients
if (address.indexOf(' ') !== -1) {
recipient.address = address.replace(' ', '');
to.push({
address: ''
});
} else if (address.length === 0 && to.length > 1) {
to.splice(to.indexOf(recipient), 1);
}
verify(recipient);
};
function verify(recipient) {
// set display to insecure while fetching keys
recipient.key = undefined;
recipient.secure = false;
// verify email address
if (!util.validateEmailAddress(recipient.address)) {
recipient.secure = undefined;
return;
}
// set display to insecure while fetching keys
$scope.toKey = undefined;
displayInsecure();
// check if to address is contained in known public keys
emailDao._keychain.getReceiverPublicKey($scope.to, function(err, key) {
emailDao._keychain.getReceiverPublicKey(recipient.address, function(err, key) {
if (err) {
$scope.onError(err);
return;
}
// compare again since model could have changed during the roundtrip
if (key && key.userId === $scope.to) {
$scope.toKey = key;
displaySecure();
if (key && key.userId === recipient.address) {
recipient.key = key;
recipient.secure = true;
$scope.$apply();
}
});
};
}
function resetDisplay() {
$scope.toSecure = undefined;
$scope.sendBtnText = undefined;
}
function displaySecure() {
$scope.toSecure = true;
$scope.sendBtnText = 'Send securely';
}
function displayInsecure() {
$scope.toSecure = false;
$scope.sendBtnText = 'Invite & send securely';
}
@ -254,16 +272,45 @@ define(function(require) {
link: function(scope, elm, attrs) {
var model = $parse(attrs.autoSize);
scope.$watch(model, function(value) {
if (!value) {
return;
var width;
if (value.length < 12) {
width = (14 * 8) + 'px';
} else {
width = ((value.length + 2) * 8) + 'px';
}
var width = ((value.length + 2) * 8) + 'px';
elm.css('width', width);
});
}
};
});
ngModule.directive('addressInput', function($timeout, $parse) {
return {
//scope: true, // optionally create a child scope
link: function(scope, element, attrs) {
element.bind('keydown', function(e) {
if (e.keyCode === 32) {
// space -> go to next input
e.preventDefault();
element[0].parent[0].nextSibling[0].children[0].focus();
}
scope.$apply();
});
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
if (value === true) {
$timeout(function() {
element[0].focus();
}, 100);
}
});
}
};
});
return WriteCtrl;
});

View File

@ -9,17 +9,25 @@
<div class="headers">
<p>
<span>To:</span>
<input type="email" ng-model="to" ng-change="verifyTo()" ng-class="{'label': toSecure === true, 'label label-primary': toSecure === false}" tabindex="1" focus-me="state.writer.open && writerTitle !== 'Reply'" auto-size="to" spellcheck="false">
<span ng-repeat="recipient in to track by $index">
<input value="{{recipient.address}}" ng-model="recipient.address" ng-trim="false" ng-class="{'label': recipient.secure === true, 'label label-primary': recipient.secure === false && recipient.valid !== true}" auto-size="recipient.address" spellcheck="false" ng-change="onAddressUpdate(recipient)">
</span>
</p>
<p>
<span>Cc:</span>
<!--<input type="email" ng-model="cc" tabindex="2">-->
<input type="email" ng-model="cc" tabindex="2">
</p>
<p>
<span>Bcc:</span>
<input type="email" ng-model="bcc" tabindex="3">
</p>
</div><!--/.address-headers-->
<div class="subject-box">
<div class="subject-line">
<input ng-model="subject" class="subject" spellcheck="true" tabindex="3" placeholder="Subject" ng-change="updatePreview()">
<input ng-model="subject" class="subject" spellcheck="true" tabindex="4" placeholder="Subject" ng-change="updatePreview()">
</div>
<button class="btn-attachment">
<div data-icon="&#xe003;"></div>
@ -27,7 +35,7 @@
</div><!--/.subject-box-->
<div class="body" focus-child>
<p ng-model="body" contentEditable="true" spellcheck="false" ng-change="updatePreview()" tabindex="4" focus-me="state.writer.open && writerTitle === 'Reply'"></p>
<p ng-model="body" contentEditable="true" spellcheck="false" ng-change="updatePreview()" tabindex="5" focus-me="state.writer.open && writerTitle === 'Reply'"></p>
<div class="encrypt-preview" ng-class="{'invisible': !ciphertextPreview}">
<p>-----BEGIN ENCRYPTED PREVIEW-----<br>{{ciphertextPreview}}<br>-----END ENCRYPTED PREVIEW-----</p>
@ -35,7 +43,7 @@
</div><!--/.body-->
<div class="send-control">
<button ng-click="sendToOutbox()" class="btn" data-icon="{{(toSecure === false) ? '&#xe001;' : (toSecure === true) ? '&#xe009;' : ''}}" ng-disabled="!to" tabindex="5">{{sendBtnText || 'Send'}}</button>
<button ng-click="sendToOutbox()" class="btn" data-icon="{{(toSecure === false) ? '&#xe001;' : (toSecure === true) ? '&#xe009;' : ''}}" ng-disabled="!to" tabindex="6">{{sendBtnText || 'Send'}}</button>
</div>
</div><!--/.write-view-->