diff --git a/scripts/FeedController.js b/scripts/FeedController.js index ff10ea4..477d783 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -22,8 +22,15 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $scope.updateColRanks($scope.cardCols[card.colNum]); }; + + + $scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + $scope.sectionId + '?subscribe-broadcast'); - $scope.feed_ws.onMessage(function(e) { + $scope.feed_ws.onMessage(function (e) { + + + console.log("oh yeaaaaaaaaaaaaaaaaaaa"); + data = JSON.parse(e.data); console.log('message', data); if (data.event_type == 'new_card') { diff --git a/scripts/FlashcardDirective.js b/scripts/FlashcardDirective.js index 895a4e2..ed91d40 100644 --- a/scripts/FlashcardDirective.js +++ b/scripts/FlashcardDirective.js @@ -1,18 +1,32 @@ angular.module('flashy.FlashcardDirective', []). directive('flashcard', - function($http, $state, $window) { - return { - templateUrl: '/app/templates/flashcard.html', - restrict: 'E', - scope: { - flashcard: '=flashcardObj', // flashcard-obj in parent html - refresh: '&' // eval refresh in parent html - }, - //link: function(scope, element) { - // $('.tooltipped').tooltip(); - // /* Handles width of the card */ - //} - }; + function ($http, $state, $window) { + return { + templateUrl: '/app/templates/flashcard.html', + restrict: 'E', + scope: { + flashcard: '=flashcardObj', // flashcard-obj in parent html + refresh: '&', // eval refresh in parent html + + }, + + + link: function (scope, element) { + $('.tooltipped').tooltip(); + /* Handles width of the card */ + //console.log(scope.flashcard); + } + } } + + + /*.directive('flashcardDeck', + function ($http, $state, $window) { + return { + + } + + })*/ + ); diff --git a/scripts/FlashcardFactory.js b/scripts/FlashcardFactory.js index 68d13d9..3d7749d 100644 --- a/scripts/FlashcardFactory.js +++ b/scripts/FlashcardFactory.js @@ -1,5 +1,5 @@ angular.module('flashy.FlashcardFactory', ['ui.router']). - factory('Flashcard', function ($http) { + factory('Flashcard', function ($http, UserService) { var FlashcardCache = []; var Deck = null; var Flashcard = function (data, deck) { @@ -40,5 +40,111 @@ angular.module('flashy.FlashcardFactory', ['ui.router']). return $http.post('/api/flashcards/' + this.id + '/hide/'); }; + Flashcard.prototype.edit = function () { + + + var editableText = this.formatted_text; + + //$('#flashcardEditText').html(this.formatted_text); + + $('.modal-trigger').leanModal({ + dismissible: true, // Modal can be dismissed by clicking outside of the modal + opacity: .5, // Opacity of modal background + in_duration: 300, // Transition in duration + out_duration: 200, // Transition out duration + ready: function () { + + $('#edit-card-input').html(editableText); + + + + }, // Callback for Modal open + complete: function () { + + console.log("EDIT MODAL CLOSED"); + + } // Callback for Modal close + }); + + }; + + + + Flashcard.prototype.refreshEditCardInput = function () { + + console.log("ASDFASDFASDFASFD"); + + + 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(); + } + $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); + } + }); + //return .closeNewCardModal(); + + } + + + return Flashcard; }); \ No newline at end of file diff --git a/templates/flashcard.html b/templates/flashcard.html index 0b74f40..56e5ee2 100644 --- a/templates/flashcard.html +++ b/templates/flashcard.html @@ -1,8 +1,12 @@ -

+
+ + + + +
@@ -13,15 +17,87 @@
-
-
+ + +
+
+ + + +
+ + + + + + + + + + + + + +
@@ -29,4 +105,9 @@
score:{{flashcard.score}}
+ + + + +