Re: Recursive function to output radios for 'threaded' data

2009-01-09 Thread Jon Bennett

hi grigri,

>  Wow, you've really added quite a bit of functionality there. I
>  actually adapted some of the code I pasted yesterday from a tree
>  helper, so it's quite fitting. I was going to rewrite bits of my tree
>  helper anyway (to make it more generic) and this might help - thanks!

glad to return the favour! One last thing, your helper had no
provision for passing the selected item in, so I've added this in.

helper: http://pastie.org/356740
usage: http://pastie.org/356743

cheers,

jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-09 Thread grigri

Hi Jon,

Wow, you've really added quite a bit of functionality there. I
actually adapted some of the code I pasted yesterday from a tree
helper, so it's quite fitting. I was going to rewrite bits of my tree
helper anyway (to make it more generic) and this might help - thanks!

cheers
grigri

On Jan 9, 8:34 am, "Jon Bennett"  wrote:
> Hi grigri,
>
> Thought you might like to see what I ended up with. It's not refined
> fully, but it does the job at the moment.
>
> helper:http://pastie.org/356423
> usage:http://pastie.org/356424
>
> Cheers the start point, super helpful!
>
> jon
>
> --
>
> jon bennett
> w:http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-09 Thread Jon Bennett

Hi grigri,

Thought you might like to see what I ended up with. It's not refined
fully, but it does the job at the moment.

helper: http://pastie.org/356423
usage: http://pastie.org/356424

Cheers the start point, super helpful!

jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread Jon Bennett

hi grigri,

I've made a small addition to your helper, to enable me to pass a
class to the UL.

helper: http://pastie.org/356229
html: http://pastie.org/356227
css: http://pastie.org/356228

Cheers,

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread Jon Bennett

Hi grigri,

>  My next challenge is to extend your helper so there's no radios, just
>  nested lists, then include the associated documents from each
>  category, with a thumbnail + link and 2 radios - wish me luck!

To expand on what I need. I have a CMS, running a few sites. The
add/edit page forms have a tab for 'images'. In this tab there's an
expandable (via jquery) 2 level nested UL, like so:

Category A
- Image B
- Image F
Category B
- Image D
- Image E

etc etc

Each image contains:

- a thumbnail, clickable to open a preview in thickbox
- a radio for 'banner', so this image can be chosen as the page banner
- a checkbox for 'content', so this (and more, it's for a HABTM) image
can be selected to show in the content (depending on teh template,
could be in the sidebar, or the main column, as a slideshow etc etc)

For one of my current projects, the requirement to have nested
categories arose, and so now I have a need to output quite a complex
set of lists/form inputs. Ideally it would be ordered so child
categories come first, followed by any images in that category, along
these lines http://pastie.org/356134

Seeing as you clearly have a good idea regarding recursion, any tips
on how you'd approach this in terms of extending your helper?

Cheers,

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread Jon Bennett

Hi grigri,

>  Oh, forgot one little thing. This code:
>
>  `if (isset($document_categories) && count($document_categories) > 0)`
>
>  can be replaced with this code:
>
>  `if (!empty($document_categories))`

I find if I just check on if (empty( I get undefined errors if the
array doesn't exist, do you not have this problem? Ahh, but I think I
usually do if (empty()) rather than if (!empty()) - perhaps that's the
key.

Cheers,

Jon


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread Jon Bennett

hi grigri,


On 1/8/09, grigri  wrote:
>
>  Ok, here's a few things to help you:
>
>  First, that view function of yours belongs in a helper. You should
>  never define functions inside a view template.

I know! was just testing out the theory, am new to recursive functions.

>  From an HTML point of view, there are 2 ways of defining label/input
>  relationships. You can either embed the input inside the label, which
>  makes the relationship obvious, or declare a unique ID for the input,
>  which is referenced by the label using the `for` attribute. This id
>  must be unique throughout the page. The most usual approach is the
>  second one.
>
>  For the data to be sent and received properly to/by cake, each radio
>  element (``) must have a name attribute and a value attribute.
>  In this case, all of the name attributes should be the same, and each
>  value attribute should be set to the corresponding id of the category.

yep! again my lack of knowledge is with recursive functions, not with
cake or html/css - I would/will clean up the html once I'd got the
looping working.

>  Anyway, here's a helper for you: http://pastie.org/355620

BRILLIANT! that is exactly what I needed :)

>  And here's sample usage with a dummy dataset: http://pastie.org/355621

Again, perfect.

My next challenge is to extend your helper so there's no radios, just
nested lists, then include the associated documents from each
category, with a thumbnail + link and 2 radios - wish me luck!

thanks again, you've saved me a huge amount of time, really appreciated!

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread grigri

Oh, forgot one little thing. This code:

`if (isset($document_categories) && count($document_categories) > 0)`

can be replaced with this code:

`if (!empty($document_categories))`

It does exactly the same thing [for an array, anyway] and is shorter
and neater [just personal preference].

hth
grigri

On Jan 8, 1:33 pm, grigri  wrote:
> Ok, here's a few things to help you:
>
> First, that view function of yours belongs in a helper. You should
> never define functions inside a view template.
>
> From an HTML point of view, there are 2 ways of defining label/input
> relationships. You can either embed the input inside the label, which
> makes the relationship obvious, or declare a unique ID for the input,
> which is referenced by the label using the `for` attribute. This id
> must be unique throughout the page. The most usual approach is the
> second one.
>
> For the data to be sent and received properly to/by cake, each radio
> element (``) must have a name attribute and a value attribute.
> In this case, all of the name attributes should be the same, and each
> value attribute should be set to the corresponding id of the category.
>
> Anyway, here's a helper for you:http://pastie.org/355620
>
> And here's sample usage with a dummy dataset:http://pastie.org/355621
>
> The output html is valid, neatly indented and should work fine with
> cake's data handling. I'm using the element id and `for` approach
> here, because the other way is too easy. (Plus I never use it because
> it wreaks havoc with my stylesheets)
>
> hth
> grigri
>
> On Jan 8, 5:09 am, "Jon Bennett"  wrote:
>
> > Hi,
>
> > I have a category system, parent/child, which I'm trying to create a
> > nested group of radio inputs for.
>
> > So far I 
> > havehttp://pastie.org/355368whichoutputshttp://pastie.org/355369-if anyone 
> > has experience of working with
> > this type of dataset and could offer some advice I'd appreciate it.
>
> > BTW it doesn't use the tree behaviour, I had issues with
> > auto-populating the data in one go, as there's 405 categories, for
> > some reason I got quite a few errors which screwed the tree and no
> > matter what i tried it was irretree-vial ;)
>
> > Thanks,
>
> > Jon
>
> > --
>
> > jon bennett
> > w:http://www.jben.net/
> > iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Recursive function to output radios for 'threaded' data

2009-01-08 Thread grigri

Ok, here's a few things to help you:

First, that view function of yours belongs in a helper. You should
never define functions inside a view template.

>From an HTML point of view, there are 2 ways of defining label/input
relationships. You can either embed the input inside the label, which
makes the relationship obvious, or declare a unique ID for the input,
which is referenced by the label using the `for` attribute. This id
must be unique throughout the page. The most usual approach is the
second one.

For the data to be sent and received properly to/by cake, each radio
element (``) must have a name attribute and a value attribute.
In this case, all of the name attributes should be the same, and each
value attribute should be set to the corresponding id of the category.

Anyway, here's a helper for you: http://pastie.org/355620

And here's sample usage with a dummy dataset: http://pastie.org/355621

The output html is valid, neatly indented and should work fine with
cake's data handling. I'm using the element id and `for` approach
here, because the other way is too easy. (Plus I never use it because
it wreaks havoc with my stylesheets)

hth
grigri

On Jan 8, 5:09 am, "Jon Bennett"  wrote:
> Hi,
>
> I have a category system, parent/child, which I'm trying to create a
> nested group of radio inputs for.
>
> So far I havehttp://pastie.org/355368which outputshttp://pastie.org/355369- 
> if anyone has experience of working with
> this type of dataset and could offer some advice I'd appreciate it.
>
> BTW it doesn't use the tree behaviour, I had issues with
> auto-populating the data in one go, as there's 405 categories, for
> some reason I got quite a few errors which screwed the tree and no
> matter what i tried it was irretree-vial ;)
>
> Thanks,
>
> Jon
>
> --
>
> jon bennett
> w:http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Recursive function to output radios for 'threaded' data

2009-01-07 Thread Jon Bennett

Hi,

I have a category system, parent/child, which I'm trying to create a
nested group of radio inputs for.

So far I have http://pastie.org/355368 which outputs
http://pastie.org/355369 - if anyone has experience of working with
this type of dataset and could offer some advice I'd appreciate it.

BTW it doesn't use the tree behaviour, I had issues with
auto-populating the data in one go, as there's 405 categories, for
some reason I got quite a few errors which screwed the tree and no
matter what i tried it was irretree-vial ;)

Thanks,

Jon

-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---