[Rt-commit] r2200 - in experiments/Bamboo: . lib/Bamboo/View
lib/Bamboo/View/mason
jesse at bestpractical.com
jesse at bestpractical.com
Thu Feb 10 00:37:18 EST 2005
Author: jesse
Date: Thu Feb 10 00:37:16 2005
New Revision: 2200
Added:
experiments/Bamboo/lib/Bamboo/View/mason/AttributeMap
experiments/Bamboo/lib/Bamboo/View/mason/Create
experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdate
experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdateAllObjects
experiments/Bamboo/lib/Bamboo/View/mason/Header
experiments/Bamboo/lib/Bamboo/View/mason/ListResults
Removed:
experiments/Bamboo/lib/Bamboo/View/AttributeMap
experiments/Bamboo/lib/Bamboo/View/Create
experiments/Bamboo/lib/Bamboo/View/CreateOrUpdate
experiments/Bamboo/lib/Bamboo/View/CreateOrUpdateAllObjects
experiments/Bamboo/lib/Bamboo/View/Header
experiments/Bamboo/lib/Bamboo/View/ListResults
Modified:
experiments/Bamboo/ (props changed)
Log:
r4647 at hualien: jesse | 2005-02-09T16:41:07.887460Z
moved some mason components
Added: experiments/Bamboo/lib/Bamboo/View/mason/AttributeMap
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/AttributeMap Thu Feb 10 00:37:16 2005
@@ -0,0 +1,13 @@
+<%args>
+$Object => undef
+</%args>
+<%init>;
+my $ObjectType = ref($Object);
+$ObjectType =~ s/:/_/gi;
+my $AttributeMap;
+if ( $m->comp_exists("ObjectType/$ObjectType") ) {
+ $AttributeMap = $m->comp( "ObjectType/$ObjectType", %ARGS );
+}
+return $AttributeMap;
+
+</%init>
Added: experiments/Bamboo/lib/Bamboo/View/mason/Create
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/Create Thu Feb 10 00:37:16 2005
@@ -0,0 +1,34 @@
+<%ARGS>
+$Object => undef
+$FormTag => undef
+$Messages => undef
+$Errors => undef
+$NewObjectIdMap => undef
+</%ARGS>
+<%init>
+
+
+
+ my %attrs;
+ foreach my $attr ( $Object->WritableAttributes ) {
+ my $attr_uri_param_name =$FormTag . "-Create-" . $attr;
+ $RT::Logger->crit( "Looking for $attr_uri_param_name");
+
+ $attrs{$attr} = $ARGS{$attr_uri_param_name}
+ if ( $ARGS{$attr_uri_param_name} );
+ }
+ use Data::Dumper;
+ $RT::Logger->crit(Dumper \%attrs);
+
+ my ( $id, $msg ) = $Object->Create(%attrs);
+ if ($id) {
+ $msg ||= loc("Object created");
+ $Messages->{'create'} = $msg;
+ $NewObjectIdMap->{$FormTag} = $id;
+ }
+ else {
+ $RT::Logger->error("Object creation failed for $FormTag / $Object");
+ $_ERRORS{$FormTag."-Create"} = $msg;
+ }
+
+</%init>
Added: experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdate
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdate Thu Feb 10 00:37:16 2005
@@ -0,0 +1,85 @@
+<%ARGS>
+$Object => undef
+$Messages => undef
+$Errors => undef
+</%ARGS>
+<%init>
+
+
+if ( $ARGS{'id'} eq 'new' ) {
+
+ my %attrs;
+ foreach my $attr ( $Object->WritableAttributes ) {
+ my $attr_uri_param_name =
+ ref($Object) . "-" . $ARGS{'id'} . "-" . $attr;
+ $attrs{$attr} = $ARGS{$attr_uri_param_name}
+ if ( $ARGS{$attr_uri_param_name} );
+ }
+ my ( $id, $msg ) = $Object->Create(%attrs);
+ if ($id) {
+ $msg ||= loc("Object created");
+ $Messages->{'create'} = $msg;
+ $session{'created_object'} = $id;
+ }
+ else {
+ $Errors->{'create'} = $msg;
+ }
+
+}
+elsif ( $ARGS{'id'} ) {
+ $Object->Load( $ARGS{'id'} );
+ unless ( $Object->id ) {
+ Abort("No such Object");
+ }
+
+ foreach my $attr ( $Object->WritableAttributes ) {
+ my $attr_uri_param_name = ref($Object) . "-" . $ARGS{'id'} . "-" . $attr;
+
+
+ my $value;
+ next unless ( exists $ARGS{$attr_uri_param_name}
+ || $ARGS{ $attr_uri_param_name . "-previous-value" } );
+
+ # If no value is set, but there was a value before, that means the user
+ # unclicked a checkbox. would be nice if html forms conveyed this information
+ # back to the server
+ if ( !exists $ARGS{$attr_uri_param_name} ) {
+ if ( $ARGS{ $attr_uri_param_name . "-previous-value" } == 1 ) {
+ $value = 0;
+ }
+
+ }
+ else {
+ $RT::Logger->debug("Found $attr_uri_param_name");
+ $value = $ARGS{$attr_uri_param_name};
+ }
+ my $AttributeMap = $m->comp( 'AttributeMap', Object => $Object );
+ if ( $AttributeMap->{$attr}->{Validator} ) {
+ if ( $m->comp_exists( "Validator/" . $AttributeMap->{$attr}->{Validator})) {
+ $value = $m->comp(
+ "Validator/" . $AttributeMap->{$attr}->{Validator},
+ Object => $Object,
+ AttributeName => $attr,
+ Value => $value
+ );
+ }
+ else {
+ $m->out( "Couldn't find " . $AttributeMap->{$attr}->{Validator} );
+ }
+ }
+
+ $RT::Logger->debug("The value is finally $value");
+ next unless ( defined $value
+ && ( $Object->$attr() ne $value ) );
+ my $set = "Set$attr";
+ my ( $val, $msg ) = $Object->$set($value);
+ if ($val) {
+ $Messages->{$attr} = $msg;
+ }
+ else {
+ $Errors->{$attr} = $msg;
+ }
+
+ }
+}
+</%init>
Added: experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdateAllObjects
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/CreateOrUpdateAllObjects Thu Feb 10 00:37:16 2005
@@ -0,0 +1,99 @@
+<%ARGS>
+$Object => undef
+$FormTag => undef
+$Messages => undef
+$Errors => undef
+$NewObjectIdMap => undef
+</%ARGS>
+<%init>
+
+use URI;
+use URI::QueryParam;
+
+# objects we're creating
+my $creates = {};
+
+# method calls we're performing
+my $calls = {};
+
+# Iterate through %ARGS and slice and dice into
+# Object we're working on
+# Method calls for those objects
+# Params for those method calls
+foreach my $attr ( keys %ARGS ) {
+
+ next unless ( $attr =~ /^(.*?)-(.*?)-(.*?)-(.*?)/ );
+ my $object_type = $1;
+ my $object_id = $2;
+ my $method = $3;
+ my $param_name = $4;
+ my $param_value = $ARGS{$attr};
+
+ push (
+ @{ $calls->{$object_type}->{$object_id}->{$method}->{$param_name} },
+ $param_value
+ );
+
+}
+
+# now that we have all the things we're doing, let's create the objects we need to and then perform all the updates to the other objects we're updating.
+
+# for each object type
+foreach my $object_type ( keys %$calls ) {
+
+ foreach my $object_id ( keys %{ $calls->{$object_type} } ) {
+
+ # Instantiate a proxy object
+ my $proxy = RT::ProxyObject->new(
+ CurrentUser => $session{'CurrentUser'},
+ Type => $object_type,
+ id => $object_id
+ );
+
+ # XXX TODO this should handle Create then any other method
+ foreach my $method ( keys %{ $calls->{$object_type}->{$object_id} } ) {
+
+ # Call the method on the proxy object with the params listed here
+ $RT::Logger->debug( "$object_type->new()->Load($object_id)->$method ( ");
+
+ my $params_ref = $calls->{$object_type}->{$object_id}->{$method};
+
+ $proxy->$method($params_ref);
+
+ #XXX TODO get URL forwarding happening
+
+ #$NewObjectIdMap->{$FormTag} = $id;
+
+ }
+
+ }
+
+}
+
+my $new_obj_id_map = {};
+
+if ( ( !keys %_ERRORS ) && $ARGS{'_OnSuccessGotoPage'} ) {
+ my $goto = $ARGS{'_OnSuccessGotoPage'};
+ my $URI = URI->new($goto);
+
+ my $goto_id = $URI->query_param('id');
+
+ if ( $goto_id =~ /^(.*?)-new-(.*?)$/ ) {
+ $URI->query_param( 'id' => $new_obj_id_map->{$goto_id} );
+ }
+
+ my $flow_id = time() . int( rand(1000) );
+
+ $URI->query_param( 'flow_id' => $flow_id );
+
+ %{ $session{ '_MESSAGES-' . $flow_id } } = %_MESSAGES;
+
+ # here we should deal with a way to preserve errors and messages when
+ # shoving off to the new page.
+ # I think the right answer is to stuff them in the session with a
+ # key that the new page can use to pull them out and clear them.
+
+ $m->redirect( $URI->as_string );
+}
+
+</%init>
Added: experiments/Bamboo/lib/Bamboo/View/mason/Header
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/Header Thu Feb 10 00:37:16 2005
@@ -0,0 +1,63 @@
+%# BEGIN LICENSE BLOCK
+%#
+%# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
+%#
+%# (Except where explictly superceded by other copyright notices)
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# Unless otherwise specified, all modifications, corrections or
+%# extensions to this work which alter its source code become the
+%# property of Best Practical Solutions, LLC when submitted for
+%# inclusion in the work.
+%#
+%#
+%# END LICENSE BLOCK
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<HTML>
+<HEAD>
+<TITLE><%$Title%></TITLE>
+% if ($Refresh > 0) {
+<META HTTP-EQUIV="REFRESH" CONTENT="<%$Refresh%>">
+% }
+
+<link rel="shortcut icon" href="<%$RT::WebImagesURL%>/favicon.png" type="image/png">
+<link rel="stylesheet" href="<%$RT::WebPath%>/NoAuth/webrt.css" type="text/css">
+</HEAD>
+<BODY BGCOLOR="<%$BgColor%>"
+% if ($Focus) {
+ONLOAD="
+ var tmp = (document.getElementsByName('<% $Focus %>'));
+ if (tmp.length > 0) tmp[tmp.length-1].focus();
+"
+% }
+>
+<%$m->content()|n%>
+</body>
+</html>
+<%INIT>
+
+$r->header_out('Pragma' => 'no-cache');
+$r->header_out('Cache-control' => 'no-cache');
+</%INIT>
+
+<%ARGS>
+$Prefs => '/User/Prefs.html'
+$Focus => 'focus'
+$Title => undef
+$Code => undef
+$Refresh => 0
+$Why => undef
+$BgColor => '#ffffff'
+$ShowBar => 1
+$LoggedIn => 1
+$URL => undef
+</%ARGS>
Added: experiments/Bamboo/lib/Bamboo/View/mason/ListResults
==============================================================================
--- (empty file)
+++ experiments/Bamboo/lib/Bamboo/View/mason/ListResults Thu Feb 10 00:37:16 2005
@@ -0,0 +1,27 @@
+<span class="system_messages">
+<ul>
+% if ($session{'_MESSAGES-'.$flow_id}) {
+% foreach my $message (%{$session{'_MESSAGES-'.$flow_id}}) {
+% next unless ($message);
+<li><% $session{'_MESSAGES-'.$flow_id}->{$message} %></li>
+% }
+%}
+% delete $session{'_MESSAGES-'.$flow_id};
+
+% foreach my $message (keys %_MESSAGES){
+% next unless ($message);
+<li><% $_MESSAGES{$message} %></li>
+% }
+</ul>
+<ul>
+% foreach my $message (keys %_ERRORS){
+<li class="error"><%$_ERRORS{$message}%></li>
+% }
+</ul>
+</span>
+<%init>
+
+my $request_args = $m->request_args();
+my $flow_id = $request_args->{'flow_id'};
+
+</%init>
More information about the Rt-commit
mailing list