changeset 57:5cf9720a2e25 extractapp

New: add reloadText to load the latest version
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 30 Mar 2015 17:23:47 +0200
parents 95f929d7b318
children a11f9103b8db
files controllers/extractapp.php models/extractapp.php views/Extractapp/TaggingText.php
diffstat 3 files changed, 51 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/controllers/extractapp.php	Mon Mar 30 15:54:04 2015 +0200
+++ b/controllers/extractapp.php	Mon Mar 30 17:23:47 2015 +0200
@@ -27,7 +27,6 @@
                 $viewmodel->GetInfoFromPreviousPage($this->postdata);
                 $response = $viewmodel->SaveFullTextToLGService($this->postdata);
                 $viewmodel->UpdateInfoByResponseFromLGService($response);    // update file_id, branch_id, user_id
-                // TODO: GetTextFromFileId?? reload saved file from LGService, necessary!
                 $viewmodel->GetTextFromFileId();     
                 $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;
@@ -38,8 +37,12 @@
             case 'SmartRegexSave':
                 $viewmodel->SmartRegexSave($this->postdata);
                 break;
-            case 'Reload':
-                // $viewmodel->Reload();
+            case 'ReloadText':
+                $viewmodel->messages .= "Reload the latest text "."<br>";
+                $viewmodel->GetInfoFromPreviousPage($this->postdata);
+                $viewmodel->ReloadSetting();    // set file_id = current_fileId, current_fileId = 0
+                $viewmodel->GetTextFromFileId();
+                $this->ReturnView($viewmodel->StartTagging(), true);
                 break;
 
             case 'ContinueTagging':
--- a/models/extractapp.php	Mon Mar 30 15:54:04 2015 +0200
+++ b/models/extractapp.php	Mon Mar 30 17:23:47 2015 +0200
@@ -348,13 +348,15 @@
 
         $status = (string)$response["status"];
         if ($status == "ok") {
-            $this->messages .= "saving success.";
+            $this->messages .= "Saving success.";
             $this->file_id = (string)$response_file["id"]; 
             $this->branch_id = (string)$response_branch["id"];
 
         } else if ($status == "error") {
             // saving not success
-            $this->messages .= "saving does not success! ".(string)$response["message"];
+            $this->messages .= "Saving Failed! ".(string)$response["message"]."<br>";
+            $this->messages .= "Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>";
+
             $response_currentFile = $response["currentFile"];
             //$this->current_fileId = $response["currentFileId"];
             $this->current_fileId = (string)$response_currentFile["id"];
@@ -363,6 +365,14 @@
         
 
     }
+
+    public function ReloadSetting() {
+        if ($this->current_fileId != 0) {
+            $this->file_id = $this->current_fileId;
+            $this->current_fileId = 0;
+        }
+    }
+
     private function AppendMetaData($text_content) {
         $text = '<?xml version="1.0" encoding="UTF-8"?>';
         $text .= "\n<text>\n";
--- a/views/Extractapp/TaggingText.php	Mon Mar 30 15:54:04 2015 +0200
+++ b/views/Extractapp/TaggingText.php	Mon Mar 30 17:23:47 2015 +0200
@@ -79,6 +79,34 @@
     }
 }
 
+function reloadText() {
+    // confirm to reload
+    var r = confirm("Your editing will be discarded. Are you sure you want to reload?");
+    if (r != true) {
+        return;
+    }
+
+    var form = document.createElement("form");
+    form.setAttribute("method", "post");
+    form.setAttribute("action", "./TaggingText");  // hand to controller
+    //form.setAttribute("target", "_self");
+    form.setAttribute("target", "_blank");
+
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "topic");
+    var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
+    hiddenField.setAttribute("value", topic_id);
+    form.appendChild(hiddenField);
+
+    var hiddenField = document.createElement("input");      
+    hiddenField.setAttribute("name", "func");
+    hiddenField.setAttribute("value", "ReloadText");
+    form.appendChild(hiddenField);
+
+    _postForContineTagging(form);
+
+}
+
 // TODO: Popup to proceeding the saving situations
 function handleFileVersionConflict() {
     var info = JSON.parse('<?php echo json_encode($info) ?>');
@@ -86,74 +114,8 @@
     
     if (info['current_fileId'] != 0 && info['current_fileId'] != info['file_id']){
         // -- there might be conflicts between different version
-        alert("Someone edited this file and saved before you.");
+        alert("Your saving failed! Someone edited this file and saved before you.");
         return;
-
-        var retVal = confirm('There were something happened/someone editing in the between of time.\nDo you want to force saving? (There might be conflicts between two versions.)');
-        if( retVal == true ){
-            // TODO: force saving with currentFileId
-            alert("You do the force saving!");
-            //saveTextToLGService();
-
-        }else{
-            var loadLastest = confirm("Do you want to reload for the lastest version? (Your current editing will lost.)");
-            
-            console.log("loadLastest="+loadLastest);
-            /*
-            var form = document.createElement("form");
-            form.setAttribute("method", "post");
-            form.setAttribute("action", "./TaggingText");  // hand to controller
-            form.setAttribute("target", "_blank");  
-
-            var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
-
-            var hiddenField = document.createElement("input");      
-            hiddenField.setAttribute("name", "topic");
-            hiddenField.setAttribute("value", topic_id);
-            form.appendChild(hiddenField);
-
-            var hiddenField = document.createElement("input");      
-            hiddenField.setAttribute("name", "func");
-            hiddenField.setAttribute("value", "Reload");  // reload
-            form.appendChild(hiddenField);
-
-            _postForContineTagging(form);
-
-            alert("You will reload the latest version.");   
-            */
-            /*
-            if (loadLastest == true) {
-                // TODO: reload page with the currentFileId
-                console.log('loadLastest is true');
-                $.ajax({
-                    type : 'POST',
-                    url : './TaggingText',
-                    async : false,
-                    data : 'func=Reload',
-                    success: function (result) {
-                        //var lastest_editing = jQuery.parseJSON(result); 
-                        console.log("lastest_editing string:"+result);
-                        // change text to the new one
-                        //var el = document.getElementById("editable-area");
-                        //el.innerHTML = lastest_editing;
-                        //alert("Reload the page!");
-                    },
-                    error: function (result) {
-                        alert("Reload Fails!");
-                    }
-                }).done(function(result) {
-                    // reload page
-                    //document.location.reload(true);
-
-                });
-
-            } else {
-                alert("Just a reminder, there is a new version for this branch.");
-            }
-            */
-            
-        }
-
     }
     return;
     
@@ -516,9 +478,6 @@
     */
 }
 
-
-
-
 function exportAll(topic_id) {
     var el = document.getElementById("editable-area");
     var str= "" + el.innerHTML;
@@ -579,7 +538,6 @@
 }
 // ===========
 
-
 function tagwithOnlytag( range, stringSelection, tag ) {
     saveUndoText();
     var topic_tag = JSON.parse('<?php echo json_encode($topic_tag) ?>');
@@ -625,9 +583,6 @@
     $('.tagItemDivClass').remove();
 }
 
-
-
-
 function replaceSmartRegex() {
     saveUndoText();
     var startPage = $('#regexPageStart2').val();
@@ -665,8 +620,6 @@
     //document.styleSheets[0].addRule("tag001", "color:green;")
 }
 
-
-
 function saveTextToLGService() {
 
     // -------------
@@ -774,8 +727,6 @@
     */
 }
 
-
-
 function chooseTopic(default_topic_id) {
     var t = JSON.parse( '<?php echo json_encode($topiclistArray) ?>' );
     var info = JSON.parse('<?php echo json_encode($info) ?>');
@@ -875,7 +826,6 @@
     var info = JSON.parse( '<?php echo json_encode($info) ?>');
 
     if (info) {
-        // TODO: different field info array based on fileId(branchId) existing or not
         if (info['file_id']) {
             var hiddenField = document.createElement("input");      
             hiddenField.setAttribute("name", "fileId");
@@ -961,7 +911,6 @@
 }
 
 
-
 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {
 
 <?php
@@ -1028,9 +977,12 @@
             <div id="follow-scroll" style="position:absolute; height:680px; overflow:scroll; margin:0 5 15 5; max-width:270px">
                 <form action="javascript:void(0);">   
                     <fieldset>
+                        <button onclick="reloadText(<?php echo $default_topic_id; ?>)">Reload</button>
+                    </fieldset>
+                    <fieldset>
                         <legend><h5 class="text-success"> Config Topic: </h5></legend>
                         <div> current topic is <?php echo $topic_name; ?> 
-                            <button onclick="chooseTopic(<?php echo $default_topic_id; ?>)" class="btn btn-xs btn-default">Change</button>
+                            <button onclick="chooseTopic()" class="btn btn-xs btn-default">Change</button>
                         </div>
                         <button onclick="configTagsInTopic(<?php echo $default_topic_id;?>)" class="btn btn-sm btn-default" style="">Manage Tags in topic</button></br>
                     </fieldset>