eb_threads.scrap.v1


list.blade.php

@if($is_logged)
    @php
       $oDB = DB::getInstance();

       // 스크랩 카운트를 가져오는 쿼리 실행 => $scrap_count
       $query = 'SELECT count(*) AS count FROM member_scrap WHERE document_srl = ?';
       $stmt = $oDB->query($query, $document->document_srl);
       $result = $stmt->fetchAll();
       $scrapped_count = $result[0]->count;

       // 스크랩 회원 리스트를 가져오는 쿼리 실행 => $scrap_member_list
       $member_columns = preg_filter('/^/', 'member.', ['member_srl', 'user_id', 'email_address', 'phone_number', 'user_name', 'nick_name', 'extra_vars']);
       $query = 'SELECT '. implode(',', $member_columns) .' FROM member_scrap LEFT JOIN member ON member_scrap.member_srl = member.member_srl WHERE member_scrap.document_srl = ?';
       $stmt = $oDB->query($query, $document->document_srl);
       $result = $stmt->fetchAll();
       $scrap_member_list = $result;
    @endphp
    @if($scrapped_count > 0)
       <a href="javascript:;" onclick="doDeleteScrap('{$document->document_srl}'); return false;" class="cnt-box"><i class="scrap-fill"></i></a>
    @else
       <a href="javascript:;" onclick="doScrap('{$document->document_srl}'); return false;" class="cnt-box"><i class="scrap"></i></a>
    @endif
@endif


script.js

function doDeleteScrap(document_srl) {
    saveScrollPosition(); // 스크롤 위치 저장
    shouldRestoreScroll = true; // 스크롤 복원을 활성화
    var params = [];
    params['document_srl'] = document_srl;
    exec_json(
       'member.procMemberDeleteScrap',
       params,
       function () {
       location.reload();
       },
       function(response){
          console.log(response);
          return false;
       });
}

function doScrap(document_srl) {
    saveScrollPosition(); // 스크롤 위치 저장
    shouldRestoreScroll = true; // 스크롤 복원을 활성화
    var params = [];
    params.document_srl = document_srl;
    exec_json(
       'member.procMemberScrapDocument',
       params,
       function () {
       location.reload();
       },
       function(response){
          console.log(response);
          if(response.error=='-1'){
             // const mid = window.location.pathname;
             const mid = window.location.pathname.replace(/^\/(.*)\/$/, '/$1');
             // console.log(mid);
             // window.location.href = mid + '/login';
             window.location.href = mid + '/?act=dispMemberLoginForm';
             return false;
          }
       });
}
1