main.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. angular.module('taboo', ['chatServices', 'tabooServices'])
  2. function partial(template) {
  3. return jsRoutes.controllers.Assets.at('partials/'+template+'.html').url;
  4. }
  5. function ViewCtrl($scope, Connection) {
  6. $scope.service = Connection;
  7. $scope.partial = partial;
  8. $scope.view = 'about';
  9. $scope.nav = [
  10. {partial: 'about', name: 'About'},
  11. {partial: 'chatRoom', name: 'Chat'},
  12. {partial: 'contribute', name: 'Contribute'}
  13. ];
  14. $scope.setView = function(p) {
  15. $scope.view = p;
  16. }
  17. $scope.$on('ws:connected', function() {
  18. $scope.view = 'chatRoom';
  19. });
  20. }
  21. function LoginCtrl($scope, Chat) {
  22. $scope.service = Chat;
  23. }
  24. function ChatCtrl($scope, Chat) {
  25. $scope.service = Chat;
  26. $scope.onType = function(event) {
  27. if(event.keyCode == 13) {
  28. Chat.send($scope.text);
  29. $scope.text = '';
  30. event.originalEvent.preventDefault();
  31. }
  32. }
  33. }
  34. function GameCtrl($scope, Taboo) {
  35. $scope.game = Taboo;
  36. }
  37. function ContributeCtrl($scope, $http) {
  38. $scope.submitting = false;
  39. function init() {
  40. $scope.card = {
  41. word: '',
  42. taboos: []
  43. };
  44. }
  45. $scope.submit = function() {
  46. if($scope.submitting) return;
  47. $scope.submitting = true;
  48. $http.post(jsRoutes.controllers.Cards.add().url, $scope.card)
  49. .then(function() {
  50. $scope.submitting = false;
  51. alert("Thank you for your contribution!");
  52. init();
  53. $('#inputWord').focus();
  54. });
  55. }
  56. init();
  57. }