Closed Bug 298841 Opened 19 years ago Closed 19 years ago

JS error: "less0 has no properties" and first lessButton in edit virtual folder not fully functional

Categories

(MailNews Core :: Filters, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

Attachments

(1 file, 5 obsolete files)

Opening the dialog for editing virtual folders shows following js error:

Error: document.getElementById("less0") has no properties
Source File: chrome://messenger/content/virtualFolderProperties.js
Line: 112

Also the disabled state of the lessButton is not updated correctly due to the
missing property disabled. Patch is on the way.
Attached patch patch v1 (obsolete) — Splinter Review
This patch adds the missing ids to the lessButtons and sets their disabled
state over setAttribute due to the missing property.
Assignee: search → hskupin
Status: NEW → ASSIGNED
Attachment #187357 - Flags: review?(mnyromyr)
Summary: JS error: "less0 has no properties" and lessButton not functional → JS error: "less0 has no properties" and first lessButton not fully functional
Summary: JS error: "less0 has no properties" and first lessButton not fully functional → JS error: "less0 has no properties" and first lessButton in edit virtual folder not fully functional
No longer depends on: 261199
Blocks: 261199
Attached patch patch v2 (obsolete) — Splinter Review
Same like patch v1 but with updated comment for function updateRemoveRowButton
Attachment #187357 - Attachment is obsolete: true
Attachment #187359 - Flags: review?(mnyromyr)
Attachment #187357 - Flags: review?(mnyromyr)
Attached patch patch v3 more simpler fix (obsolete) — Splinter Review
Ok, I simplified the patch a lot. We shouldn't add an id for each button. If
the user removes e.g. the first button we would run into trouble because
id="less0" doesn't exist anymore. This fix also fixes this part.
Attachment #187359 - Attachment is obsolete: true
Attachment #187426 - Flags: review?(mnyromyr)
Attachment #187359 - Flags: review?(mnyromyr)
Attached patch the correct patch v3 (obsolete) — Splinter Review
Attachment #187426 - Attachment is obsolete: true
Attachment #187427 - Flags: review?(mnyromyr)
Attachment #187426 - Flags: review?(mnyromyr)
Comment on attachment 187427 [details] [diff] [review]
the correct patch v3

>Index: mailnews/base/search/resources/content/searchTermOverlay.js
>===================================================================
>-    firstListItem.lastChild.lastChild.lastChild.disabled = gTotalSearchTerms == 1;
>+    firstListItem.lastChild.lastChild.lastChild.setAttribute("disabled", gTotalSearchTerms == 1);

Strangely enough, the disabled property really doesn't work, so the
setAttribute is needed! I wonder if something's broken there...

> function getSearchRowIndexForElement(aElement)
> {
>   var listitem = aElement;
>   while (listitem)
>-{
>+  {
>     if (listitem.localName == "listitem") 
>       break;
>     listitem = listitem.parentNode;
>   }
> 
>   return gSearchTermList.getIndexOfItem(listitem);

You could write that as

var listitem;
for (listitem = aElement; 
     listitem && listitem.localName == "listitem"; 
     listitem = listitem.parentNode);
return gSearchTermList.getIndexOfItem(listitem);

(if you like).

> function onLess(event)
> {
>   if (gTotalSearchTerms > 1) 
>   {
>-    var rowIndex;
>-    if (event)
>-{
>+    if (event) 
>+    {
>       removeSearchRow(getSearchRowIndexForElement(event.target));    
>       --gTotalSearchTerms;
>     }
>   }

It'd be shorter to say

if (event && gTotalSearchTerms > 1) 



r=me with the onLess nit fixed. And please fix the 

JavaScript strict warning: chrome://messenger/content/searchTermOverlay.js,
line 198: assignment to undeclared variable i

and the broken indentation there for bonus points, while your at it. ;-)
Attachment #187427 - Flags: review?(mnyromyr) → review+
Attached patch patch v4 (obsolete) — Splinter Review
(In reply to comment #5)
> You could write that as
> 
> var listitem;
> for (listitem = aElement; 
>      listitem && listitem.localName == "listitem"; 
>      listitem = listitem.parentNode);
> return gSearchTermList.getIndexOfItem(listitem);

That's not true. If you use that, no listitem will be returned. You have to
execute the for loop while "listitem.localName != "listitem"). But I won't use
that, it looks a little bit complex. So I modified the while loop to fetch your
mentioned way.

> r=me with the onLess nit fixed. And please fix the 

Carrying over r with that fixes.

> JavaScript strict warning: chrome://messenger/content/searchTermOverlay.js,
> line 198: assignment to undeclared variable i

Finally done.
Attachment #187427 - Attachment is obsolete: true
Attachment #187755 - Flags: review+
Eww, a typo :((
Attachment #187427 - Flags: review+
Attachment #187755 - Flags: superreview?(hex226)
Attachment #187755 - Flags: superreview?(hex226) → superreview?(bienvenu)
Comment on attachment 187755 [details] [diff] [review]
patch v4

Neil can probably say what's going on with the enabled/disabled attribute.
Attachment #187755 - Flags: superreview?(bienvenu) → superreview?(neil.parkwaycc.co.uk)
Comment on attachment 187755 [details] [diff] [review]
patch v4

>-    for (i = 0; i < searchTerms.Count(); i++) {
>+    for (var i = 0; i < searchTerms.Count(); i++) {
Odd, I wonder why my build isn't whining about this.

>-    firstListItem.lastChild.lastChild.lastChild.disabled = gTotalSearchTerms == 1;
>+    firstListItem.lastChild.lastChild.lastChild.setAttribute("disabled", gTotalSearchTerms == 1);
Ah, of course, I forgot that .disabled doesn't work for a newly created
element. Sigh :-[

>-  if (gTotalSearchTerms > 1) 
>+  if (event && gTotalSearchTerms > 1) 
>   {
>-    var rowIndex;
>-    if (event)
>-{
>-      removeSearchRow(getSearchRowIndexForElement(event.target));    
>-      --gTotalSearchTerms;
>-    }
>+    removeSearchRow(getSearchRowIndexForElement(event.target));    
>+    --gTotalSearchTerms;
If you thought this was bad, mscott's original patch was worse.

>     initializeSearchRows(nsMsgSearchScope.offlineMail, aSearchTerms);
>-    if (aSearchTerms.Count() == 1)
>-      document.getElementById("less0").setAttribute("disabled", "true");
>+    updateRemoveRowButton();
Doesn't initializeSearchRows already call updateRemoveRowButton?

>   }
>   else
>     onMore(null, 0);
This should just be onMore(null) now.
(In reply to comment #9)
> >	initializeSearchRows(nsMsgSearchScope.offlineMail, aSearchTerms);
> >-	if (aSearchTerms.Count() == 1)
> >-	  document.getElementById("less0").setAttribute("disabled", "true");
> >+	updateRemoveRowButton();
> Doesn't initializeSearchRows already call updateRemoveRowButton?

Uuh, you are right. I removed the crap.

> This should just be onMore(null) now.

Fixed.

I also updated the function onMore(event). gSearchTermList.getRowCount() is
called every time also when it's not needed by an event. In that case we save a
function call every time when a search term is added.
Attachment #187755 - Attachment is obsolete: true
Attachment #187829 - Flags: superreview?(neil.parkwaycc.co.uk)
Attachment #187829 - Flags: review+
Attachment #187755 - Flags: superreview?(neil.parkwaycc.co.uk)
I believe this bug should be fixed now? I hope we could checkin the fix ASAP.
Only the sr is missing.
Component: Search → MailNews: Filters
Flags: blocking1.8b3?
Flags: blocking-aviary1.1?
Comment on attachment 187829 [details] [diff] [review]
patch v5 with all mentioned changes

I noticed that the title of the virtual properties dialog for an existing saved
search isn't set correctly, is there already a bug open for this?
Attachment #187829 - Flags: superreview?(neil.parkwaycc.co.uk) → superreview+
(In reply to comment #12)
> I noticed that the title of the virtual properties dialog for an existing saved
> search isn't set correctly, is there already a bug open for this?

Yes, this is covered by bug 294407.
Attachment #187829 - Flags: approval1.8b3?
Attachment #187829 - Flags: approval-aviary1.1a2?
Comment on attachment 187829 [details] [diff] [review]
patch v5 with all mentioned changes

a=cbeard, let's get this landed ASAP to make 1.8b3
Attachment #187829 - Flags: approval1.8b3?
Attachment #187829 - Flags: approval1.8b3+
Attachment #187829 - Flags: approval-aviary1.1a2?
Attachment #187829 - Flags: approval-aviary1.1a2+
Flags: blocking1.8b3? → blocking1.8b3+
Checking in searchTermOverlay.js;
/cvsroot/mozilla/mailnews/base/search/resources/content/searchTermOverlay.js,v 
<--  searchTermOverlay.js
new revision: 1.43; previous revision: 1.42
done

Checking in virtualFolderProperties.js;
/cvsroot/mozilla/mailnews/base/resources/content/virtualFolderProperties.js,v 
<--  virtualFolderProperties.js
new revision: 1.11; previous revision: 1.10
done
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Flags: blocking1.8b3+ → blocking1.8b3?
Resolution: --- → FIXED
cbeard: sorry for killing that blocking flag! :(
But it's irrelevant now anyway. :)
Flags: blocking1.8b3?
Status: RESOLVED → VERIFIED
Flags: blocking-aviary1.1?
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: