summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/filter.js18
-rw-r--r--client/lib/keyboard.js58
-rw-r--r--client/lib/popup.js4
3 files changed, 57 insertions, 23 deletions
diff --git a/client/lib/filter.js b/client/lib/filter.js
index 507a2bb7..d96fa89c 100644
--- a/client/lib/filter.js
+++ b/client/lib/filter.js
@@ -4,6 +4,10 @@
// goal is to filter complete documents by using the local filters for each
// fields.
+var showFilterSidebar = function() {
+ Sidebar.setView('filter');
+};
+
// Use a "set" filter for a field that is a set of documents uniquely
// identified. For instance `{ labels: ['labelA', 'labelC', 'labelD'] }`.
var SetFilter = function() {
@@ -18,29 +22,27 @@ _.extend(SetFilter.prototype, {
},
add: function(val) {
- if (this.indexOfVal(val) === -1) {
+ if (this._indexOfVal(val) === -1) {
this._selectedElements.push(val);
this._dep.changed();
+ showFilterSidebar();
}
},
remove: function(val) {
var indexOfVal = this._indexOfVal(val);
- if (this.indexOfVal(val) !== -1) {
+ if (this._indexOfVal(val) !== -1) {
this._selectedElements.splice(indexOfVal, 1);
this._dep.changed();
}
},
toogle: function(val) {
- var indexOfVal = this._indexOfVal(val);
- if (indexOfVal === -1) {
- this._selectedElements.push(val);
+ if (this._indexOfVal(val) === -1) {
+ this.add(val);
} else {
- this._selectedElements.splice(indexOfVal, 1);
+ this.remove(val);
}
-
- this._dep.changed();
},
reset: function() {
diff --git a/client/lib/keyboard.js b/client/lib/keyboard.js
index 8601e623..723d498b 100644
--- a/client/lib/keyboard.js
+++ b/client/lib/keyboard.js
@@ -3,21 +3,6 @@
// XXX There is no reason to define these shortcuts globally, they should be
// attached to a template (most of them will go in the `board` template).
-// Pressing `Escape` should close the last opened “element” and only the last
-// one -- curently we handle popups and the card detailed view of the sidebar.
-Mousetrap.bind('esc', function() {
- if (currentlyOpenedForm.get() !== null) {
- currentlyOpenedForm.get().close();
-
- } else if (Popup.isOpen()) {
- Popup.back();
-
- // XXX We should have a higher level API
- } else if (Session.get('currentCard')) {
- Utils.goBoardId(Session.get('currentBoard'));
- }
-});
-
Mousetrap.bind('w', function() {
Sidebar.toogle();
});
@@ -48,3 +33,46 @@ Mousetrap.bind(['down', 'up'], function(evt, key) {
Utils.goCardId(nextCardId);
}
});
+
+// Pressing `Escape` should close the last opened “element” and only the last
+// one. Components can register themself using a priority number (smaller is
+// closed first), a condition, and an action.This is used by Popup or
+// inlinedForm for instance. When we press escape we execute the action which
+// condition is valid with the highest priority.
+EscapeActions = {
+ _actions: [],
+
+ register: function(priority, condition, action) {
+ // XXX Rewrite this with ES6: .push({ priority, condition, action })
+ this._actions.push({
+ priority: priority,
+ condition: condition,
+ action: action
+ });
+ // XXX Rewrite this with ES6: => function
+ this._actions = _.sortBy(this._actions, function(a) { return a.priority; });
+ },
+
+ executeLowest: function() {
+ var topActiveAction = _.find(this._actions, function(a) {
+ return !! a.condition();
+ });
+ return topActiveAction && topActiveAction.action();
+ },
+
+ executeLowerThan: function(maxPriority) {
+ maxPriority = maxPriority || Infinity;
+ var currentAction;
+ for (var i = 0; i < this._actions.length; i++) {
+ currentAction = this._actions[i];
+ if (currentAction.priority > maxPriority)
+ return;
+ if (!! currentAction.condition())
+ currentAction.action();
+ }
+ }
+};
+
+Mousetrap.bind('esc', function() {
+ EscapeActions.executeLowest();
+});
diff --git a/client/lib/popup.js b/client/lib/popup.js
index 04f7dbf6..70f2660f 100644
--- a/client/lib/popup.js
+++ b/client/lib/popup.js
@@ -201,3 +201,7 @@ $(document).on('click', function(evt) {
Popup.close();
}
});
+
+// Press escape to close the popup.
+var bindPopup = function(f) { return _.bind(f, Popup); };
+EscapeActions.register(20, bindPopup(Popup.isOpen), bindPopup(Popup.close));