X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Fedit.html;h=ac00fc5f09cb2364b9e3f82e856fee644305bd63;hb=088d455c563ca3b75be357727622d968e49b3ed1;hp=120c03a3c5c83581feae6d0ca9882d4168891884;hpb=2c757d7db4cb6a7b9655de13206fcc84fb7ce61f;p=freeside.git diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 120c03a3c..a238a3f04 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -1,142 +1,960 @@ -<% - - # options example... - # - # 'name' => - # 'table' => - # #? 'primary_key' => #required when the dbdef doesn't know...??? - # 'labels' => { - # 'column' => 'Label', - # } - # - # listref - each item is a literal column name (or method) or (notyet) coderef - # if not specified all columns (except for the primary key) will be editable - # 'fields' => [ - # ] - # - # 'menubar' => '', #menubar arrayref - # - # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' - # - # 'html_bottom' => '', #string - # 'html_bottom' => sub { - # my $object = shift; - # # ... - # "html_string"; - # }, - - my(%opt) = @_; - - #false laziness w/process.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 ]; - || [ grep { $_ ne $pkey } fields($table) ]; - #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields; - - my $object; - if ( $cgi->param('error') ) { +<%doc> + +Example: + + <& elements/edit.html, + 'name_singular' => #singular name for the record + # (preferred, will be pluralized automatically) + 'name' => #name for the record + # (deprecated, will be pluralized simplistically) + 'table' => + + #? 'primary_key' => #required when the dbdef doesn't know...??? + 'labels' => { + 'column' => 'Label', + } + + #listref - each item is a literal column name (or method) or hashref + # or (notyet) coderef + #if not specified all columns (except for the primary key) will be editable + 'fields' => [ + 'columname', + { 'field' => 'another_columname', + 'type' => 'text', #text + #password + #money + #percentage + #checkbox + #select + #selectlayers (can now use after a tablebreak-tr-title... but not inside columnstart/columnnext/columnend) + #title + #tablebreak-tr-title + #columnstart + #columnnext + #columnend + #hidden - hidden value from object + #fixed - display fixed value from object or here + #fixed-country + #fixed-state + 'value' => 'Y', #for checkbox, title, fixed, hidden + 'disabled' => 0, + 'onchange' => 'javascript_function', + + 'include_opt_callback' => sub { my $object = @_; + ( 'option' => 'value', ); + }, + + 'm2name_table' => 'table_name', + 'm2name_namecol' => 'name_column', + #OR# + 'm2m_method' => + #'m2m_srccol' => #opt, if not the same as this table + 'm2m_dstcol' => #required for now, eventuaully opt, if not the same as target table + #OR# + 'o2m_table' => + + 'm2_label' => 'Label', # + 'm2_new_default' => \@table_name_objects, #default + #m2 objects for + #new records + 'm2_error_callback' => sub { my($cgi, $object) = @_; }, + 'm2_remove_warnings' => \%warnings, #hashref of warning + #messages for m2 + #removal + 'm2_new_js' => 'function_name', #javascript function called + #on spawned rows (one arg: + #new_element) + 'm2_remove_js' => 'function_name', #js function called when + #a row is deleted (three + #args: value, text, + #'no_match') + #layer_fields & layer_values_callback only for selectlayer + 'layer_fields' => [ + 'fieldname' => 'Label', + 'another_field' => { + label=>'Label', + type =>'text', #text, money + }, + ], + 'layer_values_callback' => + sub { + my( $cgi, $object ) = @_; + { 'layer' => { 'fieldname' => 'current_value', + 'fieldname2' => 'field2value', + ... + }, + 'layer2' => { 'l2fieldname' => 'l2value', + ... + }, + ... + }; + }, + }, + ] + + 'menubar' => '', #menubar arrayref + + #agent virtualization + 'agent_virt' => 1, + 'agent_null' => 1, #if true, always allow no-agentnum globals + 'agent_null_right' => 'Access Right Name', + 'agent_clone_extra_sql' => '', #if provided, this overrides the extra_sql + #implementing agent virt, for clone + #operations. i.e. pass "1=1" to allow + #cloning anything + + 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' + + # overrides default popurl(1)."process/$table.html" + 'post_url' => popurl(1).'process/something', + + # optional link to delete this object; primary key will be appended + 'delete_url' => $p.'misc/delete-something.html?', + + #we're in a popup (no title/menu/searchboxes) + 'popup' => 1, + + #if you need to access the submit button + 'submit_id' => 'mysubmitbuttonid', + + #we're embedded (rows only: no header at all, no html_init, no error + # display, no
+ + <% ref( $opt{'html_foot'} ) + ? &{ $opt{'html_foot'} }( $object ) + : $opt{'html_foot'} + %> + +% my %footerdata = ( +% 'formvalidation' => $js_form_validate, +% ); + + <% include("/elements/footer.html", %footerdata) %> + +% } +<%init> + +my(%opt) = @_; + +my $curuser = $FS::CurrentUser::CurrentUser; + +#false laziness w/process.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 ]; + || [ grep { $_ ne $pkey } fields($table) ]; +my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields; + +push @actualfields, $pkey; + +my $js_form_validate = {}; + +my( $mode, $object); +my $clone = ''; +if ( $opt{'embed'} ) { + + $object = $opt{'embed'}; + $mode = $cgi->param('error') + ? 'error' + : $object->$pkey() + ? 'edit' + : 'new'; + +} else { + + #$m->comp('/elements/handle_uri_query'); + if ( $cgi->param('redirect') ) { + my $session = $cgi->param('redirect'); + my $pref = $curuser->option("redirect$session"); + die "unknown redirect session $session\n" unless length($pref); + $cgi = new CGI($pref); + } + + &{$opt{'begin_callback'}}( $cgi, $fields, \%opt ) + if $opt{'begin_callback'}; + + my %qsearch = ( + 'table' => $table, + 'extra_sql' => ( $opt{'agent_virt'} + ? ' AND '. $curuser->agentnums_sql( + 'null_right' => $opt{'agent_null_right'} + ) + : '' + ), + ); + + if ( $cgi->param('error') ) { + + $mode = 'error'; + + $object = $class->new( { + map { $_ => scalar($cgi->param($_)) } @actualfields + }); + + &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'error_callback'}; + + } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) { + + $mode = 'clone'; + + $clone = $1; + + $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'} + if $opt{'agent_clone_extra_sql'}; + + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } }) + or die "$pkey $clone not found in $table"; + + &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'clone_callback'}; + + #$object->$pkey(''); + + $opt{action} ||= 'Add'; + + } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing + + $mode = 'edit'; + + my $value; + if ( $cgi->param($pkey) ) { + $value = $cgi->param($pkey) + } else { + my( $query ) = $cgi->keywords; + $value = $query; + } + $value =~ /^(\d+)$/ or die "unparsable $pkey"; + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }) + or die "$pkey $1 not found in $table"; + + warn "$table $pkey => $1" + if $opt{'debug'}; + + &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'edit_callback'}; + + } else { #adding + + $mode = 'new'; + + my $hashref = $opt{'new_hashref_callback'} + ? &{$opt{'new_hashref_callback'}} + : {}; + + $object = $opt{'new_object_callback'} + ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt ) + : $class->new( $hashref ); + + &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'new_callback'}; + + } -"> + &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'end_callback'}; - + $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add'; -<%= include("/elements/footer.html") %> +} +%init>