From 5f16f060c1b1cd69b9db389a0ce3681c62220b66 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Wed, 25 Jan 2017 22:27:33 +0100 Subject: [PATCH] actualitzant... --- www/index.html | 17 +- www/js/app.js | 259 ++++++---- www/js/controllers.js | 815 ------------------------------ www/js/footerMenu.js | 5 + www/js/help.js | 6 + www/js/login.js | 38 ++ www/js/main.js | 5 + www/js/menu.js | 12 + www/js/newPublication.js | 5 + www/js/notifications.js | 15 + www/js/offerCar.js | 5 + www/js/settings.js | 17 + www/js/signup.js | 91 ++++ www/js/travel.js | 169 +++++++ www/js/travels.js | 238 +++++++++ www/js/user.js | 121 +++++ www/js/users.js | 54 ++ www/templates/login.html | 3 +- www/templates/main.html | 20 + www/templates/menu.html | 72 +-- www/templates/newPublication.html | 16 + www/templates/offerCar.html | 62 +++ www/templates/signup.html | 2 +- 23 files changed, 1105 insertions(+), 942 deletions(-) delete mode 100644 www/js/controllers.js create mode 100644 www/js/footerMenu.js create mode 100644 www/js/help.js create mode 100644 www/js/login.js create mode 100644 www/js/main.js create mode 100644 www/js/menu.js create mode 100644 www/js/newPublication.js create mode 100644 www/js/notifications.js create mode 100644 www/js/offerCar.js create mode 100644 www/js/settings.js create mode 100644 www/js/signup.js create mode 100644 www/js/travel.js create mode 100644 www/js/travels.js create mode 100644 www/js/user.js create mode 100644 www/js/users.js create mode 100644 www/templates/main.html create mode 100644 www/templates/newPublication.html create mode 100644 www/templates/offerCar.html diff --git a/www/index.html b/www/index.html index bcb29f4..9df15be 100644 --- a/www/index.html +++ b/www/index.html @@ -24,7 +24,22 @@ - + + + + + + + + + + + + + + + diff --git a/www/js/app.js b/www/js/app.js index 9d1b86d..643eaea 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -4,73 +4,133 @@ // 'starter' is the name of this angular module example (also set in a attribute in index.html) // the 2nd parameter is an array of 'requires' // 'starter.controllers' is found in controllers.js -angular.module('starter', ['ionic', - 'starter.controllers', - 'pascalprecht.translate']) - -.run(function($ionicPlatform) { - $ionicPlatform.ready(function() { - // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard - // for form inputs) - if (window.cordova && window.cordova.plugins.Keyboard) { - cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); - cordova.plugins.Keyboard.disableScroll(true); - } - if (window.StatusBar) { - // org.apache.cordova.statusbar required - StatusBar.styleDefault(); - } - }); -}) -.config(function($stateProvider, $urlRouterProvider) { - $stateProvider +var urlapi = "http://localhost:3000/api/"; +//var urlapi="https://collectivecar.paas.primustech.io/api/"; - .state('app', { - url: '/app', - abstract: true, - templateUrl: 'templates/menu.html', - controller: 'AppCtrl' - }) - .state('app.settings', { - url: '/settings', - views: { - 'menuContent': { - templateUrl: 'templates/settings.html', - controller: 'SettingsCtrl' +angular.module('starter', [ + 'ionic', + 'pascalprecht.translate', + 'app.login', + 'app.signup', + 'app.menu', + 'app.footerMenu', + 'app.main', + 'app.travels', + 'app.travel', + 'app.newPublication', + 'app.offerCar', +/* 'app.askCar', + 'app.askPackage',*/ + 'app.users', + 'app.user', + 'app.notifications', + 'app.settings', + 'app.help' + ]) + + .run(function($ionicPlatform) { + $ionicPlatform.ready(function() { + // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard + // for form inputs) + if (window.cordova && window.cordova.plugins.Keyboard) { + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + cordova.plugins.Keyboard.disableScroll(true); + } - } - }) - .state('app.help', { - url: '/help', - views: { - 'menuContent': { - templateUrl: 'templates/help.html', - controller: 'HelpCtrl' + if (window.StatusBar) { + // org.apache.cordova.statusbar required + StatusBar.styleDefault(); } - } + }); }) - .state('app.notifications', { - url: '/notifications/:username', - views: { - 'menuContent': { - templateUrl: 'templates/notifications.html', - controller: 'NotificationsCtrl' - } - } - }) - .state('app.users', { - url: '/users', - views: { - 'menuContent': { - templateUrl: 'templates/users.html', - controller: 'UsersCtrl' + + .config(function($stateProvider, $urlRouterProvider) { + $stateProvider + + .state('app', { + url: '/app', + abstract: true, + templateUrl: 'templates/menu.html', + controller: 'MenuCtrl' + }) + .state('app.main', { + url: '/main', + views: { + 'menuContent': { + templateUrl: 'templates/main.html', + controller: 'MainCtrl' + } } - } - }) - .state('app.user', { + }) + .state('app.login', { + url: '/login', + views: { + 'menuContent': { + templateUrl: 'templates/login.html', + controller: 'LoginCtrl' + } + } + }) + .state('app.signup', { + url: '/signup', + views: { + 'menuContent': { + templateUrl: 'templates/signup.html', + controller: 'SignupCtrl' + } + } + }) + .state('app.travels', { + url: '/travels', + views: { + 'menuContent': { + templateUrl: 'templates/travels.html', + controller: 'TravelsCtrl' + } + } + }) + + .state('app.travel', { + url: '/travels/:travelId', + views: { + 'menuContent': { + templateUrl: 'templates/travel.html', + controller: 'TravelCtrl' + } + } + }) + + .state('app.newPublication', { + url: '/newPublication', + views: { + 'menuContent': { + templateUrl: 'templates/newPublication.html', + controller: 'NewPublicationCtrl' + } + } + }) + .state('app.offerCar', { + url: '/offerCar', + views: { + 'menuContent': { + templateUrl: 'templates/offerCar.html', + controller: 'OfferCarCtrl' + } + } + }) + .state('app.users', { + url: '/users', + views: { + 'menuContent': { + templateUrl: 'templates/users.html', + controller: 'UsersCtrl' + } + } + }) + .state('app.user', { url: '/users/:username', views: { 'menuContent': { @@ -79,45 +139,66 @@ angular.module('starter', ['ionic', } } }) - .state('app.travels', { - url: '/travels', - views: { - 'menuContent': { - templateUrl: 'templates/travels.html', - controller: 'TravelsCtrl' + .state('app.notifications', { + url: '/notifications', + views: { + 'menuContent': { + templateUrl: 'templates/notifications.html', + controller: 'NotificationsCtrl' + } } - } - }) - - .state('app.travel', { - url: '/travels/:travelId', - views: { - 'menuContent': { - templateUrl: 'templates/travel.html', - controller: 'TravelCtrl' - } - } - }); - // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/app/travels'); -}) + }) + .state('app.settings', { + url: '/settings', + views: { + 'menuContent': { + templateUrl: 'templates/settings.html', + controller: 'SettingsCtrl' + } + } + }) + .state('app.help', { + url: '/help', + views: { + 'menuContent': { + templateUrl: 'templates/help.html', + controller: 'HelpCtrl' + } + } + }); + // if none of the above states are matched, use this as the fallback + if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) { + if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) { + window.location = '#/app/main'; + } + $urlRouterProvider.otherwise('/app/main'); + } else { + if ((window.location != "#/app/login") || (window.location != "#/app/signup")) { + console.log("removing data, and going to login"); + localStorage.removeItem("cim_app_token"); + localStorage.removeItem("cim_app_userdata"); + window.location = "#/app/login"; + $urlRouterProvider.otherwise('/app/login'); + } + } + }) -/* translator */ -.config(['$translateProvider',function($translateProvider) { + /* translator */ + .config(['$translateProvider', function($translateProvider) { /* get lang from the file translations.js */ - for(lang in translations){ - $translateProvider.translations(lang, translations[lang]); + for (lang in translations) { + $translateProvider.translations(lang, translations[lang]); } - if(window.localStorage.getItem('lang')) { - $translateProvider.preferredLanguage(window.localStorage.getItem('lang')); - }else{ - $translateProvider.preferredLanguage('english'); + if (window.localStorage.getItem('lang')) { + $translateProvider.preferredLanguage(window.localStorage.getItem('lang')); + } else { + $translateProvider.preferredLanguage('english'); }; $translateProvider.useSanitizeValueStrategy('escape'); -}]); + }]); diff --git a/www/js/controllers.js b/www/js/controllers.js deleted file mode 100644 index 9b8bc85..0000000 --- a/www/js/controllers.js +++ /dev/null @@ -1,815 +0,0 @@ - -//var urlapi="http://localhost:3000/api/"; -var urlapi="https://collectivecar.paas.primustech.io/api/"; - - -//localStorage.setItem("c_username", "user2"); -//localStorage.setItem("c_token", ""); - - -angular.module('starter.controllers', ['pascalprecht.translate']) - -.controller('AppCtrl', function($scope, $ionicModal, $timeout, $http, $window, $ionicLoading) { - // 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 = {}; - $scope.signupData= {}; - - $scope.storageusername=localStorage.getItem("c_username"); - $scope.storageavatar=localStorage.getItem("c_avatar"); - $scope.userdata=JSON.parse(localStorage.getItem('c_userdata')); - console.log($scope.userdata); - // Create the login modal that we will use later - $ionicModal.fromTemplateUrl('templates/login.html', { - scope: $scope - }).then(function(modal) { - $scope.modalLogin = modal; - }); - $ionicModal.fromTemplateUrl('templates/signup.html', { - scope: $scope - }).then(function(modal) { - $scope.modalSignup = modal; - }); - - // Triggered in the login modal to close it - $scope.closeLogin = function() { - $scope.modalLogin.hide(); - }; - $scope.closeSignup = function() { - $scope.modalSignup.hide(); - }; - - // Open the login modal - $scope.login = function() { - $scope.modalLogin.show(); - }; - $scope.signup = function() { - $scope.modalSignup.show(); - }; - - // Perform the login action when the user submits the login form - $scope.doLogin = function() { - console.log('Doing login', $scope.loginData); - - $http({ - url: urlapi + 'auth', - method: "POST", - data: $scope.loginData - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response.data); - if(response.data.success==true) - { - console.log("login successful"); - localStorage.setItem("c_username", $scope.loginData.username); - localStorage.setItem("c_token", response.data.token); - localStorage.setItem("c_userid", response.data.userid); - localStorage.setItem("c_avatar", response.data.avatar); - - localStorage.setItem("c_userdata", JSON.stringify(response.data.userdata)); - - $timeout(function() { - $scope.closeLogin(); - $window.location.reload(true); - }, 1000); - }else{ - console.log("login failed"); - $ionicLoading.show({ template: 'Login failed, user or password error.', noBackdrop: true, duration: 2000 }); - } - - - }, - function(response) { // optional - // failed - console.log(response); - }); - - }; - $scope.doSignup = function() { - console.log('Doing signup', $scope.signupData); - if($scope.emptyParams($scope.signupData)) - { - $http({ - url: urlapi + 'users', - method: "POST", - data: $scope.signupData - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response.data); - $scope.loginData.username=$scope.signupData.username; - $timeout(function() { - $scope.closeSignup(); - $scope.login(); - }, 1000); - - }, - function(response) { // optional - // failed - $ionicLoading.show({ template: 'Username already taken', noBackdrop: true, duration: 2000 }); - }); - }else{ - $ionicLoading.show({ template: 'First complete all parameters', noBackdrop: true, duration: 2000 }); - } - - }; - $scope.emptyParams = function(obj){ - if(obj.username==undefined) - { - return(false); - } - if(obj.password==undefined) - { - return(false); - } - if(obj.mail==undefined) - { - return(false); - } - if(obj.avatar==undefined) - { - return(false); - } - return(true); - }; - $scope.avatars=[ - "turtle", - "cat", - "toucan", - "racoon", - "tiger", - "squirrel", - "sheep", - "penguin", - "panda", - "owl", - "pelican", - "whale", - "snake", - "mouse", - "giraffe", - "macaw", - "lion", - "llama", - "kangaroo", - "hen", - "frog", - "clown-fish", - "chameleon", - "octopus" - ]; - $scope.avatarSelect = function(avat){ - $scope.signupData.avatar=avat; - //alert($scope.signupData.avatar); - }; - $scope.logout = function(){ - localStorage.removeItem("c_username"); - localStorage.removeItem("c_token"); - localStorage.removeItem("c_avatar"); - localStorage.removeItem("c_userid"); - localStorage.removeItem("c_userdata"); - $window.location.reload(true); - }; - - /* if no logged, suggest to login */ - if(localStorage.getItem('c_token')){// adding token to the headers - $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); - }else{ - setTimeout(function(){ - $scope.login(); - },1000); - } -}) - - -.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { - if(localStorage.getItem('c_token')){// adding token to the headers - //console.log("token added to headers in run module"); - //console.log($http.defaults); - $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('c_token'); - //$http.defaults.headers.post['Content-Type'] = "application/x-www-form-urlencoded; charset=UTF-8"; - //console.log($http.defaults.headers); - } - /*if(localStorage.getItem('c_token')){// adding token to the headers - $http.defaults.headers.token = localStorage.getItem('c_token'); - }*/ - - $scope.travels=""; - $scope.travels=JSON.parse(localStorage.getItem('c_travels')); - $scope.userdata=JSON.parse(localStorage.getItem('c_userdata')); - //$scope.storageusername=JSON.parse(localStorage.getItem('c_username')); - console.log($scope.userdata); - - $scope.doRefresh = function() { - /* travels refresh: */ - $http.get(urlapi + 'travels') - .success(function(data, status, headers,config){ - console.log('data success travels'); - console.log(data); // for browser console - $scope.travels = data; // for UI - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - - }) - .error(function(data, status, headers,config){ - console.log('data error'); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); - - }) - .then(function(result){ - travels = result.data; - $ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 }); - }); - - /* users refresh: */ - $http.get(urlapi + 'users') - .success(function(data, status, headers, config){ - console.log('data success users'); - 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 - - //set userdata - $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; - console.log("userdata"); - console.log($scope.userdata); - localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); - }) - .error(function(data, status, headers,config){ - console.log('data error'); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - }) - .then(function(result){ - users = result.data; - }); - }; - $scope.newtravel={}; - /*$scope.newtravel={ - title: "prova", - from: "prova", - to: "prova", - seats: 3, - package: true, - phone: 123, - telegram: "telusr", - description: "this is the description of prova" - };*/ - - // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ - $scope.newtravel.modality="offering"; - //$scope.newtravel.token=localStorage.getItem("c_token"); - 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.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.newtravel={}; - if(response.data.success==false){ - - $ionicLoading.show({ template: 'failed to generate new travel', noBackdrop: true, duration: 2000 }); - } - }, - function(response) { // optional - // failed - $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); - }); - - // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ - - $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); - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.newtravel={}; - if(response.data.success==false){ - - $ionicLoading.show({ template: 'failed to generate new asking travel', noBackdrop: true, duration: 2000 }); - } - }, - function(response) { // optional - // failed - $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); - }); - - // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ - - $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); - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.newtravel={}; - if(response.data.success==false){ - - $ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 }); - } - }, - function(response) { // optional - // failed - $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); - }); - - // 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, $ionicModal, $ionicPopup, $filter) { - if(localStorage.getItem('c_token')){// adding token to the headers - $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); - } - $scope.storageusername=localStorage.getItem("c_username"); - console.log($stateParams.travelId); - $scope.travels= JSON.parse(localStorage.getItem('c_travels')); - $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; - - /*$http.get(urlapi + 'travels/comment/'+$stateParams.travelId) - .success(function(data, status, headers,config){ - console.log(data); // for browser console - $scope.comments = data; // for UI - }) - .error(function(data, status, headers,config){ - console.log('data error'); - }) - .then(function(result){ - comments = result.data; - });*/ - - $scope.deleteTravel = function(){ - - var confirmPopup = $ionicPopup.confirm({ - title: 'Deleting publication', - template: 'Are you sure you want to delete '+ $scope.travel.title+'?' - }); - confirmPopup.then(function(res) { - if(res) { - console.log('You are sure'); - console.log("delete travel: " + $stateParams.travelId); - $http({ - url: urlapi + 'travels/' + $stateParams.travelId, - method: "DELETE" - }) - .then(function(response) { - console.log(response); - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - - }, - function(response) { // optional - // failed - }); - } else { - console.log('You are not sure'); - } - }); - - - }; - $scope.joinTravel = function(){ - $scope.newjoin={ - //travelId: $stateParams.travelId, - /*joinedUserId: localStorage.getItem("c_userid"), - joinedUsername: localStorage.getItem("c_username"), - joinedAvatar: localStorage.getItem("c_avatar")*/ - }; - $http({ - url: urlapi + 'travels/'+ $stateParams.travelId+'/join', - method: "POST", - data: $scope.newjoin - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response); - - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; - - }, - function(response) { // optional - // failed - }); - }; - $scope.unjoinTravel = function(){ - console.log("unjoin"); - $scope.unjoin={ - travelId: $stateParams.travelId, - /*joinedUserId: localStorage.getItem("c_userid"), - joinedUsername: localStorage.getItem("c_username"), - joinedAvatar: localStorage.getItem("c_avatar")*/ - }; - $http({ - url: urlapi + 'travels/'+ $stateParams.travelId+'/unjoin', - method: "POST", - data: $scope.unjoin - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response); - - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; - - }, - function(response) { // optional - // failed - }); - }; - - /* adding comment */ - $scope.doingNewComment=false; - $scope.newComment={}; - - $scope.showNewComment = function() { - $scope.doingNewComment=true; - }; - $scope.closeNewComment = function() { - $scope.doingNewComment=false; - }; - $scope.doNewComment = function() { - /*$scope.newComment.commentUserId=localStorage.getItem("c_userid"); - $scope.newComment.commentUsername=localStorage.getItem("c_username"); - $scope.newComment.commentAvatar=localStorage.getItem("c_avatar");*/ -console.log($scope.newComment); - $http({ - url: urlapi + 'travels/'+ $stateParams.travelId+'/comment', - method: "POST", - data: $scope.newComment - }) - .then(function(response) { - // success - console.log("newComment added to server: " + response); - console.log(response); - $scope.travels=response.data; - localStorage.setItem('c_travels', JSON.stringify($scope.travels)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; - - if(response.data.success==false){ - - $ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 }); - } - }, - function(response) { // optional - // failed - }); - $scope.closeNewComment(); - }; - console.log("a"); - console.log($scope.storageusername); - console.log($scope.travel.owner); - - - $scope.arrayObjectIndexOf = function(myArray, searchTerm, property) { - //console.log(myArray+", "+searchTerm+", "+property); - if(myArray) - { - for(var i = 0, len = myArray.length; i < len; i++) { - if (myArray[i][property] === searchTerm){ - //console.log("i: " + i); - return i; - } - } - } - //console.log("i: -1"); - return -1; - }; -}) - -.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { - $scope.users=""; - - $scope.users=JSON.parse(localStorage.getItem('c_users')); - - $scope.doRefresh = function() { - /* travels refresh: */ - $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)); - localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - - }) - .error(function(data, status, headers,config){ - console.log('data error'); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); - - }) - .then(function(result){ - travels = result.data; - $ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 }); - }); - - /* users refresh: */ - $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 - - //set userdata - $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; - console.log("userdata"); - console.log($scope.userdata); - localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); - }) - .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, $filter, $ionicModal) { - if(localStorage.getItem('c_token')){// adding token to the headers - $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); - } - $scope.storageusername=localStorage.getItem("c_username"); - $scope.users= JSON.parse(localStorage.getItem('c_users')); - $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; - //$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; - }); - - - - $scope.favUser = function(){ - $scope.newfav={ - //travelId: $stateParams.travelId, - /*userId: localStorage.getItem("c_userid"), - username: localStorage.getItem("c_username"), - avatar: localStorage.getItem("c_avatar")*/ - }; - $scope.user.favs.push($scope.newfav);//al unfav no cal fer aquest simulacre pq ja no existeix a l'array i no el resta dos cops en cas de que cliquin dos cops - $http({ - //url: urlapi + 'users/'+ $stateParams.username+'/fav', - url: urlapi + 'users/'+ $scope.user._id+'/fav', - method: "POST", - data: $scope.newfav - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response); - - $scope.users=response.data; - localStorage.setItem('c_users', JSON.stringify($scope.users)); - $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; - - }, - function(response) { // optional - // failed - }); - }; - $scope.unfavUser = function(){ - console.log("unfav"); - $scope.unfav={ - /*userId: localStorage.getItem("c_userid"), - username: localStorage.getItem("c_username"), - avatar: localStorage.getItem("c_avatar")*/ - }; - $http({ - //url: urlapi + 'users/'+ $stateParams.username+'/fav', - url: urlapi + 'users/'+ $scope.user._id+'/unfav', - method: "POST", - data: $scope.unfav - }) - .then(function(response) { - // success - console.log("response: "); - console.log(response); - - $scope.users=response.data; - localStorage.setItem('c_users', JSON.stringify($scope.users)); - $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; - - }, - function(response) { // optional - // failed - }); - }; - - $ionicModal.fromTemplateUrl('templates/favsList.html', { - scope: $scope - }).then(function(modal) { - $scope.modalFavsList = modal; - }); - $scope.closeModalFavsList = function() { - $scope.modalFavsList.hide(); - }; - $scope.showFavsList = function(){ - $scope.modalFavsList.show(); - }; - $scope.closeModalAndGoUser = function(){ - $scope.modalFavsList.hide(); - }; - - $scope.arrayObjectIndexOf = function(myArray, searchTerm, property) { - if(myArray){ - for(var i = 0, len = myArray.length; i < len; i++) { - if (myArray[i][property] === searchTerm){ - return i; - } - } - } - return -1; - }; -}) -.controller('NotificationsCtrl', function($scope, $stateParams, $translate, $filter) { - if(localStorage.getItem('c_token')){// adding token to the headers - // $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); - } - $scope.storageusername=localStorage.getItem("c_username"); - $scope.users= JSON.parse(localStorage.getItem('c_users')); - $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; - $scope.notifications=$scope.user.notifications; - - console.log($stateParams.username); - console.log($scope.notifications); - console.log("notifications page"); -}) - -.controller('SettingsCtrl', function($scope, $stateParams, $translate) { - if(localStorage.getItem('lang'))//initialization - { - $scope.lang=localStorage.getItem('lang'); - }else{ - localStorage.setItem('lang', 'english'); - $scope.lang=localStorage.getItem('lang'); - } - - $scope.langChange = function(lang){ - console.log(lang); - window.localStorage.setItem('lang', lang); - $translate.use(lang); - }; -}) -.controller('HelpCtrl', function($scope, $stateParams, $translate) { - console.log("help page"); -}); diff --git a/www/js/footerMenu.js b/www/js/footerMenu.js new file mode 100644 index 0000000..d5e2bbb --- /dev/null +++ b/www/js/footerMenu.js @@ -0,0 +1,5 @@ +angular.module('app.footerMenu', ['pascalprecht.translate']) + +.controller('FooterMenuCtrl', function($scope, $stateParams, $translate, $filter) { + +}); diff --git a/www/js/help.js b/www/js/help.js new file mode 100644 index 0000000..d7de1bc --- /dev/null +++ b/www/js/help.js @@ -0,0 +1,6 @@ +angular.module('app.help', ['pascalprecht.translate']) + + +.controller('HelpCtrl', function($scope, $stateParams, $translate) { + console.log("help page"); +}); diff --git a/www/js/login.js b/www/js/login.js new file mode 100644 index 0000000..e582874 --- /dev/null +++ b/www/js/login.js @@ -0,0 +1,38 @@ +angular.module('app.login', ['pascalprecht.translate']) + +.controller('LoginCtrl', function($scope, $ionicModal, $timeout, $http, $window, $ionicLoading) { + + // Form data for the login modal + $scope.loginData = {}; + // Perform the login action when the user submits the login form + $scope.doLogin = function() { + console.log('Doing login', $scope.loginData); + + $http({ + url: urlapi + 'auth', + method: "POST", + data: $scope.loginData + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response.data); + if (response.data.success == true) + { + localStorage.setItem("cim_app_token", response.data.token); + localStorage.setItem("cim_app_userdata", JSON.stringify(response.data.user)); + window.location.reload(); + }else{ + console.log("login failed"); + $ionicLoading.show({ template: 'Login failed, user or password error.', noBackdrop: true, duration: 2000 }); + } + + + }, + function(response) { // optional + // failed + console.log(response); + }); + + }; +}); diff --git a/www/js/main.js b/www/js/main.js new file mode 100644 index 0000000..f93070a --- /dev/null +++ b/www/js/main.js @@ -0,0 +1,5 @@ +angular.module('app.main', ['pascalprecht.translate']) + +.controller('MainCtrl', function($scope, $stateParams, $translate, $filter) { + +}); diff --git a/www/js/menu.js b/www/js/menu.js new file mode 100644 index 0000000..b0077b9 --- /dev/null +++ b/www/js/menu.js @@ -0,0 +1,12 @@ +angular.module('app.menu', ['pascalprecht.translate']) + + + .controller('MenuCtrl', function($scope) { + $scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); + console.log($scope.storageuser); + $scope.logout = function() { + localStorage.removeItem("cim_app_token"); + localStorage.removeItem("cim_app_userdata"); + window.location = "/"; + }; + }); diff --git a/www/js/newPublication.js b/www/js/newPublication.js new file mode 100644 index 0000000..1415c4d --- /dev/null +++ b/www/js/newPublication.js @@ -0,0 +1,5 @@ +angular.module('app.newPublication', ['pascalprecht.translate']) + +.controller('NewPublicationCtrl', function($scope, $stateParams, $translate, $filter) { + +}); diff --git a/www/js/notifications.js b/www/js/notifications.js new file mode 100644 index 0000000..10f532b --- /dev/null +++ b/www/js/notifications.js @@ -0,0 +1,15 @@ +angular.module('app.notifications', ['pascalprecht.translate']) + +.controller('NotificationsCtrl', function($scope, $stateParams, $translate, $filter) { + if(localStorage.getItem('c_token')){// adding token to the headers + // $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); + } + $scope.storageusername=localStorage.getItem("c_username"); + $scope.users= JSON.parse(localStorage.getItem('c_users')); + $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; + $scope.notifications=$scope.user.notifications; + + console.log($stateParams.username); + console.log($scope.notifications); + console.log("notifications page"); +}); diff --git a/www/js/offerCar.js b/www/js/offerCar.js new file mode 100644 index 0000000..4156324 --- /dev/null +++ b/www/js/offerCar.js @@ -0,0 +1,5 @@ +angular.module('app.offerCar', ['pascalprecht.translate']) + +.controller('OfferCarCtrl', function($scope, $stateParams, $translate, $filter) { + +}); diff --git a/www/js/settings.js b/www/js/settings.js new file mode 100644 index 0000000..095ce2e --- /dev/null +++ b/www/js/settings.js @@ -0,0 +1,17 @@ +angular.module('app.settings', ['pascalprecht.translate']) + +.controller('SettingsCtrl', function($scope, $stateParams, $translate) { + if(localStorage.getItem('lang'))//initialization + { + $scope.lang=localStorage.getItem('lang'); + }else{ + localStorage.setItem('lang', 'english'); + $scope.lang=localStorage.getItem('lang'); + } + + $scope.langChange = function(lang){ + console.log(lang); + window.localStorage.setItem('lang', lang); + $translate.use(lang); + }; +}); diff --git a/www/js/signup.js b/www/js/signup.js new file mode 100644 index 0000000..7d42798 --- /dev/null +++ b/www/js/signup.js @@ -0,0 +1,91 @@ +angular.module('app.signup', ['pascalprecht.translate']) + + .controller('SignupCtrl', function($scope, $ionicModal, $timeout, $http, $window, $ionicLoading) { + $scope.signupData = {}; + $scope.doSignup = function() { + console.log('Doing signup', $scope.signupData); + if ($scope.emptyParams($scope.signupData)) { + $http({ + url: urlapi + 'users', + method: "POST", + data: $scope.signupData + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response.data); + + if (response.data.success == true) + { + localStorage.setItem("cim_app_token", response.data.token); + localStorage.setItem("cim_app_userdata", JSON.stringify(response.data.user)); + window.location.reload(); + }else{ + console.log("signup failed"); + $ionicLoading.show({ template: 'signup failed, user or password error.', noBackdrop: true, duration: 2000 }); + } + }, + function(response) { // optional + // failed + $ionicLoading.show({ + template: 'Error on signup', + noBackdrop: true, + duration: 2000 + }); + }); + } else { + $ionicLoading.show({ + template: 'First complete all parameters', + noBackdrop: true, + duration: 2000 + }); + } + + }; + $scope.emptyParams = function(obj) { + if (obj.username == undefined) { + return (false); + } + if (obj.password == undefined) { + return (false); + } + if (obj.mail == undefined) { + return (false); + } + /*if(obj.avatar==undefined) + { + return(false); + }*/ + return (true); + }; + $scope.avatars = [ + "turtle", + "cat", + "toucan", + "racoon", + "tiger", + "squirrel", + "sheep", + "penguin", + "panda", + "owl", + "pelican", + "whale", + "snake", + "mouse", + "giraffe", + "macaw", + "lion", + "llama", + "kangaroo", + "hen", + "frog", + "clown-fish", + "chameleon", + "octopus" + ]; + $scope.avatarSelect = function(avat) { + $scope.signupData.avatar = avat; + //alert($scope.signupData.avatar); + }; + }); diff --git a/www/js/travel.js b/www/js/travel.js new file mode 100644 index 0000000..856fe8f --- /dev/null +++ b/www/js/travel.js @@ -0,0 +1,169 @@ +angular.module('app.travel', ['pascalprecht.translate']) + +.controller('TravelCtrl', function($scope, $stateParams, $http, $ionicModal, $ionicPopup, $filter) { + if(localStorage.getItem('c_token')){// adding token to the headers + $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); + } + $scope.storageusername=localStorage.getItem("c_username"); + console.log($stateParams.travelId); + $scope.travels= JSON.parse(localStorage.getItem('c_travels')); + $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; + + /*$http.get(urlapi + 'travels/comment/'+$stateParams.travelId) + .success(function(data, status, headers,config){ + console.log(data); // for browser console + $scope.comments = data; // for UI + }) + .error(function(data, status, headers,config){ + console.log('data error'); + }) + .then(function(result){ + comments = result.data; + });*/ + + $scope.deleteTravel = function(){ + + var confirmPopup = $ionicPopup.confirm({ + title: 'Deleting publication', + template: 'Are you sure you want to delete '+ $scope.travel.title+'?' + }); + confirmPopup.then(function(res) { + if(res) { + console.log('You are sure'); + console.log("delete travel: " + $stateParams.travelId); + $http({ + url: urlapi + 'travels/' + $stateParams.travelId, + method: "DELETE" + }) + .then(function(response) { + console.log(response); + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + + }, + function(response) { // optional + // failed + }); + } else { + console.log('You are not sure'); + } + }); + + + }; + $scope.joinTravel = function(){ + $scope.newjoin={ + //travelId: $stateParams.travelId, + /*joinedUserId: localStorage.getItem("c_userid"), + joinedUsername: localStorage.getItem("c_username"), + joinedAvatar: localStorage.getItem("c_avatar")*/ + }; + $http({ + url: urlapi + 'travels/'+ $stateParams.travelId+'/join', + method: "POST", + data: $scope.newjoin + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response); + + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; + + }, + function(response) { // optional + // failed + }); + }; + $scope.unjoinTravel = function(){ + console.log("unjoin"); + $scope.unjoin={ + travelId: $stateParams.travelId, + /*joinedUserId: localStorage.getItem("c_userid"), + joinedUsername: localStorage.getItem("c_username"), + joinedAvatar: localStorage.getItem("c_avatar")*/ + }; + $http({ + url: urlapi + 'travels/'+ $stateParams.travelId+'/unjoin', + method: "POST", + data: $scope.unjoin + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response); + + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; + + }, + function(response) { // optional + // failed + }); + }; + + /* adding comment */ + $scope.doingNewComment=false; + $scope.newComment={}; + + $scope.showNewComment = function() { + $scope.doingNewComment=true; + }; + $scope.closeNewComment = function() { + $scope.doingNewComment=false; + }; + $scope.doNewComment = function() { + /*$scope.newComment.commentUserId=localStorage.getItem("c_userid"); + $scope.newComment.commentUsername=localStorage.getItem("c_username"); + $scope.newComment.commentAvatar=localStorage.getItem("c_avatar");*/ +console.log($scope.newComment); + $http({ + url: urlapi + 'travels/'+ $stateParams.travelId+'/comment', + method: "POST", + data: $scope.newComment + }) + .then(function(response) { + // success + console.log("newComment added to server: " + response); + console.log(response); + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0]; + + if(response.data.success==false){ + + $ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 }); + } + }, + function(response) { // optional + // failed + }); + $scope.closeNewComment(); + }; + console.log("a"); + console.log($scope.storageusername); + console.log($scope.travel.owner); + + + $scope.arrayObjectIndexOf = function(myArray, searchTerm, property) { + //console.log(myArray+", "+searchTerm+", "+property); + if(myArray) + { + for(var i = 0, len = myArray.length; i < len; i++) { + if (myArray[i][property] === searchTerm){ + //console.log("i: " + i); + return i; + } + } + } + //console.log("i: -1"); + return -1; + }; +}); diff --git a/www/js/travels.js b/www/js/travels.js new file mode 100644 index 0000000..512c90a --- /dev/null +++ b/www/js/travels.js @@ -0,0 +1,238 @@ +angular.module('app.travels', ['pascalprecht.translate']) + +.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { + + + + + $scope.doRefresh = function() { + /* travels refresh: */ + $http.get(urlapi + 'travels') + .success(function(data, status, headers,config){ + console.log('data success travels'); + console.log(data); // for browser console + $scope.travels = data; // for UI + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + + }) + .error(function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); + + }) + .then(function(result){ + travels = result.data; + $ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 }); + }); + + /* users refresh: */ + $http.get(urlapi + 'users') + .success(function(data, status, headers, config){ + console.log('data success users'); + 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 + + //set userdata + $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; + console.log("userdata"); + console.log($scope.userdata); + localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); + }) + .error(function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + }) + .then(function(result){ + users = result.data; + }); + }; + $scope.newtravel={}; + /*$scope.newtravel={ + title: "prova", + from: "prova", + to: "prova", + seats: 3, + package: true, + phone: 123, + telegram: "telusr", + description: "this is the description of prova" + };*/ + + // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ + $scope.newtravel.modality="offering"; + //$scope.newtravel.token=localStorage.getItem("c_token"); + 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.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.newtravel={}; + if(response.data.success==false){ + + $ionicLoading.show({ template: 'failed to generate new travel', noBackdrop: true, duration: 2000 }); + } + }, + function(response) { // optional + // failed + $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); + }); + + // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ + + $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); + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.newtravel={}; + if(response.data.success==false){ + + $ionicLoading.show({ template: 'failed to generate new asking travel', noBackdrop: true, duration: 2000 }); + } + }, + function(response) { // optional + // failed + $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); + }); + + // 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.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ + + $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); + $scope.travels=response.data; + localStorage.setItem('c_travels', JSON.stringify($scope.travels)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.newtravel={}; + if(response.data.success==false){ + + $ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 }); + } + }, + function(response) { // optional + // failed + $ionicLoading.show({ template: 'failed to generate new publication, all input fields needed', noBackdrop: true, duration: 2000 }); + }); + + // Simulate a login delay. Remove this and replace with your login + // code if using a login system + $timeout(function() { + $scope.closeNewAskingPackage(); + }, 1000); + }; +}); diff --git a/www/js/user.js b/www/js/user.js new file mode 100644 index 0000000..c2d585e --- /dev/null +++ b/www/js/user.js @@ -0,0 +1,121 @@ +angular.module('app.user', ['pascalprecht.translate']) + +.controller('UserCtrl', function($scope, $stateParams, $http, $filter, $ionicModal) { + if(localStorage.getItem('c_token')){// adding token to the headers + $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); + } + $scope.storageusername=localStorage.getItem("c_username"); + $scope.users= JSON.parse(localStorage.getItem('c_users')); + $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; + //$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; + }); + + + + $scope.favUser = function(){ + $scope.newfav={ + //travelId: $stateParams.travelId, + /*userId: localStorage.getItem("c_userid"), + username: localStorage.getItem("c_username"), + avatar: localStorage.getItem("c_avatar")*/ + }; + $scope.user.favs.push($scope.newfav);//al unfav no cal fer aquest simulacre pq ja no existeix a l'array i no el resta dos cops en cas de que cliquin dos cops + $http({ + //url: urlapi + 'users/'+ $stateParams.username+'/fav', + url: urlapi + 'users/'+ $scope.user._id+'/fav', + method: "POST", + data: $scope.newfav + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response); + + $scope.users=response.data; + localStorage.setItem('c_users', JSON.stringify($scope.users)); + $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; + + }, + function(response) { // optional + // failed + }); + }; + $scope.unfavUser = function(){ + console.log("unfav"); + $scope.unfav={ + /*userId: localStorage.getItem("c_userid"), + username: localStorage.getItem("c_username"), + avatar: localStorage.getItem("c_avatar")*/ + }; + $http({ + //url: urlapi + 'users/'+ $stateParams.username+'/fav', + url: urlapi + 'users/'+ $scope.user._id+'/unfav', + method: "POST", + data: $scope.unfav + }) + .then(function(response) { + // success + console.log("response: "); + console.log(response); + + $scope.users=response.data; + localStorage.setItem('c_users', JSON.stringify($scope.users)); + $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; + + }, + function(response) { // optional + // failed + }); + }; + + $ionicModal.fromTemplateUrl('templates/favsList.html', { + scope: $scope + }).then(function(modal) { + $scope.modalFavsList = modal; + }); + $scope.closeModalFavsList = function() { + $scope.modalFavsList.hide(); + }; + $scope.showFavsList = function(){ + $scope.modalFavsList.show(); + }; + $scope.closeModalAndGoUser = function(){ + $scope.modalFavsList.hide(); + }; + + $scope.arrayObjectIndexOf = function(myArray, searchTerm, property) { + if(myArray){ + for(var i = 0, len = myArray.length; i < len; i++) { + if (myArray[i][property] === searchTerm){ + return i; + } + } + } + return -1; + }; +}); diff --git a/www/js/users.js b/www/js/users.js new file mode 100644 index 0000000..a1e1022 --- /dev/null +++ b/www/js/users.js @@ -0,0 +1,54 @@ +angular.module('app.users', ['pascalprecht.translate']) + +.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { + $scope.users=""; + + $scope.users=JSON.parse(localStorage.getItem('c_users')); + + $scope.doRefresh = function() { + /* travels refresh: */ + $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)); + localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date())); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + + }) + .error(function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); + + }) + .then(function(result){ + travels = result.data; + $ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 }); + }); + + /* users refresh: */ + $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 + + //set userdata + $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; + console.log("userdata"); + console.log($scope.userdata); + localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); + }) + .error(function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + }) + .then(function(result){ + users = result.data; + }); + }; +}); diff --git a/www/templates/login.html b/www/templates/login.html index d051458..7f22e2d 100644 --- a/www/templates/login.html +++ b/www/templates/login.html @@ -2,8 +2,7 @@

{{'Login' | translate}}

- - + {{'Signup' | translate}}
diff --git a/www/templates/main.html b/www/templates/main.html new file mode 100644 index 0000000..3675d1b --- /dev/null +++ b/www/templates/main.html @@ -0,0 +1,20 @@ + + + + + Travels + + + + Users + + + + Settings + + + + Help + + + diff --git a/www/templates/menu.html b/www/templates/menu.html index 43061a1..8e741be 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -1,6 +1,6 @@ - + @@ -10,6 +10,19 @@ + + + @@ -18,40 +31,31 @@ - - {{'Signup' | translate }} - - - {{'Login' | translate }} - - - - {{'Travels' | translate }} - - - - {{'Users' | translate }} - - - - {{'Notifications' | translate }} + + {{'Main' | translate }} + + + {{storageuser.username}} + + + {{'Travels' | translate }} + + + {{'Users' | translate }} + + + {{'Notifications' | translate }} {{userdata.notifications.length}} - - - - {{storageusername}} - - - - {{'Settings' | translate }} - - - - {{'Help' | translate }} - - - {{'Logout' | translate }} - + + + {{'Settings' | translate }} + + + {{'Help' | translate }} + + + {{'Logout' | translate }} + diff --git a/www/templates/newPublication.html b/www/templates/newPublication.html new file mode 100644 index 0000000..c1df01a --- /dev/null +++ b/www/templates/newPublication.html @@ -0,0 +1,16 @@ + + + + + Offer Car + + + + Ask for Car + + + + Ask for Package + + + diff --git a/www/templates/offerCar.html b/www/templates/offerCar.html new file mode 100644 index 0000000..335595b --- /dev/null +++ b/www/templates/offerCar.html @@ -0,0 +1,62 @@ + + +
+ + + + + + + + + + + + {{'Can_carry_package' | translate}} + + + {{'Collectivized_car' | translate}} + + + +

+ + +

+
+
+
diff --git a/www/templates/signup.html b/www/templates/signup.html index 08f6545..f7af90a 100644 --- a/www/templates/signup.html +++ b/www/templates/signup.html @@ -2,7 +2,7 @@

{{'Signup' | translate }}

- + {{'Close' | translate }}