Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

build_default_tpl dropdown menu on templates

Quote Reply
build_default_tpl dropdown menu on templates
I am trying to duplicate the build_default_tpl dropdown menu and have the
action simply 'refresh' the page I am on with t=template added to the url.

I would prefer the 'switch' to take place when the menu is released
without having to hit a submit button.

I have a dropdown menu of template sets displaying properly, but
when I hit the "go" button. It lands me on the appropriate admin page
with a message stating that the the change was successful. And it was! <g>
It switched the default template set as expected, but I want to just 'refresh'
the page I am on and switch templates.

Code:
<form method="post" action="admin/setup.cgi">
<input type="hidden" name="do" value="setup_build" />
<%Links::Tools::tpl_dir_select($cfg_build_default_tpl, '(?:browser|admin)', '', 1)%>
<select name="build_default_tpl"><%loop template_set_loop%><option<%if directory = config.build_default_tpl%> selected<%endif%>><%directory%></option><%endloop%></select>

<div class="submit">
<input type="submit" value="Go" />
</div>

</form>


I think this will require a javascript onmenu or something like that.
Also that the menu will have to have the urls added to it?
If someone could walk me through creating a menu whose action
happens when the menu is released. I would appriciate it.

Thanks,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: Apr 23, 2006, 2:56 PM
Quote Reply
Re: [rgbworld] build_default_tpl dropdown menu on templates In reply to
Ok I am close but am pretty much stuck now.
I have the dropdown menu displayed using this code..
Code:
<form method="post" action="admin/setup.cgi">
<input type="hidden" name="do" value="setup_build" />
<%Links::Tools::tpl_dir_select($cfg_build_default_tpl, '(?:browser|admin)', '', 1)%>
<select name="build_default_tpl">
<%loop template_set_loop%>
<option value="<%uri%>;t=<%directory%>"<%if $directory eq $theme%> selected="selected"<%endif%>><%directory%></option>
<%endloop%>
</select>

<div class="submit">
<input type="submit" value="Go" />
</div>

</form>

Which outputs this html...
Code:
<form method="post" action="admin/setup.cgi"><input type="hidden" name="d" value="1" />
<input type="hidden" name="do" value="setup_build" />
<select name="build_default_tpl">
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=luna">luna</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=luna_2C_Banner">luna_2C_Banner</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=luna_3C_Banner">luna_3C_Banner</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=terra_dev">terra_dev</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra">xtra</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra.terra_dev">xtra.terra_dev</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra_2C_Banner">xtra_2C_Banner</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra_2C_Banner2">xtra_2C_Banner2</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra_3C_Banner">xtra_3C_Banner</option>
<option value="/cgi-bin/links_dev/page.cgi?g=;d=1;t=xtra_3C_Banner2" selected="selected">xtra_3C_Banner2</option>
</select>
<div class="submit">
<input type="submit" value="Go" />
</div>
</form>

So, I think I am pretty faar along, I have the url as the option value and I know which item was selected.
Now with some javascript in the header, releasing the menu should be able to call the appropriate url?

Any help with the action and javascript is greatly appreciated.

Thanks again.
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_default_tpl dropdown menu on templates In reply to
Are you trying to do this on the user side or admin side?

Adrian
Quote Reply
Re: [brewt] build_default_tpl dropdown menu on templates In reply to
Well, I am just playing around, but it is on the user side.

I have it working with a couple 'issues' <g>

In include_common_head.html, I added the following javascript:
Code:
<script language="javascript" type="text/javascript">
<!--
function menu_goto( menuform )
{
if(menuform.dburl) {
var baseurl = 'http://www.supportmusicians.com';
selecteditem = menuform.dburl.selectedIndex ;
dburl = menuform.dburl.options[ selecteditem ].value ;
if (dburl.length != 0) {
location.href = baseurl + dburl ;
}
}
}
//-->
</script>

Then in incude_rightsidebar.html, I have:
Code:
<div id="rightsidebar">
<h3>Choose a Template Set:</h2>
<form method="post" action="dummy_value">
<input type="hidden" name="do" value="setup_build" />
<%Links::Tools::tpl_dir_select($cfg_build_default_tpl, '(?:browser|admin)', '', 1)%>
<select name='dburl' onchange='menu_goto(this.form)'>
<%loop template_set_loop%>
<option value="<%env_request_uri%>;t=<%directory%>"<%if $directory eq $theme%> selected="selected"<%endif%>><%directory%></option>
<%endloop%>
</select>
</form>
</div>

global:
Code:
sub {
return $ENV{'REQUEST_URI'};
}


Works ok, but I need to clean it up.
1) I would like the hard-coded 'base_url' in the javascript to be a tag.
i.e. <%domain%> I know I can create a global tag, I find it strange that
there isn't an existing one hanging around that I could use <g>
2) Do I need the 'hidden' tag in order to obtain the 'template_set_loop'?
I am guessing that the loop is being created via Links::Tools...?
Or, is template_set_loop tag always available to me?
3) Can I obtain $ENV{'REQUEST_URI'} without the global sub?
4) The only 'real' problem is that I am continually appending ";t=foo" to
the current url, so I end up with a messed-up url. i.e.
http://www.domain.com/cgi-bin/links_dev/page.cgi?g=New%2F;t=luna_2C_Banner;d=1;t=luna

So I need help stripping out "t=*;" from the url so I can add it back on :-)
I can do this in the 'env_request_uri' global sub. But how?

Thanks,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] build_default_tpl dropdown menu on templates In reply to
Ok, here it is.
I wanted to remain on the same page when switching templates via the dropdown menu,
but I was having problems with that. The following may be better though as it uses an
existing variable in the javascript (<%db_cgi_url%>) and it doesn't keep appending
t=foo; to the url again and again. Dropped the global and I don't need 'hidden' tag.
The bummer is that it sometimes lands me on the home page when switching templates.

In include_common_head.html, I added the following javascript:
Code:
<script language="javascript" type="text/javascript">
<!--
function menu_goto( menuform )
{
if(menuform.dburl) {
var baseurl = '<%db_cgi_url%>';
selecteditem = menuform.dburl.selectedIndex ;
dburl = menuform.dburl.options[ selecteditem ].value ;
if (dburl.length != 0) {
location.href = baseurl + dburl ;
}
}
}
//-->
</script>
Then in include_rightsidebar.html, I have:
Code:
<div id="rightsidebar">
<h3>Choose a Template Set:</h2>
<form method="post" action="dummy_value">
<%Links::Tools::tpl_dir_select($cfg_build_default_tpl, '(?:browser|admin)', '', 1)%>
<select name='dburl' onchange='menu_goto(this.form)'>
<%loop template_set_loop%>
<option
value="/page.cgi?t=<%directory%><%if
g%>;g=<%g%><%endif%><%if config.dynamic_pages
=1%>;d=1<%endif%>"<%if $directory eq $theme%>
selected="selected"<%endif%>><%directory%></option>
<%endloop%>
</select>
</form>
</div>

I would still prefer to use a subroutine that grabs the current page from $ENV{'REQUEST_ULI'}
and just remove the existing template reference (if there is one), and then re-add the just
switched-to template to the end of the url. This would ALWAYS keep me on same page when switching templates.

I couldn't figure out the substitution code though :-(
Substitution would need to remove "t=anything;" or ";t=anything".
Then if the url ended with a '?' mark remove that too.
To re-add the template to the url, the only thing I wasn't
sure of was the '?' There 'could' already be a ? in url, but not always so.
I might have to add "?t=foo;" or just "t=foo;" if there were already parameters
in the url. Hope that makes sense.

So if someone could still give me substitution code that would remove
the template from the url, that would be great! This is what I had (NOT working).
Code:
sub {
my $page = $ENV{'REQUEST_URI'};
$page =~ s/^\s*t=*\s*$//g;
return $page;
}
Thanks again,
Chris


RGB World, Inc. - Software &amp; Web Development.
rgbworld.com