'use strict';

angular.module('myApp')
  .controller('ViewEventCtrl', ['$scope', '$http', 'BASE_MAP', 'currentUserService',
    function ($scope, $http, BASE_MAP, currentUserService) {
      var event = _myInit.event;
      console.log("Event", event);

      $scope.event = event;

      $scope.map = _.extend(BASE_MAP, {
        center: {
          latitude: event.place.latitude,
          longitude: event.place.longitude
        },
        zoom: 16
      });

      function init() {
        var curUserId = currentUserService.userId;
        var isPart = _.find(event.participants, function(partId) {
          return partId === curUserId;
        });
        setPart(isPart);
      }

      function setPart(isPart) {
        if (isPart) {
          $scope.isPart = true;
          $scope.partBtnName = 'Отказаться от участия?';
        } else {
          $scope.isPart = false;
          $scope.partBtnName = 'Принять участие';
        }
      }

      $scope.participate = function() {
        var $partBtn = $('#partBtn');
        $partBtn.attr('disabled','disabled');

        var params = {eventId: event._id, act: $scope.isPart ? 'remove' : 'add'};
        $http({method: 'POST', url: '/api/meetua/events/participation', params: params}).
          success(function(data, status, headers, config) {
            $partBtn.removeAttr('disabled');
            setPart(data.status === 'added');
          }).
          error(function(data, status, headers, config) {
            // TODO show on UI that failed to participate in event.
            $partBtn.removeAttr('disabled');
            setPart(false);
            console.error('Failed to change participation in event', data);
          });
      };

      init();
    }]);
@@ -659,23 +659,35 @@
         
-setPart
+changeParticipation
 (isPart)
@@ -712,23 +712,35 @@
 unction 
-setPart
+changeParticipation
 (isPart)
@@ -1083,16 +1083,17 @@
 sabled',
+ 
 'disable
@@ -1387,23 +1387,35 @@
         
-setPart
+changeParticipation
 (data.st
@@ -1634,15 +1634,27 @@
     
-setPart
+changeParticipation
 (fal

Rename method