Created
September 4, 2023 12:29
-
-
Save MohamedGamil/f70bcb7830d4fd890d9c2c17f9df5f9e to your computer and use it in GitHub Desktop.
Fixed "app-quote-new.js" JS file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a quote App | |
* | |
*/ | |
(function() { | |
function QuoteFormController( | |
$rootScope, | |
$scope, | |
$http, | |
$timeout, | |
$window, | |
$animate | |
) { | |
let vm = this; | |
vm.pageLoading = false; | |
vm.submitting = false; | |
vm.stage = 1; | |
vm.totalSteps = 3; | |
vm.workspace = $window.workspace; | |
vm.seeker = $window.user; | |
vm.layouts = $window.layouts; | |
vm.working_days = $window.working_days; | |
vm.operation_hours = $window.operation_hours; | |
vm.step = 0; | |
vm.dayOffset = -1; | |
vm.accommodation = false; | |
vm.progress = 0; | |
$scope.quote_id = 0; | |
$scope.days = []; | |
$scope.moment = moment; | |
$scope.day_data = []; | |
let today = new Date(); | |
today.setHours(0,0,0,0); | |
let tomorrow = new Date(); | |
tomorrow.setHours(0,0,0,0); | |
tomorrow = tomorrow.setDate(today.getDate() + 1); | |
vm.today = moment(today).format('YYYY-MM-DD'); | |
vm.tomorrow = moment(tomorrow).format('YYYY-MM-DD'); | |
vm.quote_id = $window.quote_id; | |
$scope.quote = { | |
quote_id : vm.quote_id, | |
start_date: '', | |
end_date: '', //new Date(tomorrow), | |
// start_date: new Date(tomorrow), | |
// end_date: new Date(tomorrow), | |
address : vm.workspace.front_address ? vm.workspace.front_address : vm.workspace.venue_address, | |
fullname : vm.seeker.first_name + ' ' + vm.seeker.last_name, | |
email : vm.seeker.email, | |
phone : vm.seeker.phone, | |
company : vm.seeker.company, | |
acc_days : 0, | |
proposal_date: '', | |
lat: '', | |
lng: '', | |
budget: '', | |
budget_curr: '', | |
neighborhood: {}, | |
event_type: '', | |
event_description: '', | |
workspace_id: vm.workspace.workspace_id, | |
day:[], | |
acc_day:[], | |
start_dates:[], | |
end_dates:[], | |
m_dates:[], | |
}; | |
$scope.acc_days = []; | |
$scope.meeting_days = []; | |
$scope.dates = [{name:'start_dates[]', name:'end_dates[]', name:'remove'}]; | |
$scope.equipments = [ | |
{name: 'screen' , label: 'Projector & Screen', qty: true, image:'projector.jpg'}, | |
{name: 'lcd' , label: 'LCD Screen', qty: true, image:'lcd.jpg'}, | |
{name: 'flipchart' , label: 'Flipchart', qty: true, image: 'flipchart.jpg'}, | |
{name: 'microphone' , label: 'Microphone', qty: true, image: 'mic.jpg'}, | |
{name: 'stat' , label: 'Notepad & Stationary', qty: true, image: 'stationery.jpg'}, | |
{name: 'sound_system', label:'Sound System', qty: true, image: 'home-theater-system.png'}, | |
{name: 'wifi', label: 'Wi-Fi', qty: false, image: 'wifi-icon.png'}, | |
]; | |
$scope.lunchTypes = ['Arabic', 'Indian', 'Pakistani', 'Filipino', 'Mediterranean', 'International']; | |
$scope.dinnerTypes = ['Arabic', 'Indian', 'Pakistani', 'Filipino', 'Mediterranean', 'International']; | |
$scope.breakfastItems = ['Breakfast buffet', 'Pastries & other sweet assortments', 'Savory breakfast sandwiches', 'Fruit platter', 'Other']; | |
$scope.teaCoffeeItems = ['Tea & coffee only' , 'Tea & coffee + biscuits & pastries', 'Tea & coffee + biscuits', 'Tea & Coffee + Pastries & fruits' , 'High tea (tea & coffee with biscuits, pastries, light sandwiches)', 'Tea & coffee with other']; | |
$scope.lunchFoodItems = ['Vegetarian Buffet', 'Buffet (includes vegetarian & non-vegetarian dishes)', 'Sandwiches & other light assortments', 'Canapes (finger foods)', 'Kids Menu (finger foods)', 'Other']; | |
$scope.lunchDrinksItems = ['Water & Soft Drinks', 'Water & Juices', 'Water & Alcoholic Beverages', 'Other']; | |
$scope.dinnerFoodItems = ['Vegetarian Buffet', 'Buffet (includes vegetarian & non-vegetarian dishes)', 'Sandwiches & other light assortments', 'Canapes (finger foods)', 'Kids Menu (finger foods)', 'Other']; | |
$scope.dinnerDrinksItems = ['Water & Soft Drinks', 'Water & Juices', 'Water & Alcoholic Beverages', 'Other']; | |
$scope.currencies = {'AED' : 'AED', 'USD' : 'USD', 'GBP' : 'GBP'}; | |
$scope.startTimes = []; | |
$scope.endTimes = []; | |
// Nav next | |
$scope.next = function () { | |
if ($scope.GetQuoteForm.$valid) { | |
vm.stage++; | |
$window.scrollTo(0, 0); | |
} | |
else{ | |
vm.setFormSubmit($scope.GetQuoteForm); | |
let elem = angular.element("[name='" + $scope.GetQuoteForm.$name + "']").find('.ng-invalid:visible:first'); | |
if(elem.length){ | |
elem.focus(); | |
} | |
} | |
vm.totalSteps = vm.getTotalSteps(); | |
let progress = parseInt(((vm.stage - 1)/vm.totalSteps) * 100); | |
if(progress > vm.progress) | |
vm.progress = progress; | |
// console.log($scope.quote); | |
}; | |
vm.setFormSubmit = function(form){ | |
angular.forEach(form.$error, function (field) { | |
angular.forEach(field, function(errorField){ | |
if(errorField.$name != undefined && ( errorField.$name == 'frmChild' || errorField.$name == 'accForm')){ | |
vm.setFormSubmit(errorField); | |
} | |
else{ | |
errorField.$setTouched(); | |
} | |
}); | |
}); | |
} | |
// Nav back | |
$scope.back = function () { | |
vm.stage--; | |
$window.scrollTo(0, 0); | |
}; | |
$scope.$watch('quote', function(newVal, oldVal){ | |
if(!moment(newVal.start_date).isSame(oldVal.start_date) || !moment(newVal.end_date).isSame(oldVal.end_date)){ | |
vm.calculateMeetingDays(); | |
} | |
if(newVal.acc_from_date && (!moment(newVal.acc_from_date).isSame(oldVal.acc_from_date) || !moment(newVal.acc_to_date).isSame(oldVal.acc_to_date))){ | |
vm.calculateAccomodationDays(); | |
} | |
vm.totalSteps = vm.getTotalSteps(); | |
if(newVal.hdn_days != oldVal.hdn_days && vm.progress > 0) | |
vm.progress = parseInt(((vm.stage)/vm.totalSteps) * 100); | |
}, true); | |
// Returns total number of steps | |
vm.getTotalSteps = function(){ | |
let steps = 3; | |
if(vm.accommodation){ | |
steps = 4; | |
} | |
if($scope.quote.hdn_days > 1){ | |
steps = (steps - 1) + (2 * $scope.quote.hdn_days); | |
} | |
return steps; | |
} | |
// Calculate meeting days | |
vm.calculateMeetingDays = function(){ | |
let start_date = moment($scope.quote.start_date); | |
let end_date = moment($scope.quote.end_date); | |
let days = Math.ceil(moment.duration(end_date.diff(start_date)).asDays() + 1); | |
$scope.quote.hdn_days = days; | |
vm.getMeetingDays(); | |
// console.log(days); | |
// if($scope.quote.day.length > days){ | |
// console.log(vm.objectLength($scope.quote.day)); | |
// let oldDayslength = vm.objectLength($scope.quote.day); | |
// for(let i = days; i < oldDayslength; i++){ | |
// delete $scope.quote.day[i]; | |
// } | |
// } | |
//$scope.quote.day = []; | |
for(let i = 0; i < vm.objectLength($scope.meeting_days); i++){ | |
//$scope.quote.day[i] = {'date': $scope.meeting_days[i] }; | |
$scope.startTimes[i] = vm.startTimes(i); | |
$scope.endTimes[i] = vm.endTimes(i); | |
} | |
} | |
// Calculate accomodation days | |
vm.calculateAccomodationDays = function(){ | |
let start_date = moment($scope.quote.acc_from_date); | |
let end_date = moment($scope.quote.acc_to_date); | |
let days = Math.ceil(moment.duration(end_date.diff(start_date)).asDays() + 1); | |
$scope.quote.acc_days = days; | |
vm.getAccomodationDays(); | |
//$scope.quote.acc_day = []; | |
} | |
vm.getMeetingDays = function(){ | |
let days = []; | |
let start_date = moment($scope.quote.start_date); | |
let end_date = moment($scope.quote.end_date); | |
while(end_date.isSameOrAfter(start_date)){ | |
days.push(moment(start_date).format('MM/DD/YYYY')); | |
start_date = start_date.add( 1 , 'days'); | |
} | |
$scope.meeting_days = days; | |
} | |
vm.getAccomodationDays = function(){ | |
let days = []; | |
let start_date = moment($scope.quote.acc_from_date); | |
let end_date = moment($scope.quote.acc_to_date); | |
if(end_date.isSame(start_date)){ | |
days.push(moment(start_date).format('MM/DD/YYYY')); | |
$scope.acc_days = days; | |
} else { | |
while(end_date.isAfter(start_date)){ | |
days.push(moment(start_date).format('MM/DD/YYYY')); | |
let start_date = start_date.add( 1 , 'days'); | |
} | |
$scope.acc_days = days; | |
} | |
} | |
vm.startTimes = function(dayIndex){ | |
let day = moment($scope.quote.day[dayIndex].date, 'MM/DD/YYYY').format('ddd'); | |
let timeFrame = vm.operation_hours[day] ? vm.operation_hours[day] : { startTime: '07:00:00', endTime : '23:59:59'}; // for hotel type; | |
let startTime = moment(timeFrame.startTime.trim(), "hh:mm A"); | |
let endTime = moment(timeFrame.endTime.trim(), "hh:mm A"); | |
let times = []; | |
while(startTime.isBefore(endTime)){ | |
let value = startTime.format('HH:mm:ss'); | |
let label = startTime.format('hh:mm A'); | |
times.push({value : value , label : label}); | |
startTime = moment(startTime, "hh:mm A").add(30, 'minutes'); | |
} | |
return times; | |
} | |
vm.endTimes = function(dayIndex){ | |
let day = moment($scope.quote.day[dayIndex].date, 'MM/DD/YYYY').format('ddd'); | |
let timeFrame = vm.operation_hours[day] ? vm.operation_hours[day] : { startTime: '07:00:00', endTime : '23:59:59'}; | |
let startTime = moment(timeFrame.startTime.trim(), "hh:mm A"); | |
let endTime = moment(timeFrame.endTime.trim(), "hh:mm A"); | |
let times = []; | |
startTime = moment(startTime, "hh:mm A").add(30, 'minutes'); | |
while(!startTime.isAfter(endTime)){ | |
let value = startTime.format('HH:mm:ss'); | |
let label = startTime.format('hh:mm A'); | |
times.push({value : value , label : label}); | |
startTime = moment(startTime, "hh:mm A").add(30, 'minutes'); | |
} | |
return times; | |
} | |
vm.copyToNextDay = function(currentIndex){ | |
let data = angular.copy($scope.quote.day[currentIndex]); | |
delete data.date; | |
let stageIndex = 3; | |
if(!vm.searchObjectArray('value', data.start_time, $scope.startTimes[currentIndex + 1])){ | |
delete data.start_time; | |
stageIndex = 2; | |
} | |
if(!vm.searchObjectArray('value', data.end_time, $scope.endTimes[currentIndex + 1])){ | |
delete data.end_time; | |
stageIndex = 2; | |
} | |
if(stageIndex == 2) | |
alert('Unable to copy the timings since the workspace have different working time for the day'); | |
$scope.quote.day[currentIndex + 1] = data; | |
vm.stage = ((2 * (currentIndex + 1)) + stageIndex); | |
} | |
vm.teaChanged = function(teaIndex, dayIndex, checked){ | |
if(!checked){ | |
switch(teaIndex){ | |
case 1: | |
$scope.quote.day[dayIndex].chk_tea_coffee_second = false; | |
case 2: | |
$scope.quote.day[dayIndex].chk_tea_coffee_third = false; | |
} | |
} | |
} | |
// submit quote | |
vm.submitQuote = function(valid){ | |
let data = angular.copy($scope.quote); | |
data.workspace_id = vm.workspace.workspace_id; | |
console.info('Submit Quote: ', {data,valid}); | |
if (valid) { | |
/*let data = angular.copy($scope.quote); | |
console.log(data);*/ | |
vm.progress = 100; | |
console.log(data); | |
//vm.submitting = true; | |
notify('saving', 'Submitting...'); | |
$http({ | |
method: 'POST', | |
url: '/admin/admin/save-edit-quote', | |
data: data, | |
}).then(function successCallback(response) { | |
console.log('response', response); | |
if(response.data.status == 'success'){ | |
removeNotify(); | |
$window.submitted = true; | |
$window.location.href = $window.successPage; | |
} else{ | |
vm.submitting = false; | |
notify('error' , 'An error occurred'); | |
} | |
}, function errorCallback(response) { | |
console.log('error', response); | |
notify('error' , 'An error occurred!'); | |
vm.submitting = false; | |
}); | |
} else { | |
notify('error' , 'Error!!'); | |
console.log($scope.quote); | |
} | |
} | |
/*$scope.unCheckFoodType = function(index){ | |
delete index.rdo_food_type; | |
}*/ | |
$scope.unCheckBreakFast = function(index){ | |
delete index.rdo_breakfast; | |
} | |
$scope.unCheckTeaCofee = function(index){ | |
delete index.rdo_tea_coffee; | |
} | |
$scope.unCheckTeaSecond = function(index){ | |
delete index.rdo_tea_coffee_second; | |
} | |
$scope.unCheckTeaThird = function(index){ | |
delete index.rdo_tea_coffee_third; | |
} | |
$scope.unCheckLunch = function(index){ | |
delete index.rdo_lunch; | |
delete index.rdo_lunch_drinks; | |
} | |
$scope.unCheckDinner = function(index){ | |
delete index.rdo_dinner; | |
delete index.rdo_dinner_drinks; | |
} | |
$scope.unCheckDrinks = function(index){ | |
delete index.rdo_drinks_other; | |
} | |
// get unsubmitted form | |
let getEdit = function(){ | |
$http.get('/admin/admin/edit-quote-ajax/' + $scope.quote_id) | |
.then(function successCallback(response) { | |
$scope.quote = response.data; | |
if(response.data.start_date) | |
$scope.quote.start_date = new Date(response.data.start_date); | |
if(response.data.end_date) | |
$scope.quote.end_date = new Date(response.data.end_date); | |
if(response.data.budget) | |
$scope.quote.budget = response.data.budget; | |
if(response.data.acc_days > 0){ | |
$scope.quote.chk_bedroom = true; | |
response.data.acc_from_date = new Date(response.data.acc_start_date); | |
response.data.acc_to_date = new Date(response.data.acc_end_date); | |
} | |
$scope.quote.neighborhood = response.data.generic_neighborhood; | |
$scope.quote.city = response.data.generic_city; | |
/*$scope.quote.acc_day[0].double_room = 1; | |
$scope.quote.acc_day[1].double_room = 1; | |
*/ | |
console.log('response data : '); | |
console.log(response.data.acc_day); | |
}, function errorCallback(response) {}) | |
.then(function(){ | |
$scope.pageLoading = false; | |
}); | |
} | |
$scope.initQuote = function(data){ | |
$scope.quote_id = data.quoteId; | |
getEdit(); | |
} | |
// initialize fields | |
vm.init = function(){ | |
if(vm.workspace.accommodation == 'yes'){ | |
vm.accommodation = true; | |
} | |
/*vm.totalSteps = vm.getTotalSteps(); | |
*/ | |
vm.calculateMeetingDays(); | |
} | |
// select first layout if not alreay slect | |
vm.initLayout = function(dayIndex){ | |
/*if(!$scope.quote.day[dayIndex].rdo_layout){ | |
$scope.quote.day[dayIndex].rdo_layout = $scope.day_data[dayIndex].rdo_layout; | |
//$scope.quote.day[dayIndex].rdo_layout = 'Banquet'; | |
//$scope.quote.day[dayIndex].rdo_layout = vm.layouts[0].name; | |
}*/ | |
} | |
// get layout capacity | |
vm.layoutCapacity = function(layout){ | |
if(layout == undefined) | |
return false; | |
let capacity = 0; | |
angular.forEach(vm.layouts, function(l){ | |
if(l.name == layout){ | |
capacity = parseInt(l.capacity); | |
} | |
}); | |
return capacity; | |
} | |
// view day summary | |
vm.viewDaySummary = function(day){ | |
/*vm.dayOffset = day; | |
openPopup('summary_popup');*/ | |
} | |
vm.viewSummary = function(){ | |
/*vm.dayOffset = -1; | |
openPopup('summary_popup');*/ | |
} | |
vm.editDay = function(index){ | |
/*closePopup(); | |
vm.stage = (2*index) + 2; | |
$window.scrollTo(0, 0);*/ | |
} | |
vm.editAccommodation = function(){ | |
/*closePopup(); | |
vm.stage = vm.totalSteps - 1; | |
$window.scrollTo(0, 0);*/ | |
} | |
vm.objectLength = function(obj){ | |
let size = 0, key; | |
for (key in obj) { | |
if (obj.hasOwnProperty(key)) size++; | |
} | |
return size; | |
} | |
vm.searchObjectArray = function(nameKey, value, myArray){ | |
for (let i=0; i < myArray.length; i++) { | |
if (myArray[i][nameKey] === value) { | |
return myArray[i]; | |
} | |
} | |
return false; | |
} | |
// in_array | |
vm.inArray = function (needle, haystack) { | |
let length = haystack.length; | |
for(let i = 0; i < length; i++) { | |
if(haystack[i] == needle) return true; | |
} | |
return false; | |
}, | |
$scope.addRow = function(){ | |
let id = $scope.dates.length + 1; | |
$scope.dates.push({'id':'dynamic'+id}); | |
} | |
$scope.removeRow = function(row){ | |
let index = $scope.dates.indexOf(row); | |
$scope.dates.splice(index, 1); | |
} | |
// Check form field error | |
$scope.checkError = function(form, field, dayIndex){ | |
if(dayIndex !== undefined){ | |
field += '-'+dayIndex; | |
} | |
return (form.$submitted || form[field].$touched ) && form[field].$invalid; | |
//return false; | |
} | |
// View Quote summary | |
// $ionicModal.fromTemplateUrl('js/routes/quote/summary.html', { | |
// scope: $scope, | |
// animation: 'slide-in-up' | |
// }).then(function(modal){ | |
// vm.summaryModal = modal; | |
// }); | |
vm.init(); | |
} | |
var QuoteApp = angular.module('QuoteApp', ['ngAnimate', 'ngMessages']); | |
QuoteApp.directive('datepicker', function(){ | |
return { | |
restrict: 'A', | |
scope: { | |
'min': '@', | |
'reference': '=startDateField', | |
'working_days' : '=workingDays' | |
}, | |
require: 'ngModel', | |
link : function(scope, element, attrs, ctrl) { | |
element.datepicker({ | |
minDate: 0, | |
maxDate:150, | |
dateFormat: 'yy-mm-dd' | |
}); | |
// change min date | |
attrs.$observe('min', function(newVal) { | |
let todayDate = new Date(); | |
let minDate = 0; | |
if(moment(newVal).isSame(moment(todayDate), 'day')){ | |
minDate = 0; | |
} | |
else{ | |
minDate = moment(newVal).diff(moment(todayDate), 'days') + 1; | |
} | |
element.datepicker('option', 'minDate', minDate); | |
}); | |
function getValidity(working_days, start_date, end_date){ | |
let error = false; | |
if(working_days && working_days.length) { | |
let start_date_ = moment(start_date); | |
let end_date_ = moment(end_date); | |
let error = false; | |
while(end_date_.isSameOrAfter(start_date_)){ | |
let found = false; | |
for(let i = 0; i < working_days.length; i++) { | |
if(scope.working_days[i] == start_date_.day()){ | |
found = true; | |
break; | |
} | |
} | |
start_date_ = start_date_.add( 1 , 'days'); | |
if(!found) | |
error = true; | |
} | |
} | |
return error; | |
} | |
// check working days | |
ctrl.$parsers.unshift(function(viewValue) { | |
ctrl.$setValidity('validDate', !getValidity(scope.working_days, scope.reference, viewValue)); | |
return viewValue; | |
}); | |
scope.$watch("reference", function(viewValue) {; | |
ctrl.$setValidity('validDate', !getValidity(scope.working_days, scope.reference, ctrl.$modelValue)); | |
}); | |
} | |
} | |
}); | |
QuoteApp.directive('startTimeField', function(){ | |
return { | |
restrict: 'A', | |
scope: { | |
'reference': '=startTimeField', | |
}, | |
require: 'ngModel', | |
link : function(scope, element, attrs, ctrl) { | |
function checkTimeValidity(start_time, end_time){ | |
let startTime = moment(start_time, 'hh:mm:ss'); | |
let endTime = moment(end_time, 'hh:mm:ss'); | |
if(endTime.isAfter(startTime)){ | |
return true; | |
} | |
return false; | |
} | |
// check working days | |
ctrl.$parsers.unshift(function(viewValue) { | |
ctrl.$setValidity('minTime', checkTimeValidity(scope.reference, viewValue)); | |
return viewValue; | |
}); | |
scope.$watch("reference", function(viewValue) { | |
ctrl.$setValidity('minTime', checkTimeValidity(scope.reference, ctrl.$modelValue)); | |
}); | |
} | |
} | |
}); | |
QuoteApp.directive('limitWords', function () { | |
return { | |
restrict: 'AE', | |
link: function (scope, element, attrs) { | |
element.bind('keyup', function (e) { | |
let words = this.value.split(" "); | |
let tmp = ''; | |
if (words.length > 100){ | |
for(let i = 0; i < 100 ; i++){ | |
tmp += words[i] + ' '; | |
} | |
this.value = tmp; | |
} | |
}); | |
} | |
} | |
}); | |
QuoteApp.controller('QuoteFormController' , QuoteFormController); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment