Filtering a selection

I’m having a few problems getting my head around control filters. The feature doesn’t appear to be documented anywhere and the few examples I can find aren’t helping me do what I want.

What I have at the moment is a control where the user can select a Showcase Action item on the page;

<action-itemref name="targetShowcase" title="Showcase Gallery" advance="no" filter="filterItems">

The content of the control is filtered using this function;

function filterItems(item){
 	if (!item){ return true; }
	
	if (!item.fwFindAction(0,['com.softpress.actions.showcase'],false)){
		return false;
	}
	return true;
}

This works well and returns all of the Showcase Action items on the page. So far, so good.

Now what I REALLY want is to be able to only display the Showcase Action items that are children of the item my Action is applied to. So if I’ve applied my Action to a div then the control will only show Showcase Action items that are children of this div.

I’ve spent several hours looking at this last night and again this morning and other than a kernel panic and a Freeway crash I’ve not managed to produce much that looks like a result.

Does anyone have any ideas how to go about this?

Thanks in advance,
Tim.

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro - http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s an interesting problem. What I would do is lazy-initialize an array of elements that have the Showcase Action applied to them on the entire page (so you only have to load it once per page) and then during the publish cycle, walk that array looking for elements that respond to a recursive function, something like this pseudocode:

fwPage[‘showcases’] = fwPage.showcases || findAllTheShowcases();

//recursive find parent
function hasThisParent(elm, daddy){
var p = elm.fwFindEnclosing();
if(daddy == p){
return true;
}
if(p.id && p.id == ‘PageDiv’){
return false;
}else{
return hasThisParent(p, daddy);
}
}

Call that on a child element, and it will spin until it finds the parent you want or dies from boredom at the PageDiv.

Maybe this approach will work. Call it on each element in your page-level array, and it should find the ones you want pretty quickly.

Walter

On Apr 27, 2013, at 8:27 AM, Tim Plumb wrote:

Now what I REALLY want is to be able to only display the Showcase Action items that are children of the item my Action is applied to. So if I’ve applied my Action to a div then the control will only show Showcase Action items that are children of this div.

I’ve spent several hours looking at this last night and again this morning and other than a kernel panic and a Freeway crash I’ve not managed to produce much that looks like a result.


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Better-formatted version of that:

fwPage[‘showcases’] = fwPage.showcases || findAllTheShowcases();

//recursive find parent
function hasThisParent(elm, daddy){ 
  var p = elm.fwFindEnclosing(); 
  if(daddy == p){ return true; } 
  if(p.id && p.id == ‘PageDiv’){ 
    return false; 
  }else{ 
    return hasThisParent(p, daddy); 
  } 
}

actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,
Thanks for you input on this. I’ve shelved the idea for the moment but will certainly be picking up on this again later in the week so I’m sure I’ll revisit this code then.

So what happens in the findAllTheShowcases function? I assume this would be the bulk of my element finder and would call the hasThisParent function?
I must admit that I’ve not had too much luck with recursive functions as I always manage to get them to bring Freeway down in a flaming ball of dust as they run out of control. It is a bit like putting an alert in a fwInterface block and watch as you can’t get control of the application back because of the 10,000 alerts that spawn everywhere!
Regards,
Tim.

On 29 Apr 2013, at 17:51, waltd wrote:

Better-formatted version of that:

fwPage[‘showcases’] = fwPage.showcases || findAllTheShowcases();

//recursive find parent
function hasThisParent(elm, daddy){ 
 var p = elm.fwFindEnclosing(); 
 if(daddy == p){ return true; } 
 if(p.id && p.id == ‘PageDiv’){ 
   return false; 
 }else{ 
   return hasThisParent(p, daddy); 
 } 
}

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro - http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Apr 29, 2013, at 1:39 PM, Tim Plumb email@hidden wrote:

Hi Walter,
Thanks for you input on this. I’ve shelved the idea for the moment but will certainly be picking up on this again later in the week so I’m sure I’ll revisit this code then.

So what happens in the findAllTheShowcases function? I assume this would be the bulk of my element finder and would call the hasThisParent function?

No, this would be your wrapper on fwFindAllActions() that only selects the objects that have your Action applied to them. (I’m not in front of a Mac to give you the exact syntax, not even sure if that’s what the API method is called.)

I must admit that I’ve not had too much luck with recursive functions as I always manage to get them to bring Freeway down in a flaming ball of dust as they run out of control. It is a bit like putting an alert in a fwInterface block and watch as you can’t get control of the application back because of the 10,000 alerts that spawn everywhere!

That’s why the kill switch is in there when it reaches the PageDiv!!

Walter

Regards,
Tim.

On 29 Apr 2013, at 17:51, waltd wrote:

Better-formatted version of that:

fwPage[‘showcases’] = fwPage.showcases || findAllTheShowcases();

//recursive find parent
function hasThisParent(elm, daddy){ 
var p = elm.fwFindEnclosing(); 
if(daddy == p){ return true; } 
if(p.id && p.id == ‘PageDiv’){ 
  return false; 
}else{ 
  return hasThisParent(p, daddy); 
} 
}

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro - http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options