'use strict';
|
|
define(['app', 'angular'],
|
function (app, angular) {
|
app.provider("$tableProvider", function () {
|
return {
|
$get : function ($log) {
|
return {
|
config : function () {
|
var tableConfig = {
|
hName : "", // 헤더 이름
|
hWidth : "", // 칼럼 길이
|
hChecked : false, // 체크 박스 선택 여부
|
hAlign : "text-center", // 헤더 정렬 기준
|
hSort : true, // 정렬 가능 여부
|
dName : "", // 데이터 이름
|
dAlign : "text-left", // 데이터 정렬 기준
|
dRenderer : "", // 렌더러 여부
|
dVisible : "", // bootstrap 반응형 컬럼 표시 여부
|
dType : "none", // 태그 타입
|
dDateFormat : "", // 날짜 형식
|
rowSpan : 0, // rowspan 을 지원한다.
|
colSpan : 0, // colspan 을 지원한다.
|
subHead : false, // 만약 rowspan, colspan 을 사용하게 되면 true 로 셋팅.
|
columnHint : "", // 컬럼 정보를 추출하기 위한 힌트 정보를 준다 - tableColumnGenerator 의 사용자 정의 필드 부분에서 사용
|
setHName : function (hName) {
|
this.hName = hName;
|
return this;
|
},
|
setHWidth : function (hWidth) {
|
this.hWidth = hWidth;
|
return this;
|
},
|
setHChecked : function (hChecked) {
|
this.hChecked = hChecked;
|
return this;
|
},
|
setHAlign : function (hAlign) {
|
this.hAlign = hAlign;
|
return this;
|
},
|
setHSort : function (hSort) {
|
this.hSort = hSort;
|
return this;
|
},
|
setDName : function (dName) {
|
this.dName = dName;
|
return this;
|
},
|
setDAlign : function (dAlign) {
|
this.dAlign = dAlign;
|
return this;
|
},
|
setDRenderer : function (dRenderer) {
|
this.dRenderer = dRenderer;
|
return this;
|
},
|
setDVisible : function (dVisible) {
|
this.dVisible = dVisible;
|
return this;
|
},
|
setDType : function (dType) {
|
this.dType = dType;
|
return this;
|
},
|
setDDateFormat : function (dDateFormat) {
|
this.dDateFormat = dDateFormat;
|
return this;
|
},
|
setRowSpan : function (dRowSpan) {
|
this.rowSpan = dRowSpan;
|
return this;
|
},
|
setColSpan : function (dColSpan) {
|
this.colSpan = dColSpan;
|
return this;
|
},
|
setSubHead : function (dSubHead) {
|
this.subHead = dSubHead;
|
return this;
|
},
|
setColumnHint : function (dColumnHint) {
|
this.columnHint = dColumnHint;
|
return this;
|
}
|
};
|
|
return tableConfig;
|
},
|
toggleChecked : function (checkStatus, datas) {
|
// 전체 선택 체크 박스를 클릭했을 경우
|
angular.forEach(datas, function (data) {
|
if (angular.isDefined(data.defaultYn)) {
|
if (!data.defaultYn) {
|
data.checked = checkStatus;
|
}
|
}
|
else {
|
data.checked = checkStatus;
|
}
|
});
|
},
|
radioChecked : function (target, datas) {
|
// 해당 row 가 라디오 버튼일 경우
|
angular.forEach(datas, function (data) {
|
if (target.id == data.id) {
|
data.checked = true;
|
}
|
else {
|
data.checked = false;
|
}
|
});
|
},
|
rowChecked : function (tableConfig, target, datas) {
|
// 각 row 의 체크박스/라디오 버튼을 클릭했을 경우
|
if (tableConfig[0].dType == "checkbox") {
|
target.checked = !target.checked;
|
|
for (var data in datas) {
|
if (!data.checked) {
|
this.hChecked = false;
|
break;
|
}
|
}
|
}
|
else if (tableConfig[0].dType == "radio") {
|
this.radioChecked(target, datas);
|
}
|
},
|
orderByColumn : "", // table order By column name
|
reverse : true,
|
setOrderByColumn : function (column) {
|
if (column == "") {
|
return;
|
}
|
|
if (this.orderByColumn == column) {
|
this.reverse = !this.reverse;
|
}
|
else {
|
this.reverse = true;
|
}
|
|
this.orderByColumn = column;
|
return this;
|
},
|
getDateFormat : function (formatType, date) {
|
if (formatType == "" || formatType == null) {
|
formatType = "01";
|
}
|
Date.prototype.format = function (f) {
|
if (!this.valueOf()) {
|
return " ";
|
}
|
var weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
|
var d = this;
|
|
return f.replace(/(yyyy|yy|MM|dd|E|hh|mm|ss|a\/p)/gi, function ($1) {
|
switch ($1) {
|
case "yyyy":
|
return d.getFullYear();
|
case "yy":
|
return (d.getFullYear() % 1000).zf(2);
|
case "MM":
|
return (d.getMonth() + 1).zf(2);
|
case "dd":
|
return d.getDate().zf(2);
|
case "E":
|
return weekName[d.getDay()];
|
case "HH":
|
return d.getHours().zf(2);
|
case "hh":
|
var h = d.getHours();
|
return ((h = d.getHours() % 12) ? h : 12).zf(2);
|
case "mm":
|
return d.getMinutes().zf(2);
|
case "ss":
|
return d.getSeconds().zf(2);
|
case "a/p":
|
return d.getHours() < 12 ? "오전" : "오후";
|
default:
|
return $1;
|
}
|
});
|
};
|
|
String.prototype.string = function (len) {
|
var s = '', i = 0;
|
while (i++ < len) {
|
s += this;
|
}
|
return s;
|
};
|
String.prototype.zf = function (len) {
|
return "0".string(len - this.length) + this;
|
};
|
Number.prototype.zf = function (len) {
|
return this.toString().zf(len);
|
};
|
|
var dateFormat = "";
|
var dynamicTime = false;
|
var today = new Date().format("yyyy-MM-dd");
|
var compareDate = new Date(date).format("yyyy-MM-dd");
|
|
if (today == compareDate) {
|
dynamicTime = true;
|
}
|
|
switch (formatType) {
|
case "01": // 날짜
|
dateFormat = "yyyy-MM-dd";
|
break;
|
case "02": // 날짜 + 시간
|
dateFormat = "yyyy-MM-dd HH:mm";
|
break;
|
case "03": // 유동적 표시
|
if (dynamicTime) {
|
dateFormat = "HH:mm";
|
}
|
else {
|
dateFormat = "yyyy-MM-dd HH:mm";
|
}
|
|
break;
|
}
|
|
return dateFormat;
|
}
|
}
|
}
|
}
|
});
|
});
|