main-pwd-change-pop-up.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const _apiUri = '/api/database/user-infr/pswd';
  2. const columns = [
  3. 'id', 'old_pwd', 'pwd', 'check-pwd'
  4. ];
  5. const textArr = [
  6. 'ID', '기존 비밀번호', '신규 비밀번호', '신규 비밀번호 확인',
  7. ];
  8. const inputMap = new Map();
  9. $(()=>{
  10. for (let idx in columns) {
  11. let column = columns[idx];
  12. let box = $('.' + column).dxTextBox({
  13. stylingMode: 'outlined',
  14. width: 220,
  15. height: 27,
  16. }).dxTextBox('instance');
  17. if(column !== 'id') {
  18. box.option('placeholder', textArr[idx]);
  19. box.option('mode', 'password');
  20. }
  21. inputMap.set(column, new Map());
  22. inputMap.get(column).set('box', box);
  23. inputMap.get(column).set('text', textArr[idx]);
  24. inputMap.get(column).get('box').on('keyDown', ()=>{
  25. $('.' + column + '-text').css('display', 'none');
  26. })
  27. }
  28. //ID로 대체
  29. setValue(inputMap.get('id').get('box'), window.opener.$userId);
  30. inputMap.get('id').get('box').option('readOnly', true);
  31. creatBtn($('.save-btn'), 'save', '저장', '저장', 'outlined', changePwd);
  32. creatBtn($('.cancel-btn'), 'close', '취소', '취소', 'outlined', ()=>{window.close()});
  33. })
  34. function changePwd(ev){
  35. let data = [];
  36. let cnt = 0;
  37. inputMap.forEach((obj, key)=>{
  38. if (nullChecker(getValue(obj.get('box'))) === '') {
  39. $('.' + key + '-text').css('display', 'flex');
  40. if(key === 'old_pwd' || key === 'check-pwd'){
  41. $('.' + key + '-null').css('display', 'block');
  42. $('.' + key + '-error').css('display', 'none');
  43. }
  44. obj.get('box').focus();
  45. cnt++;
  46. }
  47. });
  48. if (cnt > 0) return;
  49. getData('/api/database/user-infr/' + getValue(inputMap.get('id').get('box')), data);
  50. if (data[0]){
  51. if (getValue(inputMap.get('old_pwd').get('box')) === data[0].pwd){
  52. if (getValue(inputMap.get('pwd').get('box')) === getValue(inputMap.get('check-pwd').get('box'))){
  53. let param = {
  54. old_pwd: getValue(inputMap.get('old_pwd').get('box')),
  55. pwd : getValue(inputMap.get('pwd').get('box')),
  56. }
  57. let result = putUpdate(_apiUri + '/' + getValue(inputMap.get('id').get('box')), param);
  58. if (result > 0) {
  59. $('.blue').css('display', 'flex');
  60. setValue(inputMap.get('old_pwd').get('box'), null);
  61. setValue(inputMap.get('pwd').get('box'), null);
  62. setValue(inputMap.get('check-pwd').get('box'), null);
  63. let timeOut = setTimeout(() => {
  64. $('.blue').css('display', 'none');
  65. clearTimeout(timeOut);
  66. }, 5000);
  67. }
  68. }
  69. else {
  70. $('.check-pwd-text').css('display', 'flex');
  71. $('.check-pwd-null').css('display', 'none');
  72. $('.check-pwd-error').css('display', 'block');
  73. inputMap.get('check-pwd').get('box').focus();
  74. }
  75. }
  76. else {
  77. $('.old_pwd-text').css('display', 'flex');
  78. $('.old_pwd-null').css('display', 'none');
  79. $('.old_pwd-error').css('display', 'block');
  80. inputMap.get('old_pwd').get('box').focus();
  81. }
  82. }
  83. }