|
|
//var urlapi="http://localhost:3000/api/";
var urlapi="http://192.168.1.40:3000/api/"; localStorage.setItem("c_username", "user2"); localStorage.setItem("c_token", "");
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $timeout) { // With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//$scope.$on('$ionicView.enter', function(e) {
//});
// Form data for the login modal
$scope.loginData = {};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', { scope: $scope }).then(function(modal) { $scope.modal = modal; });
// Triggered in the login modal to close it
$scope.closeLogin = function() { $scope.modal.hide(); };
// Open the login modal
$scope.login = function() { $scope.modal.show(); };
// Perform the login action when the user submits the login form
$scope.doLogin = function() { console.log('Doing login', $scope.loginData);
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() { $scope.closeLogin(); }, 1000); }; })
.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout) { $scope.travels="";
$scope.travels=JSON.parse(localStorage.getItem('c_travels'));
$scope.doRefresh = function() { $http.get(urlapi + 'travels') .success(function(data, status, headers,config){ console.log('data success'); console.log(data); // for browser console
$scope.travels = data; // for UI
localStorage.setItem('c_travels', JSON.stringify($scope.travels)); $scope.$broadcast('scroll.refreshComplete');//refresher stop
}) .error(function(data, status, headers,config){ console.log('data error'); $scope.$broadcast('scroll.refreshComplete');//refresher stop
}) .then(function(result){ travels = result.data; }); };
$scope.newtravel={};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/newofferingtravel.html', { scope: $scope }).then(function(modal) { $scope.modalOffering = modal; });
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/newaskingtravel.html', { scope: $scope }).then(function(modal) { $scope.modalAsking = modal; });
$ionicModal.fromTemplateUrl('templates/newaskingpackage.html', { scope: $scope }).then(function(modal) { $scope.modalPackage = modal; });
// Triggered in the login modal to close it
$scope.closeNewOfferingTravel = function() { $scope.modalOffering.hide(); }; // Triggered in the login modal to close it
$scope.closeNewAskingTravel = function() { $scope.modalAsking.hide(); }; $scope.closeNewAskingPackage = function() { $scope.modalPackage.hide(); };
// Open the login modal
$scope.showNewOfferingTravel = function() { $scope.modalOffering.show(); }; // Open the login modal
$scope.showNewAskingTravel = function() { $scope.modalAsking.show(); }; $scope.showNewAskingPackage = function() { $scope.modalPackage.show(); };
// Perform the login action when the user submits the login form
$scope.doNewOfferingTravel = function() { console.log('Doing new travel', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; $scope.newtravel.owner=localStorage.getItem("c_username");
$scope.newtravel.modality="offering"; console.log($scope.newtravel); $http({ url: urlapi + 'travels', method: "POST", data: $scope.newtravel }) .then(function(response) { // success
console.log("response: "); console.log(response); $scope.newtravel._id=response.data._id; $scope.travels.push($scope.newtravel); $scope.newtravel={}; }, function(response) { // optional
// failed
});
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() { $scope.closeNewOfferingTravel(); }, 1000); };
$scope.doNewAskingTravel = function() { console.log('Doing new travel', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; $scope.newtravel.owner=localStorage.getItem("c_username");
$scope.newtravel.modality="asking"; console.log($scope.newtravel); $http({ url: urlapi + 'travels', method: "POST", data: $scope.newtravel }) .then(function(response) { // success
console.log("response: "); console.log(response); $scope.newtravel._id=response.data._id; $scope.travels.push($scope.newtravel); }, function(response) { // optional
// failed
});
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() { $scope.closeNewAskingTravel(); }, 1000); };
$scope.doNewAskingPackage = function() { console.log('Doing new package', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; $scope.newtravel.owner=localStorage.getItem("c_username"); $scope.newtravel.package=true;
$scope.newtravel.modality="package"; console.log($scope.newtravel); $http({ url: urlapi + 'travels', method: "POST", data: $scope.newtravel }) .then(function(response) { // success
console.log("response: "); console.log(response); $scope.newtravel._id=response.data._id; $scope.travels.push($scope.newtravel); }, function(response) { // optional
// failed
});
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() { $scope.closeNewAskingPackage(); }, 1000); }; })
.controller('TravelCtrl', function($scope, $stateParams, $http) { $scope.storageusername=localStorage.getItem("c_username"); $scope.travel=""; console.log($stateParams.travelId); $http.get(urlapi + 'travels/'+$stateParams.travelId) .success(function(data, status, headers,config){ console.log('data success'); console.log(data); // for browser console
$scope.travel = data; // for UI
}) .error(function(data, status, headers,config){ console.log('data error'); }) .then(function(result){ travels = result.data; }); })
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) { $scope.users="";
$scope.users=JSON.parse(localStorage.getItem('c_users'));
$scope.doRefresh = function() { $http.get(urlapi + 'users') .success(function(data, status, headers, config){ console.log('data success'); console.log(data); // for browser console
$scope.users = data; // for UI
localStorage.setItem('c_users', JSON.stringify($scope.users)); $scope.$broadcast('scroll.refreshComplete');//refresher stop
}) .error(function(data, status, headers,config){ console.log('data error'); $scope.$broadcast('scroll.refreshComplete');//refresher stop
}) .then(function(result){ users = result.data; }); }; })
.controller('UserCtrl', function($scope, $stateParams, $http) { //$scope.user="";
console.log($stateParams.username); $http.get(urlapi + 'users/byusername/'+$stateParams.username) .success(function(data, status, headers,config){ console.log('data success'); console.log(data); // for browser console
$scope.user = data; // for UI
}) .error(function(data, status, headers,config){ console.log('data error'); }) .then(function(result){ user = result.data; });
$http.get(urlapi + 'travels/user/'+$stateParams.username) .success(function(data, status, headers,config){ console.log('data success'); console.log(data); // for browser console
$scope.travels = data; // for UI
}) .error(function(data, status, headers,config){ console.log('data error'); }) .then(function(result){ travels = result.data; }); });
|