SHARE
TWEET

Untitled

a guest Dec 2nd, 2014 148 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ProductSearchCtrl($scope, $rootScope, ProductSearchService, $state, $ionicPopup, $ionicLoading, LoaderService, ProductChecks, $timeout, $q) {
  2.         $scope.showproductoptions = true;
  3.         var showAlert = function(message) {
  4.                 $ionicPopup.alert({
  5.                         title: message
  6.                 });
  7.         };
  8.         $scope.slsm = isSlsm;
  9.        
  10.         if(isSlsm) {
  11.                 $scope.CustCode = "(" + CustCode + ")";
  12.         }
  13.         else {
  14.                 $scope.CustCode = "";
  15.         }
  16.         var canceller = $q.defer();
  17.         $scope.ProductSearchCrit = ProductChecks.checked;
  18.         $scope.ProductSearchData = {};
  19.         $scope.ProductSearchData.SearchField1 = $rootScope.SearchTerms;
  20.        
  21.         $scope.ProductSearch = function(data, $ionicLoading, $timeout, ProductChecks) {
  22.                 //do inital check to see if person is sane.
  23.                 if($scope.ProductSearchData.SearchField1 == '') {
  24.                         showAlert("Please enter search terms before making a search");
  25.                         return;
  26.                 }
  27.                 if ($scope.ProductSearchCrit.StockingSW == false &&
  28.                         $scope.ProductSearchCrit.NonStockingSW == false &&
  29.                         $scope.ProductSearchCrit.DiscontinuedSW == false &&
  30.                         $scope.ProductSearchCrit.SecondsSW == false &&
  31.                         $scope.ProductSearchCrit.CarpetSW == false &&
  32.                         $scope.ProductSearchCrit.VinylSW == false  &&
  33.                         $scope.ProductSearchCrit.SuppliesSW == false  &&
  34.                         $scope.ProductSearchCrit.CeramicSW == false  &&
  35.                         $scope.ProductSearchCrit.WoodSW == false  &&
  36.                         $scope.ProductSearchCrit.JohnsoniteSW == false &&
  37.                         $scope.ProductSearchCrit.VCTSW == false &&
  38.                         $scope.ProductSearchCrit.LaminatesSW == false) {
  39.                                 showAlert("Please enter atleast one criteria before making a search");
  40.                                 return;
  41.                         }
  42.                 canceller = $q.defer();
  43.                 //call service product search
  44.                 //LoaderService.show();
  45.                 //$ionicBackdrop.retain();
  46.                 $scope.showPopup();
  47.                 ProductSearchService.submitsearch(data, canceller.promise, canceller).then(function(message) {
  48.                         // Anything to happen on success here
  49.                         $rootScope.SearchTerms = data.SearchField1;
  50.                         //LoaderService.hide();
  51.                         $scope.productreturndata = message.data.FoundRecords;
  52.                        
  53.                         if(message.data.result=="NoRecords") {
  54.                                 $rootScope.FoundRecords = false;
  55.                         }
  56.                         else {
  57.                                 $rootScope.FoundRecords = true;
  58.                         }
  59.                        
  60.                         tempsearchres = [];
  61.                         if (angular.isArray(message.data.FoundRecords.FoundRecordsItems)) {
  62.                                 tempsearchres = message.data.FoundRecords.FoundRecordsItems;
  63.                         }
  64.                         else {
  65.                                 tempsearchres[0] = message.data.FoundRecords.FoundRecordsItems;
  66.                         }
  67.                         $state.go('tabs.productresult');
  68.                 }, function(data,status){
  69.                         //LoaderService.hide()
  70.                         // Anything to happen on failure here
  71.                         showAlert("There was an error searching products. Error message: \n" + data.status);
  72.                 });
  73.         };
  74.         $scope.cancel = function(){
  75.                 canceller.resolve();  
  76.                 showAlert("Your search has been cancelled");
  77.         };
  78.         $scope.showPopup = function() {
  79.                 // An elaborate, custom popup
  80.                 var myPopup = $ionicPopup.show({
  81.                         title: 'Searching...',
  82.                         template: '<div class="spinner"></div>',
  83.                         scope: $scope,
  84.                         buttons: [
  85.                                 {
  86.                                         text: '<b>Cancel</b>',
  87.                                         type: 'button-positive',
  88.                                         onTap: function() {
  89.                                                 $scope.cancel();
  90.                                                 myPopup.close();
  91.                                         }
  92.                                 },
  93.                         ]
  94.                 });
  95.                 $timeout(function() {
  96.                         myPopup.close();
  97.                 }, canceller.promise);
  98.         };
  99. }
  100.  
  101. function ProductSearchService ($q, $http) {
  102.         return {
  103.                 submitsearch: function(productcriteria, promise, canceller){
  104.                         var deferred = $q.defer();
  105.                         return $http({method: 'POST', url: productsearchurl, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: {
  106.                                 searchfield1: productcriteria.SearchField1,
  107.                                 custcode: CustCode,
  108.                                 token: token,
  109.                                 loginapp:"mobile" },
  110.                                 timeout: promise,
  111.                                 transformRequest: function(obj) {
  112.                                         var str = [];
  113.                                         for( var p in obj )
  114.                                                 str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  115.                                         return str.join("&");
  116.                                 } }).
  117.                         success(function(data, status, headers, config) {
  118.                                 // this callback will be called asynchronously
  119.                                 // when the response is available
  120.                                 canceller.resolve();
  121.                                 return data;
  122.                         }).
  123.                         error(function(data, status, headers, config) {
  124.                                 // called asynchronously if an error occurs
  125.                                 // or server returns response with an error status.
  126.                                 return data;
  127.                         });
  128.                 }
  129.         }
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top