wekan/client/components/swimlanes/swimlaneHeader.js

239 lines
7.3 KiB
JavaScript
Raw Normal View History

import { TAPi18n } from '/imports/i18n';
import { ReactiveCache } from '/imports/reactiveCache';
const { calculateIndexData } = Utils;
2019-01-24 16:47:09 +01:00
let swimlaneColors;
Meteor.startup(() => {
swimlaneColors = Swimlanes.simpleSchema()._schema.color.allowedValues;
});
2018-02-01 13:10:30 -03:00
BlazeComponent.extendComponent({
2019-06-28 12:52:09 -05:00
editTitle(event) {
event.preventDefault();
const newTitle = this.childComponents('inlinedForm')[0]
.getValue()
.trim();
2018-02-01 13:10:30 -03:00
const swimlane = this.currentData();
if (newTitle) {
swimlane.rename(newTitle.trim());
}
},
collapsed(check = undefined) {
const swimlane = Template.currentData();
const status = swimlane.isCollapsed();
if (check === undefined) {
// just check
return status;
} else {
swimlane.collapse(!status);
return !status;
}
},
2018-02-01 13:10:30 -03:00
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-collapse-swimlane'(event) {
event.preventDefault();
this.collapsed(!this.collapsed());
},
2019-06-28 12:52:09 -05:00
'click .js-open-swimlane-menu': Popup.open('swimlaneAction'),
'click .js-open-add-swimlane-menu': Popup.open('swimlaneAdd'),
submit: this.editTitle,
},
];
2018-02-01 13:10:30 -03:00
},
}).register('swimlaneHeader');
2018-02-01 14:23:27 -03:00
Template.swimlaneFixedHeader.helpers({
isBoardAdmin() {
return ReactiveCache.getCurrentUser().isBoardAdmin();
},
isTitleDefault(title) {
// https://github.com/wekan/wekan/issues/4763
// https://github.com/wekan/wekan/issues/4742
// Translation text for "default" does not work, it returns an object.
// When that happens, try use translation "defaultdefault" that has same content of default, or return text "Default".
// This can happen, if swimlane does not have name.
// Yes, this is fixing the symptom (Swimlane title does not have title)
// instead of fixing the problem (Add Swimlane title when creating swimlane)
// because there could be thousands of swimlanes, adding name Default to all of them
// would be very slow.
if (title.startsWith("key 'default") && title.endsWith('returned an object instead of string.')) {
if (`${TAPi18n.__('defaultdefault')}`.startsWith("key 'default") && `${TAPi18n.__('defaultdefault')}`.endsWith('returned an object instead of string.')) {
return 'Default';
} else {
return `${TAPi18n.__('defaultdefault')}`;
}
} else if (title === 'Default') {
return `${TAPi18n.__('defaultdefault')}`;
} else {
return title;
}
},
});
Template.editSwimlaneTitleForm.helpers({
isTitleDefault(title) {
// https://github.com/wekan/wekan/issues/4763
// https://github.com/wekan/wekan/issues/4742
// Translation text for "default" does not work, it returns an object.
// When that happens, try use translation "defaultdefault" that has same content of default, or return text "Default".
// This can happen, if swimlane does not have name.
// Yes, this is fixing the symptom (Swimlane title does not have title)
// instead of fixing the problem (Add Swimlane title when creating swimlane)
// because there could be thousands of swimlanes, adding name Default to all of them
// would be very slow.
if (title.startsWith("key 'default") && title.endsWith('returned an object instead of string.')) {
if (`${TAPi18n.__('defaultdefault')}`.startsWith("key 'default") && `${TAPi18n.__('defaultdefault')}`.endsWith('returned an object instead of string.')) {
return 'Default';
} else {
return `${TAPi18n.__('defaultdefault')}`;
}
} else if (title === 'Default') {
return `${TAPi18n.__('defaultdefault')}`;
} else {
return title;
}
},
});
Template.swimlaneActionPopup.events({
'click .js-set-swimlane-color': Popup.open('setSwimlaneColor'),
2023-06-13 13:43:09 -05:00
'click .js-set-swimlane-height': Popup.open('setSwimlaneHeight'),
'click .js-close-swimlane'(event) {
event.preventDefault();
this.archive();
Popup.back();
},
'click .js-move-swimlane': Popup.open('moveSwimlane'),
2021-04-22 14:05:20 +02:00
'click .js-copy-swimlane': Popup.open('copySwimlane'),
});
Template.swimlaneActionPopup.events({
isCommentOnly() {
return ReactiveCache.getCurrentUser().isCommentOnly();
},
});
BlazeComponent.extendComponent({
onCreated() {
this.currentSwimlane = this.currentData();
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
submit(event) {
event.preventDefault();
const currentBoard = Utils.getCurrentBoard();
2019-06-28 12:52:09 -05:00
const nextSwimlane = currentBoard.nextSwimlane(this.currentSwimlane);
const titleInput = this.find('.swimlane-name-input');
const title = titleInput.value.trim();
const sortValue = calculateIndexData(
this.currentSwimlane,
nextSwimlane,
1,
);
const swimlaneType = currentBoard.isTemplatesBoard()
? 'template-swimlane'
: 'swimlane';
2019-06-28 12:52:09 -05:00
if (title) {
Swimlanes.insert({
title,
boardId: Session.get('currentBoard'),
sort: sortValue.base,
type: swimlaneType,
});
2019-06-28 12:52:09 -05:00
titleInput.value = '';
titleInput.focus();
}
// XXX ideally, we should move the popup to the newly
// created swimlane so a user can add more than one swimlane
// with a minimum of interactions
Popup.back();
2019-06-28 12:52:09 -05:00
},
'click .js-swimlane-template': Popup.open('searchElement'),
},
2019-06-28 12:52:09 -05:00
];
},
}).register('swimlaneAddPopup');
2019-01-24 16:47:09 +01:00
BlazeComponent.extendComponent({
onCreated() {
this.currentSwimlane = this.currentData();
this.currentColor = new ReactiveVar(this.currentSwimlane.color);
},
colors() {
2019-06-28 12:52:09 -05:00
return swimlaneColors.map(color => ({ color, name: '' }));
2019-01-24 16:47:09 +01:00
},
isSelected(color) {
return this.currentColor.get() === color;
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-palette-color'() {
this.currentColor.set(this.currentData().color);
},
'click .js-submit'() {
this.currentSwimlane.setColor(this.currentColor.get());
Popup.back();
2019-06-28 12:52:09 -05:00
},
'click .js-remove-color'() {
this.currentSwimlane.setColor(null);
Popup.back();
2019-06-28 12:52:09 -05:00
},
2019-01-24 16:47:09 +01:00
},
2019-06-28 12:52:09 -05:00
];
2019-01-24 16:47:09 +01:00
},
}).register('setSwimlaneColorPopup');
2023-06-13 13:43:09 -05:00
BlazeComponent.extendComponent({
onCreated() {
this.currentSwimlane = this.currentData();
},
applySwimlaneHeight() {
const swimlane = this.currentData();
const board = swimlane.boardId;
const height = parseInt(
Template.instance()
.$('.swimlane-height-value')
.val(),
10,
);
// FIXME(mark-i-m): where do we put constants?
2023-08-03 19:17:36 -05:00
// also in imports/i18n/data/en.i18n.json
2023-08-03 21:48:38 -05:00
if (height != -1 && (height < 100 || !height)) {
2023-06-13 13:43:09 -05:00
Template.instance()
.$('.swimlane-height-error')
.click();
} else {
Meteor.call('applySwimlaneHeight', board, swimlane._id, height);
Popup.back();
}
},
swimlaneHeightValue() {
const swimlane = this.currentData();
const board = swimlane.boardId;
return Meteor.user().getSwimlaneHeight(board, swimlane._id);
},
events() {
return [
{
'click .swimlane-height-apply': this.applySwimlaneHeight,
'click .swimlane-height-error': Popup.open('swimlaneHeightError'),
},
];
},
}).register('setSwimlaneHeightPopup');