class AddCardPopover extends Popover { viewDidAppear() { this.cardTitleField.focus(); } setCategory(categoryId) { this.categoryId = categoryId; } onAddButtonPressed(event) { if (this.creatingCardData) { return; } if (this.cardTitleField.value.length < 1) { return; } this.addButton.disabled = true; this.creatingCardData = { title: this.cardTitleField.value, description: this.cardDescriptionField.value, id_category: this.categoryId }; TimeCards.dataManager.store("card", this.creatingCardData, this.onCardCreated.bind(this)); } onInput(event) { if (this.cardTitleField.value.length < 1) { this.addButton.disabled = true; return; } else { this.addButton.disabled = false; } //Only detect the enter key press when the active element is not the description field (we allow line breaks within that view) if (event.key == "Enter" && document.activeElement != this.cardDescriptionField) { this.onAddButtonPressed(event); } } onCardCreated(cardId, card) { this.reset(); this.dismiss(); } cardCreationError(cardId, card, error) { this.creatingCardData = null; } reset() { this.creatingCardData = null; this.cardTitleField.value = null; this.cardDescriptionField.value = null; this.addButton.disabled = true; } } UIKit.registerPopoverType(AddCardPopover);