[freeside-commits] freeside/httemplate/edit/process/elements process.html, 1.10, 1.11
Ivan,,,
ivan at wavetail.420.am
Wed Aug 1 15:25:08 PDT 2007
- Previous message: [freeside-commits] freeside/httemplate/edit/process access_group.html, 1.3, 1.4 invoice_logo.html, NONE, 1.1 invoice_template.html, NONE, 1.1 part_event.html, NONE, 1.1 quick-cust_pkg.cgi, 1.9, 1.10
- Next message: [freeside-commits] freeside/httemplate/elements checkboxes-table-name.html, 1.2, 1.3 freeside.css, 1.2, 1.3 hidden.html, NONE, 1.1 menu.html, 1.23, 1.24 select-agent.html, 1.6, 1.7 select-agent_type.html, NONE, 1.1 select-cust_main-status.html, NONE, 1.1 select-cust_pkg-status.html, 1.3, 1.4 select-part_referral.html, 1.3, 1.4 select-pkg_class.html, 1.4, 1.5 select-table.html, 1.7, 1.8 selectlayers.html, NONE, 1.1 table-grid.html, 1.4, 1.5 tr-checkbox-multiple.html, NONE, 1.1 tr-checkbox.html, NONE, 1.1 tr-fixed.html, NONE, 1.1 tr-freq.html, NONE, 1.1 tr-input-money.html, NONE, 1.1 tr-input-text.html, NONE, 1.1 tr-password.html, NONE, 1.1 tr-select-agent.html, 1.4, 1.5 tr-select-agent_type.html, NONE, 1.1 tr-select-cust_main-status.html, NONE, 1.1 tr-select-cust_pkg-status.html, 1.2, 1.3 tr-select-invoice_template.html, NONE, 1.1 tr-select-part_pkg.html, NONE, 1.1 tr-select-part_referral.html, 1.2, 1.3 tr-select-pkg_class.html, 1.4, 1.5 tr-select-reason.html, 1.3, 1.4 tr-select-taxclass.html, 1.1, 1.2 tr-select.html, NONE, 1.1 tr-selectlayers.html, NONE, 1.1 tr-selectmultiple-part_pkg.html, 1.2, 1.3 tr-td-label.html, NONE, 1.1 tr-title.html, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/httemplate/edit/process/elements
In directory wavetail:/tmp/cvs-serv23435/httemplate/edit/process/elements
Modified Files:
process.html
Log Message:
event refactor, landing on HEAD!
Index: process.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/process/elements/process.html,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- process.html 24 Jan 2007 05:33:37 -0000 1.10
+++ process.html 1 Aug 2007 22:25:05 -0000 1.11
@@ -1,111 +1,203 @@
-%
-%
-% # options example...
-% #
-% ###
-% ##req
-% ##
-% #
-% # 'table' =>
-% #
-% # #? 'primary_key' => #required when the dbdef doesn't know...???
-% # #? 'fields' => []
-% #
-% ###
-% ##opt
-% ###
-% #
-% # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
-% # OR
-% # 'redirect' => 'view/table.cgi?', # value of primary key is appended
-% #
-% # 'error_redirect' => popurl(2).'edit/table.cgi?', #query string appended
-% #
-% # 'edit_ext' => 'html', #defaults to 'html', you might want 'cgi' while the
-% # #naming is still inconsistent
-% #
-% # 'copy_on_empty' => [ 'old_field_name', 'another_old_field', ... ],
-% #
-% # 'clear_on_error' => [ 'form_field1', 'form_field2', ... ],
-% #
-% # 'process_m2m' => { 'link_table' => 'link_table_name',
-% # 'target_table' => 'target_table_name',
-% # },
-% # 'process_m2name' => { 'link_table' => 'link_table_name',
-% # 'link_static' => { 'column' => 'value' },
-% # 'num_col' => 'column', #if column name is different in
-% # #link_table than source_table
-% # 'name_col' => 'name_column',
-% # 'names_list' => [ 'list', 'names' ],
-% # },
-%
-% my(%opt) = @_;
-%
-% #false laziness w/edit.html
-% my $table = $opt{'table'};
-% my $class = "FS::$table";
-% my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
-% my $fields = $opt{'fields'}
-% #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
-% || [ fields($table) ];
-%
-% my $pkeyvalue = $cgi->param($pkey);
-%
-% my $old = qsearchs( $table, { $pkey => $pkeyvalue } ) if $pkeyvalue;
-%
-% my $new = $class->new( {
-% map {
-% $_, scalar($cgi->param($_));
-% } @$fields
-% } );
-%
-% if ($old && exists($opt{'copy_on_empty'})) {
-% foreach my $field (@{$opt{'copy_on_empty'}}) {
-% $new->set($field, $old->get($field))
-% unless scalar($cgi->param($field));
-% }
-% }
-%
-% my $error;
-% if ( $pkeyvalue ) {
-% $error = $new->replace($old);
-% } else {
-% $error = $new->insert;
-% $pkeyvalue = $new->getfield($pkey);
-% }
-%
-% if ( !$error && $opt{'process_m2m'} ) {
-% $error = $new->process_m2m( %{ $opt{'process_m2m'} },
-% 'params' => scalar($cgi->Vars),
-% );
-% }
-%
-% if ( !$error && $opt{'process_m2name'} ) {
-% $error = $new->process_m2name( %{ $opt{'process_m2name'} },
-% 'params' => scalar($cgi->Vars),
-% );
-% }
-%
-% # XXX print?!?!
-%
-% if ( $error ) {
-% $cgi->param('error', $error);
-% if (scalar(@{$opt{'clear_on_error'}})) {
-% foreach my $field (@{$opt{'clear_on_error'}}) {
-% $cgi->param($field, '')
-% }
-% }
-% my $edit_ext = $opt{'edit_ext'} || 'html';
-% my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext?";
-% print $cgi->redirect($url. $cgi->query_string );
-% } elsif ( $opt{'redirect'} ) {
-% print $cgi->redirect( $opt{'redirect'}. $pkeyvalue );
-% } else {
-% print $cgi->redirect( popurl(3).
-% ( $opt{'viewall_dir'} || 'search' ).
-% "/$table.html"
-% );
-% }
-%
-%
+<%doc>
+
+Example:
+
+ include( 'elements/process.html',
+
+ ###
+ # required
+ ###
+
+ 'table' => 'tablename',
+
+ #? 'primary_key' => #required when the dbdef doesn't know...???
+ #? 'fields' => [] #""
+
+ ###
+ # optional
+ ###
+
+ 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
+ OR
+ 'redirect' => 'view/table.cgi?', # value of primary key is appended
+
+ 'error_redirect' => popurl(2).'edit/table.cgi?', #query string appended
+
+ 'edit_ext' => 'html', #defaults to 'html', you might want 'cgi' while the
+ #naming is still inconsistent
+
+ 'copy_on_empty' => [ 'old_field_name', 'another_old_field', ... ],
+
+ 'clear_on_error' => [ 'form_field1', 'form_field2', ... ],
+
+ 'process_m2m' => { 'link_table' => 'link_table_name',
+ 'target_table' => 'target_table_name',
+ },
+ 'process_m2name' => { 'link_table' => 'link_table_name',
+ 'link_static' => { 'column' => 'value' },
+ 'num_col' => 'column', #if column name is different in
+ #link_table than source_table
+ 'name_col' => 'name_column',
+ 'names_list' => [ 'list', 'names' ],
+
+ 'param_style' => 'link_table.value checkboxes',
+ #or#
+ 'param_style' => 'name_colN values',
+
+ },
+
+ #supplies arguments to insert() and replace()
+ # for use with tables that are FS::option_Common
+ 'args_callback' => sub { my( $cgi, $object ) = @_; },
+
+ 'debug' => 1, #turns on debugging output
+
+ #agent virtualization
+ 'agent_virt' => 1,
+ 'agent_null_right' => 'Access Right Name',
+
+ )
+
+</%doc>
+<%once>
+
+ my $me = 'process.html:';
+
+</%once>
+<%init>
+
+my(%opt) = @_;
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+#false laziness w/edit.html
+my $table = $opt{'table'};
+my $class = "FS::$table";
+my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
+my $fields = $opt{'fields'}
+ #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
+ || [ fields($table) ];
+
+my $pkeyvalue = $cgi->param($pkey);
+
+my $old = '';
+if ( $pkeyvalue ) {
+ $old = qsearchs({
+ 'table' => $table,
+ 'hashref' => { $pkey => $pkeyvalue },
+ 'extra_sql' => ( $opt{'agent_virt'}
+ ? ' AND '. $curuser->agentnums_sql(
+ 'null_right' => $opt{'agent_null_right'}
+ )
+ : ''
+ ),
+ });
+}
+
+my %hash = map { $_ => scalar($cgi->param($_)) } @$fields;
+
+my $new = $class->new( \%hash );
+
+if ( $opt{'agent_virt'} ) {
+ die "illegal agentnum"
+ unless $curuser->agentnums_href->{$new->agentnum}
+ or $opt{'agent_null_right'}
+ && ! $new->agentnum
+ && $curuser->access_right($opt{'agent_null_right'});
+}
+
+if ($old && exists($opt{'copy_on_empty'})) {
+ foreach my $field (@{$opt{'copy_on_empty'}}) {
+ $new->set($field, $old->get($field))
+ unless scalar($cgi->param($field));
+ }
+}
+
+my $error = $new->check;
+
+my @args = ();
+if ( !$error && $opt{'args_callback'} ) {
+ @args = &{ $opt{'args_callback'} }( $cgi, $new );
+}
+
+if ( !$error && $opt{'debug'} ) {
+ warn "$me updating record in $table table using $class class\n";
+ warn Dumper(\%hash);
+ warn "with args: \n". Dumper(\@args) if @args;
+}
+
+if ( !$error ) {
+ if ( $pkeyvalue ) {
+ $error = $new->replace($old, @args);
+ } else {
+ $error = $new->insert(@args);
+ $pkeyvalue = $new->getfield($pkey);
+ }
+}
+
+if ( !$error && $opt{'process_m2m'} ) {
+
+ if ( $opt{'debug'} ) {
+ warn "$me processing m2m:\n". Dumper( %{ $opt{'process_m2m'} },
+ 'params' => scalar($cgi->Vars),
+ );
+ }
+
+ $error = $new->process_m2m( %{ $opt{'process_m2m'} },
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
+if ( !$error && $opt{'process_m2name'} ) {
+
+ if ( $opt{'debug'} ) {
+ warn "$me processing m2name:\n". Dumper( %{ $opt{'process_m2name'} },
+ 'params' => scalar($cgi->Vars),
+ );
+ }
+
+ $error = $new->process_m2name( %{ $opt{'process_m2name'} },
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
+# XXX print?!?!
+
+if ( $error ) {
+ $cgi->param('error', $error);
+ if ( $opt{'clear_on_error'} && scalar(@{$opt{'clear_on_error'}}) ) {
+ foreach my $field (@{$opt{'clear_on_error'}}) {
+ $cgi->param($field, '')
+ }
+ }
+ my $edit_ext = $opt{'edit_ext'} || 'html';
+ my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext";
+ if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit
+
+ my $session = int(rand(4294967296)); #XXX
+ my $pref = new FS::access_user_pref({
+ 'usernum' => $FS::CurrentUser::CurrentUser->usernum,
+ 'prefname' => "redirect$session",
+ 'prefvalue' => $cgi->query_string,
+ 'expiration' => time + 3600, #1h? 1m?
+ });
+ my $pref_error = $pref->insert;
+ if ( $pref_error ) {
+ die "FATAL: couldn't even set redirect cookie: $pref_error".
+ " attempting to set redirect$session to ". $cgi->query_string."\n";
+ }
+ print $cgi->redirect("$url?redirect=$session");
+ } else {
+ print $cgi->redirect("$url?". $cgi->query_string );
+ }
+} elsif ( $opt{'redirect'} ) {
+ print $cgi->redirect( $opt{'redirect'}. $pkeyvalue );
+} else {
+ print $cgi->redirect( popurl(3).
+ ( $opt{'viewall_dir'} || 'search' ).
+ "/$table.html"
+ );
+}
+
+</%init>
- Previous message: [freeside-commits] freeside/httemplate/edit/process access_group.html, 1.3, 1.4 invoice_logo.html, NONE, 1.1 invoice_template.html, NONE, 1.1 part_event.html, NONE, 1.1 quick-cust_pkg.cgi, 1.9, 1.10
- Next message: [freeside-commits] freeside/httemplate/elements checkboxes-table-name.html, 1.2, 1.3 freeside.css, 1.2, 1.3 hidden.html, NONE, 1.1 menu.html, 1.23, 1.24 select-agent.html, 1.6, 1.7 select-agent_type.html, NONE, 1.1 select-cust_main-status.html, NONE, 1.1 select-cust_pkg-status.html, 1.3, 1.4 select-part_referral.html, 1.3, 1.4 select-pkg_class.html, 1.4, 1.5 select-table.html, 1.7, 1.8 selectlayers.html, NONE, 1.1 table-grid.html, 1.4, 1.5 tr-checkbox-multiple.html, NONE, 1.1 tr-checkbox.html, NONE, 1.1 tr-fixed.html, NONE, 1.1 tr-freq.html, NONE, 1.1 tr-input-money.html, NONE, 1.1 tr-input-text.html, NONE, 1.1 tr-password.html, NONE, 1.1 tr-select-agent.html, 1.4, 1.5 tr-select-agent_type.html, NONE, 1.1 tr-select-cust_main-status.html, NONE, 1.1 tr-select-cust_pkg-status.html, 1.2, 1.3 tr-select-invoice_template.html, NONE, 1.1 tr-select-part_pkg.html, NONE, 1.1 tr-select-part_referral.html, 1.2, 1.3 tr-select-pkg_class.html, 1.4, 1.5 tr-select-reason.html, 1.3, 1.4 tr-select-taxclass.html, 1.1, 1.2 tr-select.html, NONE, 1.1 tr-selectlayers.html, NONE, 1.1 tr-selectmultiple-part_pkg.html, 1.2, 1.3 tr-td-label.html, NONE, 1.1 tr-title.html, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list