changeset 14:ac77748bb813

- Load regex files based on current topic. Only show the regex in this topic. To do that, it needs to lookup a table called 'topic_regex_relation' which has the relation of topic and regex filename in filesystem. - Extractapp UI with some layout modification: button, popup window, responsive (by bootstrap now). It was just for quick prototyping.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 19 Feb 2015 11:07:27 +0100
parents cc36a20a68ab
children 1f98c92ebbfb
files develop/classes/basecontroller.php develop/classes/basemodel.php develop/controllers/extractapp.php develop/index.php develop/js/taggingtext.js develop/models/extractapp.php develop/views/Extractapp/edittaglist.php develop/views/Extractapp/index.php develop/views/Extractapp/taggingtext.php develop/views/maintemplate.php
diffstat 10 files changed, 450 insertions(+), 206 deletions(-) [+]
line wrap: on
line diff
--- a/develop/classes/basecontroller.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/classes/basecontroller.php	Thu Feb 19 11:07:27 2015 +0100
@@ -20,9 +20,20 @@
 		$viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php';
 		if ($fullview) {
 			require('views/maintemplate.php');
+			require($viewloc);
 		} else {
 			require($viewloc);
 		}
 	}
+
+	protected function ReturnView_localtest($viewmodel, $fullview) {
+        $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php';
+        if ($fullview) {
+            require('views/maintemplate_local.php');
+            require($viewloc);
+        } else {
+            require($viewloc);
+        }
+    }
 }
 ?>
\ No newline at end of file
--- a/develop/classes/basemodel.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/classes/basemodel.php	Thu Feb 19 11:07:27 2015 +0100
@@ -10,6 +10,8 @@
     protected $save_to_LGService_url = "http://141.14.239.226:8080/gazetteer-server/rest/text/save";
     protected $save_new_to_LGService_url = "http://141.14.239.226:8080/gazetteer-server/rest/text/saveNew";
 
+
+
 	public function __construct() {
         global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME;
         $this->systemNAME = $systemNAME;
--- a/develop/controllers/extractapp.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/controllers/extractapp.php	Thu Feb 19 11:07:27 2015 +0100
@@ -20,29 +20,36 @@
         switch ($this->postdata['func']) {
             case 'SaveFullText':
                 $viewmodel->SaveFullText($this->postdata);          
-                $this->ReturnView($viewmodel->StartTagging(), false); 
+                $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;   
             case 'SaveFullTextToLGService':
-                echo "[Z] SaveFullTextToLGService! ";
+                $viewmodel->messages .= "[Z] SaveFullTextToLGService! ";
                 $viewmodel->GetInfoFromPreviousPage($this->postdata);
                 $response = $viewmodel->SaveFullTextToLGService($this->postdata);
                 
                 $viewmodel->UpdateInfoByResponseFromLGService($response);    // update file_id, branch_id, user_id
                 
-                $this->ReturnView($viewmodel->StartTagging(), false); 
+                $this->ReturnView($viewmodel->StartTagging(), true); 
+                break;
+
+            case 'SmartRegexLoad':
+                $viewmodel->SmartRegexLoad($this->postdata['topic_id']);
+                break;
+            case 'SmartRegexSave':
+                $viewmodel->SmartRegexSave($this->postdata);
                 break;
 
             case 'ContinueTagging':
-                echo "[Z] (Countinue tagging) ";
+                $viewmodel->messages .= "[Z] (Countinue tagging) ";
                 if ($this->postdata['topic']) {
                     $viewmodel->SetTopic($this->postdata['topic']);
                 }
                 $viewmodel->GetInfoFromPreviousPage($this->postdata);
-                $this->ReturnView($viewmodel->StartTagging(), false); 
+                $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;
+
             default:    // first time visit extraction interface from LGService
-                // TODO: get the _post data from Jorge's service
-                echo "[Z] Welcome to Extraction Interface. ";
+                $viewmodel->messages .= "[Z] Welcome to Extraction Interface. ";
 
                 if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) {
                     // get text from fileId, from LGService
@@ -56,15 +63,15 @@
                 } else if (is_numeric($this->urlvalues['id'])) {
                     // get text from local file system (for development stage only)
                     $viewmodel->GetTextFromLocal($this->urlvalues['id']);
+                    $this->ReturnView_localtest($viewmodel->StartTagging(), true); 
+                    break;                    
 
                 } else {
-                    var_dump($this->postdata);
-
-                    echo "wrong url!!";
+                    $viewmodel->messages .= "wrong url!!";
                     return;
                 }
 
-                $this->ReturnView($viewmodel->StartTagging(), false); 
+                $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;
         }
 
@@ -75,7 +82,7 @@
     protected function ExportTable() {
         //$viewmodel = new ExtractappModel();
         $viewmodel = $this->viewmodel;
-        $this->ReturnView($viewmodel->ExportTable($this->postdata), false);
+        $this->ReturnView($viewmodel->ExportTable($this->postdata), true);
 
     }
 
@@ -84,13 +91,13 @@
         $viewmodel = $this->viewmodel;
         switch ($this->postdata['func']) {
             case 'AddNewList':
-                $this->ReturnView($viewmodel->AddNewList($this->postdata), false);
+                $this->ReturnView($viewmodel->AddNewList($this->postdata), true);
                 break;
             case 'SaveWordlist':
-                $this->ReturnView($viewmodel->SaveWordlist($this->postdata), false);
+                $this->ReturnView($viewmodel->SaveWordlist($this->postdata), true);
                 break;
             default:    // EditWordlist
-                $this->ReturnView($viewmodel->EditWordlist($this->urlvalues), false);    
+                $this->ReturnView($viewmodel->EditWordlist(), true);    
             break;
          } 
     }
@@ -101,16 +108,16 @@
         $viewmodel = $this->viewmodel;
         switch ($this->postdata['func']) {
             case 'NewTagElement':
-                $this->ReturnView($viewmodel->NewTagElement($this->postdata), false);
+                $this->ReturnView($viewmodel->NewTagElement($this->postdata), true);
                 break;
             case 'SaveTagElement':
-                $this->ReturnView($viewmodel->SaveTagElement($this->postdata), false);
+                $this->ReturnView($viewmodel->SaveTagElement($this->postdata), true);
                 break;
             case 'DeleteTag':
-                $this->ReturnView($viewmodel->DeleteTag($this->postdata), false);
+                $this->ReturnView($viewmodel->DeleteTag($this->postdata), true);
                 break;
             default:    // EditTaglist
-                $this->ReturnView($viewmodel->EditTaglist($this->urlvalues), false);
+                $this->ReturnView($viewmodel->EditTaglist(), true);
                 break;
         }
     }
@@ -124,7 +131,7 @@
                 
                 break;
             default:    
-                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), false);  
+                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true);  
             break;
          } 
     }
@@ -134,6 +141,8 @@
         $this->ReturnView($viewmodel->Test(), true);
     }
 
+
+    
 	
 }
 
--- a/develop/index.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/index.php	Thu Feb 19 11:07:27 2015 +0100
@@ -1,36 +1,11 @@
 
-<html>
-<head>
-<title></title>
-
-<!-- 
-<script src="../../js/jquery-1.10.2.min.js"></script> 
-<script src="../../js/taggingtext.js"></script>
--->
-
-<!-- Bootstrap -->
-<!-- <link href="../../css/bootstrap.min.css" rel="stylesheet">
--->
-<!-- 
-<script src="../../js/bootstrap.min.js"></script>
--->
-
-
-</head>
-<body>
 <?php
 header("Content-Type: text/html;charset=utf-8");
 
 // system configiration
 include_once('config/Lib_mb_utf8.php');
 include_once('config/config.php');
-?>
 
-<script src="<?php echo $system_root_url; ?>/js/jquery-1.10.2.min.js"></script>
-<script src="<?php echo $system_root_url; ?>/js/bootstrap.min.js"></script>
-<script src="<?php echo $system_root_url; ?>/js/taggingtext.js"></script>
-
-<?php
 // require the general classes
 require("classes/loader.php");
 require("classes/basecontroller.php");
@@ -57,16 +32,10 @@
 
 
 
-
 // create the controller and execute the action
 $loader = new Loader($_GET, $_POST);
 
 $controller = $loader->CreateController();
 $controller->ExecuteAction();
 
-
 ?>
-
-</body>
-
-</html>
\ No newline at end of file
--- a/develop/js/taggingtext.js	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/js/taggingtext.js	Thu Feb 19 11:07:27 2015 +0100
@@ -310,6 +310,8 @@
     
     //document.styleSheets[0].addRule("tag001", "color:green;")
 }
+
+
 //Tagging Items
 function getSelected() {
     if(window.getSelection) {
@@ -419,8 +421,8 @@
     $('#smartRegexPopUpDiv').css("background-color", "White");
     $('#smartRegexPopUpDiv').css("width", "400px");
     $('#smartRegexPopUpDiv').css("height", "300px");
-    $('#smartRegexPopUpDiv').css("top", "100px");
-    $('#smartRegexPopUpDiv').css("left", "-200px");
+    $('#smartRegexPopUpDiv').css("top", "170px");
+    $('#smartRegexPopUpDiv').css("left", "-400px");
     $('#smartRegexPopUpDiv').css("border", "1px solid black");
     $('#smartRegexPopUpDiv').css("padding", "5px");
     
@@ -600,21 +602,63 @@
     //el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
 }
 
+function smartRegexSave() {
+    var x;
+    var name=prompt("Please enter this Regex name",RegexLoadedName);
+    if (name!=null){
+        $.ajax({
+            type : 'POST',
+            url : './TaggingText',
+            async : false,
+            data : 'func=SmartRegexSave'+'&text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name,
+            error: function (result) {
+                alert("Error when saving");
+            }
+        }).done(function(result) {
+            alert("Saved!");
+        });
+    }
+}
 
-function smartRegexLoad(section_id) {
+function smartRegexLoad(topic_id) {
     $('#load_regex_div').html("");
     $('#load_regex_div').css("display", "block");
     $('#load_regex_div').css("border", "1px solid black");
     $('#load_regex_div').css("background-color", "White");
-    $('#load_regex_div').css("width", "200px");
-    $('#load_regex_div').css("height", "150px");
+    $('#load_regex_div').css("width", "300px");
+    $('#load_regex_div').css("height", "70px");
     $('#load_regex_div').css("top", "100px");
-    $('#load_regex_div').css("left", "-200px");
+    $('#load_regex_div').css("left", "-300px");
     
     var newselect = document.createElement("select");
     newselect.id = "loadRegexSelect";
             
+    $.ajax({
+        type: 'POST', 
+        url: './TaggingText',
+        dataType: 'json',
+        data: "func=SmartRegexLoad&topic_id="+topic_id,
+        //cache: false,
+        success: function (data) {
+            $.each(data, function(index, element) {
+                newselect.innerHTML += "<option value=\""+index+"\">"+index+"</option>\n";
+                //alert(index);
+                //alert(element);
+                var newdiv = document.createElement("div");
+                $(newdiv).css("display", "none");
+                $(newdiv).html(element);
+                $(newdiv).attr("id", "div_"+index);
+                $('#load_regex_div').append(newdiv);
+            });
+            
+        },
+        error: function (data) {
+            console.log("SmartRegexLoad fails");
+        }
 
+    });
+
+    /*
     $.ajax({
         type: 'POST', 
         url: '../models/_extractapp_func.php',
@@ -639,14 +683,17 @@
         }
 
     });
+    */
     
     $('#load_regex_div').append(newselect);
     var newbutton = document.createElement("button");
     $(newbutton).html("Load");
+    $(newbutton).addClass("btn btn-info");
     $(newbutton).attr("onclick", "loadRegexAdd()");
     $('#load_regex_div').append(newbutton);
     var newbutton = document.createElement("button");
     $(newbutton).html("Close");
+    $(newbutton).addClass("btn btn-default");
     $(newbutton).attr("onclick", "$('#load_regex_div').css(\"display\", \"none\");");
     $('#load_regex_div').append(newbutton);
 }
@@ -806,7 +853,7 @@
 function showListContent( id ) {
     var xhr = new XMLHttpRequest();
     xhr.onreadystatechange = process;
-    xhr.open("POST", "../../data/wordlist/"+id+".txt?t=" + Math.random(), true);
+    xhr.open("POST", "../data/wordlist/"+id+".txt?t=" + Math.random(), true);
     // TODO: should show the latest wordlist file. eg. id_timestamp.txt, rather than open the original id.txt file 
 
 
@@ -843,5 +890,6 @@
 
 
 // ============
+// 
 
 
--- a/develop/models/extractapp.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/models/extractapp.php	Thu Feb 19 11:07:27 2015 +0100
@@ -8,7 +8,8 @@
 		return array("Index Value 1", "Value 2", "Value 3");
 	}
     
-    protected $section_id=0, $data_path, $file_id=0, $branch_id=0, $user_id=0, $lg_text="";
+    protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = "";
+    public $messages = "";
 
     private function Initialize($_urlvalues) {
         $this->SetSectionId($_urlvalues);
@@ -61,7 +62,7 @@
 
     public function GetTextFromLocal($_id){
         $this->section_id = $_id;
-        echo "DEBUG: from my local"."<br>";
+        $this->messages .= "DEBUG: from my local"."<br>";
         $this->lg_text = $this->GetSectionContent();
 
     }
@@ -157,7 +158,8 @@
         $data['topic_tag'] = $this->GetTopicTag($this->GetTopic());
         
         $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id);
-        
+        $data['messages'] = $this->messages;
+
         return $data;
         
     }
@@ -191,12 +193,11 @@
         $response_file = $response["file"];
         $response_branch = $response["branch"];
 
-        $this->file_id = (string)$response_file["id"];  // should updated
-        echo "file_id: ".$this->file_id;
-        echo "<br>";
+        $this->file_id = (string)$response_file["id"]; 
         $this->branch_id = (string)$response_branch["id"];
-        echo "branch_id: ".$this->branch_id;
-        echo "<br>";
+
+        $this->messages .= "file_id: ".$this->file_id."<br>";
+        $this->messages .= "branch_id: ".$this->branch_id."<br>";
 
     }
     public function SaveFullTextToLGService($_postdata) {
@@ -225,7 +226,6 @@
             file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
         } 
 
-        echo getcwd()."<br>";
         // ------
 
 
@@ -250,9 +250,9 @@
                 //"userId" => $_postdata['userId'],
                 // TODO: change userId when we can query by sectionId from LGService using search
                 "userId" => "12",
-                // "label" => $_postdata['label'],
+                "label" => $_postdata['label'],
                 // TODO: ask user for lable
-                "label" => "label for section ".$_postdata['sectionId'],
+                //"label" => "label for section ".$_postdata['sectionId'],
             ); 
             $save_url = $this->save_new_to_LGService_url;
         }   
@@ -286,7 +286,68 @@
         return $response;
 
     }
-    
+
+    // --- for regex ----
+    public function GetRegexFilenameById($topic_id) {
+        $query = sprintf("SELECT regex_filename FROM `topic_regex_relation` WHERE  topic_id=\"%s\"", $topic_id);
+        $result = mysql_query($query);
+        if (!$result) {
+            return json_encode("Failed during selecting topic_regex_relation table.");
+        }
+
+        $filenames = array();
+        while ($row = mysql_fetch_assoc($result)) {
+            array_push($filenames, $row['regex_filename']);
+        }
+
+        return $filenames;
+    }
+    public function SmartRegexLoad($topic_id) {
+
+        // Load regex file based on current topic. Only shows the regex in this topic --
+        $filenames = $this->GetRegexFilenameById($topic_id);
+        
+        // Get regex file from filesystem ----
+        $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
+        $returnArray = array();
+        $files1 = scandir($data_path."regex_files");
+        foreach ( $files1 as $file ) {
+            if ( $file != "." && $file != ".." && $file != ".DS_Store") {
+                foreach ($filenames as $filename) {
+                    if ($file == $filename) {
+                        $returnArray[preg_replace("/\.txt/", "", $file)] = file_get_contents( $data_path."regex_files/".$file );
+                        break;
+                    }
+                }
+            }
+        }
+        echo json_encode($returnArray);
+        return;
+    }
+
+
+    public function SmartRegexSave($_postdata) {
+        if ($_postdata['text']){
+            /*
+            $date = date('Y_m_d_H_i_s', time());
+            if ( file_exists("regex_files/".$_POST['filename'].".txt") ) {
+                $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt");
+                file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile);
+            }
+            */
+            $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
+            
+            if (get_magic_quotes_gpc()) {
+                $require = stripslashes($_postdata['text']);
+            } else {
+                $require = $_postdata['text'];
+            }
+
+            file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require);   
+        }
+    }
+
+
     // === for export table ===
     public function ExportTable($postdata) {
         // $this->Initialize($urlvalues);
@@ -413,7 +474,7 @@
     }
     
     // === for manage tag list ===
-    public function EditTaglist($urlvalues) {
+    public function EditTaglist() {
         // $this->Initialize($urlvalues);
         $result = $this->GetTaglist();
         $taglistArray = array();
@@ -565,7 +626,7 @@
     // =========================== 
 
     // === for manage wordlist ===
-    public function EditWordlist($urlvalues) {
+    public function EditWordlist() {
         $result = $this->GetWordlist();
         $wordlistArray = array();
         while ($row = mysql_fetch_assoc($result)) {
@@ -702,9 +763,6 @@
         $section_id = $this->GetSectionId();
         $section_info = $this->GetSectionInfo();
 
-        var_dump($section_id);
-        var_dump($section_info);
-
         $bookId = $section_info['bookId'];
         $startPage = $section_info['startPage'];
         $endPage = $section_info['endPage'];
--- a/develop/views/Extractapp/edittaglist.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/views/Extractapp/edittaglist.php	Thu Feb 19 11:07:27 2015 +0100
@@ -1,16 +1,17 @@
 <?php
 // --- initialize ---
 $taglistArray = $viewmodel['taglistArray'];
+
 ?>
 
 <html>
 <head>
 <title></title>
-<link rel="stylesheet" href="../../css/colorpicker.css" type="text/css" />
-<script type="text/javascript" src="../../js/colorpicker.js"></script>
-<script type="text/javascript" src="../../js/eye.js"></script>
-<script type="text/javascript" src="../../js/utils.js"></script>
-<script type="text/javascript" src="../../js/layout.js?ver=1.0.2"></script>
+<link rel="stylesheet" href="../css/colorpicker.css" type="text/css" />
+<script type="text/javascript" src="../js/colorpicker.js"></script>
+<script type="text/javascript" src="../js/eye.js"></script>
+<script type="text/javascript" src="../js/utils.js"></script>
+<script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
 </head>
 
 <body>
--- a/develop/views/Extractapp/index.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/views/Extractapp/index.php	Thu Feb 19 11:07:27 2015 +0100
@@ -1,7 +1,28 @@
-<h1>Extractapp/index.php</h1>
+<html>
+<head>
+<title></title>
+
+<!-- 
+<script src="../../js/jquery-1.10.2.min.js"></script> 
+<script src="../../js/taggingtext.js"></script>
+-->
 
-<ul>
-    <?php foreach($viewmodel as $item) { ?>
-    <li><?php echo $item; ?></li>
-    <?php } ?>
-</ul>
+<!-- Bootstrap -->
+<!-- <link href="../../css/bootstrap.min.css" rel="stylesheet">
+-->
+<!-- 
+<script src="../../js/bootstrap.min.js"></script>
+-->
+
+
+</head>
+<body>
+
+
+<script src="<?php echo $system_root_url; ?>/js/jquery-1.10.2.min.js"></script>
+<script src="<?php echo $system_root_url; ?>/js/bootstrap.min.js"></script>
+<script src="<?php echo $system_root_url; ?>/js/taggingtext.js"></script>
+
+</body>
+
+</html>
\ No newline at end of file
--- a/develop/views/Extractapp/taggingtext.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/views/Extractapp/taggingtext.php	Thu Feb 19 11:07:27 2015 +0100
@@ -8,7 +8,8 @@
 $default_topic_id = $viewmodel['default_topic_id'];
 $topic_tag = $viewmodel['topic_tag'];
 $info = $viewmodel['info'];
-var_dump($info);
+$messages = $viewmodel['messages'];
+
 
 ?>
 
@@ -59,7 +60,7 @@
 if (_GET['id']) {
     
     var info = JSON.parse('<?php echo json_encode($info) ?>');
-    var redirectUrl = "http://141.14.239.50:1080/localmonographs/develop/Extractapp/TaggingText";
+    var redirectUrl = "http://localhost:1080/localmonographs/develop/Extractapp/TaggingText";
     var section_id = info['section_id'];
 
     var form = $('<form action="' + redirectUrl + '" method="post">' +
@@ -87,6 +88,7 @@
     var originalelpos=el.offset().top; // take it where it originally is on the page
 
     //run on scroll
+    /*
     $(window).scroll(function(){
         var el = $('#follow-scroll'); // important! (local)
         var elpos = el.offset().top; // take current situation
@@ -94,6 +96,8 @@
         var finaldestination = windowpos+originalelpos;
         el.stop().animate({'top':finaldestination},500);
     });
+    */
+
 });
 $(document).on("click", "name", function (e) {
 
@@ -246,118 +250,25 @@
 }
 
 
-function smartRegexSave() {
-    var x;
-    var name=prompt("Please enter this Regex name",RegexLoadedName);
-    if (name!=null){
-        $.ajax({
-            type : 'POST',
-            url : '../models/_extractapp_func.php',
-            async : false,
-            data : 'func=SmartRegexSave'+'&text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name
-        }).done(function(result) {
-            alert("Saved!");
-        });
-    }
-}
 
-function _postForContineTagging(form) {
-    
-
-    var hiddenField = document.createElement("input");      
-    hiddenField.setAttribute("name", "text");
-    var el = document.getElementById("editable-area");
-    var text = el.innerHTML;
-    hiddenField.setAttribute("value", text);
-    form.appendChild(hiddenField);
-
-    var info = JSON.parse( '<?php echo json_encode($info) ?>');
-
-    if (info) {
-        // TODO: different field info array based on fileId(branchId) existing or not
-        var hiddenField = document.createElement("input");      
-        hiddenField.setAttribute("name", "fileId");
-        hiddenField.setAttribute("value", info['file_id']);
-        form.appendChild(hiddenField);
-        var hiddenField = document.createElement("input");      
-        hiddenField.setAttribute("name", "branchId");
-        hiddenField.setAttribute("value", info['branch_id']);
-        form.appendChild(hiddenField);
-        var hiddenField = document.createElement("input");      
-        hiddenField.setAttribute("name", "userId");
-        hiddenField.setAttribute("value", info['user_id']);
-        form.appendChild(hiddenField);
-        var hiddenField = document.createElement("input");      
-        hiddenField.setAttribute("name", "sectionId");
-        hiddenField.setAttribute("value", info['section_id']);
-        form.appendChild(hiddenField);
-        
-        
-    }
-
-    if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
-        document.body.appendChild(form);
-        form.submit();
-    } else {
-        form.submit(); // works under IE and Chrome, but not FF  
-    }
-
-}
+function saveTextToLGService() {
+    var info = JSON.parse('<?php echo json_encode($info) ?>');
 
 
-
-
-// === for config tags in topic ===
-function configTagsInTopic(topic_id) {
-    var form = document.createElement("form");
-    
-    form.setAttribute("method", "post");
-    //form.setAttribute("action", "exportTable.php");
-    form.setAttribute("action", "./ConfigTagsInTopic");  // hand to controller
-    form.setAttribute("target", "_blank");
+    // if this is a new branch, ask for label
+    if (info['branch_id'] == 0) {
+        var label = prompt("Please enter your label for this new branch", "label for section "+info['section_id']);
+        while (label == null) {
+            label = prompt("Please enter your label for this new branch (not empty)", "label for section "+info['section_id']);
+        }    
+    };
     
 
-    var hiddenField = document.createElement("input");      
-    hiddenField.setAttribute("name", "topic");
-    hiddenField.setAttribute("value", topic_id);
-    form.appendChild(hiddenField);
-
-    _postForContineTagging(form);
-
-}
-
-
-function saveTextToLGService(section_id) {
-    var info = JSON.parse('<?php echo json_encode($info) ?>');
-    
-    var el = document.getElementById("editable-area");
-    
-    /*
-    $.ajax({
-        url : './TaggingText/'+section_id,
-        async : false,
-        type : 'POST',
-        data : 'func=SaveFullTextToLGService'+'&text='+el.innerHTML+'&fileId='+info['file_id']+'&branchId='+info['branch_id']+'&userId='+info['user_id']+'&sectionId='+info['section_id'],
-        success: function (result) {
-            console.log(result);
-        },
-        error: function (data) {
-            console.log("error when saving to LGService!");
-        }
-    }).done(function(result) {
-        alert("Saved!");
-        console.log("result: "+result);
-    });
-    
-    */
-
-
-
     var form = document.createElement("form");
     form.setAttribute("method", "post");
-    // form.setAttribute("action", "./");  // hand to controller
+    form.setAttribute("action", "./TaggingText");  // hand to controller
     
-    form.setAttribute("action", "./"+info['section_id']);  // hand to controller
+    // form.setAttribute("action", "./"+info['section_id']);  // hand to controller
     form.setAttribute("target", "_self");
     
     var hiddenField = document.createElement("input");      
@@ -382,12 +293,17 @@
         hiddenField.setAttribute("name", "sectionId");
         hiddenField.setAttribute("value", info['section_id']);
         form.appendChild(hiddenField);
+     
 
     }
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "label");
+    hiddenField.setAttribute("value", label);
+    form.appendChild(hiddenField);
 
     var hiddenField = document.createElement("input");      
     hiddenField.setAttribute("name", "text");
-    //var el = document.getElementById("editable-area");
+    var el = document.getElementById("editable-area");
     //var text = encodeURIComponent(el.innerHTML);
     var text = el.innerHTML;
     hiddenField.setAttribute("value", text);
@@ -413,12 +329,14 @@
 
     $('#load_topic_div').html("");
     $('#load_topic_div').css("display", "block");
+    
     $('#load_topic_div').css("border", "1px solid black");
     $('#load_topic_div').css("background-color", "White");
-    $('#load_topic_div').css("width", "200px");
+    $('#load_topic_div').css("width", "150px");
     $('#load_topic_div').css("height", "50px");
     $('#load_topic_div').css("top", "20px");
-    $('#load_topic_div').css("left", "-200px");
+    $('#load_topic_div').css("left", "-150px");
+
 
     var topic_select = document.createElement("select");
     topic_select.id = "loadTopiclist";
@@ -468,14 +386,76 @@
 	}
 
     $('#load_topic_div').append(topic_select);
+
    
     var newbutton = document.createElement("button");
     $(newbutton).html("Close");
+    $(newbutton).addClass("btn btn-default");
     $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");");
     $('#load_topic_div').append(newbutton);
   
 }
 
+// --- for config tags in topic ---
+function _postForContineTagging(form) {
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "text");
+    var el = document.getElementById("editable-area");
+    var text = el.innerHTML;
+    hiddenField.setAttribute("value", text);
+    form.appendChild(hiddenField);
+
+    var info = JSON.parse( '<?php echo json_encode($info) ?>');
+
+    if (info) {
+        // TODO: different field info array based on fileId(branchId) existing or not
+        var hiddenField = document.createElement("input");      
+        hiddenField.setAttribute("name", "fileId");
+        hiddenField.setAttribute("value", info['file_id']);
+        form.appendChild(hiddenField);
+        var hiddenField = document.createElement("input");      
+        hiddenField.setAttribute("name", "branchId");
+        hiddenField.setAttribute("value", info['branch_id']);
+        form.appendChild(hiddenField);
+        var hiddenField = document.createElement("input");      
+        hiddenField.setAttribute("name", "userId");
+        hiddenField.setAttribute("value", info['user_id']);
+        form.appendChild(hiddenField);
+        var hiddenField = document.createElement("input");      
+        hiddenField.setAttribute("name", "sectionId");
+        hiddenField.setAttribute("value", info['section_id']);
+        form.appendChild(hiddenField);
+        
+    }
+
+    if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
+        document.body.appendChild(form);
+        form.submit();
+    } else {
+        form.submit(); // works under IE and Chrome, but not FF  
+    }
+
+}
+
+function configTagsInTopic(topic_id) {
+    var form = document.createElement("form");
+    
+    form.setAttribute("method", "post");
+    //form.setAttribute("action", "exportTable.php");
+    form.setAttribute("action", "./ConfigTagsInTopic");  // hand to controller
+    form.setAttribute("target", "_blank");
+    
+
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "topic");
+    hiddenField.setAttribute("value", topic_id);
+    form.appendChild(hiddenField);
+
+    _postForContineTagging(form);
+
+}
+
+
 
 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {
 
@@ -488,9 +468,138 @@
 ?>
 });
 
+$(function () {
+
+    $('#example').popover({
+          //selector: '.has-popover'
+        content: function () {
+            return;
+        },
+        //template: output_content,
+        title: "Load Regex"
+    });
+})
+
+
+
+// init for popover used in bootstrap
+$(function () {
+  $('[data-toggle="popover"]').popover()
+})
 
 </script>
 
+<div class="container-fluid">
+    <div class="row">
+        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-10 col-lg-offset-1"> 
+            <p class="bg-primary"> <?php echo $messages; ?> </p>
+        </div>
+    </div>
+
+    <div class="row">
+        <div id="editable-area" class="col-xs-8 col-sm-8 col-md-8 col-lg-7 col-lg-offset-1"><?php echo $stringInput; ?>
+        </div>
+        <div id="follow-scroll" class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
+            <div id="load_topic_div" style="position: absolute; display: none"></div>
+            <div id="load_regex_div" style="position: absolute; display: none"></div>
+            <div id="smartRegexPopUpDiv" style="position: absolute; display: none">
+                Name: <input id="smartRegexPopUpName"></input><br><br>
+                Word List: 
+                <select id="smartRegexPopUpSelectWord">
+                <option value="NULL" selected>無</option>
+                <?php
+                    foreach ( $wordlistArray as $wordlistValue ) {
+                        echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n";
+                    }
+                ?>
+                </select>
+                <br>
+                OR (USE "|" TO SEPARATE WORDS):<br>
+                <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br>
+                Tag:
+                <select id="smartRegexPopUpSelectTag">
+                <?php
+                    foreach ( $taglistArray as $taglistValue ) {
+                        echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n";
+                    }
+                    echo "<option value=\"title\">Title</option>\n";
+                ?>
+                <option value="NOTAG">不標記</option>
+                </select><br>
+                <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" class="btn btn-info" style="">Add</button>
+                <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" class="btn btn-success" style="">Edit</button>
+                <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" class="btn btn-warning" style="">Delete</button>
+                <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" class="btn btn-default" style=""><<</button>
+                <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" class="btn btn-default" style="">>></button>
+                <button onclick="replaceSmartClose()" class="btn btn-default" style="">Close</button>
+            </div>
+                     
+            <form action="javascript:void(0);">   
+                
+                <h4 class="text-success"> Config Topic</h4>
+                <button onclick="chooseTopic(<?php echo $default_topic_id; ?>)" class="btn-">Choose Topic</button>
+                
+                <button onclick="configTagsInTopic(<?php echo $default_topic_id;?>)" style="">Config Tags</button></br>
+            
+                <fieldset>
+                    <legend><h4 class="text-success"> Replace By <i><b>Smart Regex</b></i>©: </h4></legend>
+                    <div id="smartRegexShowDiv"></div><br>
+                    <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br>
+                    Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br>
+                    <button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br>
+                    <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br>
+                    <button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button>
+                    <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 70px">Load</button>
+                    <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br>
+                   
+                    <!--
+                    <button id="example" type="button" class="btn btn-sm btn-default" data-toggle="popover">Load</button>
+                    -->
+
+                </fieldset>
+                
+                <fieldset>
+                    <legend><h4 class="text-success"> Tag by rule:</h4></legend>
+                    <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br>
+                    <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
+                    <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>-->
+                    <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>-->
+                    <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
+                </fieldset>
+            
+                <fieldset>
+                    <legend><h4 class="text-success"> Edit:</h4></legend>
+                    <button onclick="saveTextToLGService()" style="height: 30px; width: 220px">Save to LGService</button></br>
+                
+                    <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
+                    <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>
+                    <button onclick="window.open('./EditTaglist')" style="height: 30px; width: 220px">Manage Tag List</button></br>
+                </fieldset>
+                
+                <fieldset>
+                    <legend><h4 class="text-success"> Export:</h4></legend>
+                    Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br>
+                    <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br>
+                    <button onclick="exportAll(<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export All</button></br>
+                </fieldset>
+            
+                <fieldset>
+                    <legend><h4 class="text-success"> Replace By <i><b>Regex</b></i>: </h4></legend>
+                    Range: <input type="text" size="5" id="regexPageStart2">to<input type="text" size="5" id="regexPageEnd2"><br>
+                    Regex: <input type="text" size="30" id="regexText"></br>
+                    Replace: <input type="text" size="30" id="replaceText"><br>
+                    <button onclick="replaceSmartRegex()">Replace!</button>
+                </fieldset>
+            </form>
+        </div>
+    </div>
+
+</div>
+
+
 <table width="1250" border="1">
 	<tr>
 		<td width="980">
@@ -542,7 +651,7 @@
 						<button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br>
 						<button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br>
 						<button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button>
-						<button onclick="smartRegexLoad(<?php echo $section_id;?>)" style="height: 30px; width: 70px">Load</button>
+						<button onclick="smartRegexLoad()" style="height: 30px; width: 70px">Load</button>
 						<button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br>
 					</fieldset>
 					
@@ -557,14 +666,14 @@
 					
 					<fieldset>
 						<legend>Edit:</legend>
-						<button onclick="saveTextToLGService(<?php echo $section_id;?>)" style="height: 30px; width: 220px">Save to LGService</button></br>
+						<button onclick="saveTextToLGService()" style="height: 30px; width: 220px">Save to LGService</button></br>
                     
                         <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
 						<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/<?php echo $section_id;?>')" style="height: 30px; width: 220px">Manage Word List</button></br>
-						<button onclick="window.open('./EditTaglist/<?php echo $section_id;?>')" style="height: 30px; width: 220px">Manage Tag List</button></br>
+						<button onclick="window.open('./EditWordlist')" style="height: 30px; width: 220px">Manage Word List</button></br>
+						<button onclick="window.open('./EditTaglist')" style="height: 30px; width: 220px">Manage Tag List</button></br>
 					</fieldset>
 					
 					<fieldset>
@@ -586,6 +695,9 @@
 		</td>
 	</tr>
 </table>
+
+
+
 </body>
 
 </html>
--- a/develop/views/maintemplate.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/views/maintemplate.php	Thu Feb 19 11:07:27 2015 +0100
@@ -1,15 +1,28 @@
 <html>
+<head>
+<title></title>
 
-<head>
+<!-- 
+<script src="../../js/jquery-1.10.2.min.js"></script> 
+<script src="../../js/taggingtext.js"></script>
+-->
+<script src="../js/jquery-1.10.2.min.js"></script>
+<script src="../js/bootstrap.min.js"></script>
+<script src="../js/taggingtext.js"></script>
+
+<!-- Bootstrap -->
+<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
+
+<link href="../css/bootstrap.min.css" rel="stylesheet">
+<script src="../js/bootstrap.min.js"></script>
+<script src="../js/bootstrap.js"></script>
+
+
 </head>
 <body>
 
-<ul>
-    <?php foreach($viewmodel as $item) { ?>
-    <li><?php var_dump($item); ?></li>
-    <?php } ?>
-</ul>
-
 
 </body>
+
 </html>
\ No newline at end of file