Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* services.js */
- angular.module('pollService', [])
- .factory('Polls', function ($http) {
- return {
- getAll: function () {
- return $http.get('/api/polls');
- },
- vote: function (pollID, responseID) {
- return $http.post('api/polls/' + pollID + '/vote/', responseID);
- },
- getPoll: function (id) {
- return $http.get('/api/polls/' + id);
- },
- newPoll: function () {
- return $http.post('/api/polls/' + id, pollData);
- }
- }
- });
- /* controllers.js */
- //all polls controller
- pollGangster.controller('pollsController', function ($scope, $http, Polls) {
- $scope.pageClass = 'page-home';
- Polls.getAll()
- .success(function (data) {
- $scope.polls = data;
- })
- .error(function (data) {
- console.log('Error: ' + data);
- });
- })
- //individual poll controller
- pollGangster.controller('pollController', function ($scope, $http, $routeParams, Polls) {
- $scope.pageClass = 'page-poll';
- //submit vote
- $scope.submitVote = function () {
- Polls.vote($scope.pollData.id, $scope.pollData.responses[$scope.index])
- .success(function (data) {
- $scope.pollData = data;
- })
- .error(function (data) {
- console.dir(data);
- alert(data);
- })
- }
- Polls.getPoll($routeParams.id)
- .success(function (data, etc) {
- $scope.pollData = data;
- })
- .error(function (data) {
- alert('Something went wrong...Are you trying something sneaky?');
- })
- })
- //new poll controller
- pollGangster.controller('newController', function ($scope, $http) {
- $scope.pageClass = 'page-new';
- $scope.pollData = {
- responses: []
- };
- $scope.addResponse = function () {
- $scope.pollData.responses.push({
- responseText: ''
- });
- }
- $scope.createPoll = function () {
- $http.post('/api/polls', $scope.pollData);
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement