84 lines
3.4 KiB
JavaScript
84 lines
3.4 KiB
JavaScript
var arr = window.location.href.split("/");
|
|
if (arr[3].indexOf('app') == 0)
|
|
baseUrl = '';
|
|
else
|
|
baseUrl = '/' + arr[3];
|
|
angular.module('CarbonFootprint')
|
|
.config(function ($routeProvider) {
|
|
$routeProvider.when('/Fab/Edit/:fabId', {
|
|
templateUrl: baseUrl+'/Partials/Fab-Create',
|
|
controller: 'FabEditController'
|
|
});
|
|
})
|
|
|
|
.controller('FabEditController',
|
|
['$scope', '$routeParams', '$http', '$location',
|
|
function ($scope, $routeParams, $http, $location) {
|
|
$scope.insynerger = sessionStorage.getItem("insynerger");
|
|
|
|
// 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.fab = {};
|
|
$http.get($scope.baseUrl+'/api/Fab/GetGroupIdsNames/')
|
|
.success(function (data, status, header, config) {
|
|
//console.log('api/Fab/GetGroupIdsNames', data);
|
|
$scope.fab.groupOptions = data;
|
|
});
|
|
$scope.onGroupChange = function (selectedgroup) {
|
|
//console.log('onGroupChange', selectedgroup, $scope.fab.groupOptions);
|
|
for (const [key, value] of Object.entries($scope.fab.groupOptions)) {
|
|
if (selectedgroup == value) {
|
|
$scope.fab.groupId = key;
|
|
}
|
|
//console.log(key, value);
|
|
}
|
|
};
|
|
$scope.saveFab = function () {
|
|
//$scope.fab.groupId = $scope.groupId;
|
|
//console.log($scope.fab);
|
|
for (var input in $scope.form) {
|
|
if (!input.indexOf('$') >= 0) { // if $scope.form attribte is form input
|
|
$scope.form[input].$dirty = true;
|
|
}
|
|
}
|
|
|
|
if ($scope.form.$invalid) return;
|
|
|
|
$http.post($scope.baseUrl+'/api/Fab/Save2', $scope.fab)
|
|
.success(function (data, status, headers, config) {
|
|
$location.path('Fab/Index');
|
|
})
|
|
.error(function (data, status, headers, config) {
|
|
if (data?.Message != undefined)
|
|
alert(data.Message)
|
|
else
|
|
alert('Oops! This is something happen. Maybe you can try it later');
|
|
});
|
|
};
|
|
|
|
$scope.backToFab = function () {
|
|
$location.path('/Fab/Index');
|
|
};
|
|
|
|
$http.get($scope.baseUrl+'/api/Fab/Get2/' + $routeParams.fabId)
|
|
.success(function (data, status, header, config) {
|
|
//console.log('api/Fab/Get2', data);
|
|
$scope.fab = data.fab;
|
|
$scope.fab.groupId = data.groupId;
|
|
$scope.groupId = data.groupId;
|
|
});
|
|
|
|
$scope.isoOptions = [
|
|
{ value: true, text: 'Yes' },
|
|
{ value: false, text: 'No' }
|
|
];
|
|
}]); |