[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. e2fff4ce7ccdd262c55836a79889eda9a49ddd30

Stefan Hornburg racke at rt.icdevgroup.org
Sun Mar 28 11:18:27 UTC 2010


       via  e2fff4ce7ccdd262c55836a79889eda9a49ddd30 (commit)
       via  6cc4176497c2185c250929777fb157351ba126b1 (commit)
      from  b87eabc943487244da1c131c30a42802e84dc8d5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e2fff4ce7ccdd262c55836a79889eda9a49ddd30
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Sun Mar 28 13:17:59 2010 +0200

    various changes to backend/menu functionality

commit 6cc4176497c2185c250929777fb157351ba126b1
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Sun Mar 28 13:14:11 2010 +0200

    selectby and restrict options added
    output of raw value when value is filtered

-----------------------------------------------------------------------

Summary of changes and diff:
 lib/Vend/Panel.pm                                  |   44 ++++++++++++++++----
 plugins/backend/backend.info                       |    3 +
 ...nus_load.sub => form_menus_entry_edit_load.sub} |   13 ++++-
 .../backend/code/form_menus_entry_edit_save.sub    |   37 ++++++++++++++++
 plugins/backend/code/form_menus_save.sub           |   20 ---------
 plugins/backend/components/backend_menus_menu      |   19 +++-----
 plugins/backend/pages/backend/menus/edit.itl       |    2 +-
 7 files changed, 93 insertions(+), 45 deletions(-)
 create mode 100644 plugins/backend/backend.info
 rename plugins/backend/code/{form_menus_load.sub => form_menus_entry_edit_load.sub} (52%)
 create mode 100644 plugins/backend/code/form_menus_entry_edit_save.sub
 delete mode 100644 plugins/backend/code/form_menus_save.sub

diff --git a/lib/Vend/Panel.pm b/lib/Vend/Panel.pm
index 5d4aeb2..e840c79 100644
--- a/lib/Vend/Panel.pm
+++ b/lib/Vend/Panel.pm
@@ -41,7 +41,7 @@ sub new {
 
 sub panel {
 	my ($table, $columns, $opt, $body) = @_;
-	my ($panel, $db, $set, @out, @cols, $colstr);
+	my ($panel, $db, $set, @out, @cols, @conds, $colstr, $condstr);
 
 	$panel = new Vend::Panel;
 
@@ -59,6 +59,10 @@ sub panel {
 		for (keys %{$panel->{variables}}) {
 			if ($db->column_exists($_)) {
 				push (@cols, $_);
+
+				if ($opt->{selectby}->{$_} =~ /\S/) {
+					push (@conds, "$_ = " . $db->quote($opt->{selectby}->{$_}));
+				}
 			}
 		}
 
@@ -68,14 +72,30 @@ sub panel {
 		else {
 			return $body;
 		}
+
+		for (keys %{$opt->{restrict}}) {
+			push (@conds, "$_ = " . $db->quote($opt->{restrict}->{$_}));
+		}
 		
-		$set = $db->query({sql => qq{select $colstr from $table}, hashref => 1});
+		if (@conds) {
+			$condstr = ' WHERE ' . join(' AND ', @conds);
+		}
+		else {
+			$condstr = '';
+		}
+		
+		$set = $db->query({sql => qq{select $colstr from $table$condstr}, hashref => 1});
 
 		for my $row (@$set) {
+			my $data;
+
+			%$data = %$row;
+
 			for my $fltvar (%{$opt->{filters}}) {
-				$row->{$fltvar} = Vend::Tags->filter({op => $opt->{filters}->{$fltvar}, body => $row->{$fltvar}});
+				$data->{$fltvar} = Vend::Tags->filter({op => $opt->{filters}->{$fltvar}, body => $row->{$fltvar}});
 			}
-			push(@out, $panel->fill_simple($row));
+			
+			push(@out, $panel->fill_simple($data, $row));
 		}
 	}
 
@@ -91,12 +111,13 @@ sub parse_simple {
 	$self->{variables} = {};
 	
 	while (pos $input < length $input) {
-		if ($input =~ m{ \G  (.*?)?\{([A-Z_]+)\} }gcxms) {
+		if ($input =~ m{ \G  (.*?)?\{([A-Z_]+)(:([A-Z]+))?\} }gcxms) {
 			if (defined $1) {
 				push (@{$self->{tokens}}, $1);
 			}
 			push (@{$self->{tokens}}, '');
-			push (@{$self->{variables}->{lc($2)}}, $#{$self->{tokens}});
+			push (@{$self->{variables}->{lc($2)}}, {pos => $#{$self->{tokens}},
+													type => lc($4)});
 		}
 		else {
 			push (@{$self->{tokens}}, substr($input, pos($input)));
@@ -108,14 +129,19 @@ sub parse_simple {
 }
 
 sub fill_simple {
-	my ($self, $hash) = @_;
+	my ($self, $hash, $row) = @_;
 	my ($out, $tokref);
 
 	@$tokref = @{$self->{tokens}};
 
 	for (keys %{$self->{variables}}) {
-		for my $pos (@{$self->{variables}->{$_}}) {
-			$tokref->[$pos] = $hash->{$_};
+		for my $var (@{$self->{variables}->{$_}}) {
+			if ($var->{type} eq 'raw') {
+				$tokref->[$var->{pos}] = $row->{$_};
+			}
+			else {
+				$tokref->[$var->{pos}] = $hash->{$_};
+			}
 		}
 	}
 
diff --git a/plugins/backend/backend.info b/plugins/backend/backend.info
new file mode 100644
index 0000000..a2a819e
--- /dev/null
+++ b/plugins/backend/backend.info
@@ -0,0 +1,3 @@
+name = Backend
+version = 0.1
+require = WellWell::Panel
diff --git a/plugins/backend/code/form_menus_load.sub b/plugins/backend/code/form_menus_entry_edit_load.sub
similarity index 52%
rename from plugins/backend/code/form_menus_load.sub
rename to plugins/backend/code/form_menus_entry_edit_load.sub
index aab836d..3b301ec 100644
--- a/plugins/backend/code/form_menus_load.sub
+++ b/plugins/backend/code/form_menus_entry_edit_load.sub
@@ -1,11 +1,17 @@
-Sub form_menus_load <<EOS
+Sub form_menus_entry_edit_load <<EOS
 sub {
 	my $menu_ref;
 
 	$Tag->perl({tables => 'menus'});
 
-	# load data for menu entry
-	$menu_ref = $Db{menus}->row_hash($CGI->{menu_code});
+	if ($CGI->{menu_code}) {
+		# load data for menu entry
+		$menu_ref = $Db{menus}->row_hash($CGI->{menu_code});
+	}
+	else {
+		# new menu
+		$menu_ref = {};
+	}
 
 	unless ($menu_ref) {
 		return {page => "backend/menus/$menu{menu_name}"};
@@ -14,6 +20,7 @@ sub {
 	$Values->{menu_code} = $menu_ref->{code};
 	$Values->{name} = $menu_ref->{name};
 	$Values->{url} = $menu_ref->{url};
+	$Values->{permission} = $menu_ref->{permission};
 
 	return;
 }
diff --git a/plugins/backend/code/form_menus_entry_edit_save.sub b/plugins/backend/code/form_menus_entry_edit_save.sub
new file mode 100644
index 0000000..b511b27
--- /dev/null
+++ b/plugins/backend/code/form_menus_entry_edit_save.sub
@@ -0,0 +1,37 @@
+Sub form_menus_entry_edit_save <<EOS
+sub {
+	my %menu;
+
+	$Tag->perl({tables => 'menus'});
+
+	if ($CGI->{delete}) {
+		my $menu_ref;
+
+		# get current entry
+		$menu_ref = $Db{menus}->row_hash($CGI->{menu_code});
+
+		if ($Db{menus}->delete_record($CGI->{menu_code})) {
+			$Tag->warnings(qq{Menu entry $menu_ref->{name} has been deleted.});
+		}
+		else {
+			$Tag->error({name => 'menu', set => q{Error deleting menu entry}});
+		}
+
+		return {page => "backend/menus/$menu{menu_name}"};
+	}
+
+	$menu{menu_name} = $CGI->{menu_name};
+	$menu{name} = $CGI->{name};
+	$menu{url} = $CGI->{url};
+	$menu{permission} = $CGI->{permission};
+
+	if ($CGI->{menu_code}) {
+		$ret = $Db{menus}->set_slice([{dml => 'update'}, $CGI->{menu_code}], %menu);
+	}
+	else {
+		$ret = $Db{menus}->set_slice([{dml => 'insert'}], %menu);
+	}
+		
+	return {page => "backend/menus/$menu{menu_name}"};
+}
+EOS
diff --git a/plugins/backend/code/form_menus_save.sub b/plugins/backend/code/form_menus_save.sub
deleted file mode 100644
index 8b18097..0000000
--- a/plugins/backend/code/form_menus_save.sub
+++ /dev/null
@@ -1,20 +0,0 @@
-Sub form_menus_save <<EOS
-sub {
-	my %menu;
-
-	$Tag->perl({tables => 'menus'});
-
-	$menu{menu_name} = $CGI->{menu_name};
-	$menu{name} = $CGI->{name};
-	$menu{url} = $CGI->{url};
-
-	if ($CGI->{menu_code}) {
-		$ret = $Db{menus}->set_slice([{dml => 'update'}, $CGI->{menu_code}], %menu);
-	}
-	else {
-		$ret = $Db{menus}->set_slice([{dml => 'insert'}], %menu);
-	}
-		
-	return {page => "backend/menus/$menu{menu_name}"};
-}
-EOS
diff --git a/plugins/backend/components/backend_menus_menu b/plugins/backend/components/backend_menus_menu
index 399df33..7d67747 100644
--- a/plugins/backend/components/backend_menus_menu
+++ b/plugins/backend/components/backend_menus_menu
@@ -1,13 +1,8 @@
-[query sql="select * from menus where menu_name = '[cgi menu]'" list=1]
-[on-match]
 <table>
-<tr><th>Name</th><th>URL</th><th></th></tr>
-[/on-match]
-[list]
-<tr><td>[sql-param name]</td><td>[sql-param url]</td>
-<td><a href="[area href="backend/menus/[cgi menu]/[sql-code]/edit"]">Edit</a></td></tr>
-[/list]
-[on-match]
-</table>
-[/on-match]
-[/query]
+<tr><th>[L]Name[/L]</th><th>[L]URL[/L]</th><th>[L]Permission[/L]</th><th></th></tr>
+[panel table="menus" restrict.menu_name="[cgi menu]"]
+<tr><td>{NAME}</td><td>{URL}</td>
+<td>{PERMISSION}</td>
+<td><a href="[area href="backend/menus/[cgi menu]/{CODE}/edit"]">Edit</a></td></tr>
+[/panel]
+</table>
\ No newline at end of file
diff --git a/plugins/backend/pages/backend/menus/edit.itl b/plugins/backend/pages/backend/menus/edit.itl
index 6ffb1d9..1a638f8 100644
--- a/plugins/backend/pages/backend/menus/edit.itl
+++ b/plugins/backend/pages/backend/menus/edit.itl
@@ -4,7 +4,7 @@
     components.right="login"
 
 	components.body="backend_menus_add"
-	forms.backend_menus_add.name="[if cgi menu_code]menus_entry_edit[else]menus_entry_add[/else][/if]"
+	forms.backend_menus_add.name="menus_entry_edit"
 
 	attributes.htmlhead.title="Well Well Backend"
 


hooks/post-receive
-- 
Interchange wellwell catalog



More information about the wellwell-devel mailing list