// (2018.6.11, 차재복, Cha Jae Bok, http://www.ktword.co.kr)
// (jQuery) 항목 (타이틀편집/상향이동/하향이동/삭제/생성) 관리
$( function () {
// 항목 편집(.more) 클릭하면, 하부에 편집 div 나타남
$(document).on("click", ".more",
function(event) {
// a 링크 디폴트 이벤트 방지
event.preventDefault();
// 해당 id가 아닌 것들에 대해 선택적 숨김,보임
var id = $(this).data('id'),
no = $(this).data('no');
if (no) {
// edit 클릭시, 해당 no의 toggleClass
$('.more[data-id='+id+'][data-no='+no+']').toggleClass('toggleBold');
// 해당 no인 것 만 토글
$('.more_sub[data-id='+id+'][data-no='+no+']').toggle();
// 해당 no가 아닌 것들은 hide
$('.more_sub').not('[data-id='+id+'][data-no='+no+']').hide();
} else {
// edit 클릭시, 해당 id의 toggleClass
$('.more[data-id='+id+'][data-no='+no+']').toggleClass('toggleBold');
// 해당 id인 것 만 토글
$('.more_sub[data-id='+id+'][data-no='+no+']').toggle();
// 해당 id가 아닌 것들은 hide
$('.more_sub').not('[data-id='+id+'][data-no='+no+']').hide();
}
}
);
// 노드생성(.node_gen) 누르면, 하부에 나타남
$(document).on("click", ".gen_node",
function(event) {
// a 링크 디폴트 이벤트 방지
event.preventDefault();
var act = $(this).data('act'),
id = $(this).data('id'),
no = $(this).data('no');
// toggleClass
$(this).toggleClass('toggleBold');
// .title_gen 토글
$('.more_gen[data-id='+id+'][data-no='+no+']').toggle();
// .title_gen 중 해당 id가 아닌 것들은 hide
$('.more_gen').not('[data-id='+id+']').hide();
}
);
// .submit 버튼 누르면, update ajax 호출 (타이틀편집/상향이동/하향이동/삭제/생성)
$(document).on("click", ".submit",
function(event) {
// a 링크 디폴트 이벤트 방지
event.preventDefault();
// 지역변수 선언
var id = $(this).data('id'),
no = $(this).data('no'),
act = $(this).data('act'),
str = $(this).prevAll('input').val(),
sub_cnt = $(this).data('sub_cnt'),
user_type = $('#contents_table').data('user_type'),
confirmed = true;
if (user_type=='일반사용자') {
alert("편집 권한 없음");
return;
}
// 삭제 경고
if (act == 'id_delete' || act == 'no_delete') {
if (sub_cnt > 0) {
alert("자식 노드 있으므로 삭제 불가");
return;
} else {
confirmed = confirm("삭제 대상 : "+$(this).data('title'));
}
}
// id_up,id_down,no_up,no_down 일 경우에, 경고창 없이 바로 수행
if (act != 'id_up' && act != 'id_down' && act != 'no_up' && act != 'no_down') {
confirmed = confirm('id='+id+', no='+no+', act='+act+', str='+str);
}
if (confirmed) {
$.ajax ({
type : 'POST',
url : 'yoyak_update_ajax.php',
data : { 'id' : id, 'no' : no, 'act' : act, 'str' : str },
success : function(result){
$('#test_div').html(result); // 테스트용 화면 출력
window.location = 'yoyak.php?id='+id;
},
error : function(request, status, error ) {
console.log ("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
}
});
}
}
);
// .submit 버튼 누르면, update ajax 호출 (타이틀편집/상향이동/하향이동/삭제/생성)
$(document).on("click", ".gen_no_node",
function(event) {
// 지역변수 선언
var id = $(this).data('id'),
no = $(this).data('no');
// .no_edit 토글
$('.no_edit[data-id='+id+'][data-no='+no+']').toggle();
}
);
});
// (jQuery) 항목 Move 선택 및 우측 화면 관리
$( function () {
// 노드이동(.move_node) 버튼 `M` 누르면, 우측 창에 목록이 펼쳐 나타남
$(document).on("click", ".move_node",
function(event) {
// a 링크 디폴트 이벤트 방지
event.preventDefault();
var title = $(this).data('title'),
id = $(this).data('id'),
no = $(this).data('no');
// 선택된 항목 만을 Bold
// $(this).css('font-weight','bold');
$('.move_node[data-id='+id+']').css('font-weight','bold');
$('.move_node').not('[data-id='+id+']').css('font-weight','normal');
// 선택된 id 하부 no들 만 show하고, 우측 창 source를 초기화(빈 no 값 전달)
$('.checkbox[name='+id+']').prop('checked',false).toggle();
$('.checkbox').not('[name='+id+']').hide();
$('#source').data('no','');
// td#contents_right에 해당 내용 기록
$('#contents_right').data('id',id);
$('#contents_right').data('title',title);
// 이미 우측 화면 켜 있으면, #source에 해당 내용 만 복사
if( $('#contents_right').is(':visible') ) {
$('#source').text('"'+title+'"('+id+')');
$('#source').data('id',id);
return;
}
// 우측 화면 show
$('#contents_right').show();
$.ajax ({
type : 'POST',
url : './yoyak_contents_right_ajax.php',
data : { 'id' : id, 'win' : 'right' },
success : function(result){
// $('#contents_right').html(result);
$('#contents_right_down').html(result);
// #source에 타이틀,번호 등 표출
$('#source').text('"'+title+'"');
$('#source').data('id',id);
$('.no_move_submit').prop('disabled', true);
},
error : function(request, status, error ) {
console.log ("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
}
});
}
);
// 좌측 창내 용어항목들을 그룹으로 선택
$(document).on('click', '.checkbox',
function(event) {
var title = $(this).data("title"),
id = $(this).data('id'),
no = $(this).data('no'),
no_list = $('#source').data('no');
// if ($(this).is(':checked')) {
// alert('title='+title+', id='+id+', no='+no+', no_list='+no_list);
// }
// (직전이동,직후이동,자식이동),(지정,변경) 버튼 active
$('.id_move_submit').prop('disabled', true);
$('.no_move_submit').prop('disabled', false);
// 현재 #source 내 검토
new_no_list = no_list.split(','); // 현재 #source 내 no list
pos = new_no_list.indexOf( '' + no ); // 형 변환 후(int=>str), 배열 내 해당 위치를 찾음
if (new_no_list[0]=='') { // 최초
new_no_list.splice(0,1,no);
// new_str_list.splice(0,1,str);
} else if ( pos >= 0 ) { // 배열 내 존재
new_no_list.splice(pos,1);
// new_str_list.splice(pos,1);
} else { // 배열 내 없음
new_no_list.push(no);
// new_str_list.push(str);
}
var cur_no_list = new_no_list.join(',');
$('#source').data('no', cur_no_list ); // no_list를 우측 #source에 기록
$('#source').text('('+cur_no_list+')'); // no_list를 우측 #source에서 보여줌
}
);
// 우측 창내 분류항목 선택
$(document).on('click', '.right_choice',
function(event) {
// a 링크 디폴트 이벤트 방지
event.preventDefault();
var title = $(this).data('title'),
id = $(this).data('id'),
no = $('#source').data('no');
// 우측 상단에 선택 항목 타이틀(id) 보여줌
$('#target').text('"'+title+'"');
$('#target').data('id',id);
// 선택된 항목 만을 색깔을 red
$(this).css('color','red');
$('.right_choice').not('[data-id='+id+']').css('color','black');
// (지정,변경) 버튼 active
if (no) {
$('.no_move_submit').prop('disabled', false);
}
}
);
// 우측 창 상단에 있는 지정,변경 버튼의 활성화를 위한 이벤트 체킹
// $(document).ready(function(){
// }
// 우측 창 닫기
$(document).on('click', '#contents_right_off',
function(event) {
$('#contents_right').hide();
$('.checkbox').hide();
$('.move_node').css('font-weight','normal');
}
);
// (.id_move_submit)(직후이동/직전이동/자식이동/지정/변경) 버튼 누르면, update ajax 호출
$(document).on("click", ".id_move_submit, .no_move_submit",
function(event) {
var sid = $('#source').data('id'),
tid = $('#target').data('id'),
no = $(this).data('no'),
no_list = $('#source').data('no'),
act = $(this).data('act'),
str = $(this).prevAll('input').val(),
sub_cnt = $(this).data('sub_cnt'),
user_type = $('#contents_table').data('user_type');
if (user_type=='일반사용자') {
alert("편집 권한 없음");
return;
}
var confirmed = confirm('id='+sid+', tid='+tid+', no='+no+', no-list='+no_list+', act='+act+', str='+str);
if (confirmed) {
$.ajax ({
type : 'POST',
url : 'yoyak_update_ajax.php',
data : { 'id' : sid, 'tid' : tid, 'no' : no, 'no_list' : no_list, 'act' : act, 'str' : str },
success : function(result){
console.log(result);
$('#test_div').html(result); // 테스트용 화면 출력
window.location = 'yoyak.php?id='+tid;
},
error : function(request, status, error ) {
console.log ("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
}
});
}
}
);
});