714 lines
28 KiB
JavaScript
714 lines
28 KiB
JavaScript
supersamApp.controller('CalcDoorsController', [
|
|||
|
|
'$scope',
|
||
|
|
'$http',
|
||
|
|
'$timeout',
|
||
|
|
'localStorageService',
|
||
|
|
'$filter',
|
||
|
|
'config',
|
||
|
|
function($scope,
|
||
|
|
$http,
|
||
|
|
$timeout,
|
||
|
|
localStorageService,
|
||
|
|
$filter,
|
||
|
|
config) {
|
||
|
|
var calcDoorsApp;
|
||
|
|
calcDoorsApp = (function() {
|
||
|
|
class calcDoorsApp {
|
||
|
|
constructor() {
|
||
|
|
this.loadSavedOrderDataFromDB = this.loadSavedOrderDataFromDB.bind(this);
|
||
|
|
this.clearPromises = this.clearPromises.bind(this);
|
||
|
|
this.removeDoorOrderInfo = this.removeDoorOrderInfo.bind(this);
|
||
|
|
this.isArray = this.isArray.bind(this);
|
||
|
|
this.loadDoorOrderInfo = this.loadDoorOrderInfo.bind(this);
|
||
|
|
this.saveDoorOrderInfo = this.saveDoorOrderInfo.bind(this);
|
||
|
|
this.AutoSaveData = this.AutoSaveData.bind(this);
|
||
|
|
this.confirmCleanup = this.confirmCleanup.bind(this);
|
||
|
|
this.cleanup = this.cleanup.bind(this);
|
||
|
|
this.openNotifyModal = this.openNotifyModal.bind(this);
|
||
|
|
this.openSendOrderEmailModal = this.openSendOrderEmailModal.bind(this);
|
||
|
|
this.clearCalculateLayoutAjarRequestPromise = this.clearCalculateLayoutAjarRequestPromise.bind(this);
|
||
|
|
this.calculateLayout = this.calculateLayout.bind(this);
|
||
|
|
this.onDoorCountChange = this.onDoorCountChange.bind(this);
|
||
|
|
this.onDoorChange = this.onDoorChange.bind(this);
|
||
|
|
this.bindWatches = this.bindWatches.bind(this);
|
||
|
|
this.bindDoorsCountWatches = this.bindDoorsCountWatches.bind(this);
|
||
|
|
this.unBindWatches = this.unBindWatches.bind(this);
|
||
|
|
this.printOrder = this.printOrder.bind(this);
|
||
|
|
this.printOrderConfirm = this.printOrderConfirm.bind(this);
|
||
|
|
this.sendOrderEmailNotify = this.sendOrderEmailNotify.bind(this);
|
||
|
|
this.onOrderInfoChange = this.onOrderInfoChange.bind(this);
|
||
|
|
this.bindOrderInfoWatches = this.bindOrderInfoWatches.bind(this);
|
||
|
|
this.modalScrollTo = this.modalScrollTo.bind(this);
|
||
|
|
this.openSelectDoorConfigModal = this.openSelectDoorConfigModal.bind(this);
|
||
|
|
this.selectDoorId = this.selectDoorId.bind(this);
|
||
|
|
this.confirmDoorSelection = this.confirmDoorSelection.bind(this);
|
||
|
|
this.getSelectedDoorColor = this.getSelectedDoorColor.bind(this);
|
||
|
|
this.getSelectedDoorProfile = this.getSelectedDoorProfile.bind(this);
|
||
|
|
this.getSelectedDoorVertHeight = this.getSelectedDoorVertHeight.bind(this);
|
||
|
|
this.getManufacturerLimits = this.getManufacturerLimits.bind(this);
|
||
|
|
this.isActualPriceCorrect = this.isActualPriceCorrect.bind(this);
|
||
|
|
this.onFieldEnter = this.onFieldEnter.bind(this);
|
||
|
|
if (config.savedOrderData) {
|
||
|
|
this.loadSavedOrderDataFromDB();
|
||
|
|
} else {
|
||
|
|
if (localStorageService.isSupported) {
|
||
|
|
this.loadDoorOrderInfo("AutoSavedCalcDoors");
|
||
|
|
} else {
|
||
|
|
this.cleanup();
|
||
|
|
}
|
||
|
|
this.date = new Date();
|
||
|
|
}
|
||
|
|
$scope.utilities.showContentOnLoad();
|
||
|
|
}
|
||
|
|
|
||
|
|
loadSavedOrderDataFromDB() {
|
||
|
|
var order;
|
||
|
|
this.skipNextWatchTrigger = true;
|
||
|
|
order = angular.copy(config.savedOrderData);
|
||
|
|
this.orderName = (order.name ? order.name : "");
|
||
|
|
this.orderPhone = (order.phone ? order.phone : "");
|
||
|
|
this.orderEmail = (order.email ? order.email : "");
|
||
|
|
this.orderAddress = (order.address ? order.address : "");
|
||
|
|
this.orderComment = (order.comment ? order.comment : "");
|
||
|
|
this.date = new Date(order.created);
|
||
|
|
this.orderNum = (order.order_num ? order.order_num : "");
|
||
|
|
this.actualPrice = (order.order_num && order.actual_price ? order.actual_price : "");
|
||
|
|
this.selectedDoorData = {
|
||
|
|
params: angular.copy(order.params),
|
||
|
|
order_calc_results: angular.copy(order.order_calc_results)
|
||
|
|
};
|
||
|
|
if (order.order_calc_results && order.order_calc_results.price) {
|
||
|
|
|
||
|
|
} else {
|
||
|
|
return this.calculateLayout();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
clearPromises() {
|
||
|
|
if (this.calculateLayoutPromise) {
|
||
|
|
$timeout.cancel(this.calculateLayoutPromise);
|
||
|
|
return this.calculateLayoutPromise = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
removeDoorOrderInfo(id) {
|
||
|
|
var calcDoorsParams, orderInfo;
|
||
|
|
if (localStorageService.isSupported) {
|
||
|
|
calcDoorsParams = localStorageService.get("calcDoorsParams");
|
||
|
|
if (calcDoorsParams && calcDoorsParams[id]) {
|
||
|
|
delete calcDoorsParams[id];
|
||
|
|
localStorageService.set("calcDoorsParams", calcDoorsParams);
|
||
|
|
}
|
||
|
|
orderInfo = localStorageService.get("orderInfo");
|
||
|
|
if (orderInfo && orderInfo[id]) {
|
||
|
|
orderInfo[id] = {
|
||
|
|
orderName: this.orderName,
|
||
|
|
orderPhone: this.orderPhone,
|
||
|
|
orderEmail: this.orderEmail,
|
||
|
|
orderAddress: this.orderAddress,
|
||
|
|
orderComment: ""
|
||
|
|
};
|
||
|
|
return localStorageService.set("orderInfo", orderInfo);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
isArray(value) {
|
||
|
|
return value && typeof value === 'object' && typeof value.length === 'number' && typeof value.splice === 'function' && !value.propertyIsEnumerable('length');
|
||
|
|
}
|
||
|
|
|
||
|
|
loadDoorOrderInfo(id) {
|
||
|
|
var calcDoorsParams, orderInfo;
|
||
|
|
if (localStorageService.isSupported) {
|
||
|
|
orderInfo = localStorageService.get("orderInfo");
|
||
|
|
if (orderInfo && orderInfo[id]) {
|
||
|
|
this.orderName = orderInfo[id].orderName ? angular.copy(orderInfo[id].orderName) : "";
|
||
|
|
this.orderPhone = orderInfo[id].orderPhone ? angular.copy(orderInfo[id].orderPhone) : "";
|
||
|
|
this.orderEmail = orderInfo[id].orderEmail ? angular.copy(orderInfo[id].orderEmail) : "";
|
||
|
|
this.orderAddress = orderInfo[id].orderAddress ? angular.copy(orderInfo[id].orderAddress) : "";
|
||
|
|
this.orderComment = orderInfo[id].orderComment ? angular.copy(orderInfo[id].orderComment) : "";
|
||
|
|
if (typeof orderInfo[id].skipNextWatchTrigger !== "undefined") {
|
||
|
|
this.skipNextWatchTrigger = angular.copy(orderInfo[id].skipNextWatchTrigger);
|
||
|
|
} else {
|
||
|
|
this.skipNextWatchTrigger = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
calcDoorsParams = localStorageService.get("calcDoorsParams");
|
||
|
|
if (calcDoorsParams && calcDoorsParams[id] && calcDoorsParams[id].version && (calcDoorsParams[id].version === config.version)) {
|
||
|
|
if (calcDoorsParams[id].selectedDoorData) {
|
||
|
|
this.selectedDoorData = angular.copy(calcDoorsParams[id].selectedDoorData);
|
||
|
|
delete this.selectedDoorData.eOId;
|
||
|
|
return this.calculateLayout(true);
|
||
|
|
} else {
|
||
|
|
return this.selectedDoorData = angular.copy(this.defaultSelectedDoorData);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
return this.cleanup();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
saveDoorOrderInfo(id, label, skipNextWatchTrigger) {
|
||
|
|
var calcDoorsParams, orderInfo;
|
||
|
|
if (localStorageService.isSupported) {
|
||
|
|
calcDoorsParams = localStorageService.get("calcDoorsParams");
|
||
|
|
if (!calcDoorsParams) {
|
||
|
|
calcDoorsParams = {};
|
||
|
|
}
|
||
|
|
calcDoorsParams[id] = {
|
||
|
|
selectedDoorData: this.selectedDoorData,
|
||
|
|
label: label,
|
||
|
|
time: new Date(),
|
||
|
|
version: config.version
|
||
|
|
};
|
||
|
|
orderInfo = localStorageService.get("orderInfo");
|
||
|
|
if (!orderInfo) {
|
||
|
|
orderInfo = {};
|
||
|
|
}
|
||
|
|
//null means current trigger state - ie do not recount if only order info (name, email etc) changed
|
||
|
|
if ((skipNextWatchTrigger === null) && orderInfo && orderInfo[id] && (typeof orderInfo[id].skipNextWatchTrigger !== "undefined")) {
|
||
|
|
skipNextWatchTrigger = orderInfo[id].skipNextWatchTrigger;
|
||
|
|
}
|
||
|
|
orderInfo[id] = {
|
||
|
|
orderName: this.orderName,
|
||
|
|
orderPhone: this.orderPhone,
|
||
|
|
orderEmail: this.orderEmail,
|
||
|
|
orderAddress: this.orderAddress,
|
||
|
|
orderComment: this.orderComment,
|
||
|
|
skipNextWatchTrigger: skipNextWatchTrigger
|
||
|
|
};
|
||
|
|
localStorageService.set("calcDoorsParams", calcDoorsParams);
|
||
|
|
return localStorageService.set("orderInfo", orderInfo);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
AutoSaveData(skipNextWatchTrigger) {
|
||
|
|
if (localStorageService.isSupported) {
|
||
|
|
return this.saveDoorOrderInfo("AutoSavedCalcDoors", "Автоматическое сохранение", skipNextWatchTrigger);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
confirmCleanup() {
|
||
|
|
this.fullOrderCleanup = false;
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element(this.confirmCleanupModalId).data("backdrop", "static").modal("show");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
cleanup(cleanupUrlParams = false) {
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element(this.confirmCleanupModalId).modal("hide");
|
||
|
|
});
|
||
|
|
this.selectedDoorData = angular.copy(this.defaultSelectedDoorData);
|
||
|
|
this.errors = [];
|
||
|
|
this.isSubmitting = false;
|
||
|
|
this.warnings = [];
|
||
|
|
this.orderComment = "";
|
||
|
|
this.orderNum = "";
|
||
|
|
if (this.fullOrderCleanup) {
|
||
|
|
this.orderName = "";
|
||
|
|
this.orderPhone = "";
|
||
|
|
this.orderAddress = "";
|
||
|
|
this.orderEmail = "";
|
||
|
|
}
|
||
|
|
this.removeDoorOrderInfo("AutoSavedCalcDoors");
|
||
|
|
this.date = new Date();
|
||
|
|
if (cleanupUrlParams && (window.location.href.indexOf('oid') > -1)) {
|
||
|
|
return window.location.replace(location.pathname);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
openNotifyModal() {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element(this.notifyModalId).modal("show");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
openSendOrderEmailModal() {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element(this.notifySendOrderEmailModalId).data("backdrop", "static").modal("show");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
clearCalculateLayoutAjarRequestPromise() {
|
||
|
|
if (this.calculateLayoutAjarRequestPromise) {
|
||
|
|
this.calculateLayoutAjarRequestPromise.abort();
|
||
|
|
this.calculateLayoutAjarRequestPromise = null;
|
||
|
|
}
|
||
|
|
if (this.calculateLayoutAjarRequestTimeoutPromise) {
|
||
|
|
$timeout.cancel(this.calculateLayoutAjarRequestTimeoutPromise);
|
||
|
|
return this.calculateLayoutAjarRequestTimeoutPromise = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
calculateLayout(immediateSync = false) {
|
||
|
|
var dataToSend;
|
||
|
|
if (immediateSync) { //immediate sync
|
||
|
|
this.clearPromises;
|
||
|
|
}
|
||
|
|
this.AutoSaveData(false);
|
||
|
|
if (!this.selectedDoorData.params.doorId) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
dataToSend = {
|
||
|
|
selectedDoorData: this.selectedDoorData
|
||
|
|
};
|
||
|
|
if (config.savedOrderData) {
|
||
|
|
dataToSend.selectedDoorData.eOId = config.savedOrderData.eOId;
|
||
|
|
}
|
||
|
|
this.clearCalculateLayoutAjarRequestPromise();
|
||
|
|
this.calculateLayoutAjarRequestTimeoutPromise = $timeout(() => {
|
||
|
|
this.clearCalculateLayoutAjarRequestPromise();
|
||
|
|
this.notifyMessage = "Выполнение расчет заняло слишком много времени и было отменено. Пожалуйста, уточните параметры деталей и попробуйте снова.";
|
||
|
|
return this.openNotifyModal();
|
||
|
|
}, 115000);
|
||
|
|
this.isSubmitting = true;
|
||
|
|
return this.calculateLayoutAjarRequestPromise = $http.with_abort({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.calcDoorsUrl,
|
||
|
|
data: dataToSend
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isSubmitting = false;
|
||
|
|
this.clearCalculateLayoutAjarRequestPromise();
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element(this.confirmStartCutOptimizeModalId).modal("hide");
|
||
|
|
});
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.warnings) {
|
||
|
|
this.warnings = data.warnings;
|
||
|
|
} else {
|
||
|
|
this.warnings = [];
|
||
|
|
}
|
||
|
|
if (data.status === "success") {
|
||
|
|
if (data.selectedDoorData) {
|
||
|
|
this.selectedDoorData = data.selectedDoorData;
|
||
|
|
return this.AutoSaveData(true);
|
||
|
|
} else {
|
||
|
|
return this.selectedDoorData = angular.copy(this.defaultSelectedDoorData);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (data.message) {
|
||
|
|
this.notifyMessage = data.message;
|
||
|
|
} else {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("dataLoadingError", true);
|
||
|
|
}
|
||
|
|
return this.openNotifyModal();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
this.isSubmitting = false;
|
||
|
|
if (data.warnings) {
|
||
|
|
this.warnings = data.warnings;
|
||
|
|
} else {
|
||
|
|
this.warnings = [];
|
||
|
|
}
|
||
|
|
this.clearCalculateLayoutAjarRequestPromise();
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element(this.confirmStartCutOptimizeModalId).modal("hide");
|
||
|
|
});
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("dataLoadingError", true);
|
||
|
|
return this.openNotifyModal();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
onDoorCountChange() {
|
||
|
|
if (this.selectedDoorData.params.manufacturer_id === "aristo") {
|
||
|
|
if (this.selectedDoorData.params.doorsCount > 0) {
|
||
|
|
return this.selectedDoorData.params.zagimDlyaShlegelya = parseInt(this.selectedDoorData.params.doorsCount) * 4;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onDoorChange() {
|
||
|
|
if (this.selectedDoorData.params.discount) {
|
||
|
|
this.selectedDoorData.params.discount = parseInt(this.selectedDoorData.params.discount);
|
||
|
|
this.selectedDoorData.params.discount = Math.max(0, Math.min(this.selectedDoorData.params.discount, 100));
|
||
|
|
}
|
||
|
|
if (this.skipNextWatchTrigger && (this.skipNextWatchTrigger === true)) { //ie after immediate sync after rotate
|
||
|
|
this.skipNextWatchTrigger = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.clearPromises();
|
||
|
|
return this.calculateLayoutPromise = $timeout(() => {
|
||
|
|
this.AutoSaveData(false);
|
||
|
|
return this.calculateLayout();
|
||
|
|
}, 1500);
|
||
|
|
}
|
||
|
|
|
||
|
|
bindWatches() {
|
||
|
|
if (typeof this.doorParamsWatcher === "function") {
|
||
|
|
this.doorParamsWatcher(); //unbind first
|
||
|
|
}
|
||
|
|
return this.doorParamsWatcher = $scope.$watch('calcDoors.selectedDoorData.params', $scope.calcDoors.onDoorChange, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
bindDoorsCountWatches() {
|
||
|
|
if (typeof this.doorsCountWatcher === "function") {
|
||
|
|
this.doorsCountWatcher(); //unbind first
|
||
|
|
}
|
||
|
|
return this.doorsCountWatcher = $scope.$watch('calcDoors.selectedDoorData.params.doorsCount', $scope.calcDoors.onDoorCountChange, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
unBindWatches() {
|
||
|
|
if (typeof this.doorParamsWatcher === "function") {
|
||
|
|
this.doorParamsWatcher();
|
||
|
|
}
|
||
|
|
if (typeof this.doorsCountWatcher === "function") {
|
||
|
|
return this.doorsCountWatcher();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
printOrder() {
|
||
|
|
if (config.additionalActionsAllowed) {
|
||
|
|
if (!config.savedOrderData) {
|
||
|
|
return this.sendOrderEmailNotify("printOnly");
|
||
|
|
} else {
|
||
|
|
return this.printOrderConfirm(config.savedOrderData.printOrderUrl);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
printOrderConfirm(printOrderUrl) {
|
||
|
|
var printOrderWindow;
|
||
|
|
if (printOrderUrl && (printOrderUrl.length > 0)) {
|
||
|
|
printOrderWindow = window.open(printOrderUrl, '_blank');
|
||
|
|
printOrderWindow.focus();
|
||
|
|
return $timeout(() => {
|
||
|
|
return printOrderWindow.print();
|
||
|
|
}, 1000);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
sendOrderEmailNotify(branchId) {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.selectedDoorData.params.doorId || $scope.calcDoorsConfigForm.$invalid || !this.isActualPriceCorrect() || this.warnings.length) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (this.isSubmitting) {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSendManagerCalcIsActive");
|
||
|
|
this.openNotifyModal();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (!this.isSendOrderEmailSubmitting) {
|
||
|
|
this.isSendOrderEmailSubmitting = true;
|
||
|
|
if ((branchId === "printOnly") || (this.orderEmail && (this.orderEmail.length > 0)) || (this.orderPhone && (this.orderPhone.length > 0))) {
|
||
|
|
dataToSend = {
|
||
|
|
selectedDoorData: this.selectedDoorData,
|
||
|
|
orderName: this.orderName,
|
||
|
|
orderPhone: this.orderPhone,
|
||
|
|
orderEmail: this.orderEmail,
|
||
|
|
orderAddress: this.orderAddress,
|
||
|
|
orderComment: this.orderComment,
|
||
|
|
branchId: branchId
|
||
|
|
};
|
||
|
|
if (branchId === "printOnly") {
|
||
|
|
dataToSend.printOnly = true;
|
||
|
|
} else {
|
||
|
|
dataToSend.orderEmailNotify = true;
|
||
|
|
}
|
||
|
|
if (this.orderNum && (this.orderNum.length > 0) && this.actualPrice) {
|
||
|
|
dataToSend.actualPrice = this.actualPrice;
|
||
|
|
}
|
||
|
|
if (config.savedOrderData) {
|
||
|
|
dataToSend.eOId = config.savedOrderData.eOId;
|
||
|
|
}
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.calcDoorsUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isSendOrderEmailSubmitting = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (branchId !== "printOnly") {
|
||
|
|
if (data.orderEmailNotifySent && (data.orderEmailNotifySent === "success")) {
|
||
|
|
return this.openSendOrderEmailModal();
|
||
|
|
} else {
|
||
|
|
if (config.savedOrderData) {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSaveManagerError", true);
|
||
|
|
} else {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSendManagerError", true);
|
||
|
|
}
|
||
|
|
return this.openNotifyModal();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (data.printOrderUrl) {
|
||
|
|
return this.printOrderConfirm(data.printOrderUrl);
|
||
|
|
} else {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSaveManagerError", true);
|
||
|
|
return this.openNotifyModal();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch((data) => {
|
||
|
|
this.isSendOrderEmailSubmitting = false;
|
||
|
|
if (branchId !== "printOnly") {
|
||
|
|
if (!data || (data && (data !== 'canceled'))) {
|
||
|
|
if (config.savedOrderData) {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSaveManagerError", true);
|
||
|
|
} else {
|
||
|
|
this.notifyMessage = $scope.utilities.getConfigLabel("orderSendManagerError", true);
|
||
|
|
}
|
||
|
|
return this.openNotifyModal();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onOrderInfoChange() {
|
||
|
|
if (this.orderInfoSaveTimeoutPromise) {
|
||
|
|
$timeout.cancel(this.orderInfoSaveTimeoutPromise);
|
||
|
|
this.orderInfoSaveTimeoutPromise = null;
|
||
|
|
}
|
||
|
|
return this.orderInfoSaveTimeoutPromise = $timeout(() => {
|
||
|
|
return this.AutoSaveData(null);
|
||
|
|
}, this.orderInfoSaveTimeout);
|
||
|
|
}
|
||
|
|
|
||
|
|
bindOrderInfoWatches() {
|
||
|
|
$scope.$watch('calcDoors.orderName', $scope.calcDoors.onOrderInfoChange, true);
|
||
|
|
$scope.$watch('calcDoors.orderEmail', $scope.calcDoors.onOrderInfoChange, true);
|
||
|
|
$scope.$watch('calcDoors.orderPhone', $scope.calcDoors.onOrderInfoChange, true);
|
||
|
|
$scope.$watch('calcDoors.orderAddress', $scope.calcDoors.onOrderInfoChange, true);
|
||
|
|
return $scope.$watch('calcDoors.orderComment', $scope.calcDoors.onOrderInfoChange, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
modalScrollTo(modalId, elementId) {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element(modalId + " .modal-body").scrollTo(elementId, 100, {
|
||
|
|
offset: {
|
||
|
|
top: -15
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
openSelectDoorConfigModal() {
|
||
|
|
this.selectDoorConfigModalData = angular.copy(this.selectedDoorData);
|
||
|
|
angular.element(this.selectDoorConfigModalId).modal("show");
|
||
|
|
return angular.element(this.selectDoorConfigModalId).on('shown.bs.modal', () => {
|
||
|
|
if (this.selectDoorConfigModalData.params.doorId > 0) {
|
||
|
|
this.modalScrollTo(this.selectDoorConfigModalId, "#selectDoorId" + this.selectDoorConfigModalData.params.doorId);
|
||
|
|
} else {
|
||
|
|
this.modalScrollTo(this.selectDoorConfigModalId, 0);
|
||
|
|
}
|
||
|
|
return $timeout(() => {
|
||
|
|
return lozad('.img-lazy').observe();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
selectDoorId(door) {
|
||
|
|
if (!this.selectDoorConfigModalData.params) {
|
||
|
|
this.selectDoorConfigModalData.params = {};
|
||
|
|
}
|
||
|
|
this.selectDoorConfigModalData.params.doorId = angular.copy(door.id);
|
||
|
|
return this.selectDoorConfigModalData.params.manufacturer_id = angular.copy(door.manufacturer_id);
|
||
|
|
}
|
||
|
|
|
||
|
|
confirmDoorSelection() {
|
||
|
|
var currentDoorData, forceLayoutUpdate;
|
||
|
|
currentDoorData = angular.copy(this.selectedDoorData);
|
||
|
|
this.selectedDoorData = angular.copy(this.selectDoorConfigModalData);
|
||
|
|
if (!this.selectedDoorData.params) {
|
||
|
|
this.selectedDoorData.params = {};
|
||
|
|
}
|
||
|
|
forceLayoutUpdate = true;
|
||
|
|
if (currentDoorData && (this.selectedDoorData.params.doorId === currentDoorData.params.doorId)) {
|
||
|
|
forceLayoutUpdate = false;
|
||
|
|
}
|
||
|
|
this.calculateLayout(forceLayoutUpdate);
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element(this.selectDoorConfigModalId).modal("hide");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
getSelectedDoorColor(id) {
|
||
|
|
var defaultLabel, i, label, len, ref, selectedDoor, v;
|
||
|
|
defaultLabel = "Не выбран";
|
||
|
|
label = {
|
||
|
|
color: defaultLabel,
|
||
|
|
colorNapravlyaushayaVerh: defaultLabel,
|
||
|
|
colorNapravlyaushayaNiz: defaultLabel
|
||
|
|
};
|
||
|
|
if (id > 0) {
|
||
|
|
ref = config.doors;
|
||
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
||
|
|
v = ref[i];
|
||
|
|
if (v.id === parseInt(id)) {
|
||
|
|
selectedDoor = v;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (selectedDoor) {
|
||
|
|
label = {
|
||
|
|
color: selectedDoor.color,
|
||
|
|
colorNapravlyaushayaVerh: selectedDoor.colorNapravlyaushayaVerh,
|
||
|
|
colorNapravlyaushayaNiz: selectedDoor.colorNapravlyaushayaNiz
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return label;
|
||
|
|
}
|
||
|
|
|
||
|
|
getSelectedDoorProfile(id) {
|
||
|
|
var i, label, len, ref, selectedDoor, v;
|
||
|
|
label = "Не выбран";
|
||
|
|
if (id > 0) {
|
||
|
|
ref = config.doors;
|
||
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
||
|
|
v = ref[i];
|
||
|
|
if (v.id === parseInt(id)) {
|
||
|
|
selectedDoor = v;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (selectedDoor) {
|
||
|
|
label = selectedDoor.profile;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return label;
|
||
|
|
}
|
||
|
|
|
||
|
|
getSelectedDoorVertHeight(id) {
|
||
|
|
var i, label, len, ref, selectedDoor, v;
|
||
|
|
label = {
|
||
|
|
profileVertHeight: 2400,
|
||
|
|
profileVertBelowLimit: 0,
|
||
|
|
profileVertHigherLimit: 0
|
||
|
|
};
|
||
|
|
if (id > 0) {
|
||
|
|
ref = config.doors;
|
||
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
||
|
|
v = ref[i];
|
||
|
|
if (v.id === parseInt(id)) {
|
||
|
|
selectedDoor = v;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (selectedDoor) {
|
||
|
|
label = {
|
||
|
|
profileVertHeight: selectedDoor.params.profileVertHeight,
|
||
|
|
profileVertBelowLimit: selectedDoor.params.profileVertBelowLimit,
|
||
|
|
profileVertHigherLimit: selectedDoor.params.profileVertHigherLimit
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return label;
|
||
|
|
}
|
||
|
|
|
||
|
|
getManufacturerLimits(manufacturerId) {
|
||
|
|
var i, len, limits, ref, selectedManufacturer, v;
|
||
|
|
limits = {};
|
||
|
|
if (manufacturerId > 0) {
|
||
|
|
ref = config.doorsManufacturers;
|
||
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
||
|
|
v = ref[i];
|
||
|
|
if (v.id === parseInt(manufacturerId)) {
|
||
|
|
selectedManufacturer = v;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (selectedManufacturer) {
|
||
|
|
limits = selectedManufacturer.limits;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return limits;
|
||
|
|
}
|
||
|
|
|
||
|
|
isActualPriceCorrect() {
|
||
|
|
var result;
|
||
|
|
result = true;
|
||
|
|
if (this.orderNum && (this.orderNum.length > 0) && this.actualPrice) {
|
||
|
|
if (parseFloat(this.actualPrice) < parseFloat(this.selectedDoorData.order_calc_results.price.replaceAll(" ", ""))) {
|
||
|
|
result = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
onFieldEnter(nextField) {
|
||
|
|
if (nextField) {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element('#' + nextField).focus().select();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.calculateLayoutPromise = null;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.calculateLayoutAjarRequestPromise = null;
|
||
|
|
|
||
|
|
calcDoorsApp.calculateLayoutAjarRequestTimeoutPromise = null;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.skipNextWatchTrigger = false;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderInfoSaveTimeoutPromise = null;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderInfoSaveTimeout = 1500;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.notifyModalId = "#notifyModal";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.notifySendOrderEmailModalId = "#notifySendOrderEmailModal";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.selectDoorConfigModalId = "#selectDoorConfigModal";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.confirmCleanupModalId = "#confirmCleanupModal";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.fullOrderCleanup = false;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.selectDoorConfigModalData = {};
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.manufacturersSelect = null;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.isSendOrderEmailSubmitting = false;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.warnings = [];
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.isSubmitting = false;
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderName = "";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderEmail = "";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderPhone = "";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.orderAddress = "";
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.defaultSelectedDoorData = {
|
||
|
|
params: {
|
||
|
|
manufacturer_id: null,
|
||
|
|
doorId: null,
|
||
|
|
height: "",
|
||
|
|
width: "",
|
||
|
|
discount: ""
|
||
|
|
},
|
||
|
|
order_calc_results: {
|
||
|
|
price: 0
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
calcDoorsApp.prototype.searchFilter = "";
|
||
|
|
|
||
|
|
window.onbeforeprint = () => {
|
||
|
|
//todo block browser print?
|
||
|
|
return null;
|
||
|
|
};
|
||
|
|
|
||
|
|
return calcDoorsApp;
|
||
|
|
|
||
|
|
}).call(this);
|
||
|
|
$scope.config = config;
|
||
|
|
$scope.utilities = new UtilitiesClass(config,
|
||
|
|
$filter,
|
||
|
|
$timeout);
|
||
|
|
$scope.calcDoors = new calcDoorsApp();
|
||
|
|
$scope.calcDoors.bindWatches();
|
||
|
|
$scope.calcDoors.bindDoorsCountWatches();
|
||
|
|
return $scope.calcDoors.bindOrderInfoWatches();
|
||
|
|
}
|
||
|
|
]);
|