Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var map;
- var formShown = false;
- var debtShown = false;
- var loadmap = function (mapId) {
- map = new google.maps.Map(document.getElementById(mapId), {
- center: {lat: 51.13, lng: 3.13},
- scrollwheel: false,
- zoom: 8
- });
- };
- var loadEventMap = function () {
- if (window.location.pathname === "/DebtAware/CEvent.php") {
- console.log('hey');
- loadmap('map1');
- google.maps.event.addListener(map, 'click', function (event) {
- addBar(event.latLng);
- });
- infoWindow = new google.maps.InfoWindow;
- $("#loader").show();
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function (position) {
- var pos = {
- lat: position.coords.latitude,
- lng: position.coords.longitude
- };
- infoWindow.setPosition(pos);
- $("#loader").hide();
- infoWindow.setContent('Location found.');
- infoWindow.open(map);
- map.setCenter(pos);
- }, function () {
- handleLocationError(true, infoWindow, map.getCenter());
- });
- } else {
- handleLocationError(false, infoWindow, map.getCenter());
- }
- }
- };
- var handleLocationError = function (browserHasGeolocation, infoWindow, pos) {
- infoWindow.setPosition(pos);
- $("#loadingtest").html("");
- infoWindow.setContent(browserHasGeolocation ?
- 'Error: The Geolocation service failed.' :
- 'Error: Your browser doesn\'t support geolocation.');
- infoWindow.open(map);
- };
- var startup = function () {
- regCacheApi();
- $('select').material_select();
- $('.button-collapse').sideNav({
- menuWidth: 300, // Default is 300
- edge: 'left', // Choose the horizontal origin
- closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
- draggable: true // Choose whether you can drag to open on touch screens
- });
- $(document).ready(function () {
- $('select').material_select();
- });
- $('.carousel.carousel-slider').carousel({
- fullWidth: true,
- height: 200
- });
- $('#peopleForm').hide();
- $('#addDebt').hide();
- };
- var addPeople = function (e) {
- e.preventDefault();
- var data = {
- name: $('#eventName').val(),
- description: $('#textarea1').val(),
- long: 32,
- lat: 23
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'processEventForm'},
- type: 'post',
- success: function (output) {
- console.log(output);
- }
- });
- window.location.assign('People.php');
- };
- var goToEvent = function () {
- $('#addPeople').slideUp();
- $('#event').slideDown();
- };
- var goToWelcome = function () {
- $('#addPeople').hide();
- $('#event').hide();
- $('#welcome').slideDown();
- };
- var goToAddDebt = function () {
- console.log('jow');
- if (!debtShown){
- $('#event').slideUp();
- $('#addDebt').slideDown();
- debtShown = true;
- } else{
- $('#event').slideDown();
- $('#addDebt').slideUp();
- debtShown = false;
- }
- };
- var addDebt = function (e) {
- e.preventDefault();
- $('#selectedPersonEvent').material_select();
- var id = $('#selectedPersonEvent').val();
- var amount = $('#formAmount').val();
- console.log(id + "+" + amount);
- data = {
- id: id,
- amount: amount
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'processDebt'},
- type: 'post',
- success: function (output) {
- console.log(output);
- }
- });
- window.location.assign('event.php');
- };
- var addPersonForm = function () {
- if (!formShown) {
- $('#peopleForm').slideDown();
- formShown = true;
- } else {
- $('#peopleForm').slideUp();
- formShown = false;
- }
- };
- var addPersonProcessForm = function (e) {
- e.preventDefault();
- $('#selectedPerson').material_select();
- var id = $('#selectedPerson').val();
- data = {
- id: id
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'addPerson'},
- type: 'post',
- success: function (output) {
- console.log(output);
- var newOutput = JSON.parse(output);
- showPersons(newOutput);
- }
- });
- };
- var showPersons = function (output) {
- html = "";
- output.forEach(function (o) {
- html += "<tr><td>" + o.name + "</td><td>" + o.ccnumber + "</td></tr>";
- });
- console.log(html);
- $('#addTableRow').html(html);
- };
- var showHeaderEvent = function () {
- console.log();
- data = {
- eventid: $(this).val()
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'showEvent'},
- type: 'post',
- success: function (output) {
- window.location.assign('event.php');
- }
- });
- };
- var validateRegister = function (e) {
- e.preventDefault();
- data = {
- username: $('#registername').val(),
- email: $('#registeremail').val(),
- password: $('#registerpass').val(),
- rpassword: $('#registerpass2').val(),
- ccnumber: $('#registerccNumber').val()
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'ValidateRegister'},
- type: 'post',
- success: function (output) {
- var errormessage = JSON.parse(output);
- console.log(errormessage);
- if (errormessage[0] == "error") {
- writeErrors(errormessage);
- } else {
- window.location.assign('index.php');
- }
- }
- });
- };
- var validateLogin = function (e) {
- e.preventDefault();
- data = {
- username: $('#loginusername').val(),
- password: $('#loginpassword').val()
- };
- $.ajax({
- url: '/DebtAware/process.php',
- data: {userd: data, action: 'ValidateLogin'},
- type: 'post',
- success: function (output) {
- var errormessage = JSON.parse(output);
- if (errormessage[0] == "error") {
- console.log(output);
- writeErrors(errormessage);
- } else {
- window.location.assign('index.php');
- }
- }
- });
- };
- var writeErrors = function (errors) {
- var html = "<div><i class='large material-icons'>info_outline</i>";
- errors.forEach(function (data) {
- if (data == "error") {
- } else {
- html += "<p>" + data + "</p>";
- }
- });
- $('#errors').html(html);
- };
- var regCacheApi = function () {
- if ('serviceWorker' in navigator) {
- navigator.serviceWorker.register('sw.js')
- .then(r => console.log('sw registered'))
- .catch(console.error);
- }
- };
- (function () {
- loadEventMap();
- startup();
- $('#AddPeople').on('click', addPeople);
- $('.Create').on('click', goToEvent);
- $('#DebtAware').on('click', goToWelcome);
- $('#buttonAddPeople').on('click', addPersonForm);
- $('#addPersonButton').on('click', addPersonProcessForm);
- $('#addDebtLaunchButton').on('click', goToAddDebt);
- $('#addDebtToPerson').on('click', addDebt);
- $('body').on('click', '.headerEvent', showHeaderEvent);
- $('#registerPerson').on('click', validateRegister);
- $('#login').on('click', validateLogin);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement