comparison develop/views/Extractapp/TaggingText.php @ 36:e078e1500cc2 extractapp

config for localgazetteers-dev
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 06 Mar 2015 14:13:18 +0100
parents
children 8347776a44fc
comparison
equal deleted inserted replaced
35:04736430d961 36:e078e1500cc2
1 <?php
2 // --- initialize config file and input text ---
3 $stringInput = $viewmodel['stringInput'];
4 $wordlistArray = $viewmodel['wordlistArray'];
5 $taglistArray = $viewmodel['taglistArray'];
6 $section_id = $viewmodel['section_id'];
7 $topiclistArray = $viewmodel['topiclistArray'];
8 $default_topic_id = $viewmodel['default_topic_id'];
9 $topic_name = $viewmodel['topic_name'];
10 $topic_tag = $viewmodel['topic_tag'];
11 $info = $viewmodel['info'];
12 $messages = $viewmodel['messages'];
13
14
15 ?>
16
17 <html>
18 <head>
19 <title></title>
20
21 <style>
22 dynasty
23 {
24 color:red;
25 }
26 nianhao
27 {
28 color:blue;
29 }
30 name
31 {
32 color:orange;
33 }
34 #editable-area {
35 line-height:160%;
36 letter-spacing:1.5px;
37 font-size:21px;
38 }
39
40
41 <?php
42 // color on the tags
43 foreach ( $taglistArray as $taglistValue ) {
44 echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n";
45
46 echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n";
47 }
48
49 ?>
50 </style>
51
52
53 </head>
54
55 <body>
56
57 <script type="text/javascript">
58
59 // === This is only for developing on local machine ====
60 var _GET = JSON.parse('<?php echo json_encode($_GET) ?>');
61 if (_GET['id']) {
62
63 var info = JSON.parse('<?php echo json_encode($info) ?>');
64 var redirectUrl = "http://localhost:1080/localmonographs/develop/Extractapp/TaggingText";
65 var section_id = info['section_id'];
66
67 var form = $('<form action="' + redirectUrl + '" method="post">' +
68 '<input type="hidden" name="sectionId" value="'+section_id+'" />' +
69 '</form>');
70 $('body').append(form);
71 $(form).submit();
72 }
73 // ====
74
75
76
77 // TODO: Popup to proceeding the saving situations
78 function handleFileVersionConflict() {
79 var info = JSON.parse('<?php echo json_encode($info) ?>');
80 console.log("currentFileId="+info['current_fileId']);
81
82 if (info['current_fileId'] != 0 && info['current_fileId'] != info['file_id']){
83 // -- there might be conflicts between different version
84 var retVal = confirm('There were something happened/someone editing in the between of time.\nDo you want to force saving? (There might be conflicts between two versions.)');
85 if( retVal == true ){
86 // TODO: force saving with currentFileId
87 alert("You do the force saving!");
88 //saveTextToLGService();
89
90 }else{
91 var loadLastest = confirm("Do you want to reload for the lastest version? (Your current editing will lost.)");
92
93 console.log("loadLastest="+loadLastest);
94 /*
95 var form = document.createElement("form");
96 form.setAttribute("method", "post");
97 form.setAttribute("action", "./TaggingText"); // hand to controller
98 form.setAttribute("target", "_blank");
99
100 var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
101
102 var hiddenField = document.createElement("input");
103 hiddenField.setAttribute("name", "topic");
104 hiddenField.setAttribute("value", topic_id);
105 form.appendChild(hiddenField);
106
107 var hiddenField = document.createElement("input");
108 hiddenField.setAttribute("name", "func");
109 hiddenField.setAttribute("value", "Reload"); // reload
110 form.appendChild(hiddenField);
111
112 _postForContineTagging(form);
113
114 alert("You will reload the latest version.");
115 */
116 /*
117 if (loadLastest == true) {
118 // TODO: reload page with the currentFileId
119 console.log('loadLastest is true');
120 $.ajax({
121 type : 'POST',
122 url : './TaggingText',
123 async : false,
124 data : 'func=Reload',
125 success: function (result) {
126 //var lastest_editing = jQuery.parseJSON(result);
127 console.log("lastest_editing string:"+result);
128 // change text to the new one
129 //var el = document.getElementById("editable-area");
130 //el.innerHTML = lastest_editing;
131 //alert("Reload the page!");
132 },
133 error: function (result) {
134 alert("Reload Fails!");
135 }
136 }).done(function(result) {
137 // reload page
138 //document.location.reload(true);
139
140 });
141
142 } else {
143 alert("Just a reminder, there is a new version for this branch.");
144 }
145 */
146
147 }
148 }
149 return;
150
151 }
152
153 <?php
154 foreach ( $taglistArray as $taglistValue ) {
155 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n";
156 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n";
157 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n";
158 echo "\tremoveTagNewDiv( e, \"".$taglistValue[2]."\", $(this) );\n";
159 echo "});\n";
160 }
161 ?>
162
163 $(document).ready(function(){
164
165 // --- for sidebar---
166 //run once
167 var el=$('#follow-scroll');
168 var originalelpos=el.offset().top; // take it where it originally is on the page
169
170
171 //run on scroll
172 $(window).scroll(function(){
173 var el = $('#follow-scroll'); // important! (local)
174 var elpos = el.offset().top; // take current situation
175 var windowpos = $(window).scrollTop();
176 var finaldestination = windowpos+originalelpos;
177 //el.stop().animate({'top':finaldestination},500);
178 el.stop().animate({'top':finaldestination},0);
179 });
180
181 //--- for popups ---
182 //run once
183 var el=$('#popups');
184 var originalelpos=el.offset().top; // take it where it originally is on the page
185
186 //run on scroll
187 $(window).scroll(function(){
188 var el = $('#popups'); // important! (local)
189 var elpos = el.offset().top; // take current situation
190 var windowpos = $(window).scrollTop();
191 var finaldestination = windowpos+originalelpos;
192 //el.stop().animate({'top':finaldestination},500);
193 el.stop().animate({'top':finaldestination},0);
194 });
195
196
197
198 handleFileVersionConflict();
199
200
201
202 /*
203
204 // Popup choosing topic if first time to this section. without branchId
205 if (info['file_id'] == 0) { // or info['branchId'] == 0, means new file
206 // ask to choose topic
207 $.ajax({
208
209 });
210 var popup = document.getElementById('popup-window');
211
212 // alert('choose topic!');
213 }
214 */
215
216 });
217 $(document).on("click", "name", function (e) {
218
219 if ( $("#editTextId").html() != "Edit the text" ) return 0;
220 if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0;
221
222 removeTagNewDiv( e, "name", $(this) );
223 });
224
225 $(document).on("mouseup", '#editable-area', function (e) {
226 $('.questionMarkClass').remove();
227 $('.tagItemDivClass').remove();
228
229 if ( $("#editTextId").html() != "Edit the text" ) return 0;
230 var selection = getSelected();
231 range = getSelected().getRangeAt(0);
232
233 container = document.createElement("div");
234 container.appendChild(selection.getRangeAt(0).cloneContents());
235
236 if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
237
238 var newdiv = document.createElement("div");
239 newdiv.id = "tagItemDivId";
240 newdiv.setAttribute("class", "tagItemDivClass");
241 newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px';
242
243 newdiv.style.backgroundColor = "white";
244 newdiv.style.zIndex = 2;
245
246 //console.log(selection.getRangeAt(0).cloneContents());
247 if ( container.innerHTML.indexOf( "br" ) != -1 ) {
248 var newselect = document.createElement("select");
249 newselect.id = "TitletagType";
250 <?php
251 foreach ( $taglistArray as $taglistValue ) {
252 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n";
253 }
254 ?>
255 newdiv.appendChild(newselect);
256
257 //matchValue = .match();
258 myRegexp = new RegExp("〈(.*?)〉", "g")
259 matchValue = myRegexp.exec(String(selection));
260
261 if ( matchValue != null ) {
262 newdiv.innerHTML += "<input id=\"TitletagName\" value=\""+ matchValue[1] +"\"></br>";
263 } else {
264 newdiv.innerHTML += "<input id=\"TitletagName\" value=\"\"></br>";
265 }
266
267 console.log(" container innerHTML: "+ container.innerHTML );
268
269 newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>";
270
271 /*
272 newdiv.innerHTML += "<button onclick=\"exportTable( range, container )\">Export As A Table</button></br></br>";
273 */
274
275 var newselect = document.createElement("select");
276 newselect.id = "RemoveTitletagType";
277 <?php
278 foreach ( $taglistArray as $taglistValue ) {
279 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n";
280 }
281 ?>
282 newdiv.appendChild(newselect);
283
284 newdiv.innerHTML += "<input id=\"RemoveTitletagName\" value=\"\"></br>";
285 newdiv.innerHTML += "<button onclick=\"removeTagTitle( range, container )\">Remove</button></br>";
286 } else {
287 // for pop up window on edit-area for tag list
288 newdiv.innerHTML = "Tag: "+String(selection)+"<br>";
289
290 <?php
291 foreach ( $taglistArray as $taglistValue ) {
292
293 if ($taglistValue[2] == $topic_tag) {
294 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">[TopicTag]Tag as:".$taglistValue[1]."(necessary for this topic!)</button>\";\n";
295 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n";
296 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
297
298 /*
299 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n";
300 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
301 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
302 */
303 break;
304 }
305 }
306 ?>
307
308 newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>";
309
310 <?php
311
312 foreach ( $taglistArray as $taglistValue ) {
313 /*
314 if ( $taglistValue[2] == "person") {
315 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n";
316 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
317 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
318 } else */
319 if ($taglistValue[2] == $topic_tag) {
320 // pass
321 } else if ($taglistValue[2] == "post_time") {
322 echo "newdiv.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
323 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
324 } else if ($taglistValue[2] == "office") {
325 echo "newdiv.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
326 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
327 } else {
328 echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
329 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
330 }
331
332 }
333 ?>
334 }
335
336 //$('#tagItemDivId').addClass(); // tagItemDivId is newdiv's id
337 $('body').append(newdiv);
338
339 $('#TitletagType').val(lastAddTag);
340
341 }
342 //e.stopPropagation();
343 });
344
345
346 // === for exporttable.php ===
347 function exportTable( range, container ) {
348 //MsgBox("enter function");
349 var form = document.createElement("form");
350 form.setAttribute("method", "post");
351 form.setAttribute("action", "./ExportTable");
352 form.setAttribute("target", "_blank");
353
354 var hiddenField = document.createElement("input");
355 hiddenField.setAttribute("name", "content");
356 hiddenField.setAttribute("value", container.innerHTML);
357 form.appendChild(hiddenField);
358
359 var hiddenField = document.createElement("input");
360 hiddenField.setAttribute("name", "sectionid");
361 hiddenField.setAttribute("value", "<?php echo $section_id; ?>");
362 form.appendChild(hiddenField);
363
364 var hiddenField2 = document.createElement("input");
365 hiddenField2.setAttribute("name", "topic");
366 hiddenField2.setAttribute("value", topic_id);
367 form.appendChild(hiddenField2);
368
369 var info = JSON.parse( '<?php echo json_encode($info) ?>');
370
371 if (info) {
372 var hiddenField = document.createElement("input");
373 hiddenField.setAttribute("name", "bookId");
374 hiddenField.setAttribute("value", info['book_id']);
375 form.appendChild(hiddenField);
376
377 var hiddenField = document.createElement("input");
378 hiddenField.setAttribute("name", "bookName");
379 hiddenField.setAttribute("value", info['book_name']);
380 form.appendChild(hiddenField);
381
382 var hiddenField = document.createElement("input");
383 hiddenField.setAttribute("name", "sectionName");
384 hiddenField.setAttribute("value", info['section_name']);
385 form.appendChild(hiddenField);
386
387 };
388
389 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
390 document.body.appendChild(form);
391 form.submit();
392 } else {
393 form.submit(); // works under IE and Chrome, but not FF
394 }
395 }
396
397 function exportPage(topic_id) {
398 var startPage = $('#exportPageStart').val();
399 var endPage = $('#exportPageEnd').val();
400
401 var el = document.getElementById("editable-area");
402 var str="" + el.innerHTML;
403
404 var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】";
405
406 var form = document.createElement("form");
407 form.setAttribute("method", "post");
408 form.setAttribute("action", "./ExportTable");
409 form.setAttribute("target", "_blank");
410
411 var hiddenField = document.createElement("input");
412 hiddenField.setAttribute("name", "content");
413 hiddenField.setAttribute("value", str.match(new RegExp(regexText, "g")));
414 form.appendChild(hiddenField);
415
416 var hiddenField = document.createElement("input");
417 hiddenField.setAttribute("name", "topic");
418 hiddenField.setAttribute("value", topic_id);
419 form.appendChild(hiddenField);
420
421 _postForContineTagging(form);
422
423
424 /*
425 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>');
426 console.log("section_id: "+section_id+", topic_id: "+topic_id);
427
428 var hiddenField = document.createElement("input");
429 hiddenField.setAttribute("name", "sectionId");
430 hiddenField.setAttribute("value", section_id);
431 form.appendChild(hiddenField);
432
433 var info = JSON.parse( '<?php echo json_encode($info) ?>');
434
435 if (info) {
436 var hiddenField = document.createElement("input");
437 hiddenField.setAttribute("name", "bookId");
438 hiddenField.setAttribute("value", info['book_id']);
439 form.appendChild(hiddenField);
440
441 var hiddenField = document.createElement("input");
442 hiddenField.setAttribute("name", "bookName");
443 hiddenField.setAttribute("value", info['book_name']);
444 form.appendChild(hiddenField);
445
446 var hiddenField = document.createElement("input");
447 hiddenField.setAttribute("name", "sectionName");
448 hiddenField.setAttribute("value", info['section_name']);
449 form.appendChild(hiddenField);
450
451 };
452
453
454 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
455 document.body.appendChild(form);
456 form.submit();
457 } else {
458 form.submit(); // works under IE and Chrome, but not FF
459 }
460 */
461 }
462
463
464
465
466 function exportAll(topic_id) {
467 var el = document.getElementById("editable-area");
468 var str= "" + el.innerHTML;
469 var form = document.createElement("form");
470 form.setAttribute("method", "post");
471 form.setAttribute("action", "./ExportTable");//+section_id); // hand to controller
472 form.setAttribute("target", "_blank");
473
474 var hiddenField = document.createElement("input");
475 hiddenField.setAttribute("name", "content");
476 hiddenField.setAttribute("value", str);
477 form.appendChild(hiddenField);
478
479 var hiddenField = document.createElement("input");
480 hiddenField.setAttribute("name", "topic");
481 hiddenField.setAttribute("value", topic_id);
482 form.appendChild(hiddenField);
483
484 _postForContineTagging(form);
485 /*
486 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>');
487 console.log("section_id: "+section_id+", topic_id: "+topic_id);
488
489 var hiddenField = document.createElement("input");
490 hiddenField.setAttribute("name", "sectionId");
491 hiddenField.setAttribute("value", section_id);
492 form.appendChild(hiddenField);
493
494 var info = JSON.parse( '<?php echo json_encode($info) ?>');
495
496 if (info) {
497 var hiddenField = document.createElement("input");
498 hiddenField.setAttribute("name", "bookId");
499 hiddenField.setAttribute("value", info['book_id']);
500 form.appendChild(hiddenField);
501
502 var hiddenField = document.createElement("input");
503 hiddenField.setAttribute("name", "bookName");
504 hiddenField.setAttribute("value", info['book_name']);
505 form.appendChild(hiddenField);
506
507 var hiddenField = document.createElement("input");
508 hiddenField.setAttribute("name", "sectionName");
509 hiddenField.setAttribute("value", info['section_name']);
510 form.appendChild(hiddenField);
511
512 };
513
514
515 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
516 document.body.appendChild(form);
517 form.submit();
518 } else {
519 form.submit(); // works under IE and Chrome, but not FF
520 }
521 */
522
523 }
524 // ===========
525
526
527 function tagwithOnlytag( range, stringSelection, tag ) {
528 saveUndoText();
529 var topic_tag = JSON.parse('<?php echo json_encode($topic_tag) ?>');
530 var topic_tag2 = topic_tag+"2";
531
532 range.deleteContents();
533
534
535 if ( tag==topic_tag2) {
536 var newdiv = document.createElement(topic_tag);
537 newdiv.innerHTML = stringSelection;
538 range.insertNode(newdiv);
539 var newdiv = document.createElement("br");
540 range.insertNode(newdiv);
541
542 } else {
543 var newdiv = document.createElement(tag);
544 newdiv.innerHTML = stringSelection;
545 range.insertNode(newdiv);
546 }
547
548 /*
549 if ( tag=="person2") {
550 var newdiv = document.createElement("person");
551 newdiv.innerHTML = stringSelection;
552 range.insertNode(newdiv);
553 var newdiv = document.createElement("br");
554 range.insertNode(newdiv);
555 } else if (tag=="object2") {
556 var newdiv = document.createElement("object");
557 newdiv.innerHTML = stringSelection;
558 range.insertNode(newdiv);
559 var newdiv = document.createElement("br");
560 range.insertNode(newdiv);
561
562 } else {
563 var newdiv = document.createElement(tag);
564 newdiv.innerHTML = stringSelection;
565 range.insertNode(newdiv);
566 }
567 */
568
569 $('.tagItemDivClass').remove();
570 }
571
572
573
574
575 function replaceSmartRegex() {
576 saveUndoText();
577 var startPage = $('#regexPageStart2').val();
578 var endPage = $('#regexPageEnd2').val();
579
580 var el = document.getElementById("editable-area");
581 var regexText=document.getElementById("regexText").value;
582
583 <?php
584 foreach ( $wordlistArray as $wordlistValue ) {
585 echo "\tvar regexText1=\"List ".$wordlistValue[1]."\";\n";
586 echo "\tregexText1 = preg_quote(regexText1);\n";
587 echo "\tvar replaceText1=\"".$wordlistValue[2]."\";\n";
588 echo "\tregexText = regexText.replace(new RegExp(regexText1, \"g\"), replaceText1);\n\n";
589 }
590 ?>
591
592 var replaceText=document.getElementById("replaceText").value;
593 var str="" + el.innerHTML;
594
595 if ( startPage == "" ) {
596 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" );
597 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText);
598 } else {
599 var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】";
600 var partString = ""+str.match(new RegExp(regexText2, "g"));
601 alert(partString);
602
603 alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" );
604 var resultString = partString.replace(new RegExp(regexText, "g"), replaceText);
605
606 str="" + el.innerHTML;
607 el.innerHTML = str.replace(new RegExp(regexText2, "g"), resultString);
608 }
609 //document.styleSheets[0].addRule("tag001", "color:green;")
610 }
611
612
613
614 function saveTextToLGService() {
615 var info = JSON.parse('<?php echo json_encode($info) ?>');
616 var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
617
618 // if this is a new branch, ask for label
619 if (info['branch_id'] == 0) {
620 var cnt = 0;
621 var label = prompt("Please enter your label for this new branch", "section"+info['section_id']);
622 while (label == null && cnt <= 3) {
623 cnt ++;
624 label = prompt("Please enter your label for this new branch (not empty)", "section"+info['section_id']);
625 }
626 };
627
628
629
630 var form = document.createElement("form");
631 form.setAttribute("method", "post");
632 form.setAttribute("action", "./TaggingText"); // hand to controller
633 form.setAttribute("target", "_self");
634
635 var hiddenField = document.createElement("input");
636 hiddenField.setAttribute("name", "func");
637 hiddenField.setAttribute("value", "SaveFullTextToLGService");
638 form.appendChild(hiddenField);
639
640
641 var hiddenField = document.createElement("input");
642 hiddenField.setAttribute("name", "label");
643 hiddenField.setAttribute("value", label);
644 form.appendChild(hiddenField);
645
646 var hiddenField = document.createElement("input");
647 hiddenField.setAttribute("name", "topic_id");
648 hiddenField.setAttribute("value", topic_id);
649 form.appendChild(hiddenField);
650
651 _postForContineTagging(form);
652
653 console.log("complete saving to LGService");
654
655
656 /*
657
658 if (info) {
659 var hiddenField = document.createElement("input");
660 hiddenField.setAttribute("name", "fileId");
661 hiddenField.setAttribute("value", info['file_id']);
662 form.appendChild(hiddenField);
663 var hiddenField = document.createElement("input");
664 hiddenField.setAttribute("name", "branchId");
665 hiddenField.setAttribute("value", info['branch_id']);
666 form.appendChild(hiddenField);
667 var hiddenField = document.createElement("input");
668 hiddenField.setAttribute("name", "userId");
669 hiddenField.setAttribute("value", info['user_id']);
670 form.appendChild(hiddenField);
671 var hiddenField = document.createElement("input");
672 hiddenField.setAttribute("name", "sectionId");
673 hiddenField.setAttribute("value", info['section_id']);
674 form.appendChild(hiddenField);
675
676 var hiddenField = document.createElement("input");
677 hiddenField.setAttribute("name", "bookId");
678 hiddenField.setAttribute("value", info['book_id']);
679 form.appendChild(hiddenField);
680 var hiddenField = document.createElement("input");
681 hiddenField.setAttribute("name", "sectionName");
682 hiddenField.setAttribute("value", info['section_name']);
683 form.appendChild(hiddenField);
684 var hiddenField = document.createElement("input");
685 hiddenField.setAttribute("name", "bookName");
686 hiddenField.setAttribute("value", info['book_name']);
687 form.appendChild(hiddenField);
688
689 }
690
691 var hiddenField = document.createElement("input");
692 hiddenField.setAttribute("name", "text");
693 var el = document.getElementById("editable-area");
694 //var text = encodeURIComponent(el.innerHTML);
695 var text = el.innerHTML;
696 hiddenField.setAttribute("value", text);
697 form.appendChild(hiddenField);
698
699 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
700 document.body.appendChild(form);
701 form.submit();
702 } else {
703 form.submit(); // works under IE and Chrome, but not FF
704 }
705 */
706 }
707
708
709
710 function chooseTopic(default_topic_id) {
711 var t = JSON.parse( '<?php echo json_encode($topiclistArray) ?>' );
712 var info = JSON.parse('<?php echo json_encode($info) ?>');
713
714 $('#load_topic_div').html("");
715 $('#load_topic_div').css("display", "block");
716
717 $('#load_topic_div').css("border", "1px solid black");
718 $('#load_topic_div').css("background-color", "White");
719 $('#load_topic_div').css("width", "150px");
720 $('#load_topic_div').css("height", "50px");
721 $('#load_topic_div').css("top", "20px");
722 $('#load_topic_div').css("left", "-150px");
723
724
725 var topic_select = document.createElement("select");
726 topic_select.id = "loadTopiclist";
727 var selected_topic = t[0];
728 topic_select.onchange = function(){
729
730 selected_topic = topic_select.options[topic_select.selectedIndex];
731 console.log(selected_topic.text);
732
733 var topic_id = selected_topic.value;
734
735 var form = document.createElement("form");
736 form.setAttribute("method", "post");
737 form.setAttribute("action", "./TaggingText"); // hand to controller
738 form.setAttribute("target", "_self");
739
740 var hiddenField = document.createElement("input");
741 hiddenField.setAttribute("name", "topic");
742 hiddenField.setAttribute("value", topic_id);
743 form.appendChild(hiddenField);
744
745 var hiddenField = document.createElement("input");
746 hiddenField.setAttribute("name", "func");
747 hiddenField.setAttribute("value", "ContinueTagging");
748 form.appendChild(hiddenField);
749
750 _postForContineTagging(form);
751
752 };
753
754
755 //Create and append the options
756 for (var i = 0; i < t.length; i++) {
757 console.log(t[i]['id']+","+t[i]['name']);
758 var option = document.createElement("option");
759 option.value = t[i]['id'];
760 option.text = t[i]['name'];
761 if (option.value == default_topic_id) {
762 option.selected = true;
763 };
764 topic_select.appendChild(option);
765 }
766
767 $('#load_topic_div').append(topic_select);
768
769 var newbutton = document.createElement("button");
770 $(newbutton).html("Close");
771 $(newbutton).addClass("btn btn-xs btn-default");
772 $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");");
773 $('#load_topic_div').append(newbutton);
774
775 }
776
777 // --- for config tags in topic ---
778 function _postForContineTagging(form) {
779 var hiddenField = document.createElement("input");
780 hiddenField.setAttribute("name", "text");
781 var el = document.getElementById("editable-area");
782 var text = el.innerHTML;
783 hiddenField.setAttribute("value", text);
784 form.appendChild(hiddenField);
785
786 var info = JSON.parse( '<?php echo json_encode($info) ?>');
787
788 if (info) {
789 // TODO: different field info array based on fileId(branchId) existing or not
790 if (info['file_id']) {
791 var hiddenField = document.createElement("input");
792 hiddenField.setAttribute("name", "fileId");
793 hiddenField.setAttribute("value", info['file_id']);
794 form.appendChild(hiddenField);
795 };
796 if (info['branch_id']) {
797 var hiddenField = document.createElement("input");
798 hiddenField.setAttribute("name", "branchId");
799 hiddenField.setAttribute("value", info['branch_id']);
800 form.appendChild(hiddenField);
801 };
802 if (info['user_id']) {
803 var hiddenField = document.createElement("input");
804 hiddenField.setAttribute("name", "userId");
805 hiddenField.setAttribute("value", info['user_id']);
806 form.appendChild(hiddenField);
807 };
808 if (info['section_id']) {
809 var hiddenField = document.createElement("input");
810 hiddenField.setAttribute("name", "sectionId");
811 hiddenField.setAttribute("value", info['section_id']);
812 form.appendChild(hiddenField);
813 };
814 if (info['book_id']) {
815 var hiddenField = document.createElement("input");
816 hiddenField.setAttribute("name", "bookId");
817 hiddenField.setAttribute("value", info['book_id']);
818 form.appendChild(hiddenField);
819 };
820 if (info['section_name']) {
821 var hiddenField = document.createElement("input");
822 hiddenField.setAttribute("name", "sectionName");
823 hiddenField.setAttribute("value", info['section_name']);
824 form.appendChild(hiddenField);
825 };
826 if (info['book_name']) {
827 var hiddenField = document.createElement("input");
828 hiddenField.setAttribute("name", "bookName");
829 hiddenField.setAttribute("value", info['book_name']);
830 form.appendChild(hiddenField);
831 };
832 if (info['current_fileId']) {
833 var hiddenField = document.createElement("input");
834 hiddenField.setAttribute("name", "currentFileId");
835 hiddenField.setAttribute("value", info['current_fileId']);
836 form.appendChild(hiddenField);
837 };
838
839 }
840 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
841 document.body.appendChild(form);
842 form.submit();
843 } else {
844 form.submit(); // works under IE and Chrome, but not FF
845 }
846
847 }
848
849 function configTagsInTopic(topic_id) {
850 var form = document.createElement("form");
851
852 form.setAttribute("method", "post");
853 form.setAttribute("action", "./ConfigTagsInTopic"); // hand to controller
854 form.setAttribute("target", "_blank");
855
856 var hiddenField = document.createElement("input");
857 hiddenField.setAttribute("name", "topic");
858 hiddenField.setAttribute("value", topic_id);
859 form.appendChild(hiddenField);
860
861 _postForContineTagging(form);
862
863 /*
864 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
865 document.body.appendChild(form);
866 form.submit();
867 } else {
868 form.submit(); // works under IE and Chrome, but not FF
869 }
870 */
871
872 }
873
874
875
876 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {
877
878 <?php
879 foreach ( $wordlistArray as $wordlistValue ) {
880 echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {";
881 echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");";
882 echo "}";
883 }
884 ?>
885 });
886
887
888
889 </script>
890
891 <div id="dialog-form" title="config tags for topic" style="position:fixed; top: 30px; ">
892 </div>
893
894
895 <p class="bg-info" style="margin:10 30 10 30; max-width:1250"> <?php echo $messages; ?> </p>
896
897 <table width="1270" border="1" style="margin:10 30 10 30;">
898 <tr>
899 <td width="980" style="padding:0 5 0 5; margin: 0 5 0 5;">
900 <div id="editable-area" class="area" style="max-width: 980"><?php echo $stringInput; ?></div>
901 </td>
902 <td width="290" valign="top">
903 <div id="popups" style="position:absolute; width:300px; ">
904 <div id="load_topic_div" style="position: absolute; display: none; z-index:2"></div>
905 <div id="load_regex_div" style="position: absolute; display: none; z-index:2;"></div>
906 <div id="smartRegexPopUpDiv" style="position: absolute; display: none; z-index:2">
907 Name: <input id="smartRegexPopUpName"></input><br><br>
908 Word List:
909 <select id="smartRegexPopUpSelectWord">
910 <option value="NULL" selected>無</option>
911 <?php
912 foreach ( $wordlistArray as $wordlistValue ) {
913 echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n";
914 }
915 ?>
916 </select>
917 <br>
918 OR (USE "|" TO SEPARATE WORDS):<br>
919 <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br>
920 Tag:
921 <select id="smartRegexPopUpSelectTag">
922 <?php
923 foreach ( $taglistArray as $taglistValue ) {
924 echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n";
925 }
926 echo "<option value=\"title\">Title</option>\n";
927 ?>
928 <option value="NOTAG">不標記</option>
929 </select><br>
930 <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" class="btn btn-info" style="">Add</button>
931 <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" class="btn btn-success" style="">Edit</button>
932 <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" class="btn btn-danger" style="">Delete</button>
933 <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" class="btn btn-default" style=""><<</button>
934 <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" class="btn btn-default" style="">>></button>
935 <button onclick="replaceSmartClose()" class="btn btn-default" style="">Close</button>
936 </div>
937 </div>
938
939 <div id="follow-scroll" style="position:absolute; height:680px; overflow:scroll; margin:0 5 15 5; max-width:270px">
940 <form action="javascript:void(0);">
941 <fieldset>
942 <legend><h5 class="text-success"> Config Topic: </h5></legend>
943 <div> current topic is <?php echo $topic_name; ?>
944 <button onclick="chooseTopic(<?php echo $default_topic_id; ?>)" class="btn btn-xs btn-default">Change</button>
945 </div>
946 <button onclick="configTagsInTopic(<?php echo $default_topic_id;?>)" class="btn btn-sm btn-default" style="">Manage Tags in topic</button></br>
947 </fieldset>
948
949 <fieldset>
950 <legend><h5 class="text-success"> Replace By <i><b>Smart Regex</b></i>©: </h5></legend>
951 <div id="smartRegexShowDiv"></div><br>
952 <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br>
953 Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br>
954 <button onclick="replaceSmartRun()" style="height: 30px; width: 100px">Run</button>
955 <button onclick="replaceSmartRunWithBr()" style="height: 30px; width: 100px">Run(with Br)</button></br>
956 <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br>
957 <button onclick="smartRegexSave(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 70px">Save</button>
958 <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 70px">Load</button>
959 <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br>
960 <!--
961 <button id="example" type="button" class="btn btn-sm btn-default" data-toggle="popover">Load</button>
962 -->
963 </fieldset>
964
965 <fieldset>
966 <legend><h5 class="text-success"> Tag by rule:</h5></legend>
967 <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br>
968 <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
969 <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>-->
970 <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>-->
971 <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
972 </fieldset>
973
974 <fieldset>
975 <legend><h5 class="text-success"> Edit:</h5></legend>
976 <button onclick="saveTextToLGService()" style="height: 30px; width: 220px">Save to LGService</button></br>
977
978 <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
979 <!-- save text in local. replaced by saveTextToLGService, which is also saving on copy in local in development stage -->
980 <button onclick="saveText(<?php echo $section_id; ?>)" style="height: 30px; width: 220px">Save the text</button></br>
981 <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br>
982 </br>
983 <button onclick="window.open('./EditWordlist')" style="height: 30px; width: 220px">Manage Word List</button></br>
984 <!--
985 <button onclick="window.open('./EditTaglist')" style="height: 30px; width: 220px">Manage Tag List</button></br>
986 -->
987 <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 220px">Manage Tag List</button></br>
988 </fieldset>
989
990 <fieldset>
991 <legend><h5 class="text-success"> Export:</h5></legend>
992 Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br>
993 <button onclick="exportPage(<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export</button></br>
994 <button onclick="exportAll(<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export All</button></br>
995 </fieldset>
996
997 <fieldset>
998 <legend><h5 class="text-success"> Replace By <i><b>Regex</b></i>: </h5></legend>
999 Range: <input type="text" size="5" id="regexPageStart2">to<input type="text" size="5" id="regexPageEnd2"><br>
1000 Regex: <input type="text" size="23" id="regexText"></br>
1001 Replace: <input type="text" size="23" id="replaceText"><br>
1002 <button onclick="replaceSmartRegex()">Replace!</button>
1003 </fieldset>
1004 </form>
1005 </div>
1006 </td>
1007 </tr>
1008
1009 </table>
1010
1011
1012
1013
1014 </body>
1015
1016 </html>