diff develop/views/Extractapp/TaggingText.php @ 40:2e938dc046db extractapp

load,save xml file with topic, etc.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 10 Mar 2015 13:46:16 +0100
parents 8347776a44fc
children c245d54eab9f
line wrap: on
line diff
--- a/develop/views/Extractapp/TaggingText.php	Sun Mar 08 22:28:21 2015 +0100
+++ b/develop/views/Extractapp/TaggingText.php	Tue Mar 10 13:46:16 2015 +0100
@@ -12,6 +12,8 @@
 $messages = $viewmodel['messages'];
 
 $taglist_infile = $viewmodel['taglist_infile'];
+$book_meta = $viewmodel['book_meta'];
+
 
 ?>
 
@@ -38,13 +40,12 @@
 	font-size:21px;
 }
 
-
 <?php
 // color on the tags
 foreach ( $taglistArray as $taglistValue ) {
-	echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n";
-	
-	echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n";
+    echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n";
+    
+    echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n";
 }
 
 ?>
@@ -57,36 +58,28 @@
 
 <script type="text/javascript">
 
-// === This is only for developing on local machine ====
-var _GET = JSON.parse('<?php echo json_encode($_GET) ?>');
-if (_GET['id']) {
-    
-    var info = JSON.parse('<?php echo json_encode($info) ?>');
-    var redirectUrl = "http://localhost:1080/extraction-interface/develop/Extractapp/TaggingText";
-    var section_id = info['section_id'];
+// not use this for now
+function _showTagColor(up_to_date) {
+    var taglistArray = "";
+    if (up_to_date) {
+        taglistArray = JSON.parse('<?php echo json_encode($taglistArray) ?>');
+    } else {
+        taglistArray = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
+    }
+
 
-    var form = $('<form action="' + redirectUrl + '" method="post">' +
-        '<input type="hidden" name="sectionId" value="'+section_id+'" />' +
-        '</form>');
-        $('body').append(form);
-        $(form).submit();
-}
-// ====
-// --- check if taglist in file is up-to-date ---
-var check_taglist = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
-if (check_taglist) {
-    // TODO: pop up to ask if load the latest taglist
-    var retVal = confirm("The tag list in the file is not up-to-date. \nDo you want to load file with new tag list?");
-    if( retVal == true ){
-        <?php $$taglistArray = $taglist_infile; ?>
-        alert("Load with new tag list.");
-    }else{
-        alert("You are using the old version of tag list.");
+    for (var i = 0; i < taglistArray.length; i++) {
+        var taglistValue = taglistArray[i];
+        
+        $(taglistValue[2]).css('color', taglistValue[3]);
+        /*var element = document.querySelectorAll(taglistValue[2]);
+        for (var j = 0; j < element.length; j++) {
+            element[j].style.color = taglistValue[3];
+        }
+        */
     }
 }
 
-
-
 // TODO: Popup to proceeding the saving situations
 function handleFileVersionConflict() {
     var info = JSON.parse('<?php echo json_encode($info) ?>');
@@ -206,6 +199,42 @@
         el.stop().animate({'top':finaldestination},0);
     });
 
+    // --- handle old version taglist ---
+    var _GET = JSON.parse('<?php echo json_encode($_GET) ?>');
+    if (_GET['id']) {
+        // === This case should only be possible for developing on local machine ==== 
+        var info = JSON.parse('<?php echo json_encode($info) ?>');
+        var redirectUrl = "http://localhost:1080/extraction-interface/develop/Extractapp/TaggingText";
+        var section_id = info['section_id'];
+
+        var form = $('<form action="' + redirectUrl + '" method="post">' +
+            '<input type="hidden" name="sectionId" value="'+section_id+'" />' +
+            '</form>');
+            $('body').append(form);
+            $(form).submit();
+    } else {
+        // --- TODO: check if taglist in file is up-to-date ---
+        /*
+        var taglist_infile = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
+        if (taglist_infile != "") {
+            // TODO: pop up to ask if load the latest taglist
+            var retVal = confirm("Tag list in file is not up-to-date. \nDo you want to load file with new tag list?");
+            if( retVal == true ){
+                // use $taglisArray
+                alert("Load file with new tag list.");
+            }else{
+                // use $taglist_infile as $taglistArray
+                <?php 
+                // $taglistArray = $taglist_infile; 
+                ?>
+                alert("You are viewing the file with old version of tag list. Please use the up-to-date taglist.");
+            }
+            //_showTagColor(retVal);
+            <?php $taglist_infile = ""; ?>
+        }
+        */
+    }
+
 
 
     handleFileVersionConflict();
@@ -260,6 +289,10 @@
         if ( container.innerHTML.indexOf( "br" ) != -1 ) {
             var newselect = document.createElement("select");
             newselect.id = "TitletagType";
+            
+
+            console.log(JSON.parse('<?php echo json_encode($taglistArray) ?>'));
+
             <?php 
                 foreach ( $taglistArray as $taglistValue ) {
                     echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n";
@@ -796,6 +829,26 @@
     hiddenField.setAttribute("value", text);
     form.appendChild(hiddenField);
 
+    // pass taglist
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "taglistArray");
+    var taglistObj = JSON.parse('<?php echo json_encode($taglist_infile) ?>');
+    if (!taglistObj) {
+        taglistObj = JSON.parse('<?php echo json_encode($taglistArray) ?>');
+    }
+    taglistArray = JSON.stringify(taglistObj);
+    hiddenField.setAttribute("value", taglistArray);
+    form.appendChild(hiddenField);
+
+    // pass book_meta
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "book_meta");
+    var book_metaObj = JSON.parse('<?php echo json_encode($book_meta) ?>');
+    book_metaArray = JSON.stringify(book_metaObj);
+    hiddenField.setAttribute("value", book_metaArray);
+    form.appendChild(hiddenField);    
+
+
     var info = JSON.parse( '<?php echo json_encode($info) ?>');
 
     if (info) {
@@ -990,7 +1043,10 @@
                     
                         <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
                         <!-- save text in local. replaced by saveTextToLGService, which is also saving on copy in local in development stage -->
+                        <!-- 
                         <button onclick="saveText(<?php echo $section_id; ?>)" style="height: 30px; width: 220px">Save the text</button></br>
+                        -->
+
                         <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br>
                         </br>
                         <button onclick="window.open('./EditWordlist')" style="height: 30px; width: 220px">Manage Word List</button></br>