Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!window.var) var work = angular.module('work', []).
  2.     config(function($routeProvider){
  3.         $routeProvider.
  4.             when('/', {controller:workCtrl, templateUrl:'/ang/work/list.html'}).
  5.             when('/log/:memberId', {controller:logCtrl, templateUrl:'/ang/work/log.html'}).
  6.             when('/edit/:itemId', {controller: itemEditCtrl, templateUrl:'/ang/work/edit.html'}).
  7.             when('/add/', {controller:workNewCtrl, templateUrl:'/ang/work/add.html'}).
  8.             when('/add-log/:memberId', {controller:logNewCtrl, templateUrl:'/ang/work/add-log.html'}).
  9.             //when('/del/:memberId', {controller:packageDelCtrl}).
  10.             otherwise({redirectTo:'/'});
  11.     });
  12.  
  13. //list member controller
  14. function workCtrl($scope, $http, $location){
  15.     $http({
  16.         method: 'POST',
  17.         headers: 'application/x-www-form-urlencoded',
  18.         url: "/ang/work/ajax.php",
  19.         data: {'action':"list" }
  20.     }).success(function (data, code) {
  21.         $scope.list = data.list;
  22.         $scope.status = "";
  23.     });
  24.  
  25.     // show status while loading member
  26.     $scope.status = "loading works direct";
  27.  
  28.     // return member count
  29.     $scope.list_count = function(){
  30.         if ($scope.list){
  31.             return $scope.list.length;
  32.         } else {
  33.             return 0;
  34.         }
  35.     }
  36.  
  37.     //del
  38.     $scope.del_item = function(id){
  39.         $http({
  40.             method: 'POST',
  41.             headers: 'application/x-www-form-urlencoded',
  42.             url: "/ang/work/ajax.php",
  43.             data: {'action':"del", "id":id }
  44.         }).success(function (data, code) {
  45.             $scope.status = "deleted";
  46.             var old_list = $scope.list;
  47.             $scope.list = [];
  48.             if (data.data == 'ok'){
  49.                 angular.forEach(old_list, function(item){
  50.                     if (item.id != id) $scope.list.push(item);
  51.                 });
  52.             }
  53.         });
  54.     }//*/
  55. }
  56.  
  57. //gamelog controller
  58. function logCtrl($scope, $http, $location, $routeParams){
  59.     // show status while loading members
  60.     $scope.status = "loading...";
  61.     $scope.action = "update";
  62.     $scope.result = 0;
  63.     //$scope.paypal = 1;
  64.     $scope.memberId = $routeParams.memberId;
  65.     if (!$scope.memberId){
  66.         $location.path('/');
  67.     }
  68.     $http({
  69.         method: 'POST',
  70.         headers: 'application/x-www-form-urlencoded',
  71.         url: "/ang/work/ajax.php",
  72.         data: {'action':"log", "id":$scope.memberId }
  73.     }).success(function (data, code) {
  74.         if (data.data == 'ok'){
  75.             var log = data.items;
  76.             $scope.log = [];
  77.             angular.forEach(log, function(item){
  78.                 item.amount = parseFloat(item.amount);
  79.                 if (item.result == "W"){
  80.                     $scope.result += parseFloat(item.amount);
  81.                 }
  82.                 if (item.result == "L"){
  83.                     $scope.result -= parseFloat(item.amount);
  84.                 }
  85.                 $scope.log.push(item);
  86.             });
  87.         }
  88.         $scope.status = "";
  89.     });
  90.  
  91.     //del log item
  92.     $scope.del_log_item = function(id){
  93.         $http({
  94.             method: 'POST',
  95.             headers: 'application/x-www-form-urlencoded',
  96.             url: "/ang/work/ajax.php",
  97.             data: {'action':"del-log-item", "id":id }
  98.         }).success(function (data, code) {
  99.             $scope.status = "deleted";
  100.             var old_log = $scope.log;
  101.             $scope.log = [];
  102.             if (data.data == 'ok'){
  103.                 angular.forEach(old_log, function(item){
  104.                     if (item.id != id) $scope.log.push(item);
  105.                 });
  106.             }
  107.         });
  108.     }//*/
  109.  
  110.     // return member count
  111.     $scope.log_count = function(){
  112.         if ($scope.log){
  113.             return $scope.log.length;
  114.         } else {
  115.             return 0;
  116.         }
  117.     }
  118.  
  119. }
  120.  
  121. //edit gamelog controller
  122. function itemEditCtrl($scope, $http, $location, $routeParams){
  123.     // show status while loading members
  124.     $scope.status = "loading...";
  125.     $scope.action = "update";
  126.     //$scope.paypal = 1;
  127.     $scope.itemId = $routeParams.itemId;
  128.     if (!$scope.itemId){
  129.         $location.path('/');
  130.     }
  131.     $http({
  132.         method: 'POST',
  133.         headers: 'application/x-www-form-urlencoded',
  134.         url: "/ang/work/ajax.php",
  135.         data: {'action':"get", "id":$scope.itemId }
  136.     }).success(function (data, code) {
  137.         $scope.item = data.item;
  138.         $scope.item.amount = parseInt($scope.item.amount);
  139.         $scope.status = "";
  140.     });
  141.  
  142.     $scope.update_item = function(){
  143.         $http({
  144.             method: 'POST',
  145.             headers: 'application/x-www-form-urlencoded',
  146.             url: "/ang/work/ajax.php",
  147.             data: {'action':"update", 'item':$scope.item }
  148.         }).success(function (data, code) {
  149.             $location.path('/');
  150.         });
  151.     }
  152. }
  153.  
  154. //new member controller
  155. function workNewCtrl($scope, $http, $location){
  156.     $scope.status = "";
  157.     $scope.action = "add";
  158.  
  159.     $scope.add_item = function(){
  160.         $http({
  161.             method: 'POST',
  162.             headers: 'application/x-www-form-urlencoded',
  163.             url: "/ang/work/ajax.php",
  164.             data: {'action':"add", 'item':$scope.item }
  165.         }).success(function (data, code) {
  166.             $location.path('/');
  167.         });
  168.     }
  169. }//*/
  170.  
  171. //new log controller
  172. function logNewCtrl($scope, $http, $location, $routeParams){
  173.     $scope.status = "";
  174.     $scope.action = "add-log";
  175.  
  176.     $scope.memberId = $routeParams.memberId;
  177.     if (!$scope.memberId){
  178.         $location.path('/');
  179.     }
  180.  
  181.     $scope.add_item = function(){
  182.         $http({
  183.             method: 'POST',
  184.             headers: 'application/x-www-form-urlencoded',
  185.             url: "/ang/work/ajax.php",
  186.             data: {'action':"add-log", 'item':$scope.item, 'id':$scope.memberId }
  187.         }).success(function (data, code) {
  188.             $location.path('/');
  189.         });
  190.     }
  191. }//*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement