/**
|
* Created by wisestone on 2018-05-08.
|
*/
|
'use strict';
|
|
define([
|
'app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('hostingFieldModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', 'HostingField', 'parameter', 'SweetAlert', '$filter', '$q',
|
function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, HostingField, parameter, SweetAlert, $filter, $q) {
|
|
$scope.fn = {
|
detail : detail, // 상세 조회
|
cancel : cancel, // 팝업 창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
autoHyphenPhone : autoHyphenPhone // 연락처 입력시 하이픈 자동 입력
|
};
|
|
$scope.vm = {
|
id : parameter.id,
|
form : {
|
code : "", //코드
|
name : "", //호스팅명
|
manager : "", //담당자
|
tel : "", //전화번호
|
email : "", //이메일
|
url : "", // url
|
memo : "" //메모(비고)
|
}
|
};
|
|
function autoHyphenPhone () {
|
let phone = $scope.vm.form.tel;
|
let seoul = $scope.vm.form.tel;
|
|
// 핸드폰 및 지방 지역번호 조건
|
phone.replace(/^[0-9]/g,'');
|
// 서울 지역번호 조건
|
seoul.replace(/^[0-9]/g,'');
|
var tmp = '';
|
|
if (phone.length < 4) {
|
return phone;
|
} else if (phone.length < 7) {
|
tmp += phone.substr(0, 3);
|
tmp += '-';
|
tmp += phone.substr(3)
|
$scope.vm.form.tel = tmp;
|
} else if (seoul.substring(0, 2) === "02" && seoul.length === 9) { // 서울 지역번호 조건
|
tmp += seoul.substring(0, 2);
|
tmp += '-';
|
tmp += seoul.substring(2, 5);
|
tmp += '-';
|
tmp += seoul.substr(5);
|
$scope.vm.form.tel = tmp;
|
} else if (seoul.substring(0, 2) === "02" && seoul.length === 10) { // 서울 지역번호 조건
|
tmp += seoul.substring(0, 2);
|
tmp += '-';
|
tmp += seoul.substring(2, 6);
|
tmp += '-';
|
tmp += seoul.substr(6);
|
$scope.vm.form.tel = tmp;
|
} else if (phone.length < 11) { // 핸드폰 및 지방 지역번호 조건
|
tmp += phone.substr(0, 3);
|
tmp += '-';
|
tmp += phone.substr(3, 3);
|
tmp += '-';
|
tmp += phone.substr(6);
|
$scope.vm.form.tel = tmp;
|
} else { // 핸드폰 및 지방 지역번호 조건
|
tmp += phone.substr(0, 3);
|
tmp += '-';
|
tmp += phone.substr(3, 4);
|
tmp += '-';
|
tmp += phone.substr(7);
|
$scope.vm.form.tel = tmp;
|
}
|
return phone;
|
}
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
return true;
|
}
|
|
return false;
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true;
|
$scope.vm.form.tel = $scope.vm.form.tel.replace(/\-/g,''); // 전화번호를 보낼땐 하이픈을 제거해서 DB에 저장
|
|
var content = {
|
id : parameter.id,
|
code : $rootScope.preventXss($scope.vm.form.code),
|
name : $rootScope.preventXss($scope.vm.form.name),
|
manager : $rootScope.preventXss($scope.vm.form.manager),
|
tel : $rootScope.preventXss($scope.vm.form.tel),
|
email : $rootScope.preventXss($scope.vm.form.email),
|
url : $rootScope.preventXss($scope.vm.form.url), // url
|
memo : $rootScope.preventXss($scope.vm.form.memo)
|
};
|
|
HostingField.modify($resourceProvider.getContent(
|
content,
|
$resourceProvider.getPageContent(0, 0))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
$scope.fn.cancel();
|
|
// 목록 화면 갱신
|
$rootScope.$broadcast("getPageList", {});
|
}
|
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');
|
$(document).unbind("keydown"); // 단축키 이벤트 제거
|
}
|
|
// 상세 정보
|
function detail() {
|
var deferred = $q.defer();
|
|
var conditions = {
|
id : parameter.id
|
}
|
|
HostingField.detail($resourceProvider.getContent(
|
conditions,
|
$resourceProvider.getPageContent(0, 1))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
if (angular.isDefined(result.data.content)) {
|
$scope.vm.form.code = result.data.content.code;
|
$scope.vm.form.name = result.data.content.name;
|
$scope.vm.form.manager = result.data.content.manager;
|
$scope.vm.form.email = result.data.content.email;
|
// 전화번호 하이픈 추가하여 조회
|
let hyphen = result.data.content.tel.trim();
|
let phone = hyphen.replace(/(^02.{0}|^01.{1}|[0-9]{3})([0-9]+)([0-9]{4})/,"$1-$2-$3");
|
result.data.content.tel = phone;
|
$scope.vm.form.tel = result.data.content.tel;
|
$scope.vm.form.url = result.data.content.url;
|
$scope.vm.form.memo = result.data.content.memo;
|
}
|
}
|
else {
|
SweetAlert.swal($filter("translate")("hostingField.failedToDetailHostingFieldModify"), result.data.message.message, "error"); // "상세 정보 조회 실패"
|
}
|
deferred.resolve(result.data.data);
|
});
|
return deferred.promise;
|
}
|
|
$scope.fn.detail();
|
|
}]);
|
});
|