/** * Created by wisestone on 2018-01-17. */ 'use strict'; define([ 'app', 'angular' ], function (app, angular) { app.controller('hostingFieldImportExcelController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', '$injector', '$controller', '$tableProvider', 'HostingField', 'SweetAlert', '$filter', '$timeout', function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, $injector, $controller, $tableProvider, HostingField, SweetAlert, $filter, $timeout) { $scope.fn = { cancel : cancel, // 팝업 창 닫기 formSubmit : formSubmit, // 폼 전송 formCheck : formCheck, // 폼 체크 onFileSelect : onFileSelect, // 파일 업로드 }; $scope.vm = { form : { file : "", // 업로드하는 Excel File fileName : "" }, tab : "VIDEO" }; // 파일 업로드 function onFileSelect($files) { $scope.vm.form.file = $files; if ($files.length > 0) { $scope.vm.form.fileName = $files[0].name; } else { $scope.vm.form.fileName = ""; } } // 폼 체크 function formCheck() { if ($scope.vm.form.file.length < 1) { return true; } return false; } // 폼 전송 function formSubmit() { $rootScope.spinner = true; HostingField.importExcel({ method : "POST", file : $scope.vm.form.file, // data 속성으로 별도의 데이터 전송 fileFormDataName : "file" }) .then(function (result) { if (result.data.message.status === "success") { $timeout(function () { SweetAlert.success($filter("translate")("hostingField.succeededHostingFieldRegistration"), result.data.message.message); // 등록 성공 $scope.fn.cancel(); $rootScope.$broadcast("getHostingFieldList"); $rootScope.spinner = false; }, 1000); } else { SweetAlert.error($filter("translate")("hostingField.failedHostingFieldRegistration"), result.data.message.message); // 등록 실패 $rootScope.spinner = false; } }); } function cancel() { $rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정 $uibModalInstance.dismiss('cancel'); } }]); });