templated these macros

This commit is contained in:
JT Smith 2004-07-10 05:36:05 +00:00
parent 7648c6c13f
commit 577554b904
7 changed files with 110 additions and 38 deletions

View file

@ -66,7 +66,8 @@
the master database. This will have no effect on single database users, but
can add a tremendous amount of scalability on large WebGUI sites that use
database replication.
- Templated the EditableToggle, a, and AdminToggle macros. Thanks to Colin
Kuskie.
6.0.3
- Fixed a recursive style change bug.

View file

@ -10,6 +10,7 @@ WebGUI Core..........................JT Smith / Plain Black
Contributing Developers..............Peter Beardsley / Appropriate Solutions
Leendert Bottelberghs
Richard Caelius / 100 World
Irving Carrion
Richard Clark
Doug Collinge
Flavio Curti
@ -21,13 +22,13 @@ Contributing Developers..............Peter Beardsley / Appropriate Solutions
Greg Fast / WDI
Chris Gebhardt / OpenServe
Andy Grundman
Irving Carrion
Chris Jackson
Koen de Jonge / ProcoliX
Martin Kamerbeek / ProcoliX
Christian Kocourek
John W. Krahn
Len Kranendonk
Colin Kuskie
Christophe Marcant
Tony Mountifield
Tavis Parker / ParkerOne Consulting

View file

@ -4,4 +4,7 @@ drop table international;
drop table help;
alter table WSClient add sharedCache tinyint unsigned not null default '0';
alter table WSClient add cacheTTL smallint(5) unsigned NOT NULL default '60';
INSERT INTO template VALUES (1,'Default Account','<a class="myAccountLink" href="<tmpl_var account.url>"><tmpl_var account.text></a>','Macro/a_account',1,1);
INSERT INTO template VALUES (1,'Default Editable Toggle','<a href="<tmpl_var toggle.url>"><tmpl_var toggle.text></a>','Macro/EditableToggle',1,1);
INSERT INTO template VALUES (1,'Default Admin Toggle','<a href="<tmpl_var toggle.url>"><tmpl_var toggle.text></a>','Macro/AdminToggle',1,1);

View file

@ -15,22 +15,40 @@ use WebGUI::Grouping;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Template;
use WebGUI::URL;
#-------------------------------------------------------------------
sub process {
my ($temp, @param, $turnOn, $turnOff);
if (WebGUI::Grouping::isInGroup(12)) {
@param = WebGUI::Macro::getParams($_[0]);
if ($session{var}{adminOn}) {
$turnOff = $param[1] || WebGUI::International::get(517);
$temp = '<a href="'.WebGUI::URL::page('op=switchOffAdmin').'">'.$turnOff.'</a>';
} else {
$turnOn = $param[0] || WebGUI::International::get(516);
$temp = '<a href="'.WebGUI::URL::page('op=switchOnAdmin').'">'.$turnOn.'</a>';
}
}
return $temp;
if (WebGUI::Grouping::isInGroup(12)) {
my %var;
my @param = WebGUI::Macro::getParams($_[0]);
my $templateId = 1; ##Set default template in the namespace
##1 param means use my template with default text
my ($turnOff, $turnOn) = (WebGUI::International::get(517),WebGUI::International::get(516));
if (@param == 1) {
$templateId = WebGUI::Template::getIdByName($param[0],"Macro/AdminToggle");
}
##2 params means use my text with the default template
elsif (@param == 2) {
($turnOff, $turnOn) = @param;
}
##3 or more params means use my text and template, other args ignored
elsif (@param >= 3) {
($turnOff, $turnOn) = @param[1,2];
$templateId = WebGUI::Template::getIdByName($param[0],"Macro/AdminToggle");
}
if ($session{var}{adminOn}) {
$var{'toggle.url'} = WebGUI::URL::page('op=switchOffAdmin');
$var{'toggle.text'} = $turnOff;
} else {
$var{'toggle.url'} = WebGUI::URL::page('op=switchOnAdmin');
$var{'toggle.text'} = $turnOn;
}
$templateId = 1 if $templateId == 0;
return WebGUI::Template::process($templateId,"Macro/AdminToggle",\%var);
}
return "";
}
1;

View file

@ -16,22 +16,39 @@ use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Page;
use WebGUI::Session;
use WebGUI::Template;
use WebGUI::URL;
#-------------------------------------------------------------------
sub process {
my ($temp, @param, $turnOn, $turnOff);
if (WebGUI::Page::canEdit() && WebGUI::Grouping::isInGroup(12)) {
@param = WebGUI::Macro::getParams($_[0]);
if ($session{var}{adminOn}) {
$turnOff = $param[1] || WebGUI::International::get(517);
$temp = '<a href="'.WebGUI::URL::page('op=switchOffAdmin').'">'.$turnOff.'</a>';
} else {
$turnOn = $param[0] || WebGUI::International::get(516);
$temp = '<a href="'.WebGUI::URL::page('op=switchOnAdmin').'">'.$turnOn.'</a>';
}
if (WebGUI::Page::canEdit() && WebGUI::Grouping::isInGroup(12)) {
my %var;
my @param = WebGUI::Macro::getParams($_[0]);
my $templateId = 1; ##Set default template in the namespace
my ($turnOff, $turnOn) = (WebGUI::International::get(517),WebGUI::International::get(516));
##1 param means use my template with default text
if (@param == 1) {
$templateId = WebGUI::Template::getIdByName($param[0],"Macro/EditableToggle");
}
##2 params means use my text with the default template
elsif (@param == 2) {
($turnOff, $turnOn) = @param;
}
##3 or more params means use my text and template, other args ignored
elsif (@param >= 3) {
($turnOff, $turnOn) = @param[1,2];
}
if ($session{var}{adminOn}) {
$var{'toggle.url'} = WebGUI::URL::page('op=switchOffAdmin');
$var{'toggle.text'} = $turnOff;
} else {
$var{'toggle.url'} = WebGUI::URL::page('op=switchOnAdmin');
$var{'toggle.text'} = $turnOn;
}
$templateId = 1 if $templateId == 0;
return WebGUI::Template::process($templateId,"Macro/EditableToggle",\%var);
}
return $temp;
return "";
}
1;

View file

@ -14,23 +14,25 @@ use strict;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Template;
use WebGUI::URL;
#-------------------------------------------------------------------
sub process {
my (@param, $temp);
@param = WebGUI::Macro::getParams($_[0]);
$temp = WebGUI::URL::page('op=displayAccount');
if ($param[0] ne "linkonly") {
$temp = '<a class="myAccountLink" href="'.$temp.'">';
if ($param[0] ne "") {
$temp .= $param[0];
} else {
$temp .= WebGUI::International::get(46);
}
$temp .= '</a>';
}
return $temp;
my %var;
my @param = WebGUI::Macro::getParams($_[0]);
$var{'account.url'} = WebGUI::URL::page('op=displayAccount');
my $templateId = 1; ##Set default template in the namespace
$var{'account.text'} = WebGUI::International::get(46);
if (@param == 1) {
$var{'account.text'} = $param[0] if $param[0];
}
elsif (@param == 2) {
$var{'account.text'} = $param[0] if $param[0];
$templateId = WebGUI::Template::getIdByName($param[1],"Macro/a_account");
$templateId = 1 if $templateId == 0;
}
return WebGUI::Template::process($templateId,"Macro/a_account",\%var);
}

View file

@ -38,6 +38,7 @@ This package contains utility methods for WebGUI's template system.
use WebGUI::Template;
$hashRef = WebGUI::Template::get($templateId, $namespace);
$hashRef = WebGUI::Template::getList($namespace);
$templateId = WebGUI::Template::getIdByName($name,$namespace);
$html = WebGUI::Template::process($templateId, $namespace, $vars);
$templateId = WebGUI::Template::set(\%data);
@ -134,6 +135,35 @@ sub getList {
}
#-------------------------------------------------------------------
=head2 getIdByName ( name, namespace ) {
Returns a template ID by looking up the name for it.
=over
=item name
The name to look up.
=item namespace
The namespace to focus on when searching.
=back
=cut
sub getIdByName {
my $name = shift;
my $namespace = shift;
my ($templateId) = WebGUI::SQL->quickArray("select templateId from template where namespace=".quote($namespace)." and name=".quote($name),WebGUI::SQL->getSlave);
return $templateId;
}
#-------------------------------------------------------------------
=head2 process ( templateId, namespace, vars )