# HG changeset patch # User Zoe Hong # Date 1457963022 -3600 # Node ID 5bea390e7ca99adaae210a4c7c3cf01054610a87 # Parent c1bb174a22f37d6801fe34296e57a34478052652 new: short tag in front of long tag diff -r c1bb174a22f3 -r 5bea390e7ca9 controllers/extractapp.php --- 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 { diff -r c1bb174a22f3 -r 5bea390e7ca9 js/taggingtext.js --- 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+"
Value: "+tagObject.text()+"
"; + + // TODO maybe also shown tag itself? newdiv.innerHTML = "Tag: "+tag_name+"
Value: "+tagObject.text()+"
"; + var newbutton = $('').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=//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="
<"+tag+">$1"; diff -r c1bb174a22f3 -r 5bea390e7ca9 views/Extractapp/TaggingText.php --- 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 += "
"; + + console.log(selection); + + ".$taglistValue[1]."\";\n"; - echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"\";\n"; echo "tagging_tags.innerHTML += \"
\";\n"; break; } @@ -369,14 +376,23 @@ if ($taglistValue[2] == $topic_tag) { // pass } else if ($taglistValue[2] == "post_time") { - echo "tagging_tags.innerHTML += \"\";\n"; + // this case could be deprecated + echo "tagging_tags.innerHTML += \"\";\n"; echo "tagging_tags.innerHTML += \"
\";\n"; } else if ($taglistValue[2] == "office") { - echo "tagging_tags.innerHTML += \"\";\n"; + // this case could be deprecated + echo "tagging_tags.innerHTML += \"\";\n"; echo "tagging_tags.innerHTML += \"
\";\n"; } else { + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"
\";\n"; + + /* testing... backup the original one + echo "tagging_tags.innerHTML += \"\";\n"; echo "tagging_tags.innerHTML += \"
\";\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(''); + 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(''); + 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(''); 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 + } };