Skip to content

Commit

Permalink
Preferences input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Oberndörfer committed Jan 29, 2013
1 parent d3deca1 commit a59f0c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion common/ui/keyRing.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ <h3>Preferences</h3>
<div class="control-group">
<label class="control-label">Char Code</label>
<div class="controls">
<input type="text" class="input-mini" id="secCode" maxlength="3">
<input type="text" class="input-mini" id="secCode" maxlength="3" title="Minimum 3 characters">
<span class="help-inline hide">Must be 3 characters</span>
</div>
</div>
<div class="control-group">
Expand Down
23 changes: 20 additions & 3 deletions common/ui/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,37 @@
}

function onSave() {
if (!validate()) return false;
prefs.security.display_decrypted = $('input:radio[name="decryptRadios"]:checked').val();
prefs.security.secure_code = $('#secCode').val();
prefs.security.secure_color = $('#secColor').val();
keyRing.sendMessage({ event: 'set-prefs', data: prefs }, function() {
keyRing.update();
$('.form-actions button').attr('disabled', 'disabled');
normalize();
});

return false;
}

function validate() {
var secCode = $('#secCode');
if (secCode.val().length !== 3) {
secCode.closest('.control-group').addClass('error');
secCode.next().removeClass('hide');
return false;
}
return true;
}

function normalize() {
$('#preferences .form-actions button').attr('disabled', 'disabled');
$('#preferences .control-group').removeClass('error');
$('#preferences .help-inline').addClass('hide');
}

function onCancel() {
$('.form-actions button').attr('disabled', 'disabled');
normalize();
loadPrefs();
return false;
}

function loadPrefs() {
Expand Down
Binary file modified dist/mailvelope.zip
Binary file not shown.

0 comments on commit a59f0c9

Please sign in to comment.