diff --git a/config.js b/config.js index 39469fe..de79c9a 100644 --- a/config.js +++ b/config.js @@ -119,12 +119,12 @@ angular.module('flashy', [ templateUrl: 'templates/study.html', controller: 'StudyController' }). - state('flashcard', { + /*state('flashcard', { resolve: auth_resolve, url: '/flashcard', templateUrl: 'templates/flashcard.html', controller: 'FlashcardController' - }). + }).*/ state('settings', { resolve: auth_resolve, url: '/settings', diff --git a/scripts/DeckController.js b/scripts/DeckController.js index 64144ea..28efae7 100644 --- a/scripts/DeckController.js +++ b/scripts/DeckController.js @@ -9,5 +9,98 @@ angular.module('flashy.DeckController', ['ui.router', 'ngWebSocket']). $scope.deckPullCallback = $scope.addCardToGrid; $scope.deckUnpullCallback = $scope.hideCardFromGrid; + + + + + $scope.refreshEditCardInput = function () { + + + console.log("CARD IS BEING EDITED"); + + $scope.editCardText = $('#edit-card-input').text(); + + $scope.submit_enabled = $scope.editCardText.length >= 5 && $scope.editCardText.length <= 160; + + + + var i = 0; + $scope.editCardBlanks = []; + $('#edit-card-input')[0].childNodes.forEach(function (node) { + node = $(node)[0]; + if (node.tagName == 'B') { + var text = $(node).text(); + var leftspaces = 0, rightspaces = 0; + // awful way to find the first non-space character from the left or the right. thanks.js + while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; + while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; + console.log(leftspaces, text.length); + if (leftspaces != text.length) $scope.editCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); + i += text.length; + } else if (!node.data) { + i += $(node).text().length; + } else { + i += node.data.length; + } + }); + $scope.editCardBlanks.sort(function (a, b) { + return a[0] - b[0]; + }); + i = 0; + newtext = ''; + $scope.editCardBlanks.forEach(function (blank) { + newtext += $scope.editCardText.slice(i, blank[0]); + newtext += '' + $scope.editCardText.slice(blank[0], blank[1]) + ''; + i = blank[1]; + }); + newtext += $scope.editCardText.slice(i); + //$scope.newCardFormattedText = newtext; + + + }; + + + + $scope.saveChanges = function () { + + + var myCard = { + 'text': $('#edit-card-input').text(), + 'mask': $scope.editCardBlanks, + }; + + //console.log($scope.Flashcard.id); + + if (myCard.text == '') { + console.log('blank flashcard not pushed:' + myCard.text); + //return closeNewCard(); + + $('#editModal').closeModal(); + + } + $http.patch('/api/flashcards/' + $scope.Flashcard.id, myCard). + success(function (data) { + console.log('flashcard pushed: ' + myCard.text); + if (!UserService.hasVerifiedEmail()) { + Materialize.toast("
Thanks for contributing! However, others won't see your card until you verify your email address
", 4000); + } + }); + + $('#editModal').closeModal(); + + } + + + + + $scope.discardChanges = function() { + + $('#editModal').closeModal(); + + } + + + + } ); diff --git a/scripts/FlashcardFactory.js b/scripts/FlashcardFactory.js index 6cc5a8b..4d73aae 100644 --- a/scripts/FlashcardFactory.js +++ b/scripts/FlashcardFactory.js @@ -83,86 +83,14 @@ angular.module('flashy.FlashcardFactory', ['ui.router']). }; - Flashcard.prototype.refreshEditCardInput = function () { - - this.editCardText = $('#edit-card-input').text(); - - this.submit_enabled = this.editCardText.length >= 5 && this.editCardText.length <= 160; - - - - var i = 0; - this.editCardBlanks = []; - $('#edit-card-input')[0].childNodes.forEach(function (node) { - node = $(node)[0]; - if (node.tagName == 'B') { - var text = $(node).text(); - var leftspaces = 0, rightspaces = 0; - // awful way to find the first non-space character from the left or the right. thanks.js - while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; - while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; - console.log(leftspaces, text.length); - if (leftspaces != text.length) $scope.editCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); - i += text.length; - } else if (!node.data) { - i += $(node).text().length; - } else { - i += node.data.length; - } - }); - this.editCardBlanks.sort(function (a, b) { - return a[0] - b[0]; - }); - i = 0; - newtext = ''; - this.editCardBlanks.forEach(function (blank) { - newtext += this.editCardText.slice(i, blank[0]); - newtext += '' + this.editCardText.slice(blank[0], blank[1]) + ''; - i = blank[1]; - }); - newtext += this.editCardText.slice(i); - //$scope.newCardFormattedText = newtext;*/ - - - }; + + + - Flashcard.prototype.pushCard = function () { - - //console.log() - - var myCard = { - 'text': $('#edit-card-input').text(), - 'mask': this.editCardBlanks, - //section: this.section.id - }; - if (myCard.text == '') { - console.log('blank flashcard not pushed:' + myCard.text); - //return closeNewCard(); - - $('#editModal').closeModal(modal_options); - - } - $http.patch('/api/flashcards/' + this.id, myCard). - success(function (data) { - console.log('flashcard pushed: ' + myCard.text); - if (!UserService.hasVerifiedEmail()) { - Materialize.toast("
Thanks for contributing! However, others won't see your card until you verify your email address
", 4000); - } - }); - - $('#editModal').closeModal(modal_options); - - } - - - Flashcard.prototype.discardChanges = function() { - - $('#editModal').closeModal(modal_options); - - } + return Flashcard; diff --git a/templates/deck.html b/templates/deck.html index a6ab6bf..4735e36 100644 --- a/templates/deck.html +++ b/templates/deck.html @@ -1,50 +1,66 @@ -