107 lines
4.6 KiB
JavaScript
107 lines
4.6 KiB
JavaScript
/*
|
|
2nd level route entry point
|
|
this controller is responsible for Routing Organization LCA , Product LCA with or without PCR selected
|
|
and the stutus of a LCA
|
|
---------------------------------
|
|
*/
|
|
|
|
angular.module('CarbonFootprint')
|
|
.config(function ($locationProvider, $routeProvider, CONSTANTS) {
|
|
$routeProvider.when('/LCA/RiskAssmtLayout/:LCAID', {
|
|
templateUrl: CONSTANTS.PB + 'LCA-DetailSurveyForm-RiskAssmtLayout',
|
|
controller: 'LCARiskAssmtLayoutController'
|
|
})
|
|
})
|
|
.controller('LCARiskAssmtLayoutController', ['$scope', '$location', '$routeParams', '$q', '$http',
|
|
function ($scope, $location, $routeParams, $q, $http) {
|
|
|
|
// set $scope.baseUrl
|
|
var baseUrl = $scope.baseUrl;
|
|
if (typeof (baseUrl) === 'undefined' || baseUrl == null) {
|
|
var arr = window.location.href.split("/");
|
|
if (arr[3].indexOf('app') == 0)
|
|
baseUrl = '';
|
|
else
|
|
baseUrl = '/' + arr[3];
|
|
$scope.baseUrl = baseUrl;
|
|
}
|
|
|
|
$scope.changeSelectedTab = function (selectedTab) {
|
|
switch (selectedTab) {
|
|
//case "MaterialTransport":
|
|
// window.location.href = '/Lca/RiskMaterialTransport/Index?LCAID=' + $routeParams.LCAID;
|
|
// break;
|
|
default:
|
|
//console.log('changeSelectedTab');
|
|
//console.log(selectedTab);
|
|
$scope.selectedTab = selectedTab;
|
|
$scope.$broadcast('changeSelectedTab', { selectedTab: selectedTab });
|
|
break;
|
|
}
|
|
};
|
|
|
|
$scope.updateGradingScore = function (gradingScore) {
|
|
$scope.$broadcast('updateGradingScore', { gradingScore: gradingScore });
|
|
};
|
|
|
|
getAllDataAsync($routeParams.LCAID)
|
|
.then(function (response) {
|
|
var sheetHeader = response.SheetHeader ? response.SheetHeader : {};
|
|
// $scope.sheetHeader is parent's object
|
|
$scope.sheetHeader.SheetFillerName = sheetHeader.SheetFillerName;
|
|
$scope.sheetHeader.Phone = sheetHeader.Phone;
|
|
$scope.sheetHeader.Department = sheetHeader.Department;
|
|
}, function (error) {
|
|
console.log(error);
|
|
});
|
|
function getAllDataAsync(LCAID) {
|
|
var deferred = $q.defer();
|
|
$http.get($scope.baseUrl+'/api/LCA/GetRiskAssmtLayoutSheetHeaderByLcaId/' + LCAID)
|
|
.success(function (data) {
|
|
deferred.resolve(data);
|
|
})
|
|
.error(function () {
|
|
deferred.resolve(null);
|
|
})
|
|
return deferred.promise;
|
|
}
|
|
// save sheetHeader
|
|
$scope.saveSheetHeader = function () {
|
|
$scope.isCheckOnce = true;
|
|
if ($scope.headerForm.$invalid) return;
|
|
|
|
$scope.sheetHeaderForm.resultMsg = '';
|
|
|
|
var newSheetHeader = $scope.sheetHeader;
|
|
newSheetHeader.LCAID = $routeParams.LCAID;
|
|
|
|
$http.post($scope.baseUrl+'/api/' + $routeParams.DetailType + '/SaveSheetHeader', newSheetHeader)
|
|
.success(function (data) {
|
|
$scope.sheetHeaderForm.resultMsg = resource['UpdateSuccess'];
|
|
})
|
|
.error(function (error) {
|
|
$scope.cancelEditSheetHeader();
|
|
$scope.sheetHeaderForm.resultMsg = resource['UpdateFail'];
|
|
//console.log(error);
|
|
})
|
|
.finally(function () {
|
|
// set timeout
|
|
$timeout(function () { $scope.sheetHeaderForm.resultMsg = '' }, 3000);
|
|
// switch to uneditable
|
|
$scope.sheetHeaderForm.editable = false;
|
|
});
|
|
}
|
|
// edit sheetheader
|
|
$scope.editSheetHeader = function () {
|
|
$scope.tempSheetHeader = angular.copy($scope.sheetHeader);
|
|
$scope.sheetHeaderForm.editable = true;
|
|
}
|
|
|
|
// canael edit sheetheader
|
|
$scope.cancelEditSheetHeader = function () {
|
|
$scope.headerForm.$setPristine();
|
|
$scope.sheetHeader = angular.copy($scope.tempSheetHeader);
|
|
$scope.sheetHeaderForm.editable = false;
|
|
}
|
|
}]);
|