Fix tab navigation in the form to add a new card

pull/188/head
Maxime Quandalle 10 years ago
parent 6ef9c7e95f
commit 9c2a3213eb
  1. 4
      client/components/lists/body.jade
  2. 55
      client/components/lists/body.js
  3. 13
      client/components/lists/main.js
  4. 6
      client/components/lists/menu.js

@ -2,7 +2,7 @@ template(name="listBody")
.minicards.clearfix.js-minicards .minicards.clearfix.js-minicards
if cards.count if cards.count
+inlinedForm(autoclose=false position="top") +inlinedForm(autoclose=false position="top")
+addCardForm +addCardForm(listId=_id position="top")
each cards each cards
.minicard.card.js-minicard.js-member-droppable( .minicard.card.js-minicard.js-member-droppable(
class="{{#if isSelected}}is-selected{{/if}}") class="{{#if isSelected}}is-selected{{/if}}")
@ -32,7 +32,7 @@ template(name="listBody")
span.badge-text= attachments.count span.badge-text= attachments.count
if currentUser.isBoardMember if currentUser.isBoardMember
+inlinedForm(autoclose=false position="bottom") +inlinedForm(autoclose=false position="bottom")
+addCardForm +addCardForm(listId=_id position="bottom")
else else
a.open-card-composer.js-open-inlined-form a.open-card-composer.js-open-inlined-form
i.fa.fa-plus i.fa.fa-plus

@ -7,11 +7,25 @@ BlazeComponent.extendComponent({
return Session.equals('currentCard', this.currentData()._id); return Session.equals('currentCard', this.currentData()._id);
}, },
openForm: function(options) {
options = options || {};
options.position = options.position || 'top';
var forms = this.componentChildren('inlinedForm');
var form = _.find(forms, function(component) {
return component.data().position === options.position;
});
if (! form && forms.length > 0) {
form = forms[0];
}
form.open();
},
addCard: function(evt) { addCard: function(evt) {
evt.preventDefault(); evt.preventDefault();
var textarea = $(evt.currentTarget).find('textarea'); var textarea = $(evt.currentTarget).find('textarea');
var title = textarea.val(); var title = textarea.val();
var position = this.currentData().position; var position = Blaze.getData(evt.currentTarget).position;
var sortIndex; var sortIndex;
if (position === 'top') { if (position === 'top') {
sortIndex = Utils.getSortIndex(null, this.find('.js-minicard:first')); sortIndex = Utils.getSortIndex(null, this.find('.js-minicard:first'));
@ -46,8 +60,17 @@ BlazeComponent.extendComponent({
events: function() { events: function() {
return [{ return [{
submit: this.addCard, submit: this.addCard
'keydown form textarea': function(evt) { }];
}
}).register('listBody');
BlazeComponent.extendComponent({
template: function() {
return 'addCardForm';
},
pressKey: function(evt) {
// Pressing Enter should submit the card // Pressing Enter should submit the card
if (evt.keyCode === 13) { if (evt.keyCode === 13) {
evt.preventDefault(); evt.preventDefault();
@ -58,17 +81,23 @@ BlazeComponent.extendComponent({
} else if (evt.keyCode === 9) { } else if (evt.keyCode === 9) {
evt.preventDefault(); evt.preventDefault();
var isReverse = evt.shiftKey; var isReverse = evt.shiftKey;
var list = $('#js-list-' + this.data()._id); var list = $('#js-list-' + this.data().listId);
var nextList = list[isReverse ? 'prev' : 'next']('.js-list').get(0) || var listSelector = '.js-list:not(.js-add-list)';
$('.js-list:' + (isReverse ? 'last' : 'first')).get(0); var nextList = list[isReverse ? 'prev' : 'next'](listSelector).get(0);
var nextListComponent = // If there isn't no next list, loop back to the beginning.
BlazeComponent.getComponentForElement(nextList); if (! nextList) {
nextList = $(listSelector + (isReverse ? ':last' : ':first')).get(0);
// XXX Get the real position
var position = 'bottom';
nextListComponent.openForm({position: position});
} }
BlazeComponent.getComponentForElement(nextList).openForm({
position:this.data().position
});
} }
},
events: function() {
return [{
keydown: this.pressKey
}]; }];
} }
}).register('listBody'); }).register('addCardForm');

@ -3,18 +3,9 @@ BlazeComponent.extendComponent({
return 'list'; return 'list';
}, },
// Proxy
openForm: function(options) { openForm: function(options) {
options = options || {}; this.componentChildren('listBody')[0].openForm(options);
options.position = options.position || 'top';
var listComponent = this.componentChildren('listBody')[0];
var forms = listComponent.componentChildren('inlinedForm');
if (options.position === 'top') {
forms[0].open();
} else {
forms[forms.length - 1].open();
}
}, },
// XXX The jQuery UI sortable plugin is far from ideal here. First we include // XXX The jQuery UI sortable plugin is far from ideal here. First we include

@ -1,10 +1,8 @@
Template.listActionPopup.events({ Template.listActionPopup.events({
'click .js-add-card': function() { 'click .js-add-card': function() {
// XXX We need a better API and architecture here. See
// https://github.com/peerlibrary/meteor-blaze-components/issues/19
var listDom = document.getElementById('js-list-' + this._id); var listDom = document.getElementById('js-list-' + this._id);
var listInstance = Blaze.getView(listDom).templateInstance(); var listComponent = BlazeComponent.getComponentForElement(listDom);
listInstance.get('component').openForm(); listComponent.openForm({ position: 'top' });
Popup.close(); Popup.close();
}, },
'click .js-list-subscribe': function() {}, 'click .js-list-subscribe': function() {},

Loading…
Cancel
Save