comparison views/Extractapp/TaggingText.php @ 95:9a29e9d28ece extractapp

new: create new topic
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 11 Nov 2015 14:12:55 +0100
parents b0cecc104639
children c1bb174a22f3
comparison
equal deleted inserted replaced
94:b0cecc104639 95:9a29e9d28ece
688 hiddenField.setAttribute("name", "label"); 688 hiddenField.setAttribute("name", "label");
689 hiddenField.setAttribute("value", label); 689 hiddenField.setAttribute("value", label);
690 form.appendChild(hiddenField); 690 form.appendChild(hiddenField);
691 691
692 var hiddenField = document.createElement("input"); 692 var hiddenField = document.createElement("input");
693 hiddenField.setAttribute("name", "topic_id"); 693 hiddenField.setAttribute("name", "topic");
694 hiddenField.setAttribute("value", topic_id); 694 hiddenField.setAttribute("value", topic_id);
695 form.appendChild(hiddenField); 695 form.appendChild(hiddenField);
696 696
697 _postForContineTagging(form); 697 _postForContineTagging(form);
698 698
706 $('#new_topic_div').css("display", "none"); 706 $('#new_topic_div').css("display", "none");
707 } else { 707 } else {
708 $('#new_topic_div').css("display", "block"); 708 $('#new_topic_div').css("display", "block");
709 } 709 }
710 710
711
712
713
714 // TODO input new topic
715 /* In table:
716 taglist: name, tag, color (default, user can change later in the editing page)
717 topics: tag, name_en, name_ch, name_pinyin
718
719 need transaction for the following actions:
720 taglist.name: topic_tag name in chinese
721 taglist.tag: topic_tag name in eng
722 topics.tag: (the same a taglist.tag)
723 topics.name_en:
724 topics.name_ch:
725 topics.name_pinyin:
726 add a new record in topic_tag_relation: topic_id, tag_id
727 */
728
729
730
731 var newtopic = document.getElementById("newTopicSubmit"); 711 var newtopic = document.getElementById("newTopicSubmit");
732 712
733 newtopic.onclick = function(){ 713 newtopic.onclick = function(){
714 // check if all fields are filled in
715 if ($("#newTopicNameEn").val()==""|| $("#newTopicNameCh").val()=="" || $("#newTopicNamePi").val()=="" ||
716 $("#newTopicTag").val()=="" || $("#newTopicTagName").val()=="") {
717 alert("Please fill in all the fields for the new topic.");
718 return;
719 }
720
721
734 var form = document.createElement("form"); 722 var form = document.createElement("form");
735 form.setAttribute("method", "post"); 723 form.setAttribute("method", "post");
736 form.setAttribute("action", "./ConfigTagsInTopic"); // hand to controller 724 form.setAttribute("action", "./TaggingText"); // hand to controller
737 form.setAttribute("target", "_self"); // TODO self here? 725 form.setAttribute("target", "_self");
738 726
739 // TODO
740 var hiddenField = document.createElement("input"); 727 var hiddenField = document.createElement("input");
741 hiddenField.setAttribute("name", "func"); 728 hiddenField.setAttribute("name", "func");
742 hiddenField.setAttribute("value", "CreateNewTopic"); 729 hiddenField.setAttribute("value", "CreateNewTopic");
743 form.appendChild(hiddenField); 730 form.appendChild(hiddenField);
744
745 731
746 var hiddenField = document.createElement("input"); 732 var hiddenField = document.createElement("input");
747 hiddenField.setAttribute("name", "new_topic_name_en"); 733 hiddenField.setAttribute("name", "new_topic_name_en");
748 hiddenField.setAttribute("value", $("#newTopicNameEn").val()); 734 hiddenField.setAttribute("value", $("#newTopicNameEn").val());
749 form.appendChild(hiddenField); 735 form.appendChild(hiddenField);
762 var hiddenField = document.createElement("input"); 748 var hiddenField = document.createElement("input");
763 hiddenField.setAttribute("name", "new_topic_tag_name"); 749 hiddenField.setAttribute("name", "new_topic_tag_name");
764 hiddenField.setAttribute("value", $("#newTopicTagName").val()); 750 hiddenField.setAttribute("value", $("#newTopicTagName").val());
765 form.appendChild(hiddenField); 751 form.appendChild(hiddenField);
766 752
767
768 753
769 _postForContineTagging(form); 754 _postForContineTagging(form);
770 755
771 } 756 }
772 757
843 $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");"); 828 $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");");
844 $('#load_topic_div').append(newbutton); 829 $('#load_topic_div').append(newbutton);
845 830
846 } 831 }
847 832
833
848 function _postForContineTagging(form) { 834 function _postForContineTagging(form) {
849 var hiddenField = document.createElement("input"); 835 var hiddenField = document.createElement("input");
850 hiddenField.setAttribute("name", "text"); 836 hiddenField.setAttribute("name", "text");
851 var el = document.getElementById("editable-area"); 837 var el = document.getElementById("editable-area");
852 var text = el.innerHTML; 838 var text = el.innerHTML;
854 form.appendChild(hiddenField); 840 form.appendChild(hiddenField);
855 841
856 // pass taglist 842 // pass taglist
857 var hiddenField = document.createElement("input"); 843 var hiddenField = document.createElement("input");
858 hiddenField.setAttribute("name", "taglistArray"); 844 hiddenField.setAttribute("name", "taglistArray");
845
846 // use json_encode($taglistArray), which is the up-to-date taglist (in db) instead,
847 // so replace the follwoing code
848 /*
859 var taglistObj = JSON.parse('<?php echo json_encode($taglist_infile) ?>'); 849 var taglistObj = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
860 // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file 850 // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file
861 851
862 if (!taglistObj) { 852 if (!taglistObj) {
863 // TODO: should pass the user-decided taglist to post['taglistArray'] 853 // TODO: should pass the user-decided taglist to post['taglistArray']
864 taglistObj = JSON.parse('<?php echo json_encode($taglistArray) ?>'); 854 taglistObj = JSON.parse('<?php echo json_encode($taglistArray) ?>');
865 } 855 }
866 taglistArray = JSON.stringify(taglistObj); 856 taglistArray = JSON.stringify(taglistObj);
857 */
858
859
860 var taglistArray = JSON.parse('<?php echo json_encode($taglistArray) ?>');
867 hiddenField.setAttribute("value", taglistArray); 861 hiddenField.setAttribute("value", taglistArray);
868 form.appendChild(hiddenField); 862 form.appendChild(hiddenField);
869 863
870 // pass book_meta 864 // pass book_meta
871 var hiddenField = document.createElement("input"); 865 var hiddenField = document.createElement("input");
1016 <div id="load_topic_div" class="popup-topic popup-frame"></div> 1010 <div id="load_topic_div" class="popup-topic popup-frame"></div>
1017 <div id="new_topic_div" class="popup-newtopic popup-frame"> 1011 <div id="new_topic_div" class="popup-newtopic popup-frame">
1018 <div class="form-horizontal"> 1012 <div class="form-horizontal">
1019 <h4 class="text-info">New topic name:</h4> 1013 <h4 class="text-info">New topic name:</h4>
1020 <div class="form-group form-group-sm"> 1014 <div class="form-group form-group-sm">
1021 <label for="newTopicNameEn" class="col-sm-4 control-label">name (en)</label> 1015 <label for="newTopicNameEn" class="col-sm-5 control-label">name (eng)</label>
1022 <div class="col-sm-8"> 1016 <div class="col-sm-7">
1023 <input type="text" class="form-control" id="newTopicNameEn" placeholder="name in English"> 1017 <input type="text" class="form-control" id="newTopicNameEn" placeholder="e.g. Local Product">
1024 </div> 1018 </div>
1025 </div> 1019 </div>
1026 <div class="form-group form-group-sm"> 1020 <div class="form-group form-group-sm">
1027 <label for="newTopicNameCh" class="col-sm-4 control-label">name (ch)</label> 1021 <label for="newTopicNameCh" class="col-sm-5 control-label">name (中文)</label>
1028 <div class="col-sm-8"> 1022 <div class="col-sm-7">
1029 <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Chinese"> 1023 <input type="text" class="form-control" id="newTopicNameCh" placeholder="e.g. 物產">
1030 </div> 1024 </div>
1031 </div> 1025 </div>
1032 <div class="form-group form-group-sm"> 1026 <div class="form-group form-group-sm">
1033 <label for="newTopicNamePi" class="col-sm-4 control-label">name (pi)</label> 1027 <label for="newTopicNamePi" class="col-sm-5 control-label">name (pinyin)</label>
1034 <div class="col-sm-8"> 1028 <div class="col-sm-7">
1035 <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Pinyin"> 1029 <input type="text" class="form-control" id="newTopicNamePi" placeholder="e.g. wu chan">
1036 </div> 1030 </div>
1037 </div> 1031 </div>
1038 1032
1039 1033
1040 <h4 class="text-info">New topic tag:</h4> 1034 <h4 class="text-info">Define the topic tag for the new topic:</h4>
1041 <div class="form-group form-group-sm"> 1035 <div class="form-group form-group-sm">
1042 <label for="newTopicTag" class="col-sm-4 control-label">tag (en)</label> 1036 <label for="newTopicTag" class="col-sm-5 control-label">topic tag (eng)</label>
1043 <div class="col-sm-8"> 1037 <div class="col-sm-7">
1044 <input type="text" class="form-control" id="newTopicTag" placeholder="tag in English"> 1038 <input type="text" class="form-control" id="newTopicTag" placeholder="e.g. product_name">
1045 </div> 1039 </div>
1046 </div> 1040 </div>
1047 1041
1048 <div class="form-group form-group-sm"> 1042 <div class="form-group form-group-sm">
1049 <label for="newTopicTagName" class="col-sm-4 control-label">tag (ch)</label> 1043 <label for="newTopicTagName" class="col-sm-5 control-label">topic tag (中文)</label>
1050 <div class="col-sm-8"> 1044 <div class="col-sm-7">
1051 <input type="text" class="form-control" id="newTopicTag" placeholder="tag in Chinese"> 1045 <input type="text" class="form-control" id="newTopicTagName" placeholder="e.g. 物產名稱">
1052 </div> 1046 </div>
1053 </div> 1047 </div>
1054 1048
1055 1049
1056 <div class="form-group form-group-sm"> 1050 <div class="form-group form-group-sm">
1057 <div class="col-sm-offset-4 col-sm-8"> 1051 <div class="col-sm-offset-5 col-sm-7">
1058 <button type="submit" id="newTopicSubmit" class="btn btn-primary btn-xs">Submit</button> 1052 <button type="submit" id="newTopicSubmit" class="btn btn-primary btn-xs">Submit</button>
1059 <button id="newTopicCancel" class="btn btn-default btn-xs">Cancel</button> 1053 <button id="newTopicCancel" class="btn btn-default btn-xs">Cancel</button>
1060 </div> 1054 </div>
1061 </div> 1055 </div>
1062 </div> 1056 </div>
1117 <legend><h5 class="tool-topic" data-toggle="collapse" data-target="#tool_topic"> Topic: <span class="caret"></span></h5></legend> 1111 <legend><h5 class="tool-topic" data-toggle="collapse" data-target="#tool_topic"> Topic: <span class="caret"></span></h5></legend>
1118 <div id="tool_topic" class="collapse in"> 1112 <div id="tool_topic" class="collapse in">
1119 <div> Current topic is: 1113 <div> Current topic is:
1120 <?php echo $topic_name['name_en']; ?> (<?php echo $topic_name['name_ch']; ?>, <?php echo $topic_name['name_pinyin']; ?>) 1114 <?php echo $topic_name['name_en']; ?> (<?php echo $topic_name['name_ch']; ?>, <?php echo $topic_name['name_pinyin']; ?>)
1121 <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Change Topic</button> 1115 <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Change Topic</button>
1122 <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic (TODO)</button> 1116 <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic</button>
1123 </div> 1117 </div>
1124 </div> 1118 </div>
1125 </fieldset> 1119 </fieldset>
1126 <fieldset class="tool-frame"> 1120 <fieldset class="tool-frame">
1127 <legend><h5 class="tool-topic" data-toggle="collapse" data-target="#tool_tag"> Tag: <span class="caret"></span></h5></legend> 1121 <legend><h5 class="tool-topic" data-toggle="collapse" data-target="#tool_tag"> Tag: <span class="caret"></span></h5></legend>