diff 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
line wrap: on
line diff
--- a/views/Extractapp/TaggingText.php	Mon Nov 09 12:00:24 2015 +0100
+++ b/views/Extractapp/TaggingText.php	Wed Nov 11 14:12:55 2015 +0100
@@ -690,7 +690,7 @@
     form.appendChild(hiddenField);
     
     var hiddenField = document.createElement("input");      
-    hiddenField.setAttribute("name", "topic_id");
+    hiddenField.setAttribute("name", "topic");
     hiddenField.setAttribute("value", topic_id);
     form.appendChild(hiddenField); 
 
@@ -708,40 +708,26 @@
         $('#new_topic_div').css("display", "block");
     }
 
-
-
-
-    // TODO input new topic
-    /* In table:
-          taglist: name, tag, color (default, user can change later in the editing page)
-          topics: tag, name_en, name_ch, name_pinyin
-     
-      need transaction for the following actions:
-        taglist.name: topic_tag name in chinese 
-        taglist.tag: topic_tag name in eng
-        topics.tag: (the same a taglist.tag)
-        topics.name_en:
-        topics.name_ch: 
-        topics.name_pinyin: 
-        add a new record in topic_tag_relation: topic_id, tag_id
-    */
-   
-
-
     var newtopic = document.getElementById("newTopicSubmit");
     
     newtopic.onclick = function(){
+        // check if all fields are filled in
+        if ($("#newTopicNameEn").val()==""|| $("#newTopicNameCh").val()=="" || $("#newTopicNamePi").val()=="" || 
+            $("#newTopicTag").val()=="" || $("#newTopicTagName").val()=="") {
+            alert("Please fill in all the fields for the new topic.");
+            return;
+        } 
+
+
         var form = document.createElement("form");
         form.setAttribute("method", "post");
-        form.setAttribute("action", "./ConfigTagsInTopic");  // hand to controller
-        form.setAttribute("target", "_self");   // TODO self here?
+        form.setAttribute("action", "./TaggingText");  // hand to controller
+        form.setAttribute("target", "_self");   
 
-        // TODO 
         var hiddenField = document.createElement("input");      
         hiddenField.setAttribute("name", "func");
         hiddenField.setAttribute("value", "CreateNewTopic");
         form.appendChild(hiddenField);
-    
         
         var hiddenField = document.createElement("input");     
         hiddenField.setAttribute("name", "new_topic_name_en");
@@ -764,7 +750,6 @@
         hiddenField.setAttribute("value", $("#newTopicTagName").val());
         form.appendChild(hiddenField);
 
-
         
         _postForContineTagging(form);
 
@@ -845,6 +830,7 @@
   
 }
 
+
 function _postForContineTagging(form) {
     var hiddenField = document.createElement("input");      
     hiddenField.setAttribute("name", "text");
@@ -856,6 +842,10 @@
     // pass taglist
     var hiddenField = document.createElement("input");      
     hiddenField.setAttribute("name", "taglistArray");
+    
+    // use json_encode($taglistArray), which is the up-to-date taglist (in db) instead,
+    // so replace the follwoing code
+    /*
     var taglistObj = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
     // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file
 
@@ -864,6 +854,10 @@
         taglistObj = JSON.parse('<?php echo json_encode($taglistArray) ?>');
     }
     taglistArray = JSON.stringify(taglistObj);
+    */
+    
+
+    var taglistArray = JSON.parse('<?php echo json_encode($taglistArray) ?>');
     hiddenField.setAttribute("value", taglistArray);
     form.appendChild(hiddenField);
 
@@ -1018,43 +1012,43 @@
                     <div class="form-horizontal">
                         <h4 class="text-info">New topic name:</h4>
                         <div class="form-group form-group-sm">
-                            <label for="newTopicNameEn" class="col-sm-4 control-label">name (en)</label>
-                            <div class="col-sm-8">
-                                <input type="text" class="form-control" id="newTopicNameEn" placeholder="name in English">
+                            <label for="newTopicNameEn" class="col-sm-5 control-label">name (eng)</label>
+                            <div class="col-sm-7">
+                                <input type="text" class="form-control" id="newTopicNameEn" placeholder="e.g. Local Product">
                             </div>
                          </div>
                         <div class="form-group form-group-sm">
-                            <label for="newTopicNameCh" class="col-sm-4 control-label">name (ch)</label>
-                            <div class="col-sm-8">
-                                <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Chinese">
+                            <label for="newTopicNameCh" class="col-sm-5 control-label">name (中文)</label>
+                            <div class="col-sm-7">
+                                <input type="text" class="form-control" id="newTopicNameCh" placeholder="e.g. 物產">
                             </div>
                         </div>
                         <div class="form-group form-group-sm">
-                            <label for="newTopicNamePi" class="col-sm-4 control-label">name (pi)</label>
-                            <div class="col-sm-8">
-                                <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Pinyin">
+                            <label for="newTopicNamePi" class="col-sm-5 control-label">name (pinyin)</label>
+                            <div class="col-sm-7">
+                                <input type="text" class="form-control" id="newTopicNamePi" placeholder="e.g. wu chan">
                             </div>
                         </div>
                         
 
-                        <h4 class="text-info">New topic tag:</h4>
+                        <h4 class="text-info">Define the topic tag for the new topic:</h4>
                         <div class="form-group form-group-sm">
-                            <label for="newTopicTag" class="col-sm-4 control-label">tag (en)</label>
-                            <div class="col-sm-8">
-                                <input type="text" class="form-control" id="newTopicTag" placeholder="tag in English">
+                            <label for="newTopicTag" class="col-sm-5 control-label">topic tag (eng)</label>
+                            <div class="col-sm-7">
+                                <input type="text" class="form-control" id="newTopicTag" placeholder="e.g. product_name">
                             </div>
                         </div>
 
                         <div class="form-group form-group-sm">
-                            <label for="newTopicTagName" class="col-sm-4 control-label">tag (ch)</label>
-                            <div class="col-sm-8">
-                                <input type="text" class="form-control" id="newTopicTag" placeholder="tag in Chinese">
+                            <label for="newTopicTagName" class="col-sm-5 control-label">topic tag (中文)</label>
+                            <div class="col-sm-7">
+                                <input type="text" class="form-control" id="newTopicTagName" placeholder="e.g. 物產名稱">
                             </div>
                         </div>
 
 
                         <div class="form-group form-group-sm">
-                            <div class="col-sm-offset-4 col-sm-8">
+                            <div class="col-sm-offset-5 col-sm-7">
                                 <button type="submit" id="newTopicSubmit" class="btn btn-primary btn-xs">Submit</button>
                                 <button id="newTopicCancel" class="btn btn-default btn-xs">Cancel</button>
                             </div>
@@ -1119,7 +1113,7 @@
                             <div> Current topic is:
                                     <?php echo $topic_name['name_en']; ?> (<?php echo $topic_name['name_ch']; ?>, <?php echo $topic_name['name_pinyin']; ?>)
                                 <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Change Topic</button>
-                                <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic (TODO)</button>
+                                <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic</button>
                             </div>
                             </div>
                     </fieldset>