Commit 4179fa44 authored by Curtis Adam's avatar Curtis Adam

Add a registration period setting to the bonus phase and refactor more bonus form settings

parent ec9e0e1c
......@@ -11,6 +11,7 @@
@import '../imports/ui/markdeepEditor/content/content';
@import '../imports/ui/markdeepEditor/navigation/navigation';
@import '../imports/ui/filter/filter.scss';
@import '../imports/ui/forms/bonusForm.scss';
@import '../imports/ui/forms/cardsetForm.scss';
@import '../imports/ui/profile/profile.scss';
@import '../imports/ui/learn/learn.scss';
......
......@@ -543,14 +543,18 @@
"label": "Ende der Lernphase",
"placeholder": "In 3 Monaten"
},
"registrationPeriod": {
"label": "Anmeldefrist",
"placeholder": ""
},
"intervals": {
"label": "Lernintervalle in Tagen",
"error": "Die angegebenen Intervalle sind in falscher Reihenfolge! Sie werden automatisch umsortiert."
"label": "Lernintervalle in Tagen"
},
"button": {
"start": "Starten",
"cancel": "Abbrechen",
"update": "Aktualisieren"
"update": "Aktualisieren",
"reset": "Zurücksetzen"
}
}
},
......
......@@ -566,14 +566,18 @@
"label": "",
"placeholder": ""
},
"intervals": {
"registrationPeriod": {
"label": "",
"error": ""
"placeholder": ""
},
"intervals": {
"label": ""
},
"button": {
"start": "",
"cancel": "",
"update": ""
"update": "",
"reset": ""
}
}
},
......
import {Session} from "meteor/session";
import {Cardsets} from "./cardsets";
let defaultMaxWorkload = null;
let defaultDaysBeforeReset = null;
let minWorkloadCap = 1;
let defaultMaxWorkload = 30;
let minDaysBeforeReset = 3;
let maxDaysBeforeReset = 31;
let defaultDaysBeforeReset = 7;
let dateFormat = "YYYY-MM-DD";
let defaultRegistrationPeriod = [31, 'days'];
let defaultDateRegistrationPeriod = moment().add(defaultRegistrationPeriod[0], defaultRegistrationPeriod[1]).format(dateFormat);
let defaultIntervals = [1, 3, 7, 28, 84];
let defaultDateStart = moment().format(dateFormat);
let defaultEndPeriod = [3, 'months'];
let defaultDateEnd = moment().add(defaultEndPeriod[0], defaultEndPeriod[1]).format(dateFormat);
export let BonusForm = class BonusForm {
static cleanModal () {
let start, nextDay, end, dateBonusStart, dateBonusEnd, intervals, maxWorkload, daysBeforeReset;
let start, nextDay, end, intervals, maxWorkload, daysBeforeReset, registrationPeriod;
let dateBonusStart = $('#bonusFormModal #dateBonusStart');
let dateBonusEnd = $('#bonusFormModal #dateBonusEnd');
let dateRegistrationPeriodExpires = $('#bonusFormModal #dateRegistrationPeriod');
if (Session.get('isNewBonus')) {
start = moment().format("YYYY-MM-DD");
nextDay = moment().add(1, 'day').format("YYYY-MM-DD");
end = moment().add(3, 'months').format("YYYY-MM-DD");
maxWorkload = defaultMaxWorkload;
daysBeforeReset = defaultDaysBeforeReset;
start = defaultDateStart;
dateBonusStart.attr("min", defaultDateStart);
nextDay = moment().add(1, 'day').format(dateFormat);
end = defaultDateEnd;
registrationPeriod = defaultDateRegistrationPeriod;
maxWorkload = null;
daysBeforeReset = null;
intervals = defaultIntervals;
} else {
start = moment(Session.get('activeCardset').learningStart).format("YYYY-MM-DD");
nextDay = moment(Session.get('activeCardset').learningStart).add(1, 'day').format("YYYY-MM-DD");
end = moment(Session.get('activeCardset').learningEnd).format("YYYY-MM-DD");
start = moment(Session.get('activeCardset').learningStart).format(dateFormat);
nextDay = moment(Session.get('activeCardset').learningStart).add(1, 'day').format(dateFormat);
end = moment(Session.get('activeCardset').learningEnd).format(dateFormat);
registrationPeriod = moment(Session.get('activeCardset').registrationPeriod).format(dateFormat);
maxWorkload = Session.get('activeCardset').maxCards;
daysBeforeReset = Session.get('activeCardset').daysBeforeReset;
intervals = Session.get('activeCardset').learningInterval;
dateBonusStart.attr("min", start);
}
dateBonusStart = $('#bonusFormModal #dateBonusStart');
dateBonusEnd = $('#bonusFormModal #dateBonusEnd');
$('#bonusFormModal #maxWorkload').val(maxWorkload);
$('#bonusFormModal #daysBeforeReset').val(daysBeforeReset);
$('#bonusFormModal #interval1').val(intervals[0]);
......@@ -32,9 +49,115 @@ export let BonusForm = class BonusForm {
$('#bonusFormModal #interval4').val(intervals[3]);
$('#bonusFormModal #interval5').val(intervals[4]);
dateBonusStart.attr("min", start);
dateBonusStart.attr("max", end);
dateBonusStart.val(start);
dateBonusEnd.attr("min", nextDay);
dateBonusEnd.val(end);
dateRegistrationPeriodExpires.attr("min", nextDay);
dateRegistrationPeriodExpires.attr("max", end);
dateRegistrationPeriodExpires.val(registrationPeriod);
}
static adjustRegistrationPeriod () {
let dateBonusEnd = $('#bonusFormModal #dateBonusEnd');
let dateRegistrationPeriodExpires = $('#bonusFormModal #dateRegistrationPeriod');
dateRegistrationPeriodExpires.attr("max", dateBonusEnd.val());
if (this.getDateEnd().getTime() < this.getRegistrationPeriod().getTime()) {
dateRegistrationPeriodExpires.val(moment(dateBonusEnd.val()).format(dateFormat));
}
}
static adjustDaysBeforeReset () {
if (parseInt($('#bonusFormModal #daysBeforeReset').val()) <= (minDaysBeforeReset - 1)) {
$('#bonusFormModal #daysBeforeReset').val(minDaysBeforeReset);
} else if (parseInt($('#bonusFormModal #daysBeforeReset').val()) > maxDaysBeforeReset) {
$('#bonusFormModal #daysBeforeReset').val(maxDaysBeforeReset);
}
}
static adjustInterval () {
let interval, nextInterval;
for (let i = 1; i < 5; ++i) {
interval = $('#bonusFormModal #interval' + i);
nextInterval = $('#bonusFormModal #interval' + (i + 1));
if (parseInt(interval.val()) >= parseInt(nextInterval.val())) {
nextInterval.val(parseInt(interval.val()) + 1);
}
}
}
static adjustMaxWorkload () {
if (parseInt($('#bonusFormModal #maxWorkload').val()) <= (minWorkloadCap - 1)) {
$('#bonusFormModal #maxWorkload').val(minWorkloadCap);
} else if (parseInt($('#bonusFormModal #maxWorkload').val()) > Session.get('activeCardset').quantity) {
$('#bonusFormModal #maxWorkload').val(Session.get('activeCardset').quantity);
}
}
static getMaxWorkload () {
let maxWorkload = Number($('#bonusFormModal #maxWorkload').val());
if (!maxWorkload) {
maxWorkload = Number(defaultMaxWorkload);
}
return maxWorkload;
}
static getDaysBeforeReset () {
let daysBeforeReset = Number($('#bonusFormModal #daysBeforeReset').val());
if (!daysBeforeReset) {
daysBeforeReset = Number(defaultDaysBeforeReset);
}
return daysBeforeReset;
}
static getDateStart () {
let dateStart = new Date($('#bonusFormModal #dateBonusStart').val());
if (!dateStart) {
dateStart = defaultDateStart;
}
return dateStart;
}
static getDateEnd () {
let dateEnd = new Date($('#bonusFormModal #dateBonusEnd').val());
if (!dateEnd) {
dateEnd = defaultDateEnd;
}
return dateEnd;
}
static getIntervals () {
let intervals = [];
for (let i = 0; i < 5; ++i) {
intervals[i] = Number($('#bonusFormModal #interval' + (i + 1)).val());
}
if (!intervals[0]) {
intervals[0] = 1;
}
for (let i = 0; i < 5; ++i) {
if (!intervals[i]) {
intervals[i] = Number(defaultIntervals[i]);
}
}
return intervals;
}
static getRegistrationPeriod () {
let registrationPeriod = new Date($('#bonusFormModal #dateRegistrationPeriod').val());
if (!registrationPeriod) {
registrationPeriod = defaultDateRegistrationPeriod;
}
return registrationPeriod;
}
static startBonus () {
Meteor.call("activateBonus", Session.get('activeCardset')._id, this.getMaxWorkload(), this.getDaysBeforeReset(), this.getDateStart(), this.getDateEnd(), this.getIntervals(), this.getRegistrationPeriod());
}
static updateBonus () {
Meteor.call("updateBonus", Session.get('activeCardset')._id, this.getMaxWorkload(), this.getDaysBeforeReset(), this.getDateStart(), this.getDateEnd(), this.getIntervals(), this.getRegistrationPeriod(), function (error, result) {
if (result) {
Session.set('activeCardset', Cardsets.findOne(result));
}
});
}
};
......@@ -34,7 +34,8 @@ function getLearningPhaseInfo(cardset) {
[TAPi18n.__('bonus.form.maxWorkload.label', {}, "de"), cardset.maxCards],
[TAPi18n.__('bonus.form.daysBeforeReset.label', {}, "de"), cardset.daysBeforeReset],
[TAPi18n.__('bonus.form.startDate.label', {}, "de"), moment(cardset.learningStart).locale("de").format('LL')],
[TAPi18n.__('bonus.form.endDate.label', {}, "de"), moment(cardset.learningEnd).locale("de").format('LL')]
[TAPi18n.__('bonus.form.endDate.label', {}, "de"), moment(cardset.learningEnd).locale("de").format('LL')],
[TAPi18n.__('bonus.form.registrationPeriod.label', {}, "de"), moment(cardset.registrationPeriod).locale("de").format('LL')]
];
}
......@@ -104,7 +105,7 @@ Meteor.methods({
let infoCardsetCounter = 0;
let infoCardsetLength = 6;
let infoLearningPhaseCounter = 0;
let infoLearningPhaseLength = 7;
let infoLearningPhaseLength = 8;
content = header[6] + colSep + header[7] + colSep + header[8] + colSep;
for (let i = 0; i <= 4; i++) {
content += header[i] + " [" + cardset.learningInterval[i] + "]" + colSep;
......
......@@ -178,6 +178,9 @@ const CardsetsSchema = new SimpleSchema({
learningInterval: {
type: [Number]
},
registrationPeriod: {
type: Date
},
learners: {
type: Number
},
......@@ -308,6 +311,7 @@ Meteor.methods({
daysBeforeReset: 0,
learningStart: 0,
learningEnd: 0,
registrationPeriod: 0,
learningInterval: [],
learners: 0,
mailNotification: true,
......@@ -415,39 +419,25 @@ Meteor.methods({
/**
* Activate the learning phase for the selected cardset.
* @param {String} id - ID of the cardset for which the learning phase is to be activated.
* @param {String} maxCards - Maximum number of daily learnable cards
* @param {String} daysBeforeReset - Maximum overrun in days
* @param {Date} learningStart - Start date of the learnin gphase
* @param {Date} learningEnd - End date of the learning phase
* @param {String} learningInterval - Learning interval in days
* @param {Number} maxWorkload - Maximum number of daily learnable cards
* @param {Number} daysBeforeReset - Maximum overrun in days
* @param {Date} dateStart - Start date of the learnin gphase
* @param {Date} dateEnd - End date of the learning phase
* @param {Number} intervals - Learning interval in days
* @param {Date} registrationPeriod - Period in which new users can join the bonus phase
*/
activateBonus: function (id, maxCards, daysBeforeReset, learningStart, learningEnd, learningInterval) {
activateBonus: function (id, maxWorkload, daysBeforeReset, dateStart, dateEnd, intervals, registrationPeriod) {
check(id, String);
check(maxCards, String);
check(daysBeforeReset, String);
check(learningStart, Date);
check(learningEnd, Date);
check(learningInterval, [String]);
check(maxWorkload, Number);
check(daysBeforeReset, Number);
check(dateStart, Date);
check(dateEnd, Date);
check(intervals, [Number]);
check(registrationPeriod, Date);
let cardset = Cardsets.findOne(id);
if (cardset !== undefined && !cardset.learningActive && (Roles.userIsInRole(Meteor.userId(), ["admin", "editor"]) || cardset.owner === Meteor.userId())) {
if (!maxCards) {
maxCards = 5;
}
if (!daysBeforeReset) {
daysBeforeReset = 7;
}
if (!learningStart) {
learningStart = new Date();
}
if (!learningEnd) {
learningEnd = new Date();
learningEnd.setMonth(learningEnd.getMonth() + 3);
}
if (!learningInterval) {
learningInterval = [1, 3, 7, 4 * 7, 3 * 4 * 7];
}
learningInterval = learningInterval.sort(
intervals = intervals.sort(
function (a, b) {
return a - b;
}
......@@ -455,11 +445,12 @@ Meteor.methods({
Cardsets.update(id, {
$set: {
learningActive: true,
maxCards: maxCards,
maxCards: maxWorkload,
daysBeforeReset: daysBeforeReset,
learningStart: learningStart,
learningEnd: learningEnd,
learningInterval: learningInterval
learningStart: dateStart,
learningEnd: dateEnd,
learningInterval: intervals,
registrationPeriod: registrationPeriod
}
});
Meteor.call("clearLeitnerProgress", id);
......@@ -471,34 +462,37 @@ Meteor.methods({
/**
* Updates the settings of a learning phase for the selected cardset.
* @param {String} id - ID of the cardset for which the learning phase is to be activated.
* @param {String} maxCards - Maximum number of daily learnable cards
* @param {String} daysBeforeReset - Maximum overrun in days
* @param {Date} learningStart - Start date of the learnin gphase
* @param {Date} learningEnd - End date of the learning phase
* @param {String} learningInterval - Learning interval in days
* @param {Number} maxWorkload - Maximum number of daily learnable cards
* @param {Number} daysBeforeReset - Maximum overrun in days
* @param {Date} dateStart - Start date of the learnin gphase
* @param {Date} dateEnd - End date of the learning phase
* @param {Number} intervals - Learning interval in days
* @param {Date} registrationPeriod - Period in which new users can join the bonus phase
*/
updateBonus: function (id, maxCards, daysBeforeReset, learningStart, learningEnd, learningInterval) {
updateBonus: function (id, maxWorkload, daysBeforeReset, dateStart, dateEnd, intervals, registrationPeriod) {
check(id, String);
check(maxCards, String);
check(daysBeforeReset, String);
check(learningStart, Date);
check(learningEnd, Date);
check(learningInterval, [String]);
check(maxWorkload, Number);
check(daysBeforeReset, Number);
check(dateStart, Date);
check(dateEnd, Date);
check(intervals, [Number]);
check(registrationPeriod, Date);
let cardset = Cardsets.findOne(id);
if (cardset !== undefined && cardset.learningActive && (Roles.userIsInRole(Meteor.userId(), ["admin", "editor"]) || cardset.owner === Meteor.userId())) {
learningInterval = learningInterval.sort(
intervals = intervals.sort(
function (a, b) {
return a - b;
}
);
Cardsets.update(id, {
$set: {
maxCards: maxCards,
maxCards: maxWorkload,
daysBeforeReset: daysBeforeReset,
learningStart: learningStart,
learningEnd: learningEnd,
learningInterval: learningInterval
learningStart: dateStart,
learningEnd: dateEnd,
learningInterval: intervals,
registrationPeriod: registrationPeriod
}
});
return cardset._id;
......
......@@ -185,6 +185,7 @@ Meteor.methods({
daysBeforeReset: 0,
learningStart: 0,
learningEnd: 0,
registrationPeriod: 0,
learningInterval: [],
learners: 0,
mailNotification: true,
......@@ -299,6 +300,7 @@ Meteor.methods({
daysBeforeReset: 0,
learningStart: 0,
learningEnd: 0,
registrationPeriod: 0,
learningInterval: [],
learners: 0,
mailNotification: true,
......@@ -341,6 +343,7 @@ Meteor.methods({
daysBeforeReset: 0,
learningStart: 0,
learningEnd: 0,
registrationPeriod: 0,
learningInterval: [],
learners: 0,
mailNotification: true,
......
......@@ -48,6 +48,7 @@ var initTestNotificationsCardset = function () {
"daysBeforeReset": 0,
"learningStart": (new Date().setFullYear(2017, 9, 5)),
"learningEnd": (new Date().setFullYear(2038, 0, 19)),
"registrationPeriod": (new Date().setFullYear(2038, 0, 19)),
"learningInterval": [],
"wordcloud": false,
"learners": 0,
......@@ -596,6 +597,19 @@ Meteor.startup(function () {
}
}
cardsets = Cardsets.find({registrationPeriod: {$exists: false}}).fetch();
for (let i = 0; i < cardsets.length; i++) {
Cardsets.update({
_id: cardsets[i]._id
},
{
$set: {
registrationPeriod: cardsets[i].learningEnd
}
}
);
}
let wozniak = Wozniak.find({skipped: {$exists: true}}).fetch();
for (let i = 0; i < wozniak.length; i++) {
Wozniak.update({
......
......@@ -1445,6 +1445,10 @@
<td>{{_ "bonus.form.endDate.label"}}:</td>
<td>{{getDateEnd}}</td>
</tr>
<tr>
<td>{{_ "bonus.form.registrationPeriod.label"}}:</td>
<td>{{getRegistrationPeriod}}</td>
</tr>
</tbody>
</table>
</div>
......
......@@ -1570,6 +1570,9 @@ Template.learningPhaseInfoBox.helpers({
getDateStart: function () {
return moment(this.learningStart).format("DD.MM.YYYY");
},
getRegistrationPeriod: function () {
return moment(this.registrationPeriod).format("DD.MM.YYYY");
},
getDeadline: function () {
if (this.daysBeforeReset === 1) {
return this.daysBeforeReset + " " + TAPi18n.__('panel-body-experience.day');
......
......@@ -13,14 +13,17 @@
<div class="form-horizontal">
{{> bonusFormMaxWorkload}}
{{> bonusFormDaysBeforeReset}}
{{> bonusFormStartEndDate}}
{{> bonusFormStartDate}}
{{> bonusFormEndDate}}
{{> bonusFormRegistrationPeriod}}
{{> bonusFormIntervals}}
</div>
</div>
<div class="modal-footer">
<button id="cancelBonus" class="btn btn-default btn-raised btn-block col-xs-12 col-sm-3"
data-dismiss="modal">{{_ "bonus.form.button.cancel"}}</button>
<button id="resetBonus" class="btn btn-danger btn-raised btn-block col-xs-12 col-sm-3">{{_
"bonus.form.button.reset"}}</button>
<button id="startBonus"
class="btn btn-success btn-raised btn-block col-xs-12 col-sm-3 pull-right"
data-dismiss="modal">{{#if isNewBonus}}{{_ "bonus.form.button.start"}}{{else}}{{_
......@@ -57,7 +60,7 @@
</div>
</template>
<template name="bonusFormStartEndDate">
<template name="bonusFormStartDate">
<div class="form-group">
<label class="col-md-3 control-label">{{_ "bonus.form.startDate.label"}}</label>
<div class="col-md-9">
......@@ -65,6 +68,9 @@
placeholder="{{_ "bonus.form.startDate.placeholder"}}" value="">
</div>
</div>
</template>
<template name="bonusFormEndDate">
<div class="form-group">
<label class="col-md-3 control-label">{{_ "bonus.form.endDate.label"}}</label>
<div class="col-md-9">
......@@ -99,8 +105,15 @@
class="form-control interval" id="interval5"
placeholder="84" value="84">
</div>
<div class="col-md-12">
<span id="errorInterval" class="help-block name"></span>
</div>
</template>
<template name="bonusFormRegistrationPeriod">
<div class="form-group">
<label class="col-md-3 control-label">{{_ "bonus.form.registrationPeriod.label"}}</label>
<div class="col-md-9 form-inline">
<input type="date" class="form-control" id="dateRegistrationPeriod"
placeholder="{{_ "bonus.form.registrationPeriod.placeholder"}}" value="">
</div>
</div>
</template>
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {BonusForm} from "../../api/bonusForm";
import {Cardsets} from "../../api/cardsets";
import "./bonusForm.html";
/*
......@@ -11,6 +9,7 @@ import "./bonusForm.html";
*/
Template.bonusForm.onRendered(function () {
BonusForm.cleanModal();
$('#bonusFormModal').on('show.bs.modal', function () {
BonusForm.cleanModal();
});
......@@ -27,35 +26,17 @@ Template.bonusForm.helpers({
Template.bonusForm.events({
"click #startBonus": function () {
let maxCards = $('#bonusFormModal #maxWorkload').val();
let daysBeforeReset = $('#bonusFormModal #daysBeforeReset').val();
let learningStart = new Date($('#bonusFormModal #dateBonusStart').val());
let learningEnd = new Date($('#bonusFormModal #dateBonusEnd').val());
let learningInterval = [];
for (let i = 0; i < 5; ++i) {
learningInterval[i] = $('#bonusFormModal #interval' + (i + 1)).val();
}
if (!learningInterval[0]) {
learningInterval[0] = 1;
}
for (let i = 1; i < 5; ++i) {
if (!learningInterval[i]) {
learningInterval[i] = (parseInt(learningInterval[i - 1]) + 1);
}
}
if (Session.get('isNewBonus')) {
Meteor.call("activateBonus", Router.current().params._id, maxCards, daysBeforeReset, learningStart, learningEnd, learningInterval);
BonusForm.startBonus();
} else {
Meteor.call("updateBonus", Router.current().params._id, maxCards, daysBeforeReset, learningStart, learningEnd, learningInterval, function (error, result) {
if (result) {
Session.set('activeCardset', Cardsets.findOne(result));
}
});
BonusForm.updateBonus();
}
$('#bonusFormModal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
},
"click #resetBonus": function () {
BonusForm.cleanModal();
}
});
......@@ -66,12 +47,8 @@ Template.bonusForm.events({
*/
Template.bonusFormMaxWorkload.events({
"input #maxCards": function () {
if (parseInt($('#bonusFormModal #maxWorkload').val()) <= 0) {
$('#bonusFormModal #maxWorkload').val(1);
} else if (parseInt($('#bonusFormModal #maxWorkload').val()) > 100) {
$('#bonusFormModal #maxWorkload').val(100);
}
"input #maxWorkload": function () {
BonusForm.adjustMaxWorkload();
}
});
......@@ -83,43 +60,31 @@ Template.bonusFormMaxWorkload.events({
Template.bonusFormDaysBeforeReset.events({
"input #daysBeforeReset": function () {
if (parseInt($('#bonusFormModal #daysBeforeReset').val()) <= 0) {
$('#bonusFormModal #daysBeforeReset').val(1);
} else if (parseInt($('#bonusFormModal #daysBeforeReset').val()) > 100) {
$('#bonusFormModal #daysBeforeReset').val(100);
}
BonusForm.adjustDaysBeforeReset();
}
});
/*
* ############################################################################
* bonusFormStartEndDate
* bonusFormStartDate
* ############################################################################
*/
Template.bonusFormStartEndDate.events({
Template.bonusFormStartDate.events({
"input #dateBonusStart": function () {
const start = new Date($('#bonusFormModal #dateBonusStart').val());
const end = new Date($('#bonusFormModal #dateBonusEnd').val());
if (isNaN(start.getTime()) || start < new Date()) {
const today = new Date();
$('#bonusFormModal #dateBonusStart').val(today.getFullYear() + "-" + ((today.getMonth() + 1) < 10 ? '0' : '') + (today.getMonth() + 1) + "-" + (today.getDate() < 10 ? '0' : '') + end.getDate());
}
if (start >= end) {
end.setDate(end.getDate() - 1);
$('#bonusFormModal #dateBonusStart').val(end.getFullYear() + "-" + ((end.getMonth() + 1) < 10 ? '0' : '') + (end.getMonth() + 1) + "-" + (end.getDate() < 10 ? '0' : '') + end.getDate());
}
$('#bonusFormModal #dateBonusEnd').attr("min", (start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate()));
},
BonusForm.adjustRegistrationPeriod();
}
});
/*
* ############################################################################
* bonusFormEndDate
* ############################################################################
*/
Template.bonusFormEndDate.events({
"input #dateBonusEnd": function () {
const start = new Date($('#bonusFormModal #dateBonusStart').val());
let end = new Date($('#bonusFormModal #dateBonusEnd').val());
if (isNaN(end.getTime()) || start >= end) {
end = start;
end.setDate(end.getDate() + 1);
$('#bonusFormModal #dateBonusEnd').val(end.getFullYear() + "-" + ((end.getMonth() + 1) < 10 ? '0' : '') + (end.getMonth() + 1) + "-" + (end.getDate() < 10 ? '0' : '') + end.getDate());
}
$('#bonusFormModal #dateBonusStart').attr("max", (end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + (end.getDate() - 1)));
BonusForm.adjustRegistrationPeriod();
}
});
......@@ -131,27 +96,6 @@ Template.bonusFormStartEndDate.events({
Template.bonusFormIntervals.events({
"input #interval1, input #interval2, input #interval3, input #interval4, input #interval5": function () {
var error = false;
for (let i = 1; i < 5; ++i) {
if (parseInt($('#bonusFormModal #interval' + i).val()) <= 0) {
$('#bonusFormModal #interval' + i).val(1);
} else if (parseInt($('#bonusFormModal #interval' + i).val()) > 999) {
$('#bonusFormModal #interval' + i).val(999);
}
if (parseInt($('#bonusFormModal #interval' + i).val()) > parseInt($('#bonusFormModal #interval' + (i + 1)).val())) {
error = true;
}
}
if (error) {
for (let j = 1; j <= 5; ++j) {
$('#bonusFormModal #interval' + j).parent().parent().addClass('has-warning');
$('#bonusFormModal #errorInterval').html(TAPi18n.__('bonus.form.intervals.error'));
}
} else {
for (let k = 1; k <= 5; ++k) {
$('#bonusFormModal #interval' + k).parent().parent().removeClass('has-warning');
$('#bonusFormModal #errorInterval').html('');
}
}
BonusForm.adjustInterval();
}
});
#bonusFormModal {
#resetBonus {
margin-left: 15px;
}
}
......@@ -9,6 +9,17 @@ import {check} from "meteor/check";
import {CardType} from "../imports/api/cardTypes";
function gotBonusAccess(cardset, user_id) {
let hasAccess = true;
if (cardset.registrationPeriod.getTime() <= new Date().getTime()) {
let userAlreadyJoinedBonus = Leitner.findOne({cardset_id: cardset._id, user_id: user_id}, {fields: {_id: 1}});
if (userAlreadyJoinedBonus === undefined) {
hasAccess = false;
}
}
return hasAccess;
}
/** Function returns the amount of cards inside a box that are valid to learn
* @param {string} cardset_id - The id of the cardset with active learners
* @param {string} user_id - The id of the user
......@@ -298,13 +309,15 @@ function defaultCardsetLeitnerData(cardset) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");