/*
* Document : be_pages_generic_scrumboard.js
* Author : pixelcave
* Description: Custom JS code used in Scrum Board Page
*/
// Helper variables
let scrumBoard, itemList, itemInput, itemInputVal, cardInput, cardInputVal;
class BeScrumBoard {
/*
* Description
*
*/
static initScrumBoard() {
scrumBoard = jQuery('.js-scrumboard');
// Make the main container a flex container
jQuery('#main-container').addClass('d-flex align-items-stretch');
// Fade in the main scrumboard content
scrumBoard.fadeTo(1000, 1);
}
/*
* Description
*
*/
static cardAdd() {
scrumBoard.on('submit.cb.sb.card.add', 'form[data-toggle="sb-card-add"]', e => {
e.preventDefault();
// Get input value
cardInput = jQuery(e.currentTarget).find('input');
cardInputVal = cardInput.prop('value');
// Check if the user entered something
if (cardInputVal) {
// Add Card
cardInput.parents('.scrumboard-col').before(
'
'
);
// Clear and focus input field
cardInput.prop('value', '');
// Refresh sortable
this.initDraggableItems('refresh');
}
});
}
/*
* Description
*
*/
static itemAdd() {
scrumBoard.on('submit.cb.sb.item.add', 'form[data-toggle="sb-item-add"]', e => {
e.preventDefault();
// Get input value
itemList = jQuery(e.currentTarget).parents('.scrumboard-col').find('.scrumboard-items');
itemInput = jQuery(e.currentTarget).find('input');
itemInputVal = itemInput.prop('value');
// Check if the user entered something
if (itemInputVal) {
// Add Item
itemList.prepend(
'' +
'
' +
'
' +
jQuery('').text(itemInputVal).html() +
'
' +
'
'
);
// Clear and focus input field
itemInput.prop('value', '').focus();
// Refresh sortable
this.initDraggableItems('refresh');
}
});
}
/*
* Description
*
*/
static itemRemove() {
scrumBoard.on('click.cb.sb.item.remove', 'button[data-toggle="sb-item-remove"]', e => {
jQuery(e.currentTarget).parents('.scrumboard-item').remove();
});
}
/*
* Description
*
*/
static initDraggableItems(mode) {
if (mode === 'refresh') {
jQuery('.scrumboard-items.js-draggable-enabled').sortable('destroy');
this.initDraggableItems();
} else {
jQuery('.scrumboard-items').addClass('js-draggable-enabled').sortable({
connectWith: '.scrumboard-items',
items: '.scrumboard-item',
dropOnEmpty: true,
opacity: .75,
handle: '.scrumboard-item-handler',
placeholder: 'scrumboard-item-placeholder',
tolerance: 'pointer',
start: (e, ui) => {
ui.placeholder.css({
height: ui.item.outerHeight(),
'margin-bottom': ui.item.css('margin-bottom')
});
}
});
}
}
/*
* Init functionality
*
*/
static init() {
this.initScrumBoard();
this.cardAdd();
this.itemAdd();
this.itemRemove();
this.initDraggableItems();
}
}
// Initialize when page loads
jQuery(() => { BeScrumBoard.init(); });