const template = `
`;
viewModalFactory.$inject = ['$uibModal', 'Utils'];
export function viewModalFactory(
$uibModal: ng.ui.bootstrap.IModalService,
Utils: any
) {
const service = {
Show(
callback: any,
title: any,
dataSet: any,
message: any,
optionCancel: any,
optionConfirm: any,
backdrop: boolean
) {
message = message || '';
optionCancel = optionCancel || 'Cancel';
optionConfirm = optionConfirm || 'Confirm';
backdrop = backdrop || true;
let optionWidth: number;
const tempCancelWidth = optionCancel.length;
const tempConfirmWidth = optionConfirm.length;
if (tempCancelWidth > tempConfirmWidth) {
optionWidth = tempCancelWidth * 9 + 24;
} else {
optionWidth = tempConfirmWidth * 9 + 24;
}
$uibModal
.open({
template,
backdrop,
size: 'lg',
controller: [
'$scope',
'$uibModalInstance',
function modalController(
$scope: any,
$uibModalInstance: ng.ui.bootstrap.IModalInstanceService
) {
$scope.modalTitle = title;
$scope.modalMessage = message;
$scope.optionCancel = optionCancel;
$scope.optionConfirm = optionConfirm;
$scope.optionWidth = optionWidth;
$scope.result = dataSet;
$scope.loading = false;
$scope.editable = false;
$scope.priceIndex = 0;
$scope.priceSheet =
$scope.result.pricesheets[
$scope.priceIndex
].price_sheet_id;
$scope.Cancel = function () {
$uibModalInstance.dismiss();
};
$scope.Confirm = function () {
if (
$scope.form1.$dirty ||
$scope.form2.$dirty
) {
$scope.loading = true;
const req = {
method: 'POST',
url:
localized.apiURL +
'/admin/product/modify/',
data: $scope.result,
};
Utils.getHttpPromise(req)
.then(function () {
$uibModalInstance.close();
})
.finally(function () {
$scope.loading = false;
});
} else {
$scope.Cancel();
}
};
$scope.changePricesheet = function () {
$scope.priceIndex = $scope.result.pricesheets
.map(function (e: any) {
return e.price_sheet_id;
})
.indexOf($scope.priceSheet);
};
},
],
})
.result.then(
function (results) {
callback.confirm(results);
},
function () {
callback.cancel();
}
);
},
};
return service;
}