select-table and select-part_pkg updates so we can use select-part_pkg as an edit...
authorivan <ivan>
Sun, 13 Apr 2008 20:35:10 +0000 (20:35 +0000)
committerivan <ivan>
Sun, 13 Apr 2008 20:35:10 +0000 (20:35 +0000)
httemplate/elements/select-cust-part_pkg.html
httemplate/elements/select-part_pkg.html [new file with mode: 0644]
httemplate/elements/select-table.html
httemplate/elements/tr-select-part_pkg.html

index 8b446b9..57da5cd 100644 (file)
@@ -18,14 +18,9 @@ Example:
 
 </%doc>
 
 
 </%doc>
 
-<% include( '/elements/select-table.html',
-              'table'          => 'part_pkg',
-              'name_col'       => 'pkg',
-              'empty_label'    => 'Select package',
-              'label_callback' => sub { $_[0]->pkgpart. ': '.
-                                        $_[0]->pkg.     ' - '.
-                                        $_[0]->comment;
-                                      },
+<% include( '/elements/select-part_pkg.html',
+              'empty_label'    => 'Select package', #? need here in case removed
+                                                    #from select-part_pkg ??
               %opt,
           )
 %>
               %opt,
           )
 %>
@@ -36,21 +31,9 @@ my( %opt ) = @_;
 my $cust_main = $opt{'cust_main'}
   or die "cust_main not specified";
 
 my $cust_main = $opt{'cust_main'}
   or die "cust_main not specified";
 
-$opt{'records'} = delete $opt{'part_pkg'}
-  if $opt{'part_pkg'};
-
-my $extra_sql = $opt{'extra_sql'}.
+$opt{'extra_sql'} .=
   ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
   '             WHERE typenum = '. $cust_main->agent->typenum.
   '             AND type_pkgs.pkgpart = part_pkg.pkgpart )';
 
   ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
   '             WHERE typenum = '. $cust_main->agent->typenum.
   '             AND type_pkgs.pkgpart = part_pkg.pkgpart )';
 
-$opt{'records'} ||= [ qsearch({ 
-                                'table'     => 'part_pkg',
-                                'hashref'   => { 'disabled' => '', },
-                                'extra_sql' => "$extra_sql ORDER BY pkg",
-                                #'extra_sql' => $extra_sql,
-                                #'order_by'  => 'ORDER BY pkg',
-                             })
-                    ];
-
 </%init>
 </%init>
diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html
new file mode 100644 (file)
index 0000000..a1d5f40
--- /dev/null
@@ -0,0 +1,34 @@
+<%doc>
+
+Example:
+
+  include( '/elements/select-part_pkg.html',
+
+    #strongly recommended (you want your forms to be "sticky" on errors, right?)
+    'curr_value' => 'current_value',
+  
+    #opt
+    'part_pkg'   => \@records,
+
+    #select-table.html options
+  )
+
+</%doc>
+
+<% include( '/elements/select-table.html',
+              'table'          => 'part_pkg',
+              'name_col'       => 'pkg',
+              'empty_label'    => 'Select package', #should this be the default?
+              'label_callback' => sub { shift->pkg_comment },
+              'hashref'        => { 'disabled' => '' },
+              %opt,
+          )
+%>
+<%init>
+
+my( %opt ) = @_;
+
+$opt{'records'} = delete $opt{'part_pkg'}
+  if $opt{'part_pkg'};
+
+</%init>
index 5d6c4a8..7339f36 100644 (file)
@@ -100,6 +100,7 @@ if ( $opt{'records'} ) {
     'table'     => $opt{'table'},
     'hashref'   => ( $opt{'hashref'} || {} ),
     'extra_sql' => ( $opt{'extra_sql'} || '' ),
     'table'     => $opt{'table'},
     'hashref'   => ( $opt{'hashref'} || {} ),
     'extra_sql' => ( $opt{'extra_sql'} || '' ),
+    'order_by'  => ( $opt{'order_by'} || "ORDER BY $name_col" ),
   });
 }
 
   });
 }
 
index b6d4d4d..db9afd2 100644 (file)
@@ -1,29 +1,39 @@
-% if ( scalar(@{ $opt{'part_pkg'} }) == 0 ) { 
+% if ( $opt{'part_pkg'} && scalar(@{ $opt{'part_pkg'} }) == 0 ) { 
+%   unless ( $opt{'js_only'} ) {
 
 
-  <INPUT TYPE="hidden" NAME="<% $opt{'field'} || 'pkgpart' %>" VALUE="">
+      <INPUT TYPE="hidden" NAME="<% $opt{'field'} || 'pkgpart' %>" VALUE="">
 
 
+%   }
+%
 % } else { 
 % } else { 
+%
+%   unless ( $opt{'js_only'} ) {
 
 
-  <TR>
-    <TD ALIGN="right"><% $opt{'label'} || 'Package definition' %></TD>
-    <TD>
-      <% include( '/elements/select-table.html',
-                    'table'     => 'part_pkg',
-                    'name_col'  => 'pkg',
-                    'multiple'  => 1,
-                    #N/A 'empty_label' => '(none)',
-                    %opt,
-                )
-      %>
-    </TD>
-  </TR>
+      <% include('tr-td-label.html', %opt) %>
+        <TD <% $cell_style %>>
 
 
-% } 
+%   }
+%
+          <% include( '/elements/select-part_pkg.html', %opt ) %>
+%
+%   unless ( $opt{'js_only'} ) {
+
+        </TD>
+      </TR>
 
 
+%   }
+%
+% } 
 <%init>
 
 my( %opt ) = @_;
 
 <%init>
 
 my( %opt ) = @_;
 
-$opt{'part_pkg'} ||= [ qsearch( 'part_pkg', {} ) ]; # { disabled=>'' } )
+my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+$opt{'label'} ||= 'Package definition';
+
+#taken care of (better) in select-part_pkg now (is there anything using this
+# that needs to override the disabed=>'' ??)
+#$opt{'part_pkg'} ||= [ qsearch( 'part_pkg', {} ) ]; # { disabled=>'' } )
 
 </%init>
 
 </%init>