Roundup Tracker - Issues

Issue 2550709

classification
Title: Classic template binary search "(edit)" or "(expr)" link vanishes once an expression was entered
Type: Severity: normal
Components: Versions: 1.4
process
Status: new Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ber, rouilj
Priority: Keywords: patch

Created on 2011-07-01 15:27 by ber, last changed 2016-07-08 01:52 by rouilj.

Files
File name Uploaded Description Edit Remove
Keywords_Expr_allow_continuedEdit.patch rouilj, 2016-07-08 01:52
Messages
msg4321 Author: [hidden] (ber) Date: 2011-07-01 15:27
Split out from issue2550648 (Should be possible to search for matching  
several keywords (keyword1 AND keyword2) especially from msg4204 and 
msg4302:

| One thing I noticed is that the (expr) link on the search page 
vanishes once an expression has been entered.

| 1) After (re-)discovering what was already reported in msg4204 (the
disappearance of the "(edit)" link once the keyword value was set), I
attempted to validate the generated HTML, and noticed that it was
invalid. This may be the cause for the reported behavior.
msg5779 Author: [hidden] (rouilj) Date: 2016-07-08 01:50
I don't see any invalid html after applying the expression,
however the javascript used by the expression editor is:

function modify_main() {
    main = window.opener.document.getElementById("keywords_%(prop)s");
    main.innerHTML = main_content();
}

this takes the div that surrounds both the select element and the (edit)
link identified by keywords_keyword and replaces it with the contents of
main_content which is a hidden input element with the rpn expression
from the editor plus the text expressing the infix version of the
expression.

So that clobbers both the select and the (edit) link by design.

I tried playing around with some javascript to
replace just the select element using outerHTML. This
replaced the select leaving the (edit) in place.
Note this *requires* that the select be the first element
inside the div. If there is anything before it it breaks.
I don't like this fragility but I am not sure how to handle it.

But that left me without the select element to replace
if the (edit) link was clicked again, or if the editor's
apply button was pressed again.

So I changed main_content() to put in a span with an ID
of MCkeywords_%(prop)s and changed the logic in modify_main
to look for either the span with the unique id or the select
inside the div.

The code ended up looking like:

 function main_content() {
     var out = '';
+    out += '<span id="MCkeywords_%(prop)s">';
     out += '<input type="hidden" name="%(prop)s" value="' + current +
'"\/>';
     out += parse(current).infix();
+    out += '</span>';
     return out;
 }
 
 function modify_main() {
-    main = window.opener.document.getElementById("keywords_%(prop)s");
-    main.innerHTML = main_content();
+    main = window.opener.document.getElementById("MCkeywords_%(prop)s");
+    if ( main == null ) {
+        main = window.opener.document.getElementById("keywords_%(prop)s");
+        select = main.getElementsByTagName("SELECT")[0];
+        select.outerHTML = main_content();
+    } else {
+      main.outerHTML = main_content();
+    }
 }

I used a span so the edit link would stay atthe end of the description.
If you use a div, the link is pushed to the next line.

This feels really icky and fragile.

Comments from somebody who knows javascript?

-- rouilj
History
Date User Action Args
2016-07-08 01:52:04rouiljsetfiles: + Keywords_Expr_allow_continuedEdit.patch
2016-07-08 01:51:46rouiljsetfiles: - Keywords_Expr_allow_continuedEdit.patch
2016-07-08 01:50:48rouiljsetfiles: + Keywords_Expr_allow_continuedEdit.patch
keywords: + patch
messages: + msg5779
nosy: + rouilj
2011-07-01 15:27:27bercreate