Mercurial > hg > extraction-interface
changeset 98:5bea390e7ca9 extractapp
new: short tag in front of long tag
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 14 Mar 2016 14:43:42 +0100 |
parents | c1bb174a22f3 |
children | c3e149277b58 |
files | controllers/extractapp.php js/taggingtext.js views/Extractapp/TaggingText.php |
diffstat | 3 files changed, 403 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/controllers/extractapp.php Tue Feb 16 15:07:43 2016 +0100 +++ b/controllers/extractapp.php Mon Mar 14 14:43:42 2016 +0100 @@ -73,6 +73,9 @@ $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) "; $viewmodel->SetInfoFromPreviousPage($this->postdata); $response = $viewmodel->SaveFullTextToLGService($this->postdata); + + $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id + $viewmodel->SetTextFromFileId(); } else {
--- a/js/taggingtext.js Tue Feb 16 15:07:43 2016 +0100 +++ b/js/taggingtext.js Mon Mar 14 14:43:42 2016 +0100 @@ -29,7 +29,7 @@ var regex_element_index = 0; window.onbeforeunload = function() { - return "Unsaved data will be lost."; + //return "Unsaved data will be lost."; }; @@ -249,10 +249,15 @@ newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+';'; // find tag displaying name by tagName then showing in the innerHTML + var tag_name = getTagNameByTag(tag); + // newdiv.innerHTML = "Tag: "+tag_name+"<br>Value: "+tagObject.text()+"<br>"; + + // TODO maybe also shown tag itself? newdiv.innerHTML = "Tag: "+tag_name+"<br>Value: "+tagObject.text()+"<br>"; + var newbutton = $('<button class="btn btn-default">Remove this</button>').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=/<div(.*?)<\/div>/g; @@ -411,6 +416,12 @@ function tagStringWithTag( stringValue, tag ) { saveUndoText(); var el = document.getElementById("editable-area"); + + // TODO: bug? when stringValue contain already tag, it should be preserved + + console.log(stringValue); + + var regexText="("+String(stringValue)+")"; if ( tag=="person") { var replaceText="<br><"+tag+">$1</"+tag+">";
--- a/views/Extractapp/TaggingText.php Tue Feb 16 15:07:43 2016 +0100 +++ b/views/Extractapp/TaggingText.php Mon Mar 14 14:43:42 2016 +0100 @@ -283,13 +283,16 @@ $('.tagItemDivClass').remove(); if ( $("#editTextId").html() != "Edit the text" ) return 0; - var selection = getSelected(); + + //var selection = getSelected(); + selection = getSelected(); // selection is a global variable - range = selection.getRangeAt(0); + range = selection.getRangeAt(0); // range is a global variable container = document.createElement("div"); container.appendChild(selection.getRangeAt(0).cloneContents()); + if(selection && (selection_plain = new String(selection).replace(/^\s+|\s+$/g,''))) { try{ var newdiv = document.createElement("div"); @@ -356,11 +359,15 @@ tagging_tags.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection_plain)+"' )\">Title</button></br>"; + + console.log(selection); + + <?php foreach ( $taglistArray as $taglistValue ) { if ($taglistValue[2] == $topic_tag) { - echo "tagging_tags.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection_plain)+\"', '".$taglistValue[2]."2' )\\\">".$taglistValue[1]."</button>\";\n"; - echo "tagging_tags.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection_plain)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(without new line)</button>\";\n"; + echo "tagging_tags.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, selection, '".$taglistValue[2]."2' )\\\">".$taglistValue[1]."</button>\";\n"; + echo "tagging_tags.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, selection, '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(without new line)</button>\";\n"; echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection_plain)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(ALL)</button></br>\";\n"; break; } @@ -369,14 +376,23 @@ if ($taglistValue[2] == $topic_tag) { // pass } else if ($taglistValue[2] == "post_time") { - echo "tagging_tags.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; + // this case could be deprecated + echo "tagging_tags.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, selection, '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; } else if ($taglistValue[2] == "office") { - echo "tagging_tags.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."</button>\";\n"; + // this case could be deprecated + echo "tagging_tags.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, selection, '".$taglistValue[2]."' )\\\">".$taglistValue[1]."</button>\";\n"; echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(ALL)</button></br>\";\n"; } else { + echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagwithOnlytag(range, selection, '".$taglistValue[2]."')\\\">".$taglistValue[1]."</button>\";\n"; + echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(ALL)</button></br>\";\n"; + + /* testing... backup the original one + echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."</button>\";\n"; echo "tagging_tags.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">".$taglistValue[1]."(ALL)</button></br>\";\n"; + */ + } } ?> @@ -565,9 +581,348 @@ _postForContineTagging(form); } -// =========== + + +function tagTestX(range, selection, tag) { + console.log("selection string: "); + console.log(String(selection)); + + var stringSelection = String(selection); + + saveUndoText(); + var topic_tag = JSON.parse('<?php echo json_encode($topic_tag) ?>'); + var topic_tag2 = topic_tag+"2"; + + + // stringSelection here only contains plain text (string) without the tagging structure + // how to use the existing tagging structure + + // --- + var documentFragment = range.extractContents(); + + + var tmpStringSelection = "" + var childNodes = documentFragment.childNodes + for (var i = 0; i < childNodes.length; i++){ + + if (childNodes[i].outerHTML == undefined) { + + tmpStringSelection += childNodes[i].textContent + } else { + + tmpStringSelection += childNodes[i].outerHTML + } + + } + + stringSelection = tmpStringSelection + + range.deleteContents(); + + if ( tag==topic_tag2) { + var newdiv = document.createElement(topic_tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + + } else { + var newdiv = document.createElement(tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + } + + + $('.tagItemDivClass').remove(); + + + return + + + // --- + + console.log("the anchorNode: "); + console.log(selection.anchorNode); + + console.log("the anchorNode's nextSibling"); + console.log(next); + + + // TODO if no fragment... bug + + if ( typeof selection !== 'string' ) { + var next = selection.anchorNode.nextSibling; + + + + // TODO fragment at the beginning of selection: anchorNode + var tmpStringSelection = "" + + var startInx = selection.anchorOffset + var endSelectionInx = startInx + stringSelection.length + var endInx = selection.anchorNode.length + console.log("startInx=" + startInx + " endInx= " + endInx + "; endSelectionInx= " + endSelectionInx) + + var anchorText = selection.anchorNode.textContent + + + /* + console.log("anchorNode...") + if (selection.anchorNode.nodeType == 3 && next.nodeName != "BR" && next.nodeName != "br") { + // if (next != null && selection.anchorNode.nodeType == 3 && next.nodeName != "BR" && next.nodeName != "br") { + // here the anchor node is text + + //tmpStringSelection += anchorText.substring(selection.anchorOffset, selection.anchorNode.length); + tmpStringSelection += anchorText.substring(startInx, endSelectionInx); + + console.log("append anchorText to tmpStringSelection: " + tmpStringSelection) + + endInx += endSelectionInx - startInx; + + //endInx += (selection.anchorNode.length - selection.anchorOffset); + + + } + */ + + // TODO when anchorNode is not text, but a node + + + /* + if (next != null) { + + if (selection.anchorNode.nodeType == 3 && next.nodeName != "BR" && next.nodeName != "br") { + var anchorText = selection.anchorNode.textContent + // never goes here? + tmpStringSelection += anchorText.substring(selection.anchorOffset, selection.anchorNode.length); + + console.log("append anchorText to tmpStringSelection: " + tmpStringSelection) + + + } + } + */ + + // TODO parsing stringSelection object in string, with the tagging strucutre + + var checkExtentNode = true + + while(next != null && next != undefined && next.nodeName != "BR" && next.nodeName != "br" ) { + + /* + if (endInx >= endSelectionInx) { + console.log("startInx=" + startInx + " endInx= " + endInx + "; endSelectionInx= " + endSelectionInx) + + console.log("debug: end of traverse. next=") + console.log(next) + + break; + } + */ + + startInx = endInx + + if (next.nodeType == 3) { // text case + console.log("text case.") + + endInx += next.textContent.length + + if (endInx > endSelectionInx) { + + /* + tmpStringSelection += next.textContent.substring(0, endSelectionInx-startInx) + + console.log("startInx=" + startInx + " endInx= " + endInx + "; endSelectionInx= " + endSelectionInx) + console.log("appened next.textContent.substring tmpStringSelection (text case): " + tmpStringSelection) + */ + + //checkExtentNode = false + + //break; + } else { + + + tmpStringSelection += next.textContent; + console.log("appened tmpStringSelection (text case): " + tmpStringSelection) + + + } -function tagwithOnlytag( range, stringSelection, tag ) { + + + } else if (next.nodeType == 1) { // node case + console.log("node case") + + endInx += next.innerHTML.length + + if (endInx > endSelectionInx) { + + // TODO do something about tmpStringSelection here? + + console.log("startInx=" + startInx + " endInx= " + endInx + "; endSelectionInx= " + endSelectionInx) + + + //checkExtentNode = false + + //break; + } else { + + + tmpStringSelection += next.outerHTML; + console.log("appened tmpStringSelection (node case): " + tmpStringSelection) + // endInx += next.outerHTML.length + } + + + } else { + console.log("[debug] case: nodeType=" + next.nodeType) + } + + + /* + + } else if (next.innerHTML != undefined) { + + + endInx += next.innerHTML.length; + if (endInx >= endSelectionInx) { + break; + } + + + } else { + break + } + console.log("startInx= " + startInx + "; endInx= " + endInx) + if (next.outerHTML != undefined) { + tmpStringSelection += next.outerHTML; + console.log("appened tmpStringSelection: " + tmpStringSelection) + + } + */ + + console.log("next: "); + console.log(next); + next = next.nextSibling; + + } + + + // TODO + // fragment at the end of selection: extentNode + + console.log("extentNode...") + console.log("startInx=" + startInx + " endInx= " + endInx + "; endSelectionInx= " + endSelectionInx) + + var extentNode = selection.extentNode + + + if (checkExtentNode) { + + if (endInx < endSelectionInx && startInx < endSelectionInx ) { + tmpStringSelection += anchorText.substring(endInx, endSelectionInx); + console.log("append anchorText.substring(endInx, endSelectionInx) to tmpStringSelection: " + tmpStringSelection) + + } else if (extentNode != null) { + var extentText = extentNode.textContent + + tmpStringSelection += extentText.substring(startInx, endSelectionInx); + + console.log("append extentNode to tmpStringSelection: " + tmpStringSelection) + } else { + tmpStringSelection += anchorText.substring(startInx, endSelectionInx); + console.log("append anchorText.substring(startInx, endSelectionInx) to tmpStringSelection: " + tmpStringSelection) + } + } + + /* + if (extentNode != null) { + if (extentNode.nodeType == 3 ) { // text case + var extentText = extentNode.textContent + + if (endInx >= endSelectionInx) { + + console.log("tmpStringSelection: " + tmpStringSelection) + + console.log(extentText.substring(startInx, selection.extentOffset)) + tmpStringSelection += extentText.substring(startInx, endSelectionInx); + + console.log("append extentNode to tmpStringSelection: " + tmpStringSelection) + + } else { + tmpStringSelection += anchorText.substring(endInx, endSelectionInx); + + } + } + } + */ + + console.log("tmpStringSelection:") + console.log(tmpStringSelection) + stringSelection = tmpStringSelection; + + } + + range.deleteContents(); + + if ( tag==topic_tag2) { + var newdiv = document.createElement(topic_tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + + } else { + var newdiv = document.createElement(tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + } + + + $('.tagItemDivClass').remove(); + + +} + +function tagwithOnlytag( range, selection, tag ) { + + saveUndoText(); + var topic_tag = JSON.parse('<?php echo json_encode($topic_tag) ?>'); + var topic_tag2 = topic_tag+"2"; + + var documentFragment = range.extractContents(); + + + var stringSelection = "" + var childNodes = documentFragment.childNodes + for (var i = 0; i < childNodes.length; i++){ + if (childNodes[i].outerHTML == undefined) { + stringSelection += childNodes[i].textContent + } else { + stringSelection += childNodes[i].outerHTML + } + + } + range.deleteContents(); + + if ( tag==topic_tag2) { + var newdiv = document.createElement(topic_tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + + } else { + var newdiv = document.createElement(tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + } + + + $('.tagItemDivClass').remove(); +} + +function tagwithOnlytag_old( range, stringSelection, tag ) { saveUndoText(); var topic_tag = JSON.parse('<?php echo json_encode($topic_tag) ?>'); var topic_tag2 = topic_tag+"2"; @@ -786,28 +1141,36 @@ var selected_topic = t[0]; topic_select.onchange = function(){ - selected_topic = topic_select.options[topic_select.selectedIndex]; - console.log(selected_topic.text); + var changeConfirm = confirm("You're going to change topic. \nUnsaved data will be lost."); - var topic_id = selected_topic.value; + if (changeConfirm) { + + selected_topic = topic_select.options[topic_select.selectedIndex]; + console.log(selected_topic.text); - var form = document.createElement("form"); - form.setAttribute("method", "post"); - form.setAttribute("action", "./TaggingText"); // hand to controller - form.setAttribute("target", "_self"); + var topic_id = selected_topic.value; + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "./TaggingText"); // hand to controller + form.setAttribute("target", "_self"); - 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", "topic"); + hiddenField.setAttribute("value", topic_id); + form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "func"); - hiddenField.setAttribute("value", "ContinueTagging"); - form.appendChild(hiddenField); + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "func"); + hiddenField.setAttribute("value", "ContinueTagging"); + form.appendChild(hiddenField); + + _postForContineTagging(form); + - _postForContineTagging(form); - + } else { + return + } };