Implement a new system to handle "escape actions"

The new EscapeActions object decide what to do when the user press the
Escape key (such as closing a opened popup or inlined form).

This commit also re-introduced the sidebar current view as a sidebar
component local state.
This commit is contained in:
Maxime Quandalle 2015-05-26 20:30:01 +02:00
parent 1b4fcc67f4
commit 40c2411f2a
13 changed files with 148 additions and 53 deletions

View file

@ -15,7 +15,9 @@
// We can only have one inlined form element opened at a time
// XXX Could we avoid using a global here ? This is used in Mousetrap
// keyboard.js
currentlyOpenedForm = new ReactiveVar(null);
var currentlyOpenedForm = new ReactiveVar(null);
var inlinedFormEscapePriority = 30;
BlazeComponent.extendComponent({
template: function() {
@ -32,9 +34,10 @@ BlazeComponent.extendComponent({
open: function() {
// Close currently opened form, if any
if (currentlyOpenedForm.get() !== null) {
currentlyOpenedForm.get().close();
}
// if (currentlyOpenedForm.get() !== null) {
// currentlyOpenedForm.get().close();
// }
EscapeActions.executeLowerThan(inlinedFormEscapePriority);
this.isOpen.set(true);
currentlyOpenedForm.set(this);
},
@ -46,7 +49,8 @@ BlazeComponent.extendComponent({
},
getValue: function() {
return this.isOpen.get() && this.find('textarea,input[type=text]').value;
var input = this.find('textarea,input[type=text]');
return this.isOpen.get() && input && input.value;
},
saveValue: function() {
@ -66,7 +70,7 @@ BlazeComponent.extendComponent({
'keydown form input, keydown form textarea': function(evt) {
if (evt.keyCode === 27) {
evt.preventDefault();
this.close();
EscapeActions.executeLowest();
}
},
@ -91,3 +95,9 @@ BlazeComponent.extendComponent({
}];
}
}).register('inlinedForm');
// Press escape to close the currently opened inlinedForm
EscapeActions.register(inlinedFormEscapePriority,
function() { return currentlyOpenedForm.get() !== null; },
function() { currentlyOpenedForm.get().close(); }
);