Advertisement
adelmo00

Untitled

May 10th, 2015
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var app = angular.module('dashboardApp', [ 'ngMaterial', 'ui.bootstrap']);
  2.  
  3. app.config(function($mdThemingProvider) {
  4.     $mdThemingProvider.theme('default').primaryPalette('teal').accentPalette('blue');
  5. });
  6.  
  7. app.controller('dashboardController', function($rootScope, $scope, $http, $location, OrderService) {
  8.     $scope.init = function() {
  9.         orderService.loadMyOrders();
  10.     };
  11. });
  12.  
  13. app.service('OrderService', function ($rootScope, $scope, $http, $location) {
  14.     $scope.filteredList = [];
  15.     $scope.currentPage = 1;
  16.     $scope.numPerPage = 4;
  17.     $scope.maxSize = 5;
  18.  
  19.     $scope.sort = "statusOrder";
  20.     $scope.reverse = false;
  21.  
  22.     return{
  23.         loadMyOrders : function() {
  24.             $http
  25.                     .post(
  26.                             $location.absUrl() + '/orders/list',
  27.                             {
  28.                                 headers : {
  29.                                     'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
  30.                                 }
  31.                             }).success(function(data, status) {
  32.                         $scope.message = data.message;
  33.                         $scope.isSuccess = true;
  34.                         $scope.orders = data.list;
  35.                     }).error(function(data) {
  36.                         $scope.isError = true;
  37.                         $scope.message = data.message;
  38.                     });
  39.         },
  40.         findOrder : function(order) {
  41.             $scope.filtro = {
  42.                 id : order.id
  43.             };
  44.             $scope.loading = true;
  45.             $http
  46.                     .post(
  47.                             $location.absUrl() + '/orders/find',
  48.                             $.param($scope.filtro),
  49.                             {
  50.                                 headers : {
  51.                                     'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
  52.                                 }
  53.                             }).success(function(data, status) {
  54.                         $scope.message = data.message;
  55.                         $scope.isSuccess = true;
  56.                         $scope.order = data.bean;
  57.                     }).error(function(data) {
  58.                         $scope.isError = true;
  59.                         $scope.message = data.message;
  60.                     });
  61.         },
  62.         changeSort : function(value) {
  63.             if ($scope.sort == value) {
  64.                 $scope.reverse = !$scope.reverse;
  65.                 return;
  66.             }
  67.  
  68.             $scope.sort = value;
  69.             $scope.reverse = false;
  70.         }
  71.     }
  72.  
  73.     $scope.$watch('currentPage + numPerPage', function() {
  74.         var begin = (($scope.currentPage - 1) * $scope.numPerPage), end = begin
  75.                 + $scope.numPerPage;
  76.  
  77.         $scope.filteredList = $scope.list.slice(begin, end);
  78.     });
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement