Set default values for user preferences

This commit is contained in:
Giulio Cesare Solaroli 2015-09-23 13:41:57 +02:00
parent cf3c243af2
commit efbccb5304
6 changed files with 258 additions and 174 deletions

View File

@ -2218,36 +2218,7 @@ span.count {
font-weight: bold; }
#extraFeaturesPanel .extraFeatureContent {
border-right: 1px solid #222;
color: white;
/*
.changePassphraseForm {
label {
display: block;
}
input {
display: block;
}
}
.deleteAccountForm {
margin-top: 1em;
label {
display: block;
}
input {
display: inline-block;
margin-right: 1em;
margin-bottom: 1em;
}
.confirmCheckbox {
display: inline-block;
}
}
*/ }
color: white; }
#extraFeaturesPanel .extraFeatureContent header {
display: none; }
#extraFeaturesPanel .extraFeatureContent .extraFeature .header h1 {
@ -2349,6 +2320,17 @@ span.count {
cursor: default; }
#extraFeaturesPanel .extraFeatureContent .preferences h3 {
border-bottom: 1px solid white; }
#extraFeaturesPanel .extraFeatureContent .preferences span.clickable, #extraFeaturesPanel .extraFeatureContent .preferences input[type='checkbox'] {
cursor: pointer; }
#extraFeaturesPanel .extraFeatureContent .preferences input[type='text'] {
font-size: 14pt;
padding: 2px 4px;
border: 0px;
color: white;
background-color: black;
border-bottom: 1px solid white; }
#extraFeaturesPanel .extraFeatureContent .preferences select {
font-size: 12pt; }
#extraFeaturesPanel .extraFeatureContent .preferences .row {
padding-top: 4px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.one {
@ -2380,15 +2362,45 @@ span.count {
-moz-flex: auto;
-ms-flex: auto;
flex: auto; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockEnabled input {
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockEnabled input, #extraFeaturesPanel .extraFeatureContent .preferences .row.donationReminder input {
margin-left: auto;
margin-right: auto;
display: block; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout span:after {
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .disabled {
color: gray; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .disabled input {
color: gray;
pointer-events: none;
border-bottom: 1px solid gray; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .timeUnit {
padding-left: 8px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .timeUnit:after {
content: ""; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout span:after, #extraFeaturesPanel .extraFeatureContent .preferences .row.passwordLength span:after {
color: gray;
content: ": "; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout input {
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout input, #extraFeaturesPanel .extraFeatureContent .preferences .row.passwordLength input {
width: 50px;
align: right; }
text-align: right; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .sizeUnit, #extraFeaturesPanel .extraFeatureContent .preferences .row.passwordLength .sizeUnit {
padding-left: 8px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.lockTimeout .sizeUnit:after, #extraFeaturesPanel .extraFeatureContent .preferences .row.passwordLength .sizeUnit:after {
content: ""; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.passwordCharSets p {
padding-bottom: 2px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.passwordCharSets p:after {
color: gray;
content: ":"; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.passwordCharSets ul li {
padding-bottom: 0px;
padding-left: 20px;
padding-top: 1px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.passwordCharSets ul li span {
display: inline-block;
width: 58px; }
#extraFeaturesPanel .extraFeatureContent .preferences .row.passwordCharSets ul li span:after {
color: gray;
content: ":"; }
#extraFeaturesPanel .extraFeatureContent .preferences span {
vertical-align: middle; }
#extraFeaturesPanel .extraFeatureContent .preferences input {

File diff suppressed because one or more lines are too long

View File

@ -26,117 +26,147 @@ Clipperz.Base.module('Clipperz.PM.UI.Components.ExtraFeatures');
Clipperz.PM.UI.Components.ExtraFeatures.PreferencesClass = React.createClass({
getInitialState: function() {
return {
'preferenceBeingEdited': null,
'preferenceValue': '',
};
},
propTypes: {
},
//=========================================================================
//============================================================================
setEditedPreference: function(aKey, aValue) {
this.setState({
'preferenceBeingEdited': aKey,
'preferenceValue': aValue
});
preference: function (aKeyPath) {
return this.props['userInfo']['preferences'].getValue(aKeyPath);
},
handleChange: function(anEvent) {
var newState = this.state;
setPreference: function (aKeyPath) {
return function (anEvent) {
var value;
var target;
target = anEvent.target;
if (target.type == 'checkbox') {
value = target.checked;
} else if (target.type == 'text') {
value = target.value;
} else if (target.type == 'select-one') {
value = target.value;
}
newState['preferenceValue'] = anEvent.target.value;
this.setState(newState);
},
handleSave: function() {
MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'setPreference', this.state['preferenceBeingEdited'], this.state['preferenceValue']);
this.setEditedPreference(null, '');
},
handleCancel: function() {
this.setEditedPreference(null, '');
},
handleKeyPressed: function(anEvent) {
switch (anEvent.keyCode) {
case 9: // tab
this.handleSave();
// TODO: edit next preference
break;
case 13: // enter
this.handleSave();
break;
case 27: // escape
this.handleCancel();
break;
MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'setPreference', aKeyPath, value);
}
},
//=========================================================================
renderPreferenceValueElement: function(aKey) {
var result;
var preferenceValue = this.props.userInfo.preferences.getValue(aKey);
if (this.state.preferenceBeingEdited == aKey) {
result = React.DOM.input({
'autoFocus': true,
'key': aKey,
'type': 'text',
'value': this.state.preferenceValue,
'onChange': this.handleChange,
'onKeyDown': MochiKit.Base.method(this, 'handleKeyPressed'),
});
} else {
result = React.DOM.p({
'className': 'preferenceValue',
'onClick': MochiKit.Base.method(this, 'setEditedPreference', aKey, preferenceValue)
}, preferenceValue);
}
return result;
//============================================================================
checkboxClick: function (aRef) {
return MochiKit.Base.bind(function (anEvent) {
//console.log("CHECKBOX CLICK", this, this.refs, this.refs[aRef]);
this.refs[aRef].getDOMNode().click();
}, this);
},
renderPreferences: function() {
var result;
result = [
React.DOM.li({'key': 'autoLockAfterMinutes'}, [
React.DOM.p({'className': 'preferenceName'}, "Automatic lock (minutes) - m"),
React.DOM.p({'className': 'preferenceDescription'}, "Automatically lock Clipperz after N minutes. (0 = auto lock disabled)"),
this.renderPreferenceValueElement('lock.timeoutInMinutes')
]),
React.DOM.li({'key': 'shouldShowDonationPanel'}, [
React.DOM.p({'className': 'preferenceName'}, "Donation Panel - m"),
React.DOM.p({'className': 'preferenceDescription'}, "Select whether to display the donation panel or not"),
this.renderPreferenceValueElement('shouldShowDonationPanel')
])
];
//----------------------------------------------------------------------------
return result;
handleKeyDown: function (aKeyPath) {
return MochiKit.Base.bind(function (anEvent) {
var value = anEvent.target.value;
console.log("HANDLE KEY DOWN", anEvent, anEvent.keyCode, value);
if (anEvent.target.defaultValue != value) {
switch (anEvent.keyCode) {
case 9: // tab
case 13: // enter - TODO: edit next preference
MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'setPreference', aKeyPath, value);
anEvent.target.defaultValue = anEvent.target.value;
break;
case 27: // escape
console.log("ESCAPE");
anEvent.target.value = anEvent.target.defaultValue;
break;
}
}
}, this);
},
//============================================================================
render: function () {
var result;
//console.log("PREFERENCES", this.props['userInfo']['preferences']);
if (! this.props.userInfo.preferences) {
if (! this.props['userInfo']['preferences']) {
result = React.DOM.p({}, "spinner...");
} else {
result = React.DOM.div({'className':'extraFeature preferences'}, [
React.DOM.div({'className':'header'}, [
React.DOM.h1({}, "Preferences"),
React.DOM.div({'className':'description'}, [
React.DOM.p({}, "Insert copy here..."),
])
// React.DOM.div({'className':'description'}, [
// React.DOM.p({}, "Insert copy here..."),
// ])
]),
React.DOM.div({'className':'content'}, [
React.DOM.ul({'className':'preferenceList'}, this.renderPreferences()),
React.DOM.ul({'className':'preferenceList'}, [
React.DOM.li({'key': 'lock'}, [
React.DOM.h3({'key':'1'}, "Lock"),
React.DOM.div({'key':'2', 'className':'row two lockEnabled'}, [
React.DOM.div({'className':'col one'}, [
React.DOM.input({'type':'checkbox', 'checked':this.preference('lock.enabled'), 'onChange':this.setPreference('lock.enabled'), 'ref':'lock-enabled'}),
]),
React.DOM.div({'className':'col two'}, [
React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('lock-enabled')}, "Enable auto-lock"),
]),
]),
React.DOM.div({'key':'3', 'className':'row one lockTimeout'}, [
React.DOM.p({'className':(this.preference('lock.enabled') ? 'enabled' : 'disabled')}, [
React.DOM.span({}, "Lock timeout"),
React.DOM.input({'type':'text', 'defaultValue':this.preference('lock.timeoutInMinutes'), 'onKeyDown':this.handleKeyDown('lock.timeoutInMinutes')}),
React.DOM.span({'className':'timeUnit'}, "minutes"),
])
]),
]),
React.DOM.li({'key': 'passwordGenerator'}, [
React.DOM.h3({'key':'1'}, "Password generator"),
React.DOM.div({'key':'2', 'className':'row one passwordLength'}, [
React.DOM.p({}, [
React.DOM.span({}, "Password length"),
React.DOM.input({'type':'text', 'defaultValue':this.preference('passwordGenerator.length'), 'onKeyDown':this.handleKeyDown('passwordGenerator.length')}),
React.DOM.span({'className':'sizeUnit'}, "characters"),
])
]),
React.DOM.div({'key':'3', 'className':'row one passwordCharSets'}, [
React.DOM.p({'key':'label'}, "Characters"),
React.DOM.ul({'key':'list'}, [
React.DOM.li({'key':'A-Z'}, [ React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('A-Z')}, "A-Z"), React.DOM.input({'type':'checkbox', 'checked':this.preference('passwordGenerator.characters.A-Z'), 'onChange':this.setPreference('passwordGenerator.characters.A-Z'), 'ref':'A-Z'}) ]),
React.DOM.li({'key':'a-z'}, [ React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('a-z')}, "a-z"), React.DOM.input({'type':'checkbox', 'checked':this.preference('passwordGenerator.characters.a-z'), 'onChange':this.setPreference('passwordGenerator.characters.a-z'), 'ref':'a-z'}) ]),
React.DOM.li({'key':'0-9'}, [ React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('0-9')}, "0-9"), React.DOM.input({'type':'checkbox', 'checked':this.preference('passwordGenerator.characters.0-9'), 'onChange':this.setPreference('passwordGenerator.characters.0-9'), 'ref':'0-9'}) ]),
React.DOM.li({'key':'space'}, [ React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('space')}, "space"), React.DOM.input({'type':'checkbox', 'checked':this.preference('passwordGenerator.characters.space'), 'onChange':this.setPreference('passwordGenerator.characters.space'), 'ref':'space'}) ]),
React.DOM.li({'key':'!#?'}, [ React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('!#?')}, "!#?"), React.DOM.input({'type':'checkbox', 'checked':this.preference('passwordGenerator.characters.!#?'), 'onChange':this.setPreference('passwordGenerator.characters.!#?'), 'ref':'!#?'}) ]),
])
]),
]),
React.DOM.li({'key': 'language'}, [
React.DOM.h3({'key':'1'}, "Language"),
React.DOM.div({'key':'2', 'className':'row one language'}, [
React.DOM.select({'value':this.preference('preferredLanguage'), 'onChange':this.setPreference('preferredLanguage')}, [
React.DOM.option({'value':'en'}, "English"),
React.DOM.option({'value':'fr'}, "Français"),
React.DOM.option({'value':'it'}, "Italiano"),
])
]),
]),
React.DOM.li({'key': 'donationReminder'}, [
React.DOM.h3({'key':'1'}, "Donation reminder"),
React.DOM.div({'key':'2', 'className':'row two donationReminder'}, [
React.DOM.div({'className':'col one'}, [
React.DOM.input({'type':'checkbox', 'checked':this.preference('shouldShowDonationPanel'), 'onChange':this.setPreference('shouldShowDonationPanel'), 'ref':'shouldShowDonationPanel'}),
]),
React.DOM.div({'className':'col two'}, [
React.DOM.span({'className':'clickable', 'onClick':this.checkboxClick('shouldShowDonationPanel')}, "Show donation reminder"),
]),
]),
]),
]),
])
]);
}
@ -144,7 +174,7 @@ Clipperz.PM.UI.Components.ExtraFeatures.PreferencesClass = React.createClass({
return result;
},
//=========================================================================
//============================================================================
});
Clipperz.PM.UI.Components.ExtraFeatures.Preferences = React.createFactory(Clipperz.PM.UI.Components.ExtraFeatures.PreferencesClass);

View File

@ -183,7 +183,7 @@ Clipperz.PM.UI.Components.Pages.LoginPageClass = React.createClass({
]),
React.DOM.div({'key':'formWrapper', 'className':'form body'}, [
React.DOM.div({'className':'bodyContent'}, [
this.props.mode == 'PIN' ? this.pinForm() : this.loginForm(),
this.props['mode'] == 'PIN' ? this.pinForm() : this.loginForm(),
]),
]),
this.props['isNewUserRegistrationAvailable'] ? registrationLink : null,

View File

@ -440,10 +440,10 @@ Clipperz.log("THE BROWSER IS OFFLINE");
return aValue;
});
deferredResult.addMethod(this, 'moveInPage', this.currentPage(), 'mainPage'); // #ASK or cardDetailPage
deferredResult.addMethod(this, 'moveInPage', this.currentPage(), 'mainPage');
deferredResult.addMethod(this, 'refreshUI');
deferredResult.addMethod(unlockPage, 'setProps', {'disabled': false}); // #ASK ?
deferredResult.addMethod(unlockPage, 'resetUnlockForm'); // #ASK ?
deferredResult.addMethod(unlockPage, 'setProps', {'disabled': false});
deferredResult.addMethod(unlockPage, 'resetUnlockForm');
// deferredResult.addMethod(this, 'resetLockTimeout');
deferredResult.addCallback(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'enableLock');
deferredResult.addMethod(overlay, 'done', "", 0.5);
@ -819,24 +819,18 @@ Clipperz.log("THE BROWSER IS OFFLINE");
MochiKit.Signal.disconnectAll(Clipperz.Signal.NotificationCenter, 'lock');
},
// clearLockTimeout: function () {
// clearTimeout(this._lockTimeout);
// },
resetLockTimeout: function () {
if (this.user()) {
return Clipperz.Async.callbacks("MainController.resetLockTimeout", [
MochiKit.Base.method(this.user(), 'getPreference', 'lock.timeoutInMinutes'),
MochiKit.Base.bind( function (aDelay) {
var aDelay = aDelay * 60*1000;
MochiKit.Base.method(this.user(), 'getPreference', 'lock'),
MochiKit.Base.bind(function (someLockInfo) {
if (this._lockTimeout) {
// console.log("clearing previous lock timer");
clearTimeout(this._lockTimeout);
}
if (aDelay > 0) {
// console.log("setting lock timer", aDelay);
if (someLockInfo['enabled'] == true) {
var aDelay = someLockInfo['timeoutInMinutes'] * 60 * 1000;
this._lockTimeout = setTimeout(function() {
MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'lock');
}, aDelay);
@ -1512,13 +1506,12 @@ Clipperz.log("THE BROWSER IS OFFLINE");
this.updatePreferences();
},
setPreference_handler: function(aKey, aValue) {
// return this.user().setPreference(aKey, aValue);
setPreference_handler: function(aKeyPath, aValue) {
console.log("MainController.setPrefence", aKeyPath, aValue);
return Clipperz.Async.callbacks("MainController.setPreference_handler", [
MochiKit.Base.method(this.overlay(), 'show', "", true),
MochiKit.Base.method(this.user(), 'setPreference', aKey, aValue),
MochiKit.Base.method(this, 'refreshCurrentPage'),
MochiKit.Base.method(this.user(), 'setPreference', aKeyPath, aValue),
// MochiKit.Base.method(this, 'refreshCurrentPage'),
MochiKit.Base.method(this, 'updatePreferences'),
MochiKit.Base.method(this.overlay(), 'done', "", 0.5),
], {trace:false});

View File

@ -386,10 +386,34 @@ refer to http://www.clipperz.com.
}
.preferences {
$semicolonColor: gray;
$disabledTextColor: gray;
h3 {
border-bottom: 1px solid white;
}
span.clickable, input[type='checkbox'] {
cursor: pointer;
}
input[type='text'] {
// font-size: 18pt;
font-size: 14pt;
// padding: 6px 10px;
padding: 2px 4px;
border: 0px;
color: white;
background-color: black;
border-bottom: 1px solid white;
// border: 0px solid white;
}
select {
font-size: 12pt;
}
.row {
$firstColumnWidth: 40px;
padding-top: 4px;
@ -412,7 +436,7 @@ refer to http://www.clipperz.com.
}
}
&.lockEnabled {
&.lockEnabled, &.donationReminder {
input {
margin-left: auto;
margin-right: auto;
@ -421,14 +445,69 @@ refer to http://www.clipperz.com.
}
&.lockTimeout {
.disabled {
color: $disabledTextColor;
input {
color: $disabledTextColor;
pointer-events:none;
border-bottom: 1px solid $disabledTextColor;
}
}
.timeUnit {
padding-left: 8px;
&:after {
content: "";
};
}
}
&.lockTimeout, &.passwordLength {
span {
&:after {
color: $semicolonColor;
content: ": ";
};
}
input {
width: 50px;
align: right;
text-align: right;
}
.sizeUnit {
padding-left: 8px;
&:after {
content: "";
};
}
}
&.passwordCharSets {
p {
padding-bottom: 2px;
&:after {
color: $semicolonColor;
content: ":";
};
}
ul {
li {
padding-bottom: 0px;
padding-left: 20px;
padding-top: 1px;
span {
display: inline-block;
width: 58px;
&:after {
color: $semicolonColor;
content: ":";
};
}
}
}
}
}
@ -989,36 +1068,6 @@ refer to http://www.clipperz.com.
}
}
/*
.changePassphraseForm {
label {
display: block;
}
input {
display: block;
}
}
.deleteAccountForm {
margin-top: 1em;
label {
display: block;
}
input {
display: inline-block;
margin-right: 1em;
margin-bottom: 1em;
}
.confirmCheckbox {
display: inline-block;
}
}
*/
form {
input.valid + .invalidMsg, input.empty + .invalidMsg, input:focus + .invalidMsg, input.invalid:focus + .invalidMsg {
visibility: hidden;