lib.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. $(document).on('keydown','.decimal', function (event) {
  2. handleEnterPressedinNormalCell(event, function() {})
  3. }).on('focusout','.decimal', function () {
  4. $(this).val(format_decimal(minusComma($(this).val()), $(this).data('point')))
  5. });
  6. const CheckDecimal = x => {
  7. const realStringObj = obj && obj.toString();
  8. if (!jQuery.isArray(obj) && (realStringObj - parseFloat(realStringObj) + 1) >= 0) return false;
  9. const parts = x.toString().split(".");
  10. parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  11. return parts.join(".");
  12. }
  13. const CheckMail = email => {
  14. const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  15. const result = re.test(String(email).toLowerCase());
  16. // !result && alert('Email is invalid !!!', 'error');
  17. return result;
  18. }
  19. const CheckNum = input => !isNaN(input);
  20. const LenCheck = (input, length) => {
  21. return input.length <= length;
  22. }
  23. const CheckMinMax = (elm, min, max) => {
  24. const length = $(elm).val().length;
  25. if (length < min || length > max) {
  26. $(elm).empty();
  27. $(elm).focus();
  28. }
  29. }
  30. function isEmptyArr(arr) {
  31. if(Array.isArray(arr) && arr.length === 0) {
  32. return true;
  33. }
  34. return false;
  35. }
  36. const CheckSSN = ssn => {
  37. const ssnPattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;
  38. return ssnPattern.test(ssn);
  39. }
  40. const CheckRequired = inputList => {
  41. inputList.forEach(item => {
  42. const value = item.val();
  43. if (value == null || value == '' || value == undefined) {
  44. alert(`${item.data('name')} is required !!!`, 'error');
  45. return false;
  46. }
  47. })
  48. };
  49. const ComfirmPasswd = (pass, confirmPass) => pass === confirmPass;
  50. const DisableInput = elm => $(elm).prop('disabled', function (i, v) {
  51. return !v;
  52. });
  53. const BlinkObject = elm => {
  54. $(elm).fadeOut('slow', function () {
  55. $(this).fadeIn('slow', function () {
  56. BlinkObject(this);
  57. });
  58. });
  59. }
  60. const InitCheckBox = (data, name) => {
  61. let html = '';
  62. data.forEach(item => {
  63. html += `<input type="checkbox" name="${name}" value="${item}"> ${item}`;
  64. });
  65. return html;
  66. }
  67. const InitRadio = (data, name) => {
  68. let html = '';
  69. data.forEach(item => {
  70. html += `<input type="radio" name="${name}" value="${item}"> ${item}`;
  71. });
  72. return html;
  73. }
  74. const InitSelect = (data, name) => `<select name="${name}">${ArrayToOption(data)}</select>`;
  75. const ArrayToOption = array => {
  76. let html = '';
  77. array.forEach(item => {
  78. html += `<option value="${item}">${item}</option>`
  79. });
  80. return html;
  81. }
  82. function commaCheck($this) {
  83. $($this).val(function (index, value) {
  84. value = value.replace(/,/g, '');
  85. return numberWithCommas(value);
  86. });
  87. }
  88. function minusComma(value) {
  89. let formNumber = "" + value;
  90. // 문자제거
  91. // value = formNumber.toString().replace(/[^\d]+/g, "");
  92. // 콤마제거
  93. value = formNumber.toString().replace(/,/g, "");
  94. return value;
  95. }
  96. function rand(min, max) {
  97. return Math.floor(Math.random() * (max - min)) + min;
  98. }
  99. function format_decimal(val, number) {
  100. let format = decimal_convert(number);
  101. return numeral(parseFloat(val).toFixed(number)).format(format);
  102. }
  103. function fill_zero(width, str) {
  104. return (str.length && width > 0) ? str + '.' + new Array(width + 1).join('0') : str;
  105. }
  106. function decimal_convert(point_name) {
  107. return fill_zero(parseInt(point_name), '0,0')
  108. }
  109. function remove_tag( html ) {
  110. return html.replace(/(<([^>]+)>)/gi, "");
  111. }
  112. function is_localhost() {
  113. if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') {
  114. return true
  115. }
  116. return false
  117. }
  118. function get_clusterize_rows_in_block() {
  119. return 10
  120. // return is_localhost() ? 10 : 10
  121. }
  122. function remove_comma_and_arithmetic(a, b, type) {
  123. switch (type) {
  124. case 'plus':
  125. return Number(minusComma(a)) + Number(minusComma(b))
  126. case 'minus':
  127. return Number(minusComma(a)) - Number(minusComma(b))
  128. }
  129. }
  130. function format_conver_for(data, format, display_vars = undefined) {
  131. let result = data;
  132. switch (format) {
  133. case 'YYYY-MM-DD': case 'YYYY.MM.DD': case 'YYYYMMDD':
  134. case 'YY-MM-DD': case 'YY.MM.DD': case 'YYMMDD':
  135. case 'yy-mm-dd': case 'yy.mm.dd': case 'yymmdd':
  136. result = isEmpty(data) ? '' : moment(data).format(format.toUpperCase());
  137. break;
  138. case 'unixtime':
  139. result = isEmpty(data) ? '' : moment(new Date(data * 1000)).format('YYYY-MM-DD HH:mm:ss');
  140. break;
  141. case 'unix-yyyy.mm.dd':
  142. result = isEmpty(data) ? '' : moment(new Date(data * 1000)).format('YYYY-MM-DD');
  143. break;
  144. case '$_ThumbNail':
  145. result = `<img src="${window.env['MEDIA_URL'] + data}" width="${display_vars['ListWidth']}" height="${display_vars['ListHeight']}" style="max-width: 100%;" onerror="this.src='/images/folder.jpg'"`;
  146. break;
  147. case '$_FileName':
  148. let path_list = data.split('/')
  149. result = path_list[path_list.length - 1];
  150. break;
  151. case 'check':
  152. if (data == 1 || data == true) {
  153. result = '√';
  154. } else {
  155. result = '';
  156. }
  157. break;
  158. case 'unique':
  159. result = data.split("'").join('');
  160. break;
  161. case 'date_month':
  162. result = isEmpty(data) ? '' : moment(data).format('YY.MM');
  163. break;
  164. case 'date_week':
  165. result = isEmpty(data) ? '' : `${moment(data).format('YY.MM')}-${moment(data).isoWeek()}`;
  166. break;
  167. case 'remove_tag':
  168. result = remove_tag(data);
  169. break;
  170. default:
  171. if (! isEmpty(format) && format.match(/[A-Za-z]+\s*\(\s*'(.*?)\'\s*\)\s*/)) {
  172. const func_name = format.replace(')', `, '${data}')`);
  173. try {
  174. result = eval(`format_func_${func_name}`);
  175. } catch (err) {
  176. result = 'Invalid';
  177. }
  178. }
  179. break;
  180. }
  181. return result;
  182. }
  183. function format_func_decimal(...argv) {
  184. const format = capitalize(camelCase(argv[0])) + 'Point';
  185. let data;
  186. if (window.User[format] == undefined) {
  187. return 'Invalid';
  188. }
  189. switch (argv.length) {
  190. case 2:
  191. data = format_decimal(argv[1], window.User[format]);
  192. break;
  193. case 3:
  194. data = format_decimal(argv[2], window.User[format])
  195. if (argv[1] === 'nz' && (isEmpty(data) || data == 0)) { data = 0; }
  196. else if (argv[1] === 'zn' && (isEmpty(data) || data == 0)) { data = ''; }
  197. break;
  198. }
  199. return data;
  200. }
  201. function format_func_status_update(value, data) {
  202. return { Field: 'Status', Value: format_func_status_rev(value, data), };
  203. }
  204. function format_func_status_code_update(value, data) {
  205. return { Field: 'Status', Value: data, };
  206. }
  207. function format_func_status_rev(value, data) {
  208. const status = Object.values(window.CodeTitle['status'][value]).filter(status => status.Title == data)
  209. if (isEmptyArr(status)) { return data; }
  210. return _.first(status)['Code'];
  211. }
  212. function format_func_status(value, data) {
  213. if (window.CodeTitle['status'] && window.CodeTitle['status'][value][data]) {
  214. return window.CodeTitle['status'][value][data]['Title'];
  215. }
  216. return 'Invalid';
  217. }
  218. function format_func_sort_update(value, data) {
  219. return { Field: 'Sort', Value: format_func_sort_rev(value, data), };
  220. }
  221. function format_func_sort_code_update(value, data) {
  222. return { Field: 'Sort', Value: data, };
  223. }
  224. function format_func_sort_rev(value, data) {
  225. const sort = Object.values(window.CodeTitle['sort'][value]).filter(sort => sort.Title == data)
  226. if (isEmptyArr(sort)) { return data; }
  227. return _.first(sort)['Code'];
  228. }
  229. function format_func_sort(value, data) {
  230. if (window.CodeTitle['sort'] && window.CodeTitle['sort'][value][data]) {
  231. return window.CodeTitle['sort'][value][data]['Title'];
  232. }
  233. return 'Invalid';
  234. }
  235. function format_func_deal_type_update(value, data) {
  236. return { Field: 'DealType', Value: format_func_deal_type_rev(value, data), };
  237. }
  238. function format_func_deal_type_rev(value, data) {
  239. const deal_type = Object.values(window.CodeTitle['deal-type'][value]).filter(deal_type => deal_type.Title == data)
  240. if (isEmptyArr(deal_type)) { return data; }
  241. return _.first(deal_type)['Code'];
  242. }
  243. function format_func_deal_type(value, data) {
  244. if (window.CodeTitle['deal-type'] && window.CodeTitle['deal-type'][value][data]) {
  245. return window.CodeTitle['deal-type'][value][data]['Title'];
  246. }
  247. return 'Invalid';
  248. }
  249. function format_func_paymethod_rev(value, data) {
  250. const paymethod = Object.values(window.CodeTitle['paymethod'][value]).filter(paymethod => paymethod.Title == data)
  251. if (isEmptyArr(paymethod)) { return data; }
  252. return _.first(paymethod)['Code'];
  253. }
  254. function format_func_paymethod(value, data) {
  255. if (window.CodeTitle['paymethod'] && window.CodeTitle['paymethod'][value][data]) {
  256. return window.CodeTitle['paymethod'][value][data]['Title'];
  257. }
  258. return 'Invalid';
  259. }
  260. function format_func_situation_rev(value, data) {
  261. const situation = Object.values(window.CodeTitle['situation'][value]).filter(situation => situation.Title == data)
  262. if (isEmptyArr(situation)) { return data; }
  263. return _.first(situation)['Code'];
  264. }
  265. function format_func_situation(value, data) {
  266. if (window.CodeTitle['situation'] && window.CodeTitle['situation'][value][data]) {
  267. return window.CodeTitle['situation'][value][data]['Title'];
  268. }
  269. return 'Invalid';
  270. }
  271. function check_dom_input_number(dom_array) {
  272. let arr = dom_array.filter(el => isNaN($(el).val()))
  273. arr.forEach(el => $(el).val('') );
  274. if (! isEmptyArr(arr)) {
  275. iziToast.error({
  276. title: 'Error',
  277. message: $('#please-enter-a-number').text(),
  278. });
  279. return true;
  280. }
  281. return false;
  282. }
  283. function show_iziToast_msg(page, callback = undefined) {
  284. if (page) {
  285. iziToast.success({
  286. title: 'Success',
  287. message: $('#action-completed').text(),
  288. });
  289. if (! isEmpty(callback)) {
  290. callback()
  291. }
  292. } else {
  293. iziToast.error({
  294. title: 'Error',
  295. message: page.data.body ?? $('#api-request-failed-please-check').text(),
  296. });
  297. }
  298. }
  299. function token_value(balance, unit_point, decimal_point) {
  300. if (decimal_point === -1) {
  301. return balance / (10 ** unit_point)
  302. }
  303. return format_decimal(balance / (10 ** unit_point), decimal_point)
  304. }
  305. function token_value_rev(balance, unit_point) {
  306. // return balance + '0'.repeat(unit_point);
  307. return String(balance * (10 ** unit_point))
  308. }
  309. function long_number_string(n){
  310. var str, str2= '', data= n.toExponential().replace('.','').split(/e/i);
  311. str= data[0], mag= Number(data[1]);
  312. if(mag>=0 && str.length> mag){
  313. mag+=1;
  314. if (isEmpty(str.substring(mag))) { return str.substring(0, mag) }
  315. return (str.substring(0, mag)+'.'+str.substring(mag));
  316. }
  317. if(mag<0){
  318. while(++mag) str2+= '0';
  319. return '0.'+str2+str;
  320. }
  321. mag= (mag-str.length)+1;
  322. while(mag> str2.length){
  323. str2+= '0';
  324. }
  325. return (str+str2);
  326. }
  327. // 현재 value 값이 소수점 n 자리 숫자라면 더 이상 입력 X
  328. function check_number_of_decimal_places(val, n) {
  329. // const _pattern1 = /^\d*[.]\d{16}$/
  330. const _pattern1 = new RegExp(`^\\d*[.]\\d{${n}}$`, 'g')
  331. return !_pattern1.test(val)
  332. }
  333. function is_mobile() {
  334. var user = navigator.userAgent;
  335. var is_mobile = false;
  336. if( user.indexOf("iPhone") > -1
  337. || user.indexOf("Android") > -1
  338. || user.indexOf("iPad") > -1
  339. || user.indexOf("iPod") > -1
  340. ) {
  341. is_mobile = true;
  342. }
  343. return is_mobile;
  344. }