changeset 101:a264460c77ca extractapp

new: auto save and reload page after updating taglist.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 04 May 2016 15:22:11 +0200
parents 8a97db7b9108
children 6ba742b712b0
files data/wordlist/4.txt js/taggingtext.js models/extractapp.php views/Extractapp/EditTaglist.php views/Extractapp/TaggingText.php
diffstat 5 files changed, 69 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/wordlist/4.txt	Mon May 02 15:47:03 2016 +0200
+++ b/data/wordlist/4.txt	Wed May 04 15:22:11 2016 +0200
@@ -1,1 +1,1 @@
-一<div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>七</div><div>八</div><div>九</div><div>十</div></div>
\ No newline at end of file
+一<div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>七</div><div>八</div><div>九</div><div>十</div></div><div><span style="line-height: 33.6px;">十</span><span style="line-height: 33.6px; background-color: transparent;">一</span></div>
\ No newline at end of file
--- a/js/taggingtext.js	Mon May 02 15:47:03 2016 +0200
+++ b/js/taggingtext.js	Wed May 04 15:22:11 2016 +0200
@@ -32,6 +32,23 @@
     //return "Unsaved data will be lost.";
 };
 
+function setCookie(value) {
+    document.cookie = "cookie-msg-test=" + value + "; path=/";
+    return true;
+}
+function getCookie() {
+    var cname = "cookie-msg-test=";
+    var ca = document.cookie.split(';');
+
+    for (var i=0; i < ca.length; i++) {
+        var c = ca[i];
+        while (c.charAt(0)==' ') c = c.substring(1,c.length);
+        if (c.indexOf(cname) == 0) {
+            return c.substring(cname.length, c.length);
+        }
+    }
+    return null;
+}
 
 /*
 $(document).on("mouseup", function (e) {
--- a/models/extractapp.php	Mon May 02 15:47:03 2016 +0200
+++ b/models/extractapp.php	Wed May 04 15:22:11 2016 +0200
@@ -1339,7 +1339,7 @@
                 $name = $postdata['text'];
             }
 
-            $query1 = sprintf("INSERT INTO `Wordlist` (`name`) VALUES (%s,)",
+            $query1 = sprintf("INSERT INTO `Wordlist` (`name`) VALUES (%s)",
                             $this->GetSQLValueString($name, "text"));
                             //$this->GetSQLValueString($this->systemNAME, "text"));
             $result1 = mysql_query($query1);
--- a/views/Extractapp/EditTaglist.php	Mon May 02 15:47:03 2016 +0200
+++ b/views/Extractapp/EditTaglist.php	Wed May 04 15:22:11 2016 +0200
@@ -92,6 +92,16 @@
 });
 
 
+window.onbeforeunload = function() {
+	if (getCookie() == "Saved") {
+		setCookie("reload");
+	} else {
+		setCookie("");
+	}
+	
+};
+
+
 function addTag() {
 
 	largestId++;
@@ -294,6 +304,12 @@
 	var elid = document.getElementById("tdId"+id).textContent;
 	var elname = document.getElementById("tdName"+id).textContent;
 	var eltag = document.getElementById("tdTag"+id).textContent;
+
+
+	if (elname == "" || eltag == "") {
+		alert("Name and Tag cannot be empty.");
+		return;
+	}
 	/*
 	var elid = document.getElementById("tdId"+id).innerHTML;
 	var elname = document.getElementById("tdName"+id).innerHTML;
@@ -315,7 +331,9 @@
 		},
 		success: function (e) {
 			alert("Saved!");
-			document.location.reload(true);
+
+			setCookie("Saved");
+			//document.location.reload(true);
 		}
 	}).done(function(result) {
 	});
@@ -348,12 +366,17 @@
 		},
 		success: function (e) {
 			alert("Saved!");
-			document.location.reload(true);
+
+			setCookie("Saved");
+			console.log("log success the saving.." + getCookie());
+			//document.location.reload(true);
 		}
 	}).done(function(result) {
 	});
 }
 
+
+
 function DeleteTag( id ) {	
 	$("#tr"+id).remove();
 	var topic_id = JSON.parse('<?php echo json_encode($topic_id) ?>');
@@ -364,10 +387,16 @@
 		data : 'func=DeleteTag'+'&id='+id+'&type=delete&topic_id='+topic_id
 	}).done(function(result) {
 		alert("Saved!");
+		setCookie("Saved");
+		
 	});
 }
 
 
+
+
+
+
 $(document).on("click", "[name=tdName]", function () {
 	if ( $("#input"+this.id).length > 0 ) {
 		return;
--- a/views/Extractapp/TaggingText.php	Mon May 02 15:47:03 2016 +0200
+++ b/views/Extractapp/TaggingText.php	Wed May 04 15:22:11 2016 +0200
@@ -119,6 +119,22 @@
 }
 
 
+// ---- use cookie to save text and reload page for the up-to-date taglist 
+function updatePage() {
+    var text = getCookie();
+    //document.forms['receiver'].elements['message'].value = text;
+    console.log(text);
+    if (text == "reload") {
+        setCookie("");
+        saveTextToLGService();
+
+    }
+    setTimeout(updatePage, 500);
+
+}
+updatePage();
+
+// ------
 
 function reloadText() {
     /**
@@ -1448,6 +1464,9 @@
                         }
                     ?>
                     </select>
+                    <!-- edit wordlist -->
+                    <button onclick="window.open('./EditWordlist')" class="btn btn-default">Edit WordList</button></br> 
+
                     <br>
                     OR (USE "|" TO SEPARATE WORDS):<br>
                     <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br>
@@ -1546,8 +1565,6 @@
                             -->
                             <button onclick="replaceSmartRunSpace()" class="btn btn-default btn-block">Tag (Allow space within block)</button></br>
 
-                            <button onclick="window.open('./EditWordlist')" class="btn btn-default btn-block">Edit WordList</button></br>
-
                             <!-- developing...-->
                             <!-- 
                             <button onclick="genRegexWindowOpen()" id="gen_regex_window_open_id" class="btn btn-default btn-block btn-xs">Open GenRegex (developing...)</button></br>