- function ProductSearchCtrl($scope, $rootScope, ProductSearchService, $state, $ionicPopup, $ionicLoading, LoaderService, ProductChecks, $timeout, $q) {
- $scope.showproductoptions = true;
- var showAlert = function(message) {
- $ionicPopup.alert({
- title: message
- });
- };
- $scope.slsm = isSlsm;
- if(isSlsm) {
- $scope.CustCode = "(" + CustCode + ")";
- }
- else {
- $scope.CustCode = "";
- }
- var canceller = $q.defer();
- $scope.ProductSearchCrit = ProductChecks.checked;
- $scope.ProductSearchData = {};
- $scope.ProductSearchData.SearchField1 = $rootScope.SearchTerms;
- $scope.ProductSearch = function(data, $ionicLoading, $timeout, ProductChecks) {
- //do inital check to see if person is sane.
- if($scope.ProductSearchData.SearchField1 == '') {
- showAlert("Please enter search terms before making a search");
- return;
- }
- if ($scope.ProductSearchCrit.StockingSW == false &&
- $scope.ProductSearchCrit.NonStockingSW == false &&
- $scope.ProductSearchCrit.DiscontinuedSW == false &&
- $scope.ProductSearchCrit.SecondsSW == false &&
- $scope.ProductSearchCrit.CarpetSW == false &&
- $scope.ProductSearchCrit.VinylSW == false &&
- $scope.ProductSearchCrit.SuppliesSW == false &&
- $scope.ProductSearchCrit.CeramicSW == false &&
- $scope.ProductSearchCrit.WoodSW == false &&
- $scope.ProductSearchCrit.JohnsoniteSW == false &&
- $scope.ProductSearchCrit.VCTSW == false &&
- $scope.ProductSearchCrit.LaminatesSW == false) {
- showAlert("Please enter atleast one criteria before making a search");
- return;
- }
- canceller = $q.defer();
- //call service product search
- //LoaderService.show();
- //$ionicBackdrop.retain();
- $scope.showPopup();
- ProductSearchService.submitsearch(data, canceller.promise, canceller).then(function(message) {
- // Anything to happen on success here
- $rootScope.SearchTerms = data.SearchField1;
- //LoaderService.hide();
- $scope.productreturndata = message.data.FoundRecords;
- if(message.data.result=="NoRecords") {
- $rootScope.FoundRecords = false;
- }
- else {
- $rootScope.FoundRecords = true;
- }
- tempsearchres = [];
- if (angular.isArray(message.data.FoundRecords.FoundRecordsItems)) {
- tempsearchres = message.data.FoundRecords.FoundRecordsItems;
- }
- else {
- tempsearchres[0] = message.data.FoundRecords.FoundRecordsItems;
- }
- $state.go('tabs.productresult');
- }, function(data,status){
- //LoaderService.hide()
- // Anything to happen on failure here
- showAlert("There was an error searching products. Error message: \n" + data.status);
- });
- };
- $scope.cancel = function(){
- canceller.resolve();
- showAlert("Your search has been cancelled");
- };
- $scope.showPopup = function() {
- // An elaborate, custom popup
- var myPopup = $ionicPopup.show({
- title: 'Searching...',
- template: '<div class="spinner"></div>',
- scope: $scope,
- buttons: [
- {
- text: '<b>Cancel</b>',
- type: 'button-positive',
- onTap: function() {
- $scope.cancel();
- myPopup.close();
- }
- },
- ]
- });
- $timeout(function() {
- myPopup.close();
- }, canceller.promise);
- };
- }
- function ProductSearchService ($q, $http) {
- return {
- submitsearch: function(productcriteria, promise, canceller){
- var deferred = $q.defer();
- return $http({method: 'POST', url: productsearchurl, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: {
- searchfield1: productcriteria.SearchField1,
- custcode: CustCode,
- token: token,
- loginapp:"mobile" },
- timeout: promise,
- transformRequest: function(obj) {
- var str = [];
- for( var p in obj )
- str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
- return str.join("&");
- } }).
- success(function(data, status, headers, config) {
- // this callback will be called asynchronously
- // when the response is available
- canceller.resolve();
- return data;
- }).
- error(function(data, status, headers, config) {
- // called asynchronously if an error occurs
- // or server returns response with an error status.
- return data;
- });
- }
- }
- }
SHARE
TWEET
Untitled
a guest
Dec 2nd, 2014
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.

