RT# 21110 Unparsable age error. Added javascript to validate field prior to submittin...
[freeside.git] / httemplate / edit / elements / edit.html
index 73faad4..3eb75f8 100644 (file)
@@ -7,7 +7,7 @@ Example:
                         # (preferred, will be pluralized automatically)
     'name'          =>  #name for the record
                         # (deprecated, will be pluralized simplistically)
-    'table'         =>
+    'table'         =>  #database table
 
     #? 'primary_key' => #required when the dbdef doesn't know...???
     'labels' => {
@@ -108,6 +108,9 @@ Example:
     # 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,
 
@@ -115,6 +118,11 @@ Example:
     # display, no <FORM>, no hidden fields for table name or primary key, no
     # display of primary key, no submit button, no html_foot, no footer)
     'embed' => $object, #need to pass the object
+    'tablenum' => 4, #need to specify a table number when using multiple
+                     #embedded edits on a page (and m2 stuff)
+
+    #don't show the primary key label and value
+    'no_pkey_display' => 1,
 
     ###
     # HTML callbacks
@@ -124,6 +132,11 @@ Example:
 
     'html_init'   => '', #after the header/menubar
 
+    'form_init'   => '', #after html_init, error and the opening <FORM>, but
+                         #before any other form contents
+
+    'html_table_class' => '', #HTML <TABLE CLASS=
+
     #string or coderef of additional HTML to add before </TABLE>
     'html_table_bottom' => '',
 
@@ -190,7 +203,7 @@ Example:
   &>
 
 </%doc>
-
+%
 % unless ( $opt{embed} ) {
 %
 %   my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
@@ -207,13 +220,13 @@ Example:
 %       "View all $items" => $viewall_url,
 %     );
 %   }
-
-  <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
+%
+<% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
                 $title,
                 include( '/elements/menubar.html', @menubar ),
                 $opt{'body_etc'},
              )
-  %>
+%>
 
   <% defined($opt{'html_init'}) 
         ? ( ref($opt{'html_init'})
@@ -227,6 +240,7 @@ Example:
 
 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
 
+% $js_form_validate = { 'edit_topform' => { 'name' => 'edit_topform', 'errormessage' => 'Please only numeric characters ' } };
   <FORM NAME   = "edit_topform"
         METHOD = POST
         ACTION = "<% $url %>"
@@ -234,20 +248,36 @@ Example:
   >
 
   <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
-  <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
+  <INPUT TYPE="hidden" ID="<% $pkey %>" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
 
-  <FONT SIZE="+1"><B>
-  <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
-        ? $opt{labels}->{$pkey}
-        : $pkey
+  <% defined($opt{'form_init'}) 
+        ? ( ref($opt{'form_init'})
+              ? &{$opt{'form_init'}}()
+              : $opt{'form_init'}
+          )
+        : ''
   %>
-  </B></FONT>
-  #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
+
+%   unless ( $opt{'no_pkey_display'} ) {
+
+      <FONT SIZE="+1"><B>
+      <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
+            ? $opt{labels}->{$pkey}
+            : $pkey
+      %>
+      </B></FONT>
+      #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
+
+%   }
 
 % }
 
-% my $tablenum = 0;
-<TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
+% my $tablenum = $opt{'tablenum'} || 0;
+<TABLE ID="TableNumber<% $tablenum++ %>"
+       <% $opt{html_table_class} ? 'CLASS="'. $opt{html_table_class}. '"'
+                                 : 'BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0'
+       %>
+>
 
 % my $g_row = 0;
 % my @g_row_stack = ();
@@ -282,6 +312,7 @@ Example:
 %     #text and derivitives
 %     'size'          => $f->{'size'},
 %     'maxlength'     => $f->{'maxlength'},
+%     'prefix'        => $f->{'prefix'},
 %     'postfix'       => $f->{'postfix'},
 %
 %     #textarea
@@ -292,6 +323,9 @@ Example:
 %     #& deprecated weird value hashref used only by reason.html
 %     'value'         => $f->{'value'},
 %
+%     #fixed
+%     'noescape'      => $f->{'noescape'},
+%
 %     #select(-*)
 %     'options'       => $f->{'options'},
 %     'labels'        => $f->{'labels'},
@@ -300,31 +334,46 @@ Example:
 %     'disable_empty' => $f->{'disable_empty'},
 %     #select-reason
 %     'reason_class'  => $f->{'reason_class'},
+%     #select-agent
+%     'viewall_right' => $f->{'viewall_right'},
 %
 %     #selectlayers
 %     'layer_fields'  => $f->{'layer_fields'},
 %     'layer_values'  => $layer_values,
 %     'html_between'  => $f->{'html_between'},
 %
-%     #umm.  for select-agent_types at least
+%     #umm.  for select-agent_type at least
 %     'disabled'      => $f->{'disabled'},
+%     'fixed'         => $f->{'fixed'},
+%     'label_callback'=> $f->{'label_callback'},
+%     'element_etc'   => $f->{'element_etc'},
+%
+%     #for select-ticketing_queueid at least
+%     'post_options'  => $f->{'post_options'},
 %
 %     #any?
 %     'colspan'       => $f->{'colspan'},
 %     'required'      => $f->{'required'},
+%
+%     #contact
+%     'custnum'     => $f->{'custnum'},
+%     'prospectnum' => $f->{'prospectnum'},
 %   );
 %
 %   $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
 %     qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
 %     qw( empty_label ),                                   # select-*
-%     qw( value_col ),                                     # select-table
+%     qw( value_col compare_sub order_by addl_from ), # select-table
 %     qw( table name_col ),                           #(select,checkboxes)-table
 %     qw( target_table link_table ),                       #checkboxes-table
 %     qw( hashref agent_virt agent_null agent_null_right ),#*-table
 %     qw( formatted_value ),                               #fixed
 %     qw( country ),                                       #select-country
-%     qw( width height ),                                  #htmlarea
+%     qw( width height config ),                           #htmlarea
 %     qw( alt_format ),                                    #select-cust_location
+%     qw( classnum ),                                   # select-inventory_item
+%     qw( aligned ),                                    # columnstart
+%     qw( debug ),                                      # select-table
 %   ;
 %
 %   #select-table
@@ -360,6 +409,12 @@ Example:
 %     $include_common{'layer_prefix'} = "$field$fieldnum."
 %       if $layer_prefix_on;
 %
+%     ## set conditionname field values for validation.
+%     if ($field eq 'conditionname') { 
+%       my $validate_field = $field . $fieldnum . '.after_event.run_delay';
+%       $js_form_validate->{edit_topform}{$validate_field} = 'numeric';
+%     }
+%
 %     my @include = 
 %     ( "/elements/$include.html",
 %         'field'      => "$field$fieldnum",
@@ -377,6 +432,7 @@ Example:
 %                      'value' => $opt{curr_value},
 %                      'label' => $label,
 %                      'noinit' => $f->{noinit},
+%           'required' => $f->{'required'},
 %              }
 %      );
 %     }
@@ -513,7 +569,7 @@ Example:
 %     if ( $f->{curr_value_callback} ) {
 %       $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
 %     } else {
-%       $curr_value = $object->$field();
+%       $curr_value = $object->$field() if $field;
 %     }
 %     $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
 %       if $opt{'value_callback'} && $mode ne 'error';
@@ -602,7 +658,7 @@ Example:
           var newrow =  <% include(@layer_opt, html_only=>1) |js_string %>;
 
 %         #until the rest have html/js_only
-%         if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
+%         if ( ($type eq 'selectlayers') || ($type eq 'selectlayersx') || ($type =~ /^select-cgp_rule_/) ) {
             var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
 %         } else {
             var newfunc = '';
@@ -645,7 +701,7 @@ Example:
 
           widget_cell.style.borderTop = "1px solid black";
           widget_cell.style.paddingTop = "3px";
-          widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>"
+          widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>";
 
           widget_cell.innerHTML = newrow;
 
@@ -751,13 +807,32 @@ Example:
 
   <BR>
 
-  <INPUT TYPE     = "submit"
-         ID       = "submit"
-         VALUE    = "<% ( !$clone && $object->$pkey() )
-                          ? "Apply changes"
-                          : "Add ". ( $opt{'name'} || $opt{'name_singular'} )
-                     %>"
-  >
+%   unless ($opt{'no_submit'}) {
+      <INPUT TYPE     = "submit"
+             ID       = "submit"
+             VALUE    = "<% ( !$clone && $object->$pkey() )
+                              ? "Apply changes"
+                              : "Add ". ($opt{'name'} || $opt{'name_singular'})
+                         %>"
+      >
+%     if ( $opt{'delete_url'} and $object->get($pkey) ) {
+%       my $delete_msg = 'Delete this '.
+%          ($opt{'name_singular'} || $opt{'name'});
+%       my $delete_url = $opt{'delete_url'};
+%       $delete_url .= '?' unless $delete_url =~ /\?/;
+%       $delete_url .= $object->get($pkey);
+        <SCRIPT TYPE="text/javascript">
+        function confirm_delete() {
+          if(confirm(<% $delete_msg . '?' |js_string %>)) {
+            window.location.href = <% $delete_url |js_string %>;
+          }
+        }
+        </SCRIPT>
+        <INPUT TYPE     = "button"
+               VALUE    = "<% $delete_msg |h %>"
+               onclick  = "confirm_delete()">
+%     }
+%   }
 
   </FORM>
 
@@ -766,7 +841,11 @@ Example:
         : $opt{'html_foot'}
   %>
 
-  <% include("/elements/footer.html") %>
+% my %footerdata = (
+%   'formvalidation' => $js_form_validate,
+% );  
+
+  <% include("/elements/footer.html", %footerdata) %>  
 
 % }
 <%init>
@@ -784,6 +863,8 @@ my $fields = $opt{'fields'}
              || [ grep { $_ ne $pkey } fields($table) ];
 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
 
+my $js_form_validate = {};
+
 my( $mode, $object);
 my $clone = '';
 if ( $opt{'embed'} ) {