/**
https://foulees.apeidieppe.fr/#/done?amount=1200&bkId=BK5ca09ed4bb725&auto=XXXXXX&status=00000&transac=14667597&date=31032019&time=13:04:58
*/
var app = angular.module('app', ['ngRoute', 'ngSanitize', 'angular.filter']); //, 'ui.bootstrap', 'ngSanitize', 'ngFileUpload'
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
'use strict';
app.run(['$rootScope', function($rootScope, $location, $timeout) {
$rootScope.$on('$routeChangeSuccess', function() {
window.scrollTo(0, 0);
});
}]);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/app/home/partials/home.htm?r=' + Math.random(),
controller: 'ctrlHome'
})
.when('/booking/vagues', {
templateUrl: '/app/bookings/partials/vagues.htm?r=' + Math.random(),
controller: 'ctrlBookingsVagues'
}).when('/booking/form/:vague_id', {
templateUrl: '/app/bookings/partials/form.htm?r=' + Math.random(),
controller: 'ctrlBookingForm'
}).when('/booking/payment/:bkId', {
templateUrl: '/app/bookings/partials/payment.htm?r=' + Math.random(),
controller: 'ctrlPayment'
}).when('/booking/done/:bkId', {
templateUrl: '/app/bookings/partials/done.htm?r=' + Math.random(),
controller: 'ctrlDone'
}).when('/booking/canceled/:bkId', {
templateUrl: '/app/bookings/partials/canceled.htm?r=' + Math.random(),
controller: 'ctrlCanceled'
}).when('/booking/lists', {
templateUrl: '/app/bookings/partials/lists.htm?r=' + Math.random(),
controller: 'ctrlLists'
}).when('/contact', {
templateUrl: '/app/contacts/partials/contact_form.tpl?r=' + Math.random(),
controller: 'ctrlContact'
})
.otherwise({
redirectTo: "/"
});
}])
window.set_medaillons = function() {
$('.medaillons img').each(function() {
var img = $(this);
img.replaceWith('
' + img.prop('outerHTML') + '
');
});
$('.medaillons').addClass('ready');
}/**
ctrl.home.js
*/
app.controller('ctrlHome', function ($window, $rootScope, $scope, $routeParams, $location, $interval, $timeout, $sce, $http) {
$scope.$on('$viewContentLoaded', function () {
$timeout(function () {
$window.set_medaillons();
}, 200)
});
});app.controller('ctrlBookingsVagues', function($window, $rootScope, $scope, $routeParams, $interval, $timeout, $sce, $http,$window) {
$scope.initialized = false;
$scope.vagues = {}
$scope.vague_id = '';
$scope.timestamp = $window.timestamp;
$scope.booking_timeout = $window.booking_timeout;
console.log($scope.timestamp);
$http.get('/app/bookings/data/vagues.json?v='+Math.random()).then(function(response) {
$scope.vagues = response.data;
$scope.initialized = true;
console.log($scope.vagues)
});
$scope.next = function() {
};
$scope.trust_html = function(html) {
return $sce.trustAsHtml(html);
}
$scope.select= function(vague_id) {
$scope.vague_id = vague_id;
if ($scope.vague_id != '') {
$window.location.href = "#/booking/form/" + $scope.vague_id;
}
}
});
/**
ctrl.booking.js
*/
app.controller('ctrlBookingForm', function ($window, $rootScope, $scope, $routeParams, $interval, $timeout, $sce, $http, $window) {
$scope.initialized = false;
$scope.timestamp = $window.timestamp;
$scope.booking_timeout = $window.booking_timeout;
console.log($scope.timestamp);
$scope.result_message = '';
$scope.vagues = {};
if (typeof $routeParams.vague_id == 'undefined' || $routeParams.vague_id.trim() == '') {
$window.location.href = "#/";
throw ({})
}
var vague_id = $routeParams.vague_id;
$scope.booking = {
error: undefined,
vague_id: vague_id,
// bkTeam:"Vippo",
runners_count: vague_id == 'relai_par_equipe' ? '2' : '1',
runners: [{
error: '',
title: vague_id != 'course_binome' ? 'Participant 1' : 'Participant adulte',
runName: '',
runFirstname: '',
runBirthday: '',
runGender: '',
runEmail: '',
runPhone: '',
/*
runName: 'Picard',// ,
runFirstname: 'vincent',// ,
runBirthday: '24/12/1967',// ,
runGender: 'F',
runEmail: 'vpicard@animanet.fr',
runPhone: '06.07.23.36.75'
*/
},
{
error: '',
title: vague_id != 'course_binome' ? 'Participant 2' : 'Participant enfant',
},
{
error: '',
title: 'Participant 3'
},
{
error: '',
title: 'Participant 4'
},
{
error: '',
title: 'Participant 5'
}]
}
$scope.runners_error = ['', '', '', '', ''];
$scope.next = function () {
var debug = false;
$scope.result_message = '';
if (debug == false) {
// $('body').addClass('frozen');
}
var params = {
action: 'save',
booking: $scope.booking
}
$http.post('/app/bookings/ajax/booking-ajax.php', params).then(function (response) {
$scope.result_message = response.data.message;
if (response.data.status == 'success' && debug == false) {
$window.location.href = "#/booking/payment/" + response.data.bkId;
} else {
console.log(response.data);
}
});
};
$scope.$watch('booking', function (nv, ov) {
if ($scope.initialized == true) {
console.log(nv)
$scope.booking.error = false
/*
angular.forEach($scope.booking.runners, function(runner, idx) {
$scope.runners_error[idx] = '';
if (idx < parseInt($scope.booking.runners_count)) {
if (typeof runner.runBirthday != 'undefined') {
if (typeof $scope.vagues[$scope.booking.vague_id].validation != 'undefined') {
try {
var exp = $scope.vagues[$scope.booking.vague_id].validation;
var parts = runner.runBirthday.split('/');
var $birthday = parts[2] + '-' + parts[1] + '-' + parts[0];
console.log($birthday, exp, eval(exp));
if (eval(exp) == false) {
$scope.runners_error[idx] = "La date de naissance n'est pas valide pour cette épreuve.";
$scope.booking.error = true;
}
} catch (e) {
console.log(e.message)
}
}
}
} else {
$scope.booking.runners[idx] = {
error: ''
}
}
});
*/
console.log($scope.runners_error);
}
}, true);
$scope.range = function (min, max) {
max = parseInt(max);
var output = [];
for (var i = min; i <= max; i += 1) {
output.push(i);
}
return output;
};
$http.get('/app/bookings/data/vagues.json?v=' + Math.random()).then(function (response) {
$scope.vagues = response.data;
$timeout(function () {
$scope.initialized = true;
$scope.booking.error = false; // pour générer un $watch et valider les données présentes par défaut
$('body').removeClass('frozen');
})
})
});/**
ctrl.home.js
*/
app.controller('ctrlPayment', function($window, $rootScope, $scope, $routeParams, $location, $interval, $timeout, $sce, $http) {
$scope.message = '';
$scope.rules_accepted = false;
$scope.booking = {
bkId: null
}
if (typeof $routeParams.bkId == 'undefined' || $routeParams.bkId.trim() == '') {
$window.location.href = "#/";
throw ({})
}
$scope.bkId = $routeParams.bkId;
$http.get('/app/bookings/ajax/booking-ajax.php?action=payment&bkId=' + $scope.bkId).then(function(response) {
if (response.data.status == 'success') {
$scope.booking = response.data.booking;
} else {
$scope.message = response.data.message;
}
$('body').removeClass('frozen');
});
$scope.trust_html = function(html) {
return $sce.trustAsHtml(html);
}
})/**
ctrl.done.js
url retout paybox :
https://foulees.apeidieppe.fr/#/done?amount=1200&bkId=BK5ca09ed4bb725&auto=XXXXXX&status=00000&transac=14667597&date=31032019&time=13:04:58
https://foulees.apeidieppe.fr/#/done/?amount=1200&bkId=BK5ca09ed4bb725&auto=XXXXXX&status=00000&transac=14667597&date=31032019&time=13:04:58
*/
app.controller('ctrlDone', function($window, $rootScope, $routeParams, $scope) {
if (typeof $routeParams.bkId != 'undefined' && $routeParams.bkId.trim() != '') {
$scope.bkId = $routeParams.bkId
} else {
$window.location.href = "#/";
throw ({
'message': 'no query string'
})
}
});/**
ctrl.home.js
*/
app.controller('ctrlCanceled', function($window, $rootScope, $routeParams, $scope) {
if (typeof $routeParams.bkId != 'undefined' && $routeParams.bkId.trim() != '') {
$scope.bkId = $routeParams.bkId
} else {
$window.location.href = "#/";
throw ({
'message': 'no query string'
})
}
});app.controller('ctrlLists', function($window, $rootScope, $scope, $routeParams, $interval, $timeout, $sce, $http, $window) {
$scope.initialized = false;
$scope.vagues = {}
$scope.vague_id = '';
$http.get('/app/bookings/data/vagues.json?v='+Math.random()).then(function(response) {
$scope.vagues = response.data;
console.log($scope.vagues)
$http.get('/app/bookings/ajax/booking-ajax.php?action=lists').then(function(response) {
console.log(response.data);
$scope.bookings = response.data.bookings;
$scope.initialized = true;
});
});
$scope.is_vp = typeof $window.is_vp != 'undefined' ? $window.is_vp : '';
$scope.trust_html = function(html) {
return $sce.trustAsHtml(html);
}
$scope.select= function(vague_id) {
$scope.vague_id = vague_id;
if ($scope.vague_id != '') {
$window.location.href = "#/booking/form/" + $scope.vague_id;
}
}
});
var cta_contact_dialog = function(data) { // apppel depuis les shortcodes [[CTA::email=user@domain.tld]]
var scope = angular.element('[ng-controller=ctrlContact]').scope();
scope.data.ctTo = data;
scope.data.context = 'contact';
$('#modal-contact').modal({
show: true,
backdrop: 'static',
keyboard: false
});
}
app.requires.push('ngFileUpload');
app.factory('srvContact', ['$http', '$window', '$timeout', function($http, $window, $timeout) {
var obj = {};
obj.send = function(ct) {
console.log(ct);
return $http.post('/app/contacts/ajax/submit.php', {
ct: ct
}).then(function(response) {
return response.data;
});
}
return obj
}]);
app.controller('ctrlContact', function($rootScope, $scope, $window, $timeout, srvContact, Upload) {
$scope.result = {
status: '',
message: '',
}
$scope.uploading = false;
$scope.upload_progress = 0;
$scope.submitted = false;
$scope.data = {};
$scope.submit = function(context, ctTo) {
$scope.data.context = context;
if (typeof ctTo != 'undefined') {
$scope.data.ctTo = ctTo;
}
console.log($scope.data);
$scope.submitted = true;
srvContact.send($scope.data).then(function(data) {
$scope.result = {
status: data.status,
message: data.message,
}
if (data.status == 'success') {
reset_data();
}
});
$timeout(function() {
$scope.submitted = false;
}, 7000);
}
$scope.upload = function(files, invalidFiles) {
if (files && files.length > 0) {
angular.forEach(files, function(file) {
$scope.upload_progress = 0;
$scope.uploading = true;
$scope.upload = Upload.upload({
url: '/app/contacts/ajax/submit.php',
method: 'POST',
file: file
}).progress(function(evt) {
$scope.upload_progress = parseInt(Math.min(100, parseInt(100.0 * evt.loaded / evt.total)));
}).success(function(response, status, headers, config) {
$scope.data.ctAttachment = response.filepath
$scope.uploading = false;
}).error(function(response, status, headers, config) {
try {
$scope.result.status = response.status
$scope.result.message = response.message;
} catch (e) {}
}).xhr(function(xhr) {
$scope.upload.abort = function() {
xhr.abort();
$scope.uploading = false
};
});
})
};
}
$scope.$watch('data', function(nv) {
console.log(nv)
});
$scope.$watch('submitted', function(nv) {
$scope.result = {
status: '',
message: '',
}
});
var reset_data = function() {
$scope.data = angular.extend($scope.data, {
ctSenderName: '',
ctSenderPC: '',
ctSenderEmail: '',
ctSenderCompany: '',
ctSenderPhone1: '',
ctMessageBody: '',
ctAttachment: '',
});
}
reset_data();
$timeout(function() {}, 1000)
});
app.filter('basename', function () {
return function (path) {
console.log('Lola', path);
return path.replace(/\\/g,'/').replace(/.*\//, '');;
};
});