/* Logic Solution WeeeCarbonFootprint this directive is resiponsible for quote UX , and deep clone the quoted data therefore we need the caller to provide 1.query api 2.save back function paramas:{ queryDataAsyncFn : function (LCAID) //to get the list of survey form data saveAsyncFn : function(List) //call back to save new quoted data with ID set to 0 fillterProductLCA : true/false //if product lca should be diplay in options } */ angular.module('View.Directive') .directive('quote', function (CONSTANTS) { var arr = window.location.href.split("/"); if (arr[3].indexOf('app') == 0) baseUrl = ''; else baseUrl = '/' + arr[3]; return { restrict: 'A', scope: { paramas: "=quoteOptions", }, transclude: true, controller: function ($scope, $http, $routeParams) { var lcaList = $scope.lcaList = []; $scope.error = null; $http.get(baseUrl+'/api/LCA/GetMyLCAforQuote').success(function (data) { angular.forEach(data, function (entry) { entry.isProductLCA = isProductLCA(entry.LCAType); if (entry.ID != $routeParams.LCAID) lcaList.push(entry); }); }); $scope.fetchQuoteData = function (selectedLCA) { var quoteResult = selectedLCA.quoteResult = []; $scope.paramas.queryDataAsyncFn(selectedLCA.ID).then(function (result) { angular.copy(result, quoteResult); angular.forEach(quoteResult, function (entry) { entry.ID = 0; entry.LCAID = $routeParams.LCAID; }); $scope.error = null; }, function (error) { $scope.error = error; }); } $scope.quote = function (selected) { $scope.paramas.saveAsyncFn(selected.quoteResult).then(function (result) { $scope.error = null; }, function (error) { $scope.error = error; }); } }, templateUrl: CONSTANTS.TB + 'quote' } })