From 600a0939e7e7e589dae4f4f5bfef3650728940b7 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 8 Mar 2006 10:05:01 +0000 Subject: Add a new table for inventory with for DIDs/serials/etc., and an additional new table for inventory category (i.e. to distinguish DIDs, serials, MACs, etc.) --- httemplate/edit/elements/edit.html | 118 ++++++++++++++++++++++++++ httemplate/edit/inventory_class.html | 9 ++ httemplate/edit/process/elements/process.html | 46 ++++++++++ httemplate/edit/process/inventory_class.html | 4 + 4 files changed, 177 insertions(+) create mode 100644 httemplate/edit/elements/edit.html create mode 100644 httemplate/edit/inventory_class.html create mode 100644 httemplate/edit/process/elements/process.html create mode 100644 httemplate/edit/process/inventory_class.html (limited to 'httemplate/edit') diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html new file mode 100644 index 000000000..ce6e2dbb1 --- /dev/null +++ b/httemplate/edit/elements/edit.html @@ -0,0 +1,118 @@ +<% + + # 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 + + 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 $object; + if ( $cgi->param('error') ) { + + $object = $class->new( { + map { $_ => scalar($cgi->param($_)) } fields($table) + }); + + } elsif ( $cgi->keywords ) { #editing + + my( $query ) = $cgi->keywords; + $query =~ /^(\d+)$/; + $object = qsearchs( $table, { $pkey => $1 } ); + + } else { #adding + + $object = $class->new( {} ); + + } + + my $action = $object->$pkey() ? 'Edit' : 'Add'; + + my $title = "$action $opt{'name'}"; + + my @menubar = (); + if ( $opt{'menubar'} ) { + @menubar = @{ $opt{'menubar'} }; + } else { + @menubar = ( + 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done + "View all $opt{'name'}s" => "${p}search/$table.html", #eventually use Lingua::bs to pluralize + ); + } + +%> + + +<%= include("/elements/header.html", $title, + include( '/elements/menubar.html', @menubar ) + ) +%> + +<% if ( $cgi->param('error') ) { %> + Error: <%= $cgi->param('error') %> +

+<% } %> + +
+ +<%= ( $opt{labels} && exists $opt{labels}->{$pkey} ) + ? $opt{labels}->{$pkey} + : $pkey +%> +#<%= $object->$pkey() || "(NEW)" %> + +<%= ntable("#cccccc",2) %> + +<% foreach my $field ( @$fields ) { %> + + + + + <%= ( $opt{labels} && exists $opt{labels}->{$field} ) + ? $opt{labels}->{$field} + : $field + %> + + + <% + #just text in one size for now... eventually more options for + # uneditable, hidden, + + + + +<% } %> + + + +
+ +"> + +
+ +<%= include("/elements/footer.html") %> + diff --git a/httemplate/edit/inventory_class.html b/httemplate/edit/inventory_class.html new file mode 100644 index 000000000..5dde2e595 --- /dev/null +++ b/httemplate/edit/inventory_class.html @@ -0,0 +1,9 @@ +<%= include( 'elements/edit.html', + 'name' => 'Inventory Class', + 'table' => 'inventory_class', + 'labels' => { + 'classnum' => 'Class number', + 'classname' => 'Class name', + }, + ) +%> diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html new file mode 100644 index 000000000..52c876720 --- /dev/null +++ b/httemplate/edit/process/elements/process.html @@ -0,0 +1,46 @@ +<% + + # options example... + # + # 'table' => + # #? 'primary_key' => #required when the dbdef doesn't know...??? + # #? 'fields' => [] + + 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 + } ); + + my $error; + if ( $pkeyvalue ) { + $error = $new->replace($old); + } else { + warn $new; + $error = $new->insert; + warn $error; + $pkeyvalue = $new->getfield($pkey); + } + + if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(2). "$table.html?". $cgi->query_string ); + } else { + print $cgi->redirect(popurl(3). "search/$table.html"); + } + +%> diff --git a/httemplate/edit/process/inventory_class.html b/httemplate/edit/process/inventory_class.html new file mode 100644 index 000000000..e30e74e7b --- /dev/null +++ b/httemplate/edit/process/inventory_class.html @@ -0,0 +1,4 @@ +<%= include( 'elements/process.html', + 'table' => 'inventory_class', + ) +%> -- cgit v1.2.1