X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=ecomp-portal-FE-common%2Fclient%2Fapp%2Fviews%2Fwidget-onboarding%2Fwidget-details-dialog%2Fwidget-details.controller.js;h=bf0df9f0e3cdc60bc50dae973660b5325f463b92;hb=a70761c096192e38800bf38d6c7f61f52bf72007;hp=b6429015d4594055716e579ba483b3f27ed0ed8d;hpb=3992004ee5f2b0b1635e2aef19c375db87079b52;p=portal.git diff --git a/ecomp-portal-FE-common/client/app/views/widget-onboarding/widget-details-dialog/widget-details.controller.js b/ecomp-portal-FE-common/client/app/views/widget-onboarding/widget-details-dialog/widget-details.controller.js index b6429015..bf0df9f0 100644 --- a/ecomp-portal-FE-common/client/app/views/widget-onboarding/widget-details-dialog/widget-details.controller.js +++ b/ecomp-portal-FE-common/client/app/views/widget-onboarding/widget-details-dialog/widget-details.controller.js @@ -38,7 +38,7 @@ 'use strict'; (function () { class WidgetOnboardingDetailsModalCtrl { - constructor($scope, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies,items) { + constructor($scope, $timeout, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies,items) { this.appUpdate = function(){ this.hasSelectedApp = false; @@ -398,12 +398,46 @@ }); } }; + // Caches the file name supplied by the event handler. + $scope.widgetFileHandler = (event, files) => { + if(files[0]){ + var fileName = files[0].name; + var validFormats = ['zip']; + //Get file extension + var ext = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); + //Check for valid format + if(validFormats.indexOf(ext) == -1){ + document.getElementById('widget-onboarding-details-upload-file').value = null; + $scope.widgetFileTypeError=true; + $timeout(function(){ + $scope.widgetFileTypeError=false; + }, 5000); + } + } + }; // file change handler + init(); $scope.$on('$stateChangeStart', e => { e.preventDefault(); }); } } - WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies','items']; + WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$timeout', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies','items']; angular.module('ecompApp').controller('WidgetOnboardingDetailsModalCtrl', WidgetOnboardingDetailsModalCtrl); + + angular.module('ecompApp').directive('fileChange', ['$parse', function($parse){ + return { + require: 'ngModel', + restrict: 'A', + link : function($scope, element, attrs, ngModel) { + var attrHandler = $parse(attrs['fileChange']); + var handler=function(e) { + $scope.$apply(function() { + attrHandler($scope, { $event:e, files:e.target.files } ); + }); + }; + element[0].addEventListener('change',handler,false); + } + } + }]); })();