app.controller('StandardsCtrl', function($scope, $http, $routeParams, User, Flight, Hotel, Activity, Upload, $filter, $timeout) { $scope.isCampLoaded = false; $scope.isRoomOptionSelected = false; $scope.carriers = []; $scope.countries = []; $scope.verbergenTonen = []; $scope.selectedHotelOption = {}; $scope.campData = {}; $scope.pageType = 'standards' // Get the training camp data $scope.getTrainingCamp = function(id) { if (id) { var req = { method: 'GET', url: '/training_camp/getWith/' + id, } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { $scope.campData = response.data.data[0]; $scope.campData = $scope.formatCampData(false); if ($scope.campData.iatas && !Array.isArray($scope.campData.iatas)) { try { $scope.campData.iatas = JSON.parse($scope.campData.iatas); } catch (error) { $scope.campData.iatas = [] } } $scope.isCampLoaded = true; } else { // Error swal({ title: 'Foutmelding', text: 'Het trainingskamp kon niet worden geladen', icon: 'error', }); } }); } } $scope.getMonthLabel = function(monthNr){ var Months = ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December', ] return Months[monthNr - 1]; } $scope.formatCampData = function(reverse) { campData = angular.copy($scope.campData); // Format the flight data angular.forEach(campData.flights, function(flight, key) { if (angular.isArray(flight.carrier)) { flight.carrier = {}; } if (reverse) { if (flight && flight['carrier'] != undefined && flight['carrier']['id'] != undefined) { flight['carrier_id'] = flight['carrier']['id']; } } $scope.changeCarrier(flight); Flight.formatData(flight, reverse, $scope); }); // hotel rooms to and from JSON angular.forEach(campData.hotels, function(hotel, key) { if (reverse) { hotel['rooms'] = JSON.stringify(hotel['rooms']); hotel['information_lines'] = JSON.stringify(hotel['information_lines']); } else { if (typeof hotel['rooms'] == 'string'){ try { hotel['rooms'] = JSON.parse(hotel['rooms']); } catch (e) { hotel['rooms'] = []; } } if (hotel['information_lines'] && typeof hotel['information_lines'] == 'string') { try { hotel['information_lines'] = JSON.parse(hotel['information_lines']); } catch (e) { hotel['information_lines'] = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, } } } else { hotel['information_lines'] = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, } } } }); // camp information_lines to and from JSON if (reverse) { campData['information_lines'] = JSON.stringify(campData['information_lines']); } else { if (campData['information_lines'] && typeof campData['information_lines'] == 'string') { try{ campData['information_lines'] = JSON.parse(campData['information_lines']); } catch (e) { campData['information_lines'] = { 'info_header': { 'TRANS': 'Transfers', 'PACKAGE': 'Sportpakket', 'OPTIONAL': 'Optioneel', }, 'info': {}, } } } else { campData['information_lines'] = { 'info_header': { 'TRANS': 'Transfers', 'PACKAGE': 'Sportpakket', 'OPTIONAL': 'Optioneel', }, 'info': {}, } } } // Format the hotel data angular.forEach(campData.hotels, function(hotel) { Hotel.formatData(hotel); }); // Format the activity data angular.forEach(campData.activities, function(activity, key) { Activity.formatData(activity, reverse, $scope); }); if (!reverse) { $timeout(function() { $scope.scheduleActivities = []; $scope.isLoadingScheduleActivities = true; $timeout(function() { $scope.scheduleActivities = $filter('orderBy')(angular.copy(campData.activities), 'day'); delete $scope.isLoadingScheduleActivities; }, 2000); }, 0); } return campData; } $scope.setMatchPanel = function(activity){ return Activity.setMatchPanel(activity, $scope); } $scope.initActivityTable = function() { $scope.activities_table.call("initiate"); } $scope.setActivitiesForSelect = function() { var activities = []; angular.forEach($scope.activities_table.data.rows, function(row) { var activity = {}; angular.forEach($scope.activities_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { activity[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { activity[field.name] = row[field.name]; } }); activities.push(activity); }); Activity.set($scope, activities); } $scope.setMatchesForSelect = function() { var matches = []; angular.forEach($scope.football_matches_table.data.rows, function(row) { var match = {}; angular.forEach($scope.football_matches_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { match[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { match[field.name] = row[field.name]; } }); matches.push(match); }); Activity.setMatches($scope, matches); } // For the flights, hotels, activities: add an option to create a new item $scope.tableReady = function(tableName) { switch (tableName) { case 'Trainingskamp': $scope.training_camps_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; break; case 'Vlucht': //translate table functions $scope.flights_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; var flights = []; angular.forEach($scope.flights_table.data.rows, function(row) { var flight = {}; angular.forEach($scope.flights_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { flight[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { flight[field.name] = row[field.name]; } }); flights.push(flight); }); Flight.set($scope, flights); break; case 'Hotel': $scope.hotels_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; Hotel.set($scope, $scope.hotels_table.data.rows); break; case 'Activiteit': $scope.activities_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; $scope.setActivitiesForSelect(); break; case 'Wedstrijd': $scope.football_matches_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; $scope.setMatchesForSelect(); break; case 'Activiteit types': $scope.activity_types_table.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; var activity_types = []; angular.forEach($scope.activity_types_table.data.rows, function(row) { var activity_type = {}; angular.forEach($scope.activity_types_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { activity_type[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { activity_type[field.name] = row[field.name]; } }); activity_types.push(activity_type); }); break; } } // after change function for the different CRUD tables on the page $scope.afterChange = function(tableName, row, type) { if (tableName == 'Hotel') { var currentRows = angular.copy($scope.hotels_table.data.rows); if (type == 'DELETE') { var searchRowIndex = currentRows.indexOf(row); currentRows.splice(searchRowIndex, 1); } Hotel.set($scope, currentRows); } else if (tableName == 'Vlucht') { var flights = []; var currentRows = angular.copy($scope.flights_table.data.rows); if (type == 'DELETE') { var searchRowIndex = currentRows.indexOf(row); currentRows.splice(searchRowIndex, 1); } angular.forEach(currentRows, function(row) { var flight = {}; angular.forEach($scope.flights_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { flight[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { flight[field.name] = row[field.name]; } }); flights.push(flight); }); Flight.set($scope, flights); } else if (tableName == 'Verblijf') { //reload hotels scope $scope.hotels = []; var req = { method: 'GET', url: '/hotel/getWithLabel', } $http(req).then(function(response) { if (response.status && response.data.status) { // Set the flight details to show $scope.hotels = response.data.data; } else { swal('Foutmelding', 'De accommodaties konden niet worden opgehaald', 'error'); } }, function(error) { swal('Foutmelding', 'De accommodaties konden niet worden opgehaald, gelieve contact op te nemen met SBA', 'error'); }); } else if (tableName == 'Activiteit') { var activities = []; var currentRows = angular.copy($scope.activities_table.data.rows); if (type == 'DELETE') { var searchRowIndex = currentRows.indexOf(row); currentRows.splice(searchRowIndex, 1); } angular.forEach(currentRows, function(row) { var activity = {}; angular.forEach($scope.activities_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { activity[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { activity[field.name] = row[field.name]; } }); activities.push(activity); }); Activity.set($scope, activities); } else if (tableName == 'Wedstrijd') { var matches = []; var currentRows = angular.copy($scope.football_matches_table.data.rows); if (type == 'DELETE') { var searchRowIndex = currentRows.indexOf(row); currentRows.splice(searchRowIndex, 1); } angular.forEach(currentRows, function(row) { var match = {}; angular.forEach($scope.football_matches_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { match[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { match[field.name] = row[field.name]; } }); matches.push(match); }); Activity.setMatches($scope, matches); } else if (tableName == 'Activiteit type') { var activity_types = []; var currentRows = angular.copy($scope.activity_types_table.data.rows); angular.forEach(currentRows, function(row) { var match = {}; angular.forEach($scope.activity_types_table.data.originalFields, function(field) { if (row['original_' + field.name] != undefined) { activity_type[field.name] = row['original_' + field.name]; } else if (row[field.name] != undefined) { activity_typ[field.name] = row[field.name]; } }); activity_types.push(activity_type); }); Activity_types.set($scope, activity_types); } } $scope.showCampPage = false; $scope.createCamp = function(btn, row, blnSubmit) { $scope.isCampLoaded = false; $scope.showCampPage = true; $scope.resetCampVariables(); // Get the training camp data $scope.getAirports(); $scope.getCarriers(); $scope.getHotels(); $scope.isCampLoaded = true; } $scope.hideCampPage = function() { $scope.showCampPage = false; } $scope.updateCamp = function(btn, row, blnSubmit) { $scope.isCampLoaded = false; $scope.showCampPage = true; $scope.resetCampVariables(); // Get the training camp data $scope.getAirports(); $scope.getCarriers(); $scope.getHotels(); $scope.getTrainingCamp(row.id); } $scope.backCampPage = function() { delete $scope.showCampPage; delete $scope.campData; } $scope.getAirports = function() { if ($scope.airports && $scope.airports.length) { return; } $scope.airports = []; var req = { method: 'GET', url: '/airport/getForSelect', } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.airports = response.data.data; } else { swal('Foutmelding', 'De vliegvelden c.q. IATA codes konden niet worden opgehaald', 'error'); } }, function(error) { swal('Foutmelding', 'De vliegvelden c.q. IATA codes konden niet worden opgehaald, gelieve contact op te nemen met SBA', 'error'); }); } $scope.getCarriers = function() { if ($scope.carriers && $scope.carriers.length) { return; } $scope.carriers = []; var req = { method: 'GET', url: '/carrier/getAll', } $http(req).then(function(response) { if (response.status && response.data.status) { // Set the flight details to show $scope.carriers = response.data.data; } else { swal('Foutmelding', 'De vluchtmaatschappijen konden niet worden opgehaald', 'error'); } }, function(error) { swal('Foutmelding', 'De vluchtmaatschappijen konden niet worden opgehaald, gelieve contact op te nemen met SBA', 'error'); }); } $scope.getHotels = function(force = false) { if ($scope.hotels && $scope.hotels.length && !force) { return; } $scope.hotels = []; var req = { method: 'GET', url: '/hotel/getWithLabel', } $http(req).then(function(response) { if (response.status && response.data.status) { // Set the flight details to show $scope.hotels = response.data.data; } else { swal('Foutmelding', 'De accommodaties konden niet worden opgehaald', 'error'); } }, function(error) { swal('Foutmelding', 'De accommodaties konden niet worden opgehaald, gelieve contact op te nemen met SBA', 'error'); }); } // Set the training camp CRUD table $scope.training_camps_table = { name: 'Trainingskamp', controller: 'training_camp', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, subQueries: { user: { lfield: 'user_id', ffield: 'id', controller: 'user', }, country: { lfield: 'country_id', ffield: 'id', controller: 'country', }, }, fieldDetails: { id: { label: '#', hideEdit: true, }, user_id: { label: 'Gebruiker', changeTo: 'user.name', hideEdit: true, }, country_id: { label: 'Land', changeTo: 'country.dutch_name', }, description: { label: 'Beschrijving', hideList: true, }, exclusive: { label: 'Exclusief', hideList: true, }, exclusive_extension: { label: 'Exclusief uitbreiding', hideList: true, }, name: { label: 'Naam', }, location: { label: 'Locatie', }, information_lines: { label: 'Informatie regels', hideList: true, }, has_flights: { label: 'Bevat vluchten', hideList: true, }, has_hotels: { label: 'Bevat hotels', hideList: true, }, has_tourist_tax: { label: 'Bevat Toeristenbelasting', hideList: true, }, transfers: { label: 'Transfers', hideList: true, }, iatas: { label: 'Iatas', hideList: true, hideEdit: true, } }, buttons: { C: { id: 'c', name: 'Trainingskamp toevoegen', label: 'Trainingskamp toevoegen', cancelName: 'Annuleer', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', parentScope: true, action: 'createCamp', }, R: { id: 'r', name: 'Bekijk trainingskamp', label: 'Bekijk', cancelName: 'Annuleer', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: false, action: 'read', }, U: { id: 'u', name: 'Wijzig trainingskamp', label: 'Open', cancelName: 'Annuleer', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', parentScope: true, action: 'updateCamp', }, D: { id: 'd', name: 'Verwijder trainingskamp', label: 'Verwijder', cancelName: 'Annuleer', confirmName: 'Verwijderen', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', } } } // Set the flights CRUD table $scope.flights_table = { name: 'Vlucht', controller: 'flight', // Panel class panelClass: 'panel-trainingskampen', showFilters: false, pageLimit: 10, subQueries: { carrier: { lfield: 'carrier_id', ffield: 'id', controller: 'carrier', }, from_airport: { lfield: 'from', ffield: 'iata', controller: 'airport', function: 'getForSelect', }, to_airport: { lfield: 'to', ffield: 'iata', controller: 'airport', function: 'getForSelect', }, }, fieldDetails: { id: { label: '#', hideEdit: true, }, carrier_id: { label: 'Maatschappij', changeTo: ['carrier.id', ' - ', 'carrier.name'], // autoChangeTo: , required: true, }, flight_number: { label: 'Vluchtnummer', required: true, }, from: { label: 'Van', required: true, type: 'combobox', changeTo: ['from_airport.iata', ' - ', 'from_airport.name'], }, to: { label: 'Naar', required: true, type: 'combobox', changeTo: ['to_airport.iata', ' - ', 'to_airport.name'], }, departure_date: { label: 'Vertrek', //hideList: true, required: true, 'label': 'VertrekDatum', }, arrival_date: { label: 'Aankomst', hideList: true, required: true, }, sent: { hideList: true, hideEdit: true, }, revision: { label: 'Versienr.', type: 'Number', hideEdit: true, default: '0', }, is_allotment: { label: 'Allotment?', }, allotment: { label: 'Aantal Stoelen', }, price: { label: 'Prijs', currency: '€ ', }, luggage_price: { label: 'Bagagetarief', currency: '€ ', }, filename: { label: 'Bestandsnaam', hideList: true, hideEdit: true, }, }, buttons: { C: { id: 'c', name: 'Vlucht toevoegen', label: 'Vlucht toevoegen', cancelName: 'Annuleer', confirmName: 'Toevoegen', confirmClass: 'success', icon: 'fa-plus-square', header: false, inline: false, action: 'create', }, CC: { id: 'cc', name: 'Vlucht toevoegen', label: 'Vlucht toevoegen', cancelName: 'Annuleer', confirmName: 'Toevoegen', confirmClass: 'success', icon: 'fa-plus-square', header: true, inline: false, header: true, action: 'addNewFlight', parentScope: true, }, R: { id: 'r', name: 'Bekijk', label: 'Bekijk', cancelName: 'Annuleer', confirmName: 'Select', confirmClass: 'info', icon: 'fa-eye', inline: true, action: 'read', }, U: { id: 'u', name: 'Update', label: 'Bewerk', cancelName: 'Annuleer', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', name: 'Verwijderen', label: 'Verwijderen', cancelName: 'Annuleer', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', } } } $scope.sbaCrudTableChange = function(tableName, fieldName, fieldValue, eventType){ if (tableName.toLowerCase() == 'vlucht') { switch(fieldName){ case 'is_allotment': if (fieldValue) { $scope.flights_table.fieldDetails['allotment'].hideEdit = false; $scope.flights_table.fieldDetails['price'].hideEdit = false; } else { $scope.flights_table.fieldDetails['allotment'].hideEdit = true; $scope.flights_table.fieldDetails['price'].hideEdit = true; } break; } } else if (tableName.toLowerCase() == 'activiteit') { switch(fieldName){ case 'activity_type_id': if (fieldValue.label !== undefined && fieldValue.label.toString().toLowerCase() == '5 - wedstrijd') { $scope.activities_table.fieldDetails['football_match_id'].hideEdit = false; } else { $scope.activities_table.fieldDetails['football_match_id'].hideEdit = true; } break; } } } /* Insert function flight */ $scope.addNewFlight = function() { // set hidden fields $scope.flights_table.fieldDetails['allotment'].hideEdit = true; $scope.flights_table.fieldDetails['price'].hideEdit = true; row = {}; btn = $scope.flights_table.buttons['C']; $scope.flights_table.toggleButton(btn, row); } /* -----[START Hotel] ----- */ // Set the hotels CRUD table $scope.hotels_table = { name: 'Verblijf', controller: 'hotel', label: 'Verblijf', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, subQueries: { country: { lfield: 'country_id', ffield: 'id', controller: 'country', }, }, fields: [ 'name', 'contactperson', 'phone_number', 'email', 'address', 'postalcode', 'place', 'country_id', 'stars', 'description', /* 'price', 'price_surcharge_single', 'price_surcharge_single_sales', */ 'price_laundry_service', // default room 'price_per_person_per_night', 'price_per_person_per_night_sales', 'room_name', 'service_level', 'room_amount_of_singles', 'room_amount_of_doubles', ], fieldDetails: { id: { label: '#', hideEdit: true, }, country_id: { label: 'Land', changeTo: ['country.id', ' - ', 'country.dutch_name'], required: true, }, name: { label: 'Naam', required: true, }, description: { label: 'Beschrijving', hideList: true, type: 'textarea', }, phone_number: { label: 'Telefoon nummer', }, email: { label: 'Email adres', }, address: { label: 'Adres', }, postalcode: { label: 'Postcode', }, place: { label: 'Plaats', required: true, }, longitude: { label: 'Lengtegraad', hideList: true, hideEdit: true, }, latitude: { label: 'Breedtegraad', hideList: true, hideEdit: true, }, zoom_level: { hideList: true, hideEdit: true, }, contactperson: { label: 'Contactpersoon', }, stars: { label: 'Aantal Sterren', type: 'number', }, images: { label: 'Afbeeldingen', hideList: true, hideEdit: true, }, rooms: { label: 'Kamers', hideList: true, hideEdit: true, }, /* price: { label: 'Prijs p.p.p.n.', currency: '€ ', }, price_surcharge_single: { label: 'Toeslag 1-persoonskamer p.p.p.n.', currency: '€ ', hideList: true, }, price_surcharge_single_sales: { label: 'Toeslag 1-persoonskamer p.p.p.n. verkoop', currency: '€ ', hideList: true, }, */ price_laundry_service: { label: 'Prijs wasbeurt', currency: '€ ', hideList: true, }, // default room price_per_person_per_night: { label: 'Prijs p.p.p.n. inkoop', currency: '€ ', hideList: true, }, price_per_person_per_night_sales: { label: 'Prijs p.p.p.n. verkoop', currency: '€ ', }, room_name: { label: 'Standaardkamer naam', hideList: true, }, service_level: { label: 'Standaardkamer service', hideList: true, type: 'enum', options: [{ id: 'Logies', name:'Logies', },{ id: 'Ontbijt', name:'Ontbijt', },{ id: 'Halfpension', name:'Halfpension', },{ id: 'Volpension', name:'Volpension', },{ id: 'All-inclusive', name:'All-inclusive', }], }, room_amount_of_singles: { label: 'Aantal 1-persoonsbedden in standaardkamer', hideList: true, }, room_amount_of_doubles: { label: 'Aantal 2-persoonsbedden in standaardkamer', hideList: true, }, }, buttons: { C: { id: 'c', name: 'Verblijf toevoegen', label: 'Verblijf toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk verblijf', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: true, action: 'read', }, U: { id: 'u', name: 'Wijzig verbijf', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', inline: false, }, I: { id: 'i', name: 'Afbeelding toevoegen', label: 'Afbeeldingen', cancelName: 'Annuleren', confirmName: 'Afbeelding toevoegen', confirmClass: 'success', inline: true, icon: 'fa-photo', parentScope: true, action: 'showHotelImageUploader', }, L: { id: 'l', name: 'Locatie aangeven', label: 'Locatie', cancelName: 'Annuleer', confirmName: 'Locatie aangeven', confirmClass: 'success', inline: true, icon: 'fa-map-marker', parentScope: true, action: 'showHotelLocationPicker', }, K: { id: 'k', name: 'Kamer Opties', label: 'Kamers', cancelName: 'Annuleer', confirmName: 'Kameropties', confirmClass: 'success', inline: true, icon: 'fa-bed', label: 'Kamer Opties', parentScope: true, action: 'showRoomOptions', }, In: { id: 'in', name: 'Informatie regels', label: 'Informatie Regels', inline: true, icon: 'fa-info', parentScope: true, action: 'showInformationOptions', }, DE: { id: 'de', name: 'Verwijder verblijf', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } } $scope.hotel_rooms_table = { name: 'Kamer Opties', controller: 'hotel_room', function: 'getByHotel/0', // default hotel with id 0 label: 'Kamer Opties', // Panel class panelClass: 'panel-trainingskampen', showFilters: false, pageLimit: 10, showRowCount: true, autoChangeTo: ['hotel_id'], fieldDetails: { id: { hideEdit: true, hideList: true, }, hotel_id: { label: 'Hotel', default: 0, hideList: true, hideEdit: true, disabled: true, }, // default room price_surcharge: { label: 'Toeslag inkoop', currency: '€ ', }, price_surcharge_sales: { label: 'Toeslag verkoop', currency: '€ ', }, price_surcharge_per: { label: 'Toeslag per', type: 'enum', options: [ { name: 'Persoon', value: 'PERSON', id: 'PERSON', }, { name: 'Kamer', value: 'ROOM', id: 'ROOM', } ] }, service_level: { label: 'Service', type: 'enum', options: [{ id: 'Logies', name:'Logies', },{ id: 'Ontbijt', name:'Ontbijt', },{ id: 'Halfpension', name:'Halfpension', },{ id: 'Volpension', name:'Volpension', },{ id: 'All-inclusive', name:'All-inclusive', }], }, name: { label: 'Kamernaam', }, amount_of_singles: { label: 'Aantal 1-persoonsbedden', }, amount_of_doubles: { label: 'Aantal 2-persoonsbedden', }, } }; /* -----[END Hotel] ----- */ // Set the activities CRUD table $scope.activities_table = { name: 'Activiteit', controller: 'activity', // Panel class panelClass: 'panel-trainingskampen', showFilters: false, pageLimit: 10, subQueries: { country: { lfield: 'country_id', ffield: 'id', controller: 'country', }, activity: { lfield: 'activity_type_id', ffield: 'id', controller: 'activity_type', }, football_match: { lfield: 'football_match_id', ffield: 'id', controller: 'football_match', }, }, fields: [ 'name', 'activity_type_id', 'description', 'phone_number', 'from', 'till', 'football_match_id', 'contactperson', 'address', 'postalcode', 'place', 'country_id', 'terms_and_conditions', 'price', 'price_sales', 'pay_per_camp', 'hide_from_scenario', 'show_on_quotation', ], fieldDetails: { id: { label: '#', hideEdit: true, }, activity_type_id: { label: 'Type', changeTo: ['activity.id', ' - ', 'activity.name'], }, country_id: { label: 'Land', changeTo: ['country.id', ' - ', 'country.dutch_name'], }, football_match_id: { label: 'Wedstrijd', changeTo: ['football_match.id', ' - ', 'football_match.club'], }, phone_number: { label: 'Telefoon nummer', hideList: true, }, name: { label: 'Naam', required: true, }, address: { label: 'Adres', }, postalcode: { label: 'Postcode', }, place: { label: 'Plaats', }, contactperson: { label: 'Contactpersoon', }, from: { label: 'Van', }, till: { label: 'Tot', }, description: { label: 'Beschrijving', }, terms_and_conditions: { label: 'Voorwaarden', }, pay_per_camp:{ label: 'Betaal eenmalig', }, hide_from_scenario:{ label: 'Verberg van draaiboek', }, price: { label: 'Prijs p.p.', currency: '€ ', }, price_sales: { label: 'Verkoopprijs p.p.', currency: '€ ', }, images: { label: 'Afbeeldingen', hideList: true, hideEdit: true, }, show_on_quotation: { label: 'Toon op offerte', }, }, buttons: { C: { id: 'c', name: 'Activiteit toevoegen', label: 'Activiteit toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk activiteit', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: true, action: 'read', }, U: { id: 'u', name: 'Wijzig activiteit', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', inline: false, }, I: { id: 'i', name: 'Afbeelding toevoegen', label: 'Afbeeldingen', cancelName: 'Annuleren', confirmName: 'Afbeelding toevoegen', confirmClass: 'warning', inline: true, icon: 'fa-photo', parentScope: true, action: 'showActivityImageUploader', }, DE: { id: 'de', name: 'Verwijder activiteit', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } } // Set the football_matches CRUD table $scope.football_matches_table = { name: 'Wedstrijd', controller: 'football_match', // Panel class panelClass: 'panel-trainingskampen', showFilters: false, pageLimit: 10, fieldDetails: { id: { label: '#', hideEdit: true, }, club: { label: 'Clubnaam', }, field: { label: 'Veld', }, stadium: { label: 'Stadion', }, referee: { label: 'Referentie', }, images: { label: 'Afbeeldingen', hideList: true, hideEdit: true, }, }, buttons: { C: { id: 'c', name: 'Wedstrijd toevoegen', label: 'Wedstrijd toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk wedstrijd', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: true, action: 'read', }, U: { id: 'u', name: 'Wijzig wedstrijd', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', inline: false, }, I: { id: 'i', name: 'Afbeelding toevoegen', label: 'Afbeelding', cancelName: 'Annuleren', confirmName: 'Afbeelding toevoegen', confirmClass: 'warning', inline: true, icon: 'fa-photo', parentScope: true, action: 'showMatchImageUploader', }, DE: { id: 'de', name: 'Verwijder wedstrijd', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } } // Set the activity_type CRUD table $scope.activity_types_table = { name: 'Activiteit types', controller: 'Activity_type', // Panel class panelClass: 'panel-trainingskampen', showFilters: false, pageLimit: 10, fieldDetails: { id: { hideList: true, hideEdit: true, }, name: { label: 'Type', } }, buttons: { C: { id: 'c', name: 'Activiteit type toevoegen', label: 'Activiteit type toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', inline: false, }, U: { id: 'u', name: 'Wijzig activiteit type', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', inline: false, }, } } // Set the Standard text table $scope.standard_text_table = { name: 'Draaiboek teksten', controller: 'scenario_information_default', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, fieldDetails: { id: { hideList: true, hideEdit: true, }, name: { label: 'naam', }, title: { label: 'titel', }, description: { label: 'beschrijving', hideList: true, }, is_homeland: { label: 'binnenlands', }, is_foreign: { label: 'buitenlands', } }, buttons: { C: { id: 'c', name: 'Draaiboek tekst toevoegen', label: 'Draaiboek tekst toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk draaiboek tekst', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: true, action: 'read', }, U: { id: 'u', name: 'Wijzig draaiboek tekst', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', inline: false, }, } } // Set the Quotation text table $scope.quotation_text_table = { name: 'Offerte teksten', controller: 'standard_text', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, fieldDetails: { id: { hideList: true, hideEdit: true, }, name: { hideList: true, hideEdit: true, }, tag: { label: 'tag', type: 'enum', options: [{id:'TRANS', name: 'Transfer'}, {id:'MEALS', name: 'Maaltijden'}, {id: 'FACILITIES', name: 'Faciliteiten'}, {id: 'PACKAGE', name: 'Sportpakket'}, {id: 'OPTIONAL', name: 'Optioneel'}], }, text: { label: 'tekst', }, }, buttons: { C: { id: 'c', name: 'Standaard offerte tekst toevoegen', label: 'Standaard tekst toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk offerte tekst', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: false, action: 'read', }, U: { id: 'u', name: 'Wijzig offerte tekst', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', name: 'Verwijder offerte tekst', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } } // carrier texts $scope.standard_carrier_text_table = { name: 'Maatschappij teksten', controller: 'standard_carrier_text', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, showRowCount: true, subQueries: { carrier: { lfield: 'carrier_id', ffield: 'id', controller: 'carrier', }, standard_carrier_text_type: { lfield: 'standard_carrier_text_type_id', ffield: 'id', controller: 'standard_carrier_text_type', } }, fieldDetails: { id: { hideList: true, hideEdit: true, }, carrier_id: { label: 'Maatschappij', changeTo: 'carrier.name', required: true, }, standard_carrier_text_type_id: { label: 'Type', changeTo: 'standard_carrier_text_type.name', required: true, }, text: { label: 'Tekst', required: true, }, }, buttons: { C: { id: 'c', name: 'Maatschappij tekst toevoegen', label: 'Maatschappij tekst toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk maatschappij tekst', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: false, action: 'read', }, U: { id: 'u', name: 'Wijzig maatschappij tekst', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', name: 'Verwijder maatschappij tekst', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } }; // default texts $scope.default_text_table = { name: 'Overige standaard teksten', controller: 'default_text', // Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, showRowCount: true, fieldDetails: { id: { hideList: true, hideEdit: true, }, name: { label: 'Naam', hideEdit: true, }, title: { label: 'Titel', }, description: { label: 'Beschrijving', type: 'textarea', }, }, buttons: { C: { id: 'c', name: 'Standaard tekst toevoegen', label: 'Standaard tekst toevoegen', cancelName: 'Annuleren', confirmName: 'Toevoegen', confirmClass: 'success', header: true, inline: false, icon: 'fa-plus-square', action: 'create', }, R: { id: 'r', name: 'Bekijk standaard tekst', label: 'Bekijk', cancelName: 'Annuleren', confirmName: 'Bekijk', confirmClass: 'info', icon: 'fa-eye', inline: false, action: 'read', }, U: { id: 'u', name: 'Wijzig standaard tekst', label: 'Wijzig', cancelName: 'Annuleren', confirmName: 'Wijzig', confirmClass: 'success', inline: true, icon: 'fa-pencil', action: 'update', }, D: { id: 'd', name: 'Verwijder standaard tekst', label: 'Verwijder', cancelName: 'Annuleren', confirmName: 'Verwijder', confirmClass: 'warning', inline: true, icon: 'fa-trash', action: 'delete', }, } }; $scope.resetCampVariables = function() { $scope.scheduleActivities = []; // The selected options $scope.campData = { flights: [], hotels: [], transports: [], activities: [], numOfDays: 1, exclusive: ($scope.defaultTexts['OFFERTE-EXCLUSIEF'] !== undefined ? $scope.defaultTexts['OFFERTE-EXCLUSIEF']['description'] : ''), }; } $scope.onChangeCountry = function(countryId) { if (countryId == 166 || countryId == 20 || countryId == 57) { $scope.campData['exclusive'] =($scope.defaultTexts['OFFERTE-EXCLUSIEF-NEDERLAND'] !== undefined ? $scope.defaultTexts['OFFERTE-EXCLUSIEF-NEDERLAND']['description'] : ''); } else { $scope.campData['exclusive'] = ($scope.defaultTexts['OFFERTE-EXCLUSIEF'] !== undefined ? $scope.defaultTexts['OFFERTE-EXCLUSIEF']['description'] : ''); } } $scope.showHotelLocationPicker = function(btn, row, blnSubmit, model = 'hotel') { $scope.selectedHotelOption = row; if ($scope.createMap(row, model)) { $scope.showGoogleMap = true; $('#hotelLocationModal').modal('show'); } } // Room options $scope.showRoomOptions = function(btn, row, blnSubmit) { $scope.selectedHotelOption = row; // set filter $scope.hotels_table.updatePredefinedFilters('id', row['id']); $scope.hotel_rooms_table.function = 'getByHotel/' + row['id']; $scope.hotel_rooms_table.fieldDetails.hotel_id.default = row['id']; $scope.hotel_rooms_table.call('initiate'); $scope.isRoomOptionSelected = true; } $scope.hotelInformationHeaders = [{tag: 'MEALS', name: 'Maaltijden'}, {tag: 'FACILITIES', name: 'Faciliteiten'}]; $scope.informationHeaders = [{tag: 'TRANS', name: 'Transfers'}, {tag: 'PACKAGE', name: 'Sportpakket'}, {tag: 'OPTIONAL', name: 'Optioneel'}]; $scope.showInformationOptions = function(btn, row, blnSubmit) { $scope.selectedHotelOption = row; if ($scope.selectedHotelOption.information_lines && typeof $scope.selectedHotelOption.information_lines == 'string') { try{ $scope.selectedHotelOption.information_lines = JSON.parse($scope.selectedHotelOption.information_lines); } catch (e) { $scope.selectedHotelOption.information_lines = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, }; } } else { $scope.selectedHotelOption.information_lines = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, }; } $('#hotelInformationModal').modal('show'); } $scope.standardTexts = []; $scope.getStandardTexts = function() { // Get standard texts var req = { method: 'GET', url: '/standard_text/get/', } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK $scope.standardTexts = response.data.data; } else { // Error alertify.warning('De standaard teksten konden niet worden opgehaald'); } }); } $scope.newInformationLine = {}; $scope.filterStandardTexts = function(header) { if ($scope.standardTexts && header){ let standardTextLines = $scope.standardTexts.filter(function(text) { return text.tag == header.tag }); return standardTextLines; } } $scope.addNewInformationLine = function(header, value) { if (value['info'] === undefined) { value['info'] = {}; } if (value['info'][header] === undefined) { value['info'][header] = []; } value['info'][header].push($scope.newInformationLine[header]); $scope.newInformationLine[header] = ''; } $scope.saveInformationLines = function() { // Update the hotel information lines var req = { method: 'POST', url: '/hotel/update/' + $scope.selectedHotelOption.id, data: { information_lines: JSON.stringify($scope.selectedHotelOption.information_lines), } } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK $scope.selectedHotelOption.information_lines = response.data.data.information_lines; alertify.success('De informatie regels van het hotel is succesvol opgeslagen'); } else { // Error alertify.warning('De informatie regels van het hotel kon niet succesvol worden opgeslagen'); } }); } $scope.saveHotelLocation = function(model) { // Update the hotel location var req = { method: 'POST', url: '/' + model + '/update/' + $scope.selectedHotelOption.id, data: { latitude: $scope.selectedHotelOption.latitude, longitude: $scope.selectedHotelOption.longitude, zoom_level: $scope.selectedHotelOption.zoom_level, } } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK alertify.success('De locatie van het hotel is succesvol opgeslagen'); } else { // Error alertify.warning('De locatie van het hotel kon niet succesvol worden opgeslagen'); } }); } /** * Functions for the image modal */ $scope.showImageModal = function (model, id, item = []) { $scope.$broadcast('showImageModal', { model: model, id: id, item: item, }); } $scope.showHotelImageUploader = function(btn, row, blnSubmit) { $scope.showImageModal('hotels', row.id, row); } $scope.showActivityImageUploader = function(btn, row, blnSubmit) { $scope.showImageModal('activities', row.id, row); } $scope.showMatchImageUploader = function(btn, row, blnSubmit) { $scope.showImageModal('football_matches', row.id, row); } $scope.showCampHotelImageUploader = function(item, key) { if (item.id == undefined) { // Save the camp, without giving feedback on success $scope.save('showCampHotelImageModal', item.id, key); } else { $scope.showImageModal('training_camp_hotels', item.id); } } $scope.showCampHotelImageModal = function(itemId, key) { if (itemId == undefined) { itemId = $scope.campData.hotels[key].id; } $scope.showImageModal('training_camp_hotels', itemId); } $scope.showCampActivityImageUploader = function(item, key) { if (item.id == undefined) { // Save the camp, without giving feedback on success $scope.save('showCampActivityImageModal', item.id, key); } else { $scope.showImageModal('training_camp_activities', item.id); } } $scope.showCampActivityImageModal = function(itemId, key) { if (itemId == undefined) { itemId = $scope.campData.activities[key].id; } $scope.showImageModal('training_camp_activities', itemId); } $scope.showCampMatchImageUploader = function(item, key) { if (item) { if (item.id == undefined) { // Save the camp, without giving feedback on success $scope.save('showCampMatchImageModal', item.id, key); } else { $scope.showImageModal('training_camp_football_matches', item.id); } } else { swal('Let op!', 'Voer wedstrijdgegevens in.', 'warning') } } $scope.showCampMatchImageModal = function(itemId, key) { if (itemId == undefined) { itemId = $scope.campData.activities[key].football_match.id; } $scope.showImageModal('training_camp_football_matches', itemId); } /** * Function to initiate Google Maps */ $scope.createMap = function(hotelOption, model) { if (!hotelOption) { swal('Foutmelding', 'De kaart kan niet weergegeven worden omdat er geen hotel is geselecteerd.', 'danger'); return false; } // Get lat and long from the hotel if (hotelOption.latitude != undefined && !isNaN(parseFloat(hotelOption.latitude)) && hotelOption.longitude != undefined && !isNaN(parseFloat(hotelOption.longitude))) { // Set lat en long from hotel var LatLng = {lat: parseFloat(hotelOption.latitude), lng: parseFloat(hotelOption.longitude)}; setMarker = true; } else { //if undefined set Amsterdam lat en long var LatLng = {lat: 52.3545653, lng: 4.7585435}; setMarker = false; } // Get the zoom level var zoomLevel = parseInt(hotelOption.zoom_level); if (!zoomLevel || isNaN(zoomLevel)) { zoomLevel = 4; } // Init map mapId = 'hotelMap' if (mapElement = document.getElementById(mapId)) { var map = new google.maps.Map(mapElement, { zoom: zoomLevel, center: LatLng }); if (setMarker) { $scope.marker = new google.maps.Marker({ position: LatLng, map: map, title: "Hotel" }); } else { $scope.marker = null } // Create the search box and link it to the UI element. //autocomplete already inited? if ($scope.standardsMapsInit !== undefined && document.getElementById('pac-card') === null) { document.body.appendChild($scope.standardsMapsInit); } var card = document.getElementById('pac-card'); //save pac-card $scope.standardsMapsInit = card; var input = document.getElementById('pac-input'); var infowindowContent = document.getElementById('infowindow-content'); map.controls[google.maps.ControlPosition.LEFT_TOP].push(card); var autocomplete = new google.maps.places.Autocomplete(input); var infowindow = new google.maps.InfoWindow(); infowindow.setContent(infowindowContent); autocomplete.addListener('place_changed',function() { document.getElementById("location-error").style.display = 'none'; infowindow.close(); var place = autocomplete.getPlace(); if (!place.geometry) { document.getElementById("location-error").style.display = 'inline-block'; document.getElementById("location-error").innerHTML = "Cannot Locate '" + input.value + "' on map"; return; } map.fitBounds(place.geometry.viewport); if ($scope.marker != null) { $scope.marker.setPosition(place.geometry.location); $scope.marker.setVisible(true); } else { $scope.marker = new google.maps.Marker({ position: place.geometry.location, map: map, title: "Hotel" }); } //save after search hotelOption.latitude = place.geometry.location.lat(); hotelOption.longitude = place.geometry.location.lng(); hotelOption.zoom_level = 17; if (hotelOption.id != undefined && angular.isNumber(parseInt(hotelOption.id))) { $scope.saveHotelLocation(model); } }); google.maps.event.addListener(map, 'click', function( event ){ var LatLng = new google.maps.LatLng(event.latLng.lat(), event.latLng.lng()); if ($scope.marker) { // Replace the current marker $scope.marker.setPosition(LatLng); } else { // Place a new marker $scope.marker = new google.maps.Marker({ position: LatLng, map: map, title: "Hotel" }); } hotelOption.latitude = event.latLng.lat(); hotelOption.longitude = event.latLng.lng(); hotelOption.zoom_level = map.getZoom(); if (hotelOption.id != undefined && angular.isNumber(parseInt(hotelOption.id))) { $scope.saveHotelLocation(model); } }); } else { console.error('Google map element ' + mapId + ' is not found.') } return true; } // Add a flight $scope.addFlight = function(newItem) { // set carrier id in right field for general view, and set the bagage texts for the carrier if (newItem && newItem['carrier_id'] != undefined && newItem['carrier_id']) { newItem['carrier'] = { 'id': newItem['carrier_id'], } $scope.changeCarrier(newItem); } Flight.add($scope, $scope.campData, newItem); } // Delete a flight $scope.deleteFlight = function(key) { if ((id = $scope.campData.flights[key].id) != undefined) { if ($scope.campData.deletedFlights == undefined) { $scope.campData.deletedFlights = []; } $scope.campData.deletedFlights.push(id); } $scope.campData.flights.splice(key, 1); } //Add an iata $scope.addIata = function(newIata) { if (!$scope.campData['iatas'] || !Array.isArray($scope.campData['iatas'])) { $scope.campData['iatas'] = []; } if (newIata !== null) { $scope.campData['iatas'].push(newIata); } } //Delete an iata $scope.deleteIata = function(index) { if ($scope.campData['iatas'] && $scope.campData['iatas'][index]) { $scope.campData['iatas'].splice(index, 1); } } // Add a hotel $scope.addHotel = function(newItem) { if (!newItem){ newItem = {}; } if (newItem['information_lines'] && typeof newItem['information_lines'] == 'string') { try { newItem['information_lines'] = JSON.parse(newItem['information_lines']); } catch (e) { newItem['information_lines'] = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, }; } } else { newItem['information_lines'] = { 'info_header': { 'MEALS': 'Maaltijden', 'FACILITIES': 'Faciliteiten', }, 'info': {}, }; } if (newItem['id'] && !isNaN(newItem['id'])) { newItem['hotel_id'] = newItem['id']; } Hotel.add($scope.campData, newItem); } // Delete a hotel $scope.deleteHotel = function(key) { if ((id = $scope.campData.hotels[key].id) != undefined) { if ($scope.campData.deletedHotels == undefined) { $scope.campData.deletedHotels = []; } $scope.campData.deletedHotels.push(id); } $scope.campData.hotels.splice(key, 1); } // Add an activity $scope.addActivity = function(newItem) { Activity.add($scope, $scope.campData, newItem); $scope.reloadAgenda(); } // Delete an activity $scope.deleteActivity = function(key) { if ((id = $scope.campData.activities[key].id) != undefined) { if ($scope.campData.deletedActivities == undefined) { $scope.campData.deletedActivities = []; } $scope.campData.deletedActivities.push(id); } Activity.delete(key, $scope.campData); $scope.reloadAgenda(); } // Get the countries $scope.getCountries = function() { var req = { method: 'GET', url: '/country/getNames', } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { $scope.countries = response.data.data; } else { // Error swal({ title: 'Foutmelding', text: 'De landen konden niet worden opgehaald', icon: 'error', }); } }); } //Get country by ID $scope.getCountryById = function(id) { if (!isNaN(id)) { var tmpId = parseInt(id); var arrCountries = $filter('filter')($scope.countries, {id: tmpId}); if (arrCountries[0] !== undefined) { return arrCountries[0].name; } else { return ''; } } else { return ''; } } $scope.init = function() { // Get the data, initialize variables $scope.scheduleActivities = []; $scope.getCountries(); Activity.init($scope, $http); // Get the football matches $scope.days = [...Array(21).keys()].slice(1); $scope.resetCampVariables(); // Init the image upload card data $scope.cardModel = {}; $scope.cardSubjectId = {}; $scope.currentImages = {}; $scope.getStandardTexts(); } $scope.init(); // On changing the activity $scope.changeActivity = function(activity) { if (activity && activity.till && (typeof(activity.till) === 'object')) { Activity.formatData(activity, false, $scope) } $scope.reloadAgenda(); } $scope.reloadAgenda = function() { $timeout(function() { $scope.scheduleActivities = []; $scope.isLoadingScheduleActivities = true; $timeout(function() { $scope.scheduleActivities = $filter('orderBy')(angular.copy($scope.campData.activities), 'day'); delete $scope.isLoadingScheduleActivities; }, 2000); }, 0); } $scope.changeActivityMatch = function (activity) { Activity.setMatch($scope, activity); } $scope.changeTitle = function (type, key) { if ($scope.verbergenTonen[type][key] && $scope.verbergenTonen[type][key] == 'Tonen') { $scope.verbergenTonen[type][key] = 'Verbergen'; } else { $scope.verbergenTonen[type][key] = 'Tonen'; } } // Save the values $scope.save = function(confirmFunction = null, confirmValue = null, cVal2 = null) { campData = $scope.formatCampData(true); // Save the general training camp data: name, location, country var req = { method: 'POST', url: '/training_camp/saveCamp', data: campData, } $http(req).then(function(response) { // Success? if (response.status && response.data.status) { // OK, get the IDs of the flights, hotels and activities if (response.data.data.flightIds) { angular.forEach(response.data.data.flightIds, function(id, key) { $scope.campData.flights[key].id = id }) } if (response.data.data.hotelIds) { angular.forEach(response.data.data.hotelIds, function(id, key) { $scope.campData.hotels[key].id = id }) } if (response.data.data.activityIds) { angular.forEach(response.data.data.activityIds, function(id, key) { $scope.campData.activities[key].id = id }) } if (response.data.data.matchIds) { angular.forEach(response.data.data.matchIds, function(id, key) { if ($scope.campData.activities[key].football_match == undefined) { $scope.campData.activities[key].football_match = {}; } $scope.campData.activities[key].football_match.id = id }) } if (response.data.data.campId) { $scope.campData.id = response.data.data.campId; } // Reload the TK CRUD table $scope.training_camps_table.call('initiate'); // Call the confirm function if (confirmFunction && (typeof $scope[confirmFunction] === 'function')) { $scope[confirmFunction](confirmValue, cVal2); } else { swal({ title: 'Opgeslagen', text: 'Het trainingskamp is opgeslagen', icon: 'success', }); } } else { // Error swal({ title: 'Foutmelding', text: response.data.message, icon: 'warning', }); } }, function(error) { swal({ title: 'Niet opgeslagen', text: 'Het trainingskamp kon niet worden opgeslagen', icon: 'error', }); }); } $scope.convertDateObjToJS = function(objDate, reverse, type) { if (!objDate) { return objDate; } if(!reverse){ if (typeof objDate === 'object') { return objDate; } tempTime = objDate.split(/[- :T.]/); switch(type){ case 'date': tempNewTime = new Date(tempTime[0], tempTime[1]-1, tempTime[2], 0, 0, 0); break; case 'time': if(!tempTime[2]){ tempTime[2] = 0; } tempNewTime = new Date(0 ,0, 0, tempTime[0], tempTime[1], 0); break; case 'datetime': tempNewTime = new Date(tempTime[0], tempTime[1]-1, tempTime[2], tempTime[3], tempTime[4], tempTime[5] ? tempTime[5] : 0); break; } return tempNewTime; }else{ if (typeof objDate === 'string') { return objDate; } switch(type){ case 'date': if(typeof objDate.getFullYear !== 'function'){ return null; } return ([objDate.getFullYear(), objDate.getMonth()+1, objDate.getDate()].join('-')); break; case 'time': if(typeof objDate.getHours !== 'function'){ return null; } return ([('00' + objDate.getHours()).slice(-2), ('00' + objDate.getMinutes()).slice(-2)].join(':')); break; case 'datetime': if(typeof objDate.getFullYear !== 'function'){ return null; } return ([objDate.getFullYear(), objDate.getMonth()+1, objDate.getDate()].join('-')+' '+[('00' + objDate.getHours()).slice(-2), ('00' + objDate.getMinutes()).slice(-2)].join(':')); break; default: return objDate; break; } } } }); app.directive('stringToNumber', function() { return { require: 'ngModel', link: function(scope, element, attrs, ngModel) { ngModel.$parsers.push(function(value) { return '' + value; }); ngModel.$formatters.push(function(value) { return parseFloat(value); }); } }; });