Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.  
  3.  
  4.     var app = angular.module('store', ['ngRoute'], function($interpolateProvider) {
  5.         $interpolateProvider.startSymbol('<%');
  6.         $interpolateProvider.endSymbol('%>');
  7.     });
  8.  
  9.     app.config(['$httpProvider', '$locationProvider','$routeProvider',
  10.         function($httpProvider,$locationProvider,$routeProvider) {
  11.         $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
  12.         $locationProvider.html5Mode(true);
  13.  
  14.         $routeProvider
  15.         /*
  16.         * Route for home page
  17.          */
  18.         .when('/', {
  19.             templateUrl : 'pages/home.html',
  20.             controller  : 'MainController'
  21.         })
  22.  
  23.         /*
  24.         * Route for cart
  25.          */
  26.         .when('/kosar',{
  27.             templateUrl : 'pages/cart.html',
  28.             controller  : 'CartController'
  29.         })
  30.  
  31.         /*
  32.          * Route for registration
  33.          */
  34.         .when('/regisztracio',{
  35.             templateUrl : 'pages/regform.html',
  36.             controller  : 'RegController'
  37.         })
  38.  
  39.         /*
  40.          * Route for profile edit
  41.          */
  42.         .when('/adatmodosítas',{
  43.             templateUrl : 'pages/editform.html',
  44.             controller  : 'RegController'
  45.         })
  46.  
  47.         /*
  48.         * Route for search main page
  49.          */
  50.         .when('/kereses',{
  51.             templateUrl : 'pages/list.html',
  52.             controller : 'SearchController'
  53.         })
  54.  
  55.         /*
  56.         * Route for search results
  57.          */
  58.         .when('/kereses/:param1/:param2?/oldal/:pagenum',{
  59.             templateUrl : 'pages/list.html',
  60.             controller : 'SearchController'
  61.         })
  62.  
  63.         /*
  64.         * Route for news(news list)
  65.          */
  66.         .when('/hirek/oldal/:pagenum',{
  67.             templateUrl : 'pages/article_list.html',
  68.             controller : 'NewsController'
  69.         })
  70.  
  71.         /*
  72.         * Route for news with params (specific news page)
  73.          */
  74.         .when('/hirek/:article',{
  75.             templateUrl : 'pages/article.html',
  76.             controller : 'NewsController'
  77.         })
  78.  
  79.         .when('/:platform',{
  80.             templateUrl : 'pages/list.html',
  81.             controller : 'ProductController'
  82.         })
  83.  
  84.         .when('/:platform/:category/:pagenum',{
  85.             templateUrl : 'pages/list.html',
  86.             controller : 'ProductController'
  87.         })
  88.  
  89.         .when('/:platform/:product',{
  90.             templateUrl : 'pages/list.html',
  91.             controller : 'ProductController'
  92.         });
  93.  
  94.     }]);
  95.  
  96.     app.run(["$rootScope","$http","$location", function ($rootScope,$http,$location) {
  97.         $http.post("login",{check: true}).success(function(data){
  98.             $rootScope.authenticated = true;
  99.             $rootScope.userData = data;
  100.         });
  101.  
  102.         $rootScope.$on("$routeChangeStart", function(event, next, current) {
  103.             if($location.path() == "/adatmodositas") {
  104.                 if(!$rootScope.authenticated){
  105.                     event.preventDefault();
  106.                 }
  107.             }
  108.         });
  109.     }]);
  110.  
  111.     app.controller("SearchController", ["$http", function ($http) {
  112.         this.term = "";
  113.         this.result = "";
  114.         var search = this;
  115.  
  116.         this.search = function () {
  117.             if(this.term.length>2){
  118.                 $http.post("/gp/new/public/kereses", {search: this.term})
  119.                     .success(function(data){
  120.                         search.result = data;
  121.                     })
  122.                     .error(function(){
  123.                         search.result = false;
  124.                     });
  125.             }
  126.         };
  127.  
  128.         this.showResult = function(){
  129.             return this.term.length > 2;
  130.         };
  131.     }]);
  132.  
  133.     app.controller("UserController", ["$http", "$rootScope", function($http,$rootScope){
  134.         this.login = false;
  135.         this.email = "";
  136.         this.password = "";
  137.         var user = this;
  138.  
  139.         this.showLogin = function(){
  140.             this.login?this.login=false:this.login=true;
  141.         };
  142.  
  143.         this.auth = function(){
  144.             $http.post("login",{email: user.email, password: user.password})
  145.                 .success(function(data){
  146.                     $rootScope.authenticated = true;
  147.                     $rootScope.userData = data;
  148.                 });
  149.         };
  150.  
  151.         this.logout = function(){
  152.             $http.post("logout",{logout: true}).success(function(){
  153.                 $rootScope.authenticated = false;
  154.                 $rootScope.userData = {};
  155.             });
  156.         };
  157.     }]);
  158.  
  159.     app.controller("MainController",["$scope", "$http", function($scope,$http){
  160.         $http.get("https://www.videojatekbolt.hu/gp/new/public/carousel")
  161.             .success(function(data){
  162.                 $scope.carousel = data;
  163.             });
  164.     }]);
  165.  
  166.     app.controller("CartController",["$rootScope", function($rootScope){
  167.  
  168.     }]);
  169.  
  170.     app.controller("RegController",["$http", "$rootScope", function($http,$rootScope){
  171.         $rootScope.form = {};
  172.  
  173.         $rootScope.submit = function(){
  174.             $http.post("regisztracio",$rootScope.form).success(function(){
  175.                 $rootScope.authenticated = true;
  176.                 $rootScope.userData = data;
  177.             });
  178.         }
  179.     }]);
  180.  
  181.     app.controller("ProductController", ["$routeParams", "$scope", function($routeParams,$scope){
  182.         $scope.name = "Product";
  183.     }]);
  184.  
  185.     app.controller("NewsController", ["$routeParams", "$http", "$scope", "$sce",
  186.         function($routeParams,$http,$scope,$sce){
  187.         var news = this;
  188.  
  189.         if($routeParams.article !== undefined){
  190.             $http.post("article",{url: $routeParams.article}).success(function(data){
  191.                 $scope.article = data;
  192.                 $scope.article.data = $sce.trustAsHtml($scope.article.data);
  193.                 $scope.found = true;
  194.             }).error(function(){
  195.                 $scope.found = false;
  196.             });
  197.         }
  198.         else{
  199.             $http.post("news",{get: true}).success(function(data){
  200.                 $scope.news = data;
  201.                 $scope.found = true;
  202.             }).error(function(){
  203.                 $scope.found = false;
  204.             });
  205.         }
  206.     }]);
  207.  
  208.     app.controller("SearchController", ["$routeParams", "$scope", function($routeParams,$scope){
  209.         $scope.name = "Search";
  210.     }]);
  211. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement