Commit 4aa96714 authored by Curtis Adam's avatar Curtis Adam

Edit Card: Add a button to directly jump to the next card

parent e3895a9b
......@@ -1414,6 +1414,7 @@
"confirmcard": "Sicher?",
"savecard": "Speichern & neue Karte",
"savecardReturn": "Speichern & zurück",
"savecardNext": "Speichern & nächste Karte",
"savecardSuccess": "Die Karte wurde gespeichert",
"deletecardSuccess": "Die Karte wurde gelöscht",
"valuation": "Bewertung",
......
......@@ -6,6 +6,8 @@ import {CardNavigation} from "./cardNavigation";
import {Cardsets} from "./cardsets";
import {BertAlertVisuals} from "./bertAlertVisuals";
import {CardVisuals} from "./cardVisuals";
import {CardIndex} from "./cardIndex";
import {Cards} from "./cards";
const subjectMaxLength = 255;
const contentMaxLength = 300000;
......@@ -21,12 +23,17 @@ export let CardEditor = class CardEditor {
editorButtonIndex = 0;
editorButtons = [];
editorButtons.push('#subjectEditor');
if ($('#learningGoalLevelGroup').length) {
if (CardType.gotLearningGoal(Session.get('cardType'))) {
editorButtons.push(learningGoalLevelGroupName);
}
editorButtons.push(cardNavigationName);
editorButtons.push('#cardSave');
if (Route.isNewCard()) {
editorButtons.push('#cardSave');
}
editorButtons.push('#cardSaveReturn');
if (Route.isEditCard()) {
editorButtons.push('#cardSaveNext');
}
editorButtons.push('#cardCancel');
this.setEditorButtonFocus();
}
......@@ -131,7 +138,7 @@ export let CardEditor = class CardEditor {
Session.set('content6', '');
Session.set('learningGoalLevel', 0);
Session.set('backgroundStyle', 1);
Session.set('cameFromEditMode');
Session.set('cameFromEditMode', false);
CardType.setDefaultCenteredText(Session.get('cardType'));
}
......@@ -220,7 +227,7 @@ export let CardEditor = class CardEditor {
}
static saveCard (card_id, returnToCardset) {
static saveCard (card_id, navigationTarget) {
this.initializeContent();
let content1 = Session.get('content1');
let content2 = Session.get('content2');
......@@ -287,17 +294,18 @@ export let CardEditor = class CardEditor {
Meteor.call("addCard", Router.current().params._id, subject, content1, content2, content3, content4, content5, content6, centerTextElement, alignType, date, Number(learningGoalLevel), Number(backgroundStyle), learningIndex, learningUnit, function (error, result) {
if (result) {
BertAlertVisuals.displayBertAlert(TAPi18n.__('savecardSuccess'), "success", 'growl-top-left');
Session.set('activeCard', result);
if (returnToCardset) {
Router.go('cardsetdetailsid', {
_id: Router.current().params._id
});
} else {
if (navigationTarget === 0) {
$('#contentEditor').val('');
$('#editor').attr('data-content', '');
CardEditor.resetSessionData();
window.scrollTo(0, 0);
CardEditor.setEditorButtonIndex(0);
CardNavigation.selectButton();
} else {
Session.set('activeCard', result);
Router.go('cardsetdetailsid', {
_id: Router.current().params._id
});
}
}
});
......@@ -305,15 +313,21 @@ export let CardEditor = class CardEditor {
Meteor.call("updateCard", card_id, subject, content1, content2, content3, content4, content5, content6, centerTextElement, alignType, Number(learningGoalLevel), Number(backgroundStyle), learningIndex, learningUnit);
BertAlertVisuals.displayBertAlert(TAPi18n.__('savecardSuccess'), "success", 'growl-top-left');
Session.set('activeCard', Router.current().params.card_id);
if (returnToCardset) {
if (navigationTarget === 1) {
Router.go('cardsetdetailsid', {
_id: Router.current().params._id
});
} else {
Session.set('cameFromEditMode', true);
Router.go('newCard', {
_id: Router.current().params._id
CardEditor.setEditorButtonIndex(0);
CardNavigation.selectButton();
window.scrollTo(0, 0);
let nextId = CardIndex.getNextCardID(card_id);
Router.go('editCard', {
_id: Router.current().params._id,
card_id: nextId
});
Session.set('activeCard', nextId);
CardEditor.loadEditModeContent(Cards.findOne({_id: nextId, cardset_id: Router.current().params._id}));
}
}
}
......
......@@ -25,7 +25,9 @@ export let CardIndex = class CardIndex {
}
if (Route.isEditMode()) {
result = this.getEditModeCard();
Session.set('activeCard', -1);
if (Route.isNewCard()) {
Session.set('activeCard', -1);
}
}
if (Session.get('activeCard') === undefined && result[0] !== undefined) {
CardNavigation.setActiveCardData(result[0]._id);
......@@ -233,8 +235,12 @@ export let CardIndex = class CardIndex {
* @return {Collection} The Session Data of the card.
*/
static getEditModeCard () {
this.initializeIndex();
let id = "-1";
if (Route.isEditMode()) {
if (Route.isEditCard()) {
if (Session.get('activeCard') === undefined) {
Session.set('activeCard', Router.current().params.card_id);
}
id = Session.get('activeCard');
} else {
Session.set('activeCard', undefined);
......@@ -287,4 +293,20 @@ export let CardIndex = class CardIndex {
});
return cards;
}
static getNextCardID (card_id) {
let cardIndex = this.getCardIndex();
let index = cardIndex.findIndex(item => item === card_id);
++index;
if (index >= cardIndex.length) {
return cardIndex[0];
} else {
return cardIndex[index];
}
}
static getActiveCardIndex (card_id) {
let cardIndex = this.getCardIndex();
return cardIndex.findIndex(item => item === card_id) + 1;
}
};
......@@ -40,28 +40,45 @@ export let Dictionary = class Dictionary {
static initializeQuery (card) {
let searchText = "";
switch (Session.get('activeCardContentId')) {
case 1:
searchText = card.front.trim();
break;
case 2:
searchText = card.back.trim();
break;
case 3:
searchText = card.hint.trim();
break;
case 4:
searchText = card.lecture.trim();
break;
case 5:
searchText = card.top.trim();
break;
case 6:
searchText = card.bottom.trim();
break;
if (card !== undefined) {
switch (Session.get('activeCardContentId')) {
case 1:
if (card.front !== undefined) {
searchText = card.front.trim();
}
break;
case 2:
if (card.back !== undefined) {
searchText = card.back.trim();
}
break;
case 3:
if (card.hint !== undefined) {
searchText = card.hint.trim();
}
break;
case 4:
if (card.lecture !== undefined) {
searchText = card.lecture.trim();
}
break;
case 5:
if (card.top !== undefined) {
searchText = card.top.trim();
}
break;
case 6:
if (card.bottom !== undefined) {
searchText = card.bottom.trim();
}
break;
}
let rawQuery = searchText.split(/\s+/);
Session.set('wordCount', rawQuery.length);
} else {
Session.set('wordCount', 0);
}
let rawQuery = searchText.split(/\s+/);
Session.set('wordCount', rawQuery.length);
return searchText;
}
......
......@@ -429,6 +429,13 @@ Template.registerHelper("hasCardsetPermission", function () {
return UserPermissions.hasCardsetPermission(Router.current().params._id);
});
Template.registerHelper("isEditCard", function () {
return Route.isEditCard();
});
Template.registerHelper("isNewCard", function () {
return Route.isNewCard();
});
//Returns all Colleges
Template.registerHelper("getColleges", function () {
......
......@@ -18,6 +18,7 @@ import './content/content.js';
import './navigation/navigation.js';
import './modal/settings.js';
import {BertAlertVisuals} from "../../api/bertAlertVisuals";
import {CardEditor} from "../../api/cardEditor";
/*
* ############################################################################
......@@ -78,6 +79,9 @@ Template.flashcards.onRendered(function () {
});
CardVisuals.resizeFlashcard();
CardVisuals.setTextZoom();
if (Route.isEditMode()) {
CardEditor.setEditorButtonIndex(0);
}
});
Template.flashcards.onDestroyed(function () {
......@@ -113,8 +117,7 @@ Template.flashcards.helpers({
return CardIndex.getCards();
},
cardsIndex: function (card_id) {
let cardIndex = CardIndex.getCardIndex();
return cardIndex.findIndex(item => item === card_id) + 1;
return CardIndex.getActiveCardIndex(card_id);
},
isBeolingusDictionary: function () {
if (CardType.gotDictionary(this.cardType)) {
......
......@@ -11,6 +11,9 @@
{{#if isDemo}}
{{> cardContentItemCountCards this}}
{{/if}}
{{#if isEditCard}}
{{> cardContentItemCountCards this}}
{{/if}}
{{#if isBox}}
{{> cardContentItemCountCardsLeitner this}}
{{/if}}
......
......@@ -12,8 +12,7 @@ import {Cardsets} from "../../../../api/cardsets";
Template.cardContentItemCountCards.helpers({
cardsIndex: function (card_id) {
let cardIndex = CardIndex.getCardIndex();
return cardIndex.findIndex(item => item === card_id) + 1;
return CardIndex.getActiveCardIndex(card_id);
},
getCardsetCount: function (isPreview) {
if (Route.isDemo()) {
......
......@@ -5,7 +5,6 @@ import {Cardsets} from "../../../api/cardsets";
import {CardEditor} from "../../../api/cardEditor.js";
import {CardVisuals} from "../../../api/cardVisuals";
import ResizeSensor from "../../../../client/thirdParty/resizeSensor/ResizeSensor";
import {Cards} from "../../../api/cards";
import "../card.js";
import "./modal/deeplTranslation.js";
import "./modal/learningUnit.js";
......@@ -13,6 +12,7 @@ import "./item/buttons.js";
import "./item/learningGoalLevel.js";
import "./item/subject.js";
import "./editor.html";
import {Cards} from "../../../api/cards";
/*
* ############################################################################
......@@ -80,7 +80,7 @@ Template.newCard.onCreated(function () {
* ############################################################################
*/
Template.editCard.onCreated(function () {
CardEditor.loadEditModeContent(Cards.findOne({_id: Router.current().params.card_id, cardset_id: Router.current().params._id}));
Session.set('cardType', Cardsets.findOne({_id: Router.current().params._id}).cardType);
Session.set('difficultyColor', Cardsets.findOne({_id: Router.current().params._id}).difficulty);
CardEditor.loadEditModeContent(Cards.findOne({_id: Router.current().params.card_id}));
});
<template name="btnCard">
<div id="button-row" class="col-xs-12 actionButtons editorElement">
<button id="cardSave"
class="btn btn-success btn-raised saveFirst col-xs-12 col-sm-4" {{disableIfOffline}}
tabindex="13">
{{_ "savecard"}}
</button>
{{#if isNewCard}}
<button id="cardSave"
class="btn btn-success btn-raised saveFirst col-xs-12 col-sm-4" {{disableIfOffline}}
tabindex="13">
{{_ "savecard"}}
</button>
{{/if}}
<button id="cardSaveReturn"
class="btn btn-default btn-raised save col-xs-12 col-sm-4" {{disableIfOffline}}
class="btn {{#if
isEditCard}}btn-success{{else}}btn-default{{/if}} btn-raised save col-xs-12 col-sm-4" {{disableIfOffline}}
tabindex="14">
{{_ "savecardReturn"}}
</button>
{{#if isEditCard}}
{{#if gotMultipleCards}}
<button id="cardSaveNext"
class="btn btn-default btn-raised saveNext col-xs-12 col-sm-4" {{disableIfOffline}}
tabindex="15">{{_ "savecardNext"}}</button>
{{/if}}
{{/if}}
<button id="cardCancel" class="btn btn-danger btn-raised cancel col-xs-12 col-sm-3 pull-right"
tabindex="15" data-toggle="modal"
tabindex="16" data-toggle="modal"
data-target="#cancelEditModal">{{_
"declinecard"}}</button>
</div>
......
import {Route} from "../../../../api/route.js";
import {CardEditor} from "../../../../api/cardEditor.js";
import {Cardsets} from "../../../../api/cardsets.js";
import "./buttons.html";
import {CardIndex} from "../../../../api/cardIndex";
/*
* ############################################################################
......@@ -10,19 +10,23 @@ import "./buttons.html";
*/
Template.btnCard.helpers({
isEditMode: function () {
return Route.isEditMode();
},
learningActive: function () {
return Cardsets.findOne(Router.current().params._id).learningActive;
},
gotMultipleCards: function () {
CardIndex.initializeIndex();
return CardIndex.getCardIndex().length > 1;
}
});
Template.btnCard.events({
"click #cardSave": function () {
CardEditor.saveCard(Router.current().params.card_id, false);
CardEditor.saveCard(Router.current().params.card_id, 0);
},
"click #cardSaveReturn": function () {
CardEditor.saveCard(Router.current().params.card_id, true);
CardEditor.saveCard(Router.current().params.card_id, 1);
},
"click #cardSaveNext": function () {
CardEditor.saveCard(Router.current().params.card_id, 2);
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment