Browse Source

actualitzant...

master
arnaucode 7 years ago
parent
commit
5f16f060c1
23 changed files with 1105 additions and 942 deletions
  1. +16
    -1
      www/index.html
  2. +170
    -89
      www/js/app.js
  3. +0
    -815
      www/js/controllers.js
  4. +5
    -0
      www/js/footerMenu.js
  5. +6
    -0
      www/js/help.js
  6. +38
    -0
      www/js/login.js
  7. +5
    -0
      www/js/main.js
  8. +12
    -0
      www/js/menu.js
  9. +5
    -0
      www/js/newPublication.js
  10. +15
    -0
      www/js/notifications.js
  11. +5
    -0
      www/js/offerCar.js
  12. +17
    -0
      www/js/settings.js
  13. +91
    -0
      www/js/signup.js
  14. +169
    -0
      www/js/travel.js
  15. +238
    -0
      www/js/travels.js
  16. +121
    -0
      www/js/user.js
  17. +54
    -0
      www/js/users.js
  18. +1
    -2
      www/templates/login.html
  19. +20
    -0
      www/templates/main.html
  20. +38
    -34
      www/templates/menu.html
  21. +16
    -0
      www/templates/newPublication.html
  22. +62
    -0
      www/templates/offerCar.html
  23. +1
    -1
      www/templates/signup.html

+ 16
- 1
www/index.html

@ -24,7 +24,22 @@
<!-- your app's js --> <!-- your app's js -->
<script src="js/translations.js"></script> <script src="js/translations.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/login.js"></script>
<script src="js/signup.js"></script>
<script src="js/menu.js"></script>
<script src="js/footerMenu.js"></script>
<script src="js/main.js"></script>
<script src="js/travels.js"></script>
<script src="js/travel.js"></script>
<script src="js/newPublication.js"></script>
<script src="js/offerCar.js"></script>
<!--<script src="js/askCar.js"></script>
<script src="js/askPackage.js"></script>-->
<script src="js/users.js"></script>
<script src="js/user.js"></script>
<script src="js/notifications.js"></script>
<script src="js/settings.js"></script>
<script src="js/help.js"></script>
</head> </head>
<body ng-app="starter"> <body ng-app="starter">

+ 170
- 89
www/js/app.js

@ -4,73 +4,133 @@
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires' // the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js // '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', url: '/users/:username',
views: { views: {
'menuContent': { '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 */ /* 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'); $translateProvider.useSanitizeValueStrategy('escape');
}]);
}]);

+ 0
- 815
www/js/controllers.js

@ -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 <b>'+ $scope.travel.title+'</b>?'
});
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");
});

+ 5
- 0
www/js/footerMenu.js

@ -0,0 +1,5 @@
angular.module('app.footerMenu', ['pascalprecht.translate'])
.controller('FooterMenuCtrl', function($scope, $stateParams, $translate, $filter) {
});

+ 6
- 0
www/js/help.js

@ -0,0 +1,6 @@
angular.module('app.help', ['pascalprecht.translate'])
.controller('HelpCtrl', function($scope, $stateParams, $translate) {
console.log("help page");
});

+ 38
- 0
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);
});
};
});

+ 5
- 0
www/js/main.js

@ -0,0 +1,5 @@
angular.module('app.main', ['pascalprecht.translate'])
.controller('MainCtrl', function($scope, $stateParams, $translate, $filter) {
});

+ 12
- 0
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 = "/";
};
});

+ 5
- 0
www/js/newPublication.js

@ -0,0 +1,5 @@
angular.module('app.newPublication', ['pascalprecht.translate'])
.controller('NewPublicationCtrl', function($scope, $stateParams, $translate, $filter) {
});

+ 15
- 0
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");
});

+ 5
- 0
www/js/offerCar.js

@ -0,0 +1,5 @@
angular.module('app.offerCar', ['pascalprecht.translate'])
.controller('OfferCarCtrl', function($scope, $stateParams, $translate, $filter) {
});

+ 17
- 0
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);
};
});

+ 91
- 0
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);
};
});

+ 169
- 0
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 <b>'+ $scope.travel.title+'</b>?'
});
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;
};
});

+ 238
- 0
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);
};
});

+ 121
- 0
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;
};
});

+ 54
- 0
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;
});
};
});

+ 1
- 2
www/templates/login.html

@ -2,8 +2,7 @@
<ion-header-bar> <ion-header-bar>
<h1 class="title">{{'Login' | translate}}</h1> <h1 class="title">{{'Login' | translate}}</h1>
<div class="buttons"> <div class="buttons">
<button class="button button-balanced" ng-click="signup()">{{'Signup' | translate}}</button>
<button class="button button-dark" ng-click="closeLogin()">{{'Close' | translate}}</button>
<a class="button button-balanced" ng-href="#/app/signup">{{'Signup' | translate}}</a>
</div> </div>
</ion-header-bar> </ion-header-bar>
<ion-content> <ion-content>

+ 20
- 0
www/templates/main.html

@ -0,0 +1,20 @@
<ion-view view-title="Main">
<ion-content>
<a ng-href="#/app/user/{{storageuser._id}}" class="item item-icon-left o_bBlue">
<i class="icon ion-android-car"></i>
Travels
</a>
<a href="#/app/dashboard" class="item item-icon-left o_bGreen">
<i class="icon ion-person-stalker"></i>
Users
</a>
<a href="#/app/marks/{{storageuser._id}}" class="item item-icon-left o_bOrange">
<i class="icon ion-settings"></i>
Settings
</a>
<a href="#/app/runs/{{storageuser._id}}" class="item item-icon-left o_bPurple">
<i class="icon ion-ios-help-outline"></i>
Help
</a>
</ion-content>
</ion-view>

+ 38
- 34
www/templates/menu.html

@ -1,6 +1,6 @@
<ion-side-menus enable-menu-with-back-views="false"> <ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content> <ion-side-menu-content>
<ion-nav-bar class="bar-calm">
<ion-nav-bar class="bar-calm" ng-show="storageuser">
<ion-nav-back-button> <ion-nav-back-button>
</ion-nav-back-button> </ion-nav-back-button>
@ -10,6 +10,19 @@
</ion-nav-buttons> </ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view> <ion-nav-view name="menuContent"></ion-nav-view>
<!-- menu footer -->
<div class="tabs tabs-icon-left" ng-controller="FooterMenuCtrl" ng-show="storageuser" ng-hide="location=='message'">
<a class="tab-item" ng-href="#/app/notifications">
<i class="icon ion-android-notifications-none"></i> Notifications
</a>
<a class="tab-item" ng-href="#/app/main">
<i class="icon ion-home"></i> Home
</a>
<a ng-href="#/app/newPublication" class="tab-item">
<i class="icon ion-paper-airplane"></i> New publication
</a>
</div>
<!-- /menu footer -->
</ion-side-menu-content> </ion-side-menu-content>
<ion-side-menu side="left"> <ion-side-menu side="left">
@ -18,40 +31,31 @@
</ion-header-bar> </ion-header-bar>
<ion-content> <ion-content>
<ion-list> <ion-list>
<ion-item menu-close ng-click="signup()" ng-show="!storageusername">
{{'Signup' | translate }}
</ion-item>
<ion-item menu-close ng-click="login()" ng-show="!storageusername">
{{'Login' | translate }}
</ion-item>
<ion-item menu-close href="#/app/travels">
<img class='o-imgMenu' src="img/road.png" />
{{'Travels' | translate }}
</ion-item>
<ion-item menu-close href="#/app/users">
<img class='o-imgMenu' src="img/users.png" />
{{'Users' | translate }}
</ion-item>
<ion-item menu-close href="#/app/notifications/{{storageusername}}" ng-show="storageusername">
<img class='o-imgMenu' src="img/notification.png" />
{{'Notifications' | translate }}
<a class="item item-icon-left" menu-close href="#/app/main">
<i class="icon ion-home"></i> {{'Main' | translate }}
</a>
<a class="item item-icon-left" menu-close href="#/app/users/{{storageuser}}" ng-show="storageuser">
<i class="icon ion-person"></i> {{storageuser.username}}
</a>
<a class="item item-icon-left" menu-close href="#/app/travels">
<i class="icon ion-android-car"></i> {{'Travels' | translate }}
</a>
<a class="item item-icon-left" menu-close href="#/app/users">
<i class="icon ion-person-stalker"></i> {{'Users' | translate }}
</a>
<a class="item item-icon-left" menu-close href="#/app/notifications" ng-show="storageuser">
<i class="icon ion-android-notifications-none"></i> {{'Notifications' | translate }}
<span class="badge badge-positive">{{userdata.notifications.length}}</span> <span class="badge badge-positive">{{userdata.notifications.length}}</span>
</ion-item>
<ion-item menu-close href="#/app/users/{{storageusername}}" ng-show="storageusername">
<img class='o-imgMenu' ng-src="img/avatars/{{storageavatar}}.png" />
{{storageusername}}
</ion-item>
<ion-item menu-close href="#/app/settings">
<img class='o-imgMenu' src="img/settings.png" />
{{'Settings' | translate }}
</ion-item>
<ion-item menu-close href="#/app/help">
<img class='o-imgMenu' src="img/help.png" />
{{'Help' | translate }}
</ion-item>
<ion-item menu-close ng-click="logout()" ng-show="storageusername">
{{'Logout' | translate }}
</ion-item>
</a>
<a class="item item-icon-left" menu-close href="#/app/settings">
<i class="icon ion-settings"></i> {{'Settings' | translate }}
</a>
<a class="item item-icon-left" menu-close href="#/app/help">
<i class="icon ion-ios-help-outline"></i> {{'Help' | translate }}
</a>
<a class="item item-icon-left" menu-close ng-click="logout()" ng-show="storageuser">
<i class="icon ion-home"></i> {{'Logout' | translate }}
</a>
</ion-list> </ion-list>
</ion-content> </ion-content>
</ion-side-menu> </ion-side-menu>

+ 16
- 0
www/templates/newPublication.html

@ -0,0 +1,16 @@
<ion-view view-title="New Publication">
<ion-content>
<a ng-href="#/app/offerCar" class="item item-icon-left o_bBlue">
<i class="icon ion-android-car"></i>
Offer Car
</a>
<a href="#/app/dashboard" class="item item-icon-left o_bGreen">
<i class="icon ion-help"></i>
Ask for Car
</a>
<a href="#/app/marks/{{storageuser._id}}" class="item item-icon-left o_bOrange">
<i class="icon ion-ios-box"></i>
Ask for Package
</a>
</ion-content>
</ion-view>

+ 62
- 0
www/templates/offerCar.html

@ -0,0 +1,62 @@
<ion-view view-title="Offer Car">
<ion-content>
<form class="list">
<label class="item item-input">
<span class="input-label"t>{{'Title' | translate}}</span>
<input ng-model="newtravel.title" class="positive" type="text" placeholder="">
</label>
<label class="item item-input">
<img class='o-imgMenu' src="img/localization.png" />
<span class="input-label">{{'From' | translate}}</span>
<input ng-model="newtravel.from" type="text" placeholder="">
</label>
<label class="item item-input">
<img class='o-imgMenu' src="img/localization.png" />
<span class="input-label">{{'To' | translate}}</span>
<input ng-model="newtravel.to" type="text" placeholder="">
</label>
<label class="item item-input">
<span class="input-label">{{'n_Seats' | translate}}</span>
<input ng-model="newtravel.seats" type="number" placeholder="">
</label>
<label class="item item-input">
<span class="input-label">{{'Date' | translate}}</span>
<input ng-model="newtravel.date" type="date" placeholder="">
</label>
<label class="item item-input">
<span class="input-label">{{'Hour' | translate}}</span>
<input ng-model="newtravel.date" type="time" placeholder="">
</label>
<!--<label class="item item-input">
<span class="input-label"><i class="icon ion-iphone"></i> {{'Phone_contact' | translate}}</span>
<input ng-model="newtravel.phone" type="number" placeholder="">
</label>
<label class="item item-input">
<span class="input-label">{{'Telegram_user' | translate}}</span>
<input ng-model="newtravel.telegram" type="text" placeholder="">
</label>-->
<ion-toggle ng-model="newtravel.package" toggle-class="toggle-calm">
<img class='o-imgMenu' src="img/package.png" />
{{'Can_carry_package' | translate}}
</ion-toggle>
<ion-toggle ng-model="newtravel.collectivized" toggle-class="toggle-calm">
{{'Collectivized_car' | translate}}
</ion-toggle>
<label class="item item-input item-floating-label">
<span class="input-label">{{'Description' | translate}}</span>
<input ng-model="newtravel.description" type="text" placeholder="Description">
</label>
<p class="padding">
<button ng-click="closeNewOfferingTravel()" class="button button-assertive">
{{'Cancel' | translate}}
</button>
<button ng-click="doNewOfferingTravel()" class="button button-calm">
{{'Create_travel' | translate}}
</button>
</p>
</form>
</ion-content>
</ion-view>

+ 1
- 1
www/templates/signup.html

@ -2,7 +2,7 @@
<ion-header-bar> <ion-header-bar>
<h1 class="title">{{'Signup' | translate }}</h1> <h1 class="title">{{'Signup' | translate }}</h1>
<div class="buttons"> <div class="buttons">
<button class="button button-dark" ng-click="closeSignup()">{{'Close' | translate }}</button>
<a class="button button-dark" ng-href="#/app/login">{{'Close' | translate }}</a>
</div> </div>
</ion-header-bar> </ion-header-bar>
<ion-content> <ion-content>

Loading…
Cancel
Save