소스 파일 : /yoyak/yoyak_editor.js (2018-06-11)     소스 설명 : (분류요약관리) 요약관리 편집자용 javascript/jquery
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// (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);
						}
					});
				}
			}
		);


});


Copyrightⓒ written by 차재복 (Cha Jae Bok)
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"