public.javascripts.site.controllers.js


 

var c = angular.module('Spotdekhoapp.controllers', []);

c.controller('wPController', function($scope,spotdekhoAPIservice){
    var loc = location.pathname;
    loc = loc.replace("\/","");
    spotdekhoAPIservice.getWelcomePage(loc).success(function(data){
            $scope.venues = data.venue;
            $scope.city = loc;
    });
});

c.controller('typeController', function ($scope, spotdekhoAPIservice){
    var loc = location.pathname;
    spotdekhoAPIservice.getWelcomePageByType(loc).success(function(data){
            $scope.venues = data.venue;
            $scope.city = loc;
    });
});

c.filter('capitalize', function() {
    return function(input) {
      return (!!input) ? input.charAt(0).toUpperCase() + input.substr(1).toLowerCase() : '';
    }
});

c.controller('offersController',function($scope, $routeParams,spotdekhoAPIservice){
        spotdekhoAPIservice.getOffers(getCPage('offers')).success(function(data){
            $scope.O = data.O;
    });
});

c.controller('venuesController',function($scope, $routeParams,spotdekhoAPIservice){
    spotdekhoAPIservice.getVenues( getCPage('venues')).success(function(data){
            $scope.venues = data;
    });
});

c.controller('subListController', function($scope,spotdekhoAPIservice,$filter){
    spotdekhoAPIservice.getsubList( getCPage('subList')).success(function(data){
        $scope.S = data.S;
        $scope.r = data.r;
        $scope.verify = data.c;
        $scope.a = data.a;
        $scope.t = data.t;
        $scope.u = data.u;
        $scope.avgForStar = ( $scope.a / 5) * 100 ;

          $('#map-canvas').each(function () {

                var latlng = new google.maps.LatLng(data.S.loc.coordinates[1], data.S.loc.coordinates[0]);
                var mapOptions = {
                  zoom: 14,
                  center: latlng,
                  disableDefaultUI: true
                };

                var map = new google.maps.Map(this, mapOptions);
                var marker = new google.maps.Marker({
                  position: latlng,
                  map: map,
                  title: data.v.name
                });
          });
    });
    $scope.postNewPost = function() {
        if (!$scope.newMessage) return;
        var commment = $scope.newMessage;
        var id = getCPage('subList');
        var date = new Date();
        var curdate = $filter('date')(new Date(), 'dd, MMMM yyyy HH:mm:ss');
        spotdekhoAPIservice.postComment(id, commment, curdate).success(function (data) {
            if (data.hasError) {
                $('#login-modal').modal({
                    show: false
                });
                $('#login-modal').on('show.bs.modal', function (eve) {
                    modal = $(this);
        //                    modal.find('.modal-body').text(data.error);
                })
                $('#login-modal').modal('show');
            } else {
                $('#comment-modal').modal({
                    show: false
                });
                $('#comment-modal').on('show.bs.modal', function (eve) {
                    modal = $(this);
       //              modal.find('.modal-body').text("Thanks for your comment. It will be soon available after review.");
                })
                $('#comment-modal').modal('show');
                $scope.newMessage = null;

            }
        });
    };

    $scope.rateFunction = function(rating) {
       var id = getCPage('subList');
       spotdekhoAPIservice.postRating(id, rating).success(function (data) {
         if (data.hasError) {
             $('#login-modal').modal({
                 show: false
             });
             $('#login-modal').on('show.bs.modal', function (eve) {
                 modal = $(this);
//                    modal.find('.modal-body').text(data.error);
             })
             $('#login-modal').modal('show');
         }
         else{
           if ($scope.u =='0' && $scope.t =='0'){
             $scope.u = rating;
             $scope.t = $scope.t +1;
             $scope.a = rating;
             $scope.avgForStar = ($scope.a / 5) * 100 ;
           }
           if ($scope.u =='0' && $scope.t !='0'){
             $scope.u = rating;
             $scope.a = ((($scope.a * $scope.t) + rating )/ ($scope.t + 1) );
             $scope.t = $scope.t +1;
             $scope.avgForStar = ($scope.a / 5) * 100 ;
           }
           if ($scope.u !='0' && $scope.t !='0'){
             $scope.a = (((($scope.a * $scope.t) - $scope.u) + rating)/ ($scope.t));
             $scope.u = rating;
             $scope.avgForStar = ($scope.a / 5) * 100 ;
           }
           $scope.a = parseFloat($scope.a).toFixed(2);
         }
       });
     };
});

c.controller('venueController',function($scope,spotdekhoAPIservice,$filter){
    spotdekhoAPIservice.getVenueDetail( getCPage('venues')).success(function(data){
            $scope.v = data.v;
            $scope.o = data.o;
            $scope.s = data.s;
            $scope.r = data.r;
            $scope.verify = data.c;
            $scope.a = data.a;
            $scope.t = data.t;
            $scope.u = data.u;
            $scope.avgForStar = ( $scope.a / 5) * 100 ;

              $('#map-canvas').each(function () {

                var latlng = new google.maps.LatLng(data.v.loc.coordinates[1], data.v.loc.coordinates[0]);
                var mapOptions = {
                  zoom: 14,
                  center: latlng,
                  disableDefaultUI: true
                };

                var map = new google.maps.Map(this, mapOptions);
                var marker = new google.maps.Marker({
                  position: latlng,
                  map: map,
                  title: data.v.name
                });
              });
    });

    $scope.postNewPost = function() {
        if (!$scope.newMessage) return;
        var commment = $scope.newMessage;
        var id = getCPage('venues');
        var date = new Date();
        var curdate = $filter('date')(new Date(), 'dd, MMMM yyyy HH:mm:ss');
        spotdekhoAPIservice.postComment(id, commment, curdate).success(function (data) {
            if (data.hasError) {
                $('#login-modal').modal({
                    show: false
                });
                $('#login-modal').on('show.bs.modal', function (eve) {
                    modal = $(this);
//                    modal.find('.modal-body').text(data.error);
                })
                $('#login-modal').modal('show');
            } else {
                $('#comment-modal').modal({
                    show: false
                });
                $('#comment-modal').on('show.bs.modal', function (eve) {
                    modal = $(this);
//                    modal.find('.modal-body').text("Thanks for your comment. It will be soon available after review.");
                })
                $('#comment-modal').modal('show');
                $scope.newMessage = null;

            }
        });
      };

      $scope.rateFunction = function(rating) {
         var id = getCPage('venues');
         spotdekhoAPIservice.postRating(id, rating).success(function (data) {
           if (data.hasError) {
               $('#login-modal').modal({
                   show: false
               });
               $('#login-modal').on('show.bs.modal', function (eve) {
                   modal = $(this);
//                    modal.find('.modal-body').text(data.error);
               })
               $('#login-modal').modal('show');
           }
           else{
             if ($scope.u =='0' && $scope.t =='0'){
               $scope.u = rating;
               $scope.t = $scope.t +1;
               $scope.a = rating;
               $scope.avgForStar = ($scope.a / 5) * 100 ;
             }
             if ($scope.u =='0' && $scope.t !='0'){
               $scope.u = rating;
               $scope.a = ((($scope.a * $scope.t) + rating )/ ($scope.t + 1) );
               $scope.t = $scope.t +1;
               $scope.avgForStar = ($scope.a / 5) * 100 ;
             }
             if ($scope.u !='0' && $scope.t !='0'){
               $scope.a = (((($scope.a * $scope.t) - $scope.u) + rating)/ ($scope.t));
               $scope.u = rating;
               $scope.avgForStar = ($scope.a / 5) * 100 ;
             }
             $scope.a = parseFloat($scope.a).toFixed(2);
           }
         });
       };
});

c.directive('starRating',
	function() {
		return {
			restrict : 'A',
			template : '<ul class="rating background">'
					 + '	<li ng-repeat="star in stars" ng-class="star" ng-click="toggle($index)">'
           + '<i class="fa fa-star" style="font-size:21px">'
           + '</i>'
					 + '</li>'
					 + '</ul>'
           + '<ul class="rating foreground" style="width:{{average}}%">'
           + '	<li ng-repeat="star in stars" ng-class="star" ng-click="toggle($index)">'
           + '<i class="fa fa-star" style="font-size:21px">'
           + '</i>'
           + '</li>'
           + '</ul>',
			scope : {
				ratingValue : '=',
				max : '=',
        average: '=',
				onRatingSelected : '&'
			},
			link : function(scope, elem, attrs) {
				var updateStars = function() {
					scope.stars = [];
					for ( var i = 0; i < scope.max; i++) {
						scope.stars.push({
							filled : i < scope.ratingValue
						});
					}
        };

				scope.toggle = function(index) {
					scope.ratingValue = index + 1;
					scope.onRatingSelected({
						rating : index + 1
					});
				};

				scope.$watch('ratingValue',
					function(oldVal, newVal) {
						if (newVal) {
							updateStars();
						}
					});
			}
		};
	});


function getCPage(s){
    var loc = location.pathname;
    loc = loc.replace(s,"");
    var find = '\/';
    var re = new RegExp(find, 'g');
    loc = loc.replace(re,"");
    return loc;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *