/**
|
* Created by wisestone on 2018-02-19.
|
*/
|
'use strict';
|
|
define([
|
'app'
|
],
|
function (app) {
|
app.controller('companyFieldAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'SweetAlert', '$uibModal', '$uibModalInstance', '$state', 'CompanyField', '$filter', '$injector','$controller',
|
function ($scope, $rootScope, $log, $resourceProvider, SweetAlert, $uibModal, $uibModalInstance, $state, CompanyField, $filter, $injector, $controller) {
|
|
$scope.fn = {
|
cancel : cancel, // 팝업 창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
getIssueIspFieldListCallBack : getIssueIspFieldListCallBack,
|
getIssueHostingFieldListCallBack : getIssueHostingFieldListCallBack
|
};
|
|
$scope.vm = {
|
form : {
|
name : "", //업체명
|
ispId : "",
|
ispName : "",
|
hostingName : "",
|
hostingId : "",
|
manager : "", //담당자
|
tel : "", //전화번호
|
email : "", //이메일
|
url : "", // url
|
memo : "" //비고
|
},
|
autoCompletePage : {
|
ispField : {
|
page : 0,
|
totalPage : 0
|
},
|
hostingField : {
|
page : 0,
|
totalPage : 0
|
}
|
}
|
};
|
|
angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector}));
|
|
|
// ISP정보 autocomplete page 업데이트
|
function getIssueIspFieldListCallBack(result) {
|
$scope.vm.autoCompletePage.ispField.totalPage = result.data.page.totalPage;
|
}
|
|
// 호스팅정보 autocomplete page 업데이트
|
function getIssueHostingFieldListCallBack(result) {
|
$scope.vm.autoCompletePage.hostingField.totalPage = result.data.page.totalPage;
|
}
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
return true;
|
}
|
return false;
|
}
|
|
$scope.$on("ispFieldEvent", function (event, result) {
|
$scope.vm.form.ispId = result[0].id;
|
});
|
|
$scope.$on("hostingFieldEvent", function (event, result) {
|
$scope.vm.form.hostingId = result[0].id;
|
});
|
|
// 폼 전송
|
function formSubmit(condition) {
|
$rootScope.spinner = true;
|
|
var content = {
|
name : $rootScope.preventXss($scope.vm.form.name), // 업체명
|
ispId : (function () { // ISP 아이디
|
var ispId = -1;
|
if ($scope.vm.form.issueIspFields != null) {
|
ispId = $scope.vm.form.ispId;
|
}
|
return ispId;
|
})(),
|
hostingId : (function () { // Hosting 아이디
|
var hostingId = -1;
|
if ($scope.vm.form.issueHostingFields != null) {
|
hostingId = $scope.vm.form.hostingId;
|
}
|
return hostingId;
|
})(),
|
manager : $scope.vm.form.manager, //담당자
|
tel : $scope.vm.form.tel, //전화번호
|
email : $scope.vm.form.email, //이메일
|
url : $scope.vm.form.url, // url
|
memo : $scope.vm.form.memo //비고
|
};
|
|
CompanyField.add($resourceProvider.getContent(content,
|
$resourceProvider.getPageContent(0, 10))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
$scope.fn.cancel();
|
// 목록 화면 갱신
|
$rootScope.$broadcast("getPageList", {});
|
}
|
else {
|
SweetAlert.error($filter("translate")("companyField.failedCompanyFieldRegistration"), result.data.message.message);
|
}
|
|
$rootScope.spinner = false;
|
});
|
|
}
|
|
// 팝업 창 닫기
|
function cancel() {
|
$rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
|
$uibModalInstance.dismiss('cancel');
|
$(document).unbind("keydown"); // 단축키 이벤트 제거
|
}
|
|
}
|
|
]);
|
}
|
);
|