var page = 1, maxPage = 0, pageCount = 0, pagingCount = 10, maxLine = 10; var isType = ''; var searchText = ''; function init(){ page = $('#page').val() == 'exit'? 1 : Number($('#page').val()); searchText = $('#search').val() == 'exit'? '' : $('#search').val(); isType = searchText == ''? 'list' : 'search'; setNoticeList(isType); isCheckMoveBtn(); } function isCheckMoveBtn(){ if(page == 1){ $('.prev').addClass('hide'); $('.prev-end').addClass('hide'); } else{ $('.prev').removeClass('hide'); $('.prev-end').removeClass('hide'); } if(page == maxPage){ $('.next').addClass('hide'); $('.next-end').addClass('hide'); }else{ $('.next').removeClass('hide'); $('.next-end').removeClass('hide'); } } function setNoticeList(type){ let res = ''; let Mlist = ''; let endCount = pagingCount; let limitStartPage = (page - 1) * pagingCount; if(type == 'list'){ res = HttpPostJson('/Notice/getItgoNoticeList',{ limit_start_page : limitStartPage, paging_count : pagingCount }); }else if(type == 'search'){ res = HttpPostJson('/Notice/getItgoTitleSearch',{ title : searchText, limit_start_page : limitStartPage, paging_count : pagingCount }); } if(res.result){ if(res.list.length < pagingCount){ endCount = res.list.length; } for(let c = 0; c < endCount; c++){ let value = res.list[c]; Mlist += '' + '' + value.idx + '' + '' + value.title + '' + '' + value.reg_date.substr(0, 10) + '' + ''; } $('.itgo-notice-table > tbody').html(Mlist); } if(type == 'list'){ res = HttpPostJson('/Notice/getItgoNoticeCount'); }else if(type == 'search'){ res = HttpPostJson('/Notice/getItgoNoticeSearchCount', { title : searchText }); } pageCount = res.list['count']; maxPage = parseInt(pageCount/pagingCount) + 1; let startCount = parseInt((page - 1) / maxLine) * maxLine + 1; endCount = startCount + maxLine - 1; if(endCount > maxPage){ endCount = maxPage; } Mlist = ''; for(let pg = startCount; pg <= endCount; pg++){ let pageColor = (pg == page)? 'black-page' : 'gray-page'; Mlist += '' + pg + ''; } $('.itgo-notice-page-nation-tag > a').remove(); $('.prev').after(Mlist); isCheckMoveBtn(); } $(function(){ init(); $('.itgo-notice-table').on('click', '.table-tr', function(){ let el = $(this); let idx = el.children().eq(0).html(); location.href = '/Notice/view?idx=' + idx; }); $('#itgo-notice-search-text').keyup(function(e){ if(e.keyCode == 13){ $('.img-search').click(); } }); $('.img-search').click(function(){ let keyText = $('#itgo-notice-search-text').val(); if(keyText == ''){ isType = 'list'; location.href = '/Notice/board'; return; } const res = HttpPostJson('/Notice/checkItgoTitleSearch', { title : keyText }); if(res.list['count'] > 0){ searchText = keyText; isType = 'search'; page = 1; setNoticeList('search'); $('.search-msg').html('검색 하신 결과가 총 ' + res.list['count'] + ' 개 입니다.'); }else{ $('.search-msg').html('검색 하신 결과가 없습니다.'); } }); $('.itgo-notice-page-nation-tag').on('click', '.reset-btn, .prev-end, .prev, .next, .next-end', function(){ var cls = $(this)[0].classList[0]; if(cls == 'reset-btn'){ location.href = '/Notice/board'; }else if(cls == 'prev'){ page--; setNoticeList(isType); }else if(cls == 'prev-end'){ page = 1; setNoticeList(isType); }else if(cls == 'next'){ page++; setNoticeList(isType); }else if(cls == 'next-end'){ page = maxPage; setNoticeList(isType); } }); });