Commit 0846e906 authored by Curtis Adam's avatar Curtis Adam

Refacotr card checks

parent 3946bbbe
Copyright (c) 2013 Marc J. Schmidt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This diff is collapsed.
......@@ -170,9 +170,6 @@ var CardsSchema = new SimpleSchema({
difficulty: {
type: Number
},
cardGroup: {
type: String
},
lecture: {
type: String,
optional: true,
......@@ -207,14 +204,13 @@ var CardsSchema = new SimpleSchema({
Cards.attachSchema(CardsSchema);
Meteor.methods({
addCard: function (cardset_id, subject, hint, front, back, difficulty, cardGroup, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
addCard: function (cardset_id, subject, hint, front, back, difficulty, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
check(cardset_id, String);
check(subject, String);
check(hint, String);
check(front, String);
check(back, String);
check(difficulty, Number);
check(cardGroup, String);
check(lecture, String);
check(centerTextElement, [Boolean]);
check(date, Date);
......@@ -227,9 +223,6 @@ Meteor.methods({
if (cardset.owner !== Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ["firstLogin", "blocked"])) {
throw new Meteor.Error("not-authorized");
}
if (!cardset.shuffled) {
cardGroup = "0";
}
if (cardset.cardType !== 2 || cardset.cardType !== 3 || cardset.cardType !== 5) {
if (subject === "") {
throw new Meteor.Error("Missing subject");
......@@ -246,7 +239,6 @@ Meteor.methods({
back: back,
cardset_id: cardset_id,
difficulty: difficulty,
cardGroup: cardGroup,
lecture: lecture,
centerTextElement: centerTextElement,
date: date,
......@@ -409,8 +401,7 @@ Meteor.methods({
date: date,
learningGoalLevel: learningGoalLevel,
backgroundStyle: backgroundStyle,
learningUnit: learningUnit,
cardType: cardset.cardType
learningUnit: learningUnit
}
});
Cardsets.update(card.cardset_id, {
......
......@@ -108,8 +108,12 @@ Template.registerHelper("canCopyCard", function (cardset_id) {
});
Template.registerHelper("isCardsetOwner", function (cardset_id) {
var owner = Cardsets.findOne({"_id": cardset_id}).owner;
return owner === Meteor.userId();
let cardset = Cardsets.findOne({"_id": cardset_id});
if (cardset !== undefined) {
return cardset.owner === Meteor.userId();
} else {
return false;
}
});
Template.registerHelper("isShuffleRoute", function () {
......
......@@ -74,7 +74,6 @@ var initTestNotificationsCards = function () {
"back": "Back of NotificationsTest: Card Nr. 1",
"hint": "Hint of NotificationsTest: Card Nr. 1",
"cardset_id": "NotificationsTestCardset",
"cardGroup": "0",
"lecture": "",
"centerTextElement": [false, false, false, false],
"learningGoalLevel": 0,
......@@ -89,7 +88,6 @@ var initTestNotificationsCards = function () {
"back": "Back of NotificationsTest: Card Nr. 2",
"hint": "Hint of NotificationsTest: Card Nr. 2",
"cardset_id": "NotificationsTestCardset",
"cardGroup": "0",
"lecture": "",
"centerTextElement": [false, false, false, false],
"learningGoalLevel": 1,
......@@ -104,7 +102,6 @@ var initTestNotificationsCards = function () {
"back": "Back of NotificationsTest: Card Nr. 3",
"hint": "Hint of NotificationsTest: Card Nr. 3",
"cardset_id": "NotificationsTestCardset",
"cardGroup": "0",
"lecture": "",
"centerTextElement": [false, false, false, false],
"learningGoalLevel": 2,
......@@ -119,7 +116,6 @@ var initTestNotificationsCards = function () {
"back": "Back of NotificationsTest: Card Nr. 4",
"hint": "Hint of NotificationsTest: Card Nr. 4",
"cardset_id": "NotificationsTestCardset",
"cardGroup": "0",
"lecture": "",
"centerTextElement": [false, false, false, false],
"learningGoalLevel": 3,
......@@ -134,7 +130,6 @@ var initTestNotificationsCards = function () {
"back": "Back of NotificationsTest: Card Nr. 5",
"hint": "Hint of NotificationsTest: Card Nr. 5",
"cardset_id": "NotificationsTestCardset",
"cardGroup": "0",
"lecture": "",
"centerTextElement": [false, false, false, false],
"learningGoalLevel": 4,
......@@ -508,17 +503,6 @@ Meteor.startup(function () {
}
}
);
Cards.update({
cardset_id: cardsets[i]._id
},
{
$set: {
cardGroup: "0"
}
},
{
multi: true
});
}
cardsets = Cardsets.find({}).fetch();
......
......@@ -113,7 +113,7 @@ Template.admin_card.events({
var front = $('#editCardFrontAdmin').val();
var back = $('#editCardBackAdmin').val();
var difficulty = $('input[name=difficulty]:checked').val();
Meteor.call("updateCard", this._id, subject, hint, front, back, Number(difficulty), Number(this.cardType), this.lecture, this.centerTextElement, this.date);
Meteor.call("updateCard", this._id, subject, hint, front, back, Number(difficulty), this.lecture, this.centerTextElement, this.date);
window.history.go(-1);
}
},
......
......@@ -94,10 +94,15 @@
</div>
</div>
{{isTextCentered}}
<div class="hidden-lg">
{{> btnCard}}
</div>
<div id="preview" class="col-xs-12 {{#unless fullscreenActive}}col-lg-6{{/unless}} cardtext">
<h5 class="editorElement">{{_ "previewEdit"}}</h5>
{{> flashcards cardset=this}}
</div>
</div>
<div class="row visible-lg">
{{> btnCard}}
</div>
</template>
......@@ -296,18 +301,16 @@
</template>
<template name="btnCard">
<div class="col-xs-12 col-sm-9 col-md-6 editorButtonGroup">
<div class="col-xs-12 col-sm-9 col-md-6">
<div class="actionButtons editorElement">
<br>
<button id="cardSave"
class="btn btn-success btn-raised saveFirst col-xs-12 col-sm-4" {{disableIfOffline}} tabindex="13">
<button class="btn btn-success btn-raised saveFirst col-xs-12 col-sm-4 cardSave" {{disableIfOffline}} tabindex="13">
{{_ "savecard"}}
</button>
<button id="cardSaveReturn"
class="btn btn-default btn-raised save col-xs-12 col-sm-4" {{disableIfOffline}} tabindex="14">
<button class="btn btn-default btn-raised save col-xs-12 col-sm-4 cardSaveReturn" {{disableIfOffline}} tabindex="14">
{{_ "savecardReturn"}}
</button>
<button id="cardCancel" class="btn btn-danger btn-raised cancel col-xs-12 col-sm-3 pull-right"
<button class="btn btn-danger btn-raised cancel col-xs-12 col-sm-3 cardCancel pull-right"
tabindex="15" data-toggle="modal"
data-target="#cancelEditModal">{{_
"declinecard"}}</button>
......@@ -315,11 +318,10 @@
</div>
{{#if isEditMode}}
{{#if isCardsetOwner this.cardset_id}}
<div class="col-xs-12 col-sm-3 col-md-6 editorButtonGroup">
<div class="col-xs-12 col-sm-3 col-md-6">
<div class="actionButtons editorElement">
<br>
<button id="cardDelete"
class="btn btn-danger btn-raised col-xs-12 col-md-3 pull-right" {{isDisabled}}
<button class="btn btn-danger btn-raised col-xs-12 col-md-3 pull-right cardDelete" {{isDisabled}}
tabindex="16" data-toggle="modal"
data-target="#deleteCardModal">{{_
"deletecard"}}</button>
......@@ -647,7 +649,7 @@
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12 {{#unless gotHint}}placeholder{{/unless}}">
<span class="{{#if gotHint}}{{#if isCentered}}center-align{{/if}}{{/if}}">
<span class="{{#if isCentered}}center-align{{/if}}">
{{#if gotHint}}
{{#mathjax}}{{getHint}}{{/mathjax}}
{{else}}
......
This diff is collapsed.
......@@ -399,7 +399,6 @@ img.cardside {
.cardHeader {
min-height: 90px;
height: 100%;
text-align: center;
font-size: 12px;
padding: 20px 100px 0 100px;
......@@ -529,7 +528,7 @@ img.cardside {
.cardtext h5, .editorHeader {
margin: 0;
padding-top: 20px;
padding-top: 15px;
padding-bottom: 5px;
color: white;
font-weight: bold;
......
......@@ -123,7 +123,7 @@
<tr>
<td><strong id="license_strong">{{_ "cardset.info.license"}}:</strong></td>
<td>
{{#unless isShuffledCardset this._id}}
{{#unless isShuffledCardset _id}}
<a id="info_license" href="#" data-id="{{_id}}" data-toggle="modal"
data-target="#showLicenseModal">{{getLicense}}</a>
{{else}}
......@@ -260,7 +260,7 @@
{{#if isCardsetOwner _id}}
<div class="panel-footer">
{{#unless learningActive}}
{{#unless isShuffledCardset this._id}}
{{#unless isShuffledCardset _id}}
<div class="btn-group btn-group-raised">
<a type="button" id="newCardBtn" class="btn btn-raised btn-success"
href="{{pathFor 'newCard'}}"
......@@ -1222,7 +1222,7 @@
{{#if isInRole 'blocked'}}
{{> access_denied_content_only}}
{{else}}
{{#unless isCardsetOwner this._id}}
{{#unless isCardsetOwner _id}}
{{> access_denied_content_only}}
{{else}}
<div class="container">
......
This diff is collapsed.
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