/* the option example: { modelBuilder : ModelFactory, saveAsync : callback fn , to save parsed result } */ angular.module('View.Directive') .directive('fileImportProcess', function (CONSTANTS) { return { scope: { fileImportOption: "=importOption" }, link: function (scope, element, attr) { scope.$watch('selectedFile', function (newValue) { if (newValue) scope.hideOnNextBtn = false; else { element.find('input[file]')[0].value = ''; scope.hideOnNextBtn = true; } }) scope.$watch('result', function (newValue) { if (newValue) { scope.hideOnNextBtn = true; scope.hideOnOkBtn = false; scope.hideOnCancelBtn = false; } else { scope.hideOnNextBtn = true; scope.hideOnOkBtn = true; scope.hideOnCancelBtn = true; } }) }, controller: function ($scope, ImportCsvService, $routeParams) { $scope.fileImportOption.fileSelected = function (file) { $scope.selectedFile = file; $scope.$apply();//this apply is because fileselected function is called by file.js directive ? , (digest does not work) } $scope.fileImportOption.onNextFn = function () { ImportCsvService.startImportAsync($routeParams.LCAID, $scope.fileImportOption.modelBuilder, $scope.selectedFile, function () { }).then( function (result) { $scope.result = result; }) }; $scope.fileImportOption.onOkFn = function () { $scope.fileImportOption.saveAsync($scope.result.data).then(function (result) { $scope.selectedFile = null; $scope.result = null; }, function (error) { $scope.result.errors = []; $scope.result.errors.push({ error: error }); }); } $scope.fileImportOption.onCancelFn = function () { $scope.selectedFile = null; $scope.result = null; } }, templateUrl: CONSTANTS.TB + 'file_import' }; })