diff --git a/src/main/java/com/itn/admin/itn/dictionary/mapper/DictionaryMapper.java b/src/main/java/com/itn/admin/itn/dictionary/mapper/DictionaryMapper.java index 3a08e82..3d41f27 100644 --- a/src/main/java/com/itn/admin/itn/dictionary/mapper/DictionaryMapper.java +++ b/src/main/java/com/itn/admin/itn/dictionary/mapper/DictionaryMapper.java @@ -11,4 +11,8 @@ public interface DictionaryMapper { List findAll(); void save(DictionaryVO dictionaryVO); + + void delete(DictionaryVO dictionaryVO); + + void insert(DictionaryVO dictionaryVO); } diff --git a/src/main/java/com/itn/admin/itn/dictionary/service/impl/DictionaryServiceImpl.java b/src/main/java/com/itn/admin/itn/dictionary/service/impl/DictionaryServiceImpl.java index 6e3fd67..897da09 100644 --- a/src/main/java/com/itn/admin/itn/dictionary/service/impl/DictionaryServiceImpl.java +++ b/src/main/java/com/itn/admin/itn/dictionary/service/impl/DictionaryServiceImpl.java @@ -33,15 +33,17 @@ public class DictionaryServiceImpl implements DictionaryService { Map data = (Map) dictionaryMap.get("data"); String action = (String) dictionaryMap.get("action"); + DictionaryVO dictionaryVO = getSingleDate(dictionaryMap); if("edit".equals(action)) { - DictionaryVO dictionaryVO = getSingleDate(dictionaryMap); System.out.println(dictionaryVO); dictionaryMapper.save(dictionaryVO); }else if("remove".equals(action)) { - List getMultiDate = getMultiDate(dictionaryMap); + System.out.println(dictionaryVO); + dictionaryMapper.delete(dictionaryVO); }else if("create".equals(action)) { - DictionaryVO dictionaryVO = getSingleDate(dictionaryMap); + System.out.println(dictionaryVO); + dictionaryMapper.insert(dictionaryVO); } } @@ -69,25 +71,5 @@ public class DictionaryServiceImpl implements DictionaryService { } - private static List getMultiDate(Map dictionaryMap) { - Map data = (Map) dictionaryMap.get("data"); - - List dictionaries = new ArrayList<>(); - - for (Map.Entry entry : data.entrySet()) { - Map dictionaryData = (Map) entry.getValue(); - DictionaryVO dictionary = new DictionaryVO(); - dictionary.setId(Long.parseLong(entry.getKey())); - dictionary.setEnglishWord((String) dictionaryData.get("englishWord")); - dictionary.setKoreanWord((String) dictionaryData.get("koreanWord")); - dictionary.setAbbreviation((String) dictionaryData.get("abbreviation")); - dictionary.setIsConfirmed((String) dictionaryData.get("isConfirmed")); - dictionary.setIsActive((String) dictionaryData.get("isActive")); - - dictionaries.add(dictionary); - } - return dictionaries; - } - } diff --git a/src/main/resources/mapper/itn/dictionary/DictionaryMapper.xml b/src/main/resources/mapper/itn/dictionary/DictionaryMapper.xml index b86f08f..504503c 100644 --- a/src/main/resources/mapper/itn/dictionary/DictionaryMapper.xml +++ b/src/main/resources/mapper/itn/dictionary/DictionaryMapper.xml @@ -46,4 +46,29 @@ + + DELETE FROM dictionary + WHERE id = #{id} + + + + insert into dictionary + ( + KOREAN_WORD + , ENGLISH_WORD + , ABBREVIATION + , IS_CONFIRMED + , FRST_REGIST_PNTTM + ) + values + ( + #{koreanWord} + , #{englishWord} + , #{abbreviation} + , #{isConfirmed} + , NOW() + ); + + + \ No newline at end of file diff --git a/src/main/resources/templates/dictionary/list.html b/src/main/resources/templates/dictionary/list.html index cbcb1e0..6210a49 100644 --- a/src/main/resources/templates/dictionary/list.html +++ b/src/main/resources/templates/dictionary/list.html @@ -20,6 +20,9 @@ border: none; color: inherit; } + .dtcenter { + text-align: center; + } @@ -61,7 +64,7 @@
-

목록

+

목록 - 클릭하면 수정 가능합니다.

@@ -137,39 +140,30 @@ }, idSrc: 'id', // 이렇게 `idSrc` 속성을 사용하여 식별자를 지정합니다. table: '#dicTb', - i18n: { - remove: { - title: '행 삭제 확인', - confirm: { - _: '선택하신 %d개의 행을 삭제하시겠습니까?', // 복수 행 삭제 시 메시지 - 1: '이 행을 삭제하시겠습니까?' // 단일 행 삭제 시 메시지 - } - } - }, formOptions: { inline: { onBlur: 'submit' } }, fields: [ - { - label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경 - name: 'id' - }, + // { + // label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경 + // name: 'id' + // }, { label: '한국어 단어:', // "koreanWord"의 레이블을 "한국어 단어"로 변경 - name: 'koreanWord' + name: 'koreanWord', attr: { required: 'required' } }, { label: '영어 단어:', // "englishWord"의 레이블을 "영어 단어"로 변경 - name: 'englishWord' + name: 'englishWord', attr: { required: 'required' } }, { label: '약어:', // "abbreviation"의 레이블을 "약어"로 변경 - name: 'abbreviation' + name: 'abbreviation', attr: { required: 'required' } }, { - label: '확인 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경 + label: '확정 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경 name: 'isConfirmed', type: 'select', options: [ @@ -192,12 +186,7 @@ dataSrc: '' }, columns: [ - // { - // data: 'id', - // orderable: false, - // render: DataTable.render.select() - // },, - { data: 'id' }, // ID 컬럼을 추가하고 숨깁니다. + { data: 'id' }, { data: null, className: 'dt-center editor-delete', @@ -224,29 +213,69 @@ ] } }, - order: [1, 'asc'], + order: [0, 'asc'], select: { style: 'os', selector: 'td:first-child' } }); - $('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) { - editor.inline(this); - }); - editor.on('submitSuccess', function() { - // editor.DataTable().destroy(); - table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드 - }); - - // Delete a record - table.on('click', 'td.editor-delete button', function (e) { - editor.remove(e.target.closest('tr'), { - title: 'Delete record', - message: 'Are you sure you wish to remove this record?', - buttons: 'Delete' + // 필드 클릭해서 수정할수 있는 옵션 + $('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) { + editor.inline(this); + }); + editor.on('submitSuccess', function() { + // editor.DataTable().destroy(); + table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드 + }); + + // 삭제 버튼 클릭 이벤트 + table.on('click', 'td.editor-delete button', function (e) { + var tr = $(this).closest('tr'); + var row = table.row(tr).data(); + + var message = '"' + row.koreanWord + '" (' + row.englishWord + ') 삭제 하시겠습니까?'; + editor.message(message); + + editor.remove(tr, { + title: 'Delete record', + message: message, // 직접 메시지 전달 + buttons: 'Delete' + }); + }); + + // 데이터 제출 전에 유효성 검사 수행 + editor.on('preSubmit', function (e, data, action) { + + if(action == 'create'){ + + var error = false; + var errorMsg = ''; + + // Loop through all the data items + for (var key in data.data) { + var entry = data.data[key]; + + // Validate Korean Word + if (!entry.koreanWord || entry.koreanWord.trim() === '') { + error = true; + errorMsg += '한국어 단어를 입력해주세요.\n'; + }else if (!entry.englishWord || entry.englishWord.trim() === '') { + error = true; + errorMsg += '영어 단어를 입력해주세요.\n'; + }else if (!entry.abbreviation || entry.abbreviation.trim() === '') { + error = true; + errorMsg += '약어를 입력해주세요.\n'; + } + } + + // If any error was detected, prevent submission and display the error message + if (error) { + this.error(errorMsg); + return false; // prevent submission + } + } }); - });