4.x style
[freeside.git] / httemplate / edit / elements / edit.html
index 8dd15dc..829b776 100644 (file)
@@ -114,6 +114,9 @@ Example:
     #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 <FORM>, no hidden fields for table name or primary key, no
     # display of primary key, no submit button, no html_foot, no footer)
@@ -240,6 +243,7 @@ Example:
 
 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
 
+% $js_form_validate = { 'edit_topform' => { 'name' => 'edit_topform' } };
   <FORM NAME   = "edit_topform"
         METHOD = POST
         ACTION = "<% $url %>"
@@ -247,7 +251,7 @@ 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() %>">
 
   <% defined($opt{'form_init'}) 
         ? ( ref($opt{'form_init'})
@@ -259,12 +263,12 @@ Example:
 
 %   unless ( $opt{'no_pkey_display'} ) {
 
-      <FONT SIZE="+1"><B>
+      <FONT CLASS="fsinnerbox-title">
       <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
             ? $opt{labels}->{$pkey}
             : $pkey
       %>
-      </B></FONT>
+      </FONT>
       #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
 
 %   }
@@ -273,9 +277,7 @@ Example:
 
 % my $tablenum = $opt{'tablenum'} || 0;
 <TABLE ID="TableNumber<% $tablenum++ %>"
-       <% $opt{html_table_class} ? 'CLASS="'. $opt{html_table_class}. '"'
-                                 : 'BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0'
-       %>
+       CLASS="<% $opt{html_table_class} || 'fsinnerbox' %>"
 >
 
 % my $g_row = 0;
@@ -357,6 +359,7 @@ Example:
 %     #contact
 %     'custnum'     => $f->{'custnum'},
 %     'prospectnum' => $f->{'prospectnum'},
+%
 %   );
 %
 %   $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
@@ -369,9 +372,10 @@ Example:
 %     qw( formatted_value ),                               #fixed
 %     qw( country ),                                       #select-country
 %     qw( width height config ),                           #htmlarea
-%     qw( alt_format ),                                    #select-cust_location
+%     qw( is_optional alt_format ),                        #select-cust_location
 %     qw( classnum ),                                   # select-inventory_item
 %     qw( aligned ),                                    # columnstart
+%     qw( debug ),                                      # select-table
 %   ;
 %
 %   #select-table
@@ -395,6 +399,8 @@ Example:
 %
 %   my $layer_prefix_on = '';
 %
+%   my $submitid   = $opt{submit_id} ? $opt{submit_id} : '';
+%
 %   my $include_sub = sub {
 %     my %opt = @_;
 %
@@ -407,11 +413,19 @@ 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_fields}{$validate_field} = 'digits: true';
+%       $js_form_validate->{edit_topform}->{error_message}{$validate_field} = 'Please only enter numbers here.';
+%     }
+%
 %     my @include = 
 %     ( "/elements/$include.html",
 %         'field'      => "$field$fieldnum",
 %         'id'         => "$field$fieldnum", #separate?
 %         'label_id'   => $field."_label$fieldnum", #don't want field0_label0...
+%         'submit_id'  => $submitid,
 %         %include_common,
 %         %opt,
 %     );
@@ -499,12 +513,15 @@ Example:
 %     }
 %     foreach my $name_obj ( @existing ) {
 %
+%       my $m2_label = $f->{'m2_label'};
+%       $m2_label = &{ $f->{'m2_label_callback'} }($name_obj) if $f->{'m2_label_callback'};
+%
 %       my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
 %                      lc($f->{'m2_label'}).
 %                      qq(" onClick="remove_$field($fieldnum);").
 %                      ' STYLE="color:#ff0000;font-weight:bold;'.
 %                              'padding-left:2px;padding-right:2px"'.
-%                      '>&nbsp;'. ($f->{'m2_label'} || $field ). ' ';
+%                      '>&nbsp;'. ($m2_label || $field ). ' ';
 %       
 %       if ( $f->{'layer_values_callback'} ) {
 %         my %switches = ( 'mode' => $mode );
@@ -621,7 +638,7 @@ Example:
 
           // only spawn if we're the last element... return if not
 
-          var field_regex = /(\d+)(_[a-z_]+)?$/;
+          var field_regex = /(\d+)(_[a-z_0-9]+)?$/;
           var match = field_regex.exec(what.name);
           if ( !match ) {
             alert(what.name + " didn't match for " + what);
@@ -631,6 +648,15 @@ Example:
             return;
           }
 
+%         if ( exists( $f->{'js_spawn_test'} ) ) {
+            // XXX check a passed-in hook here and optionall return
+            if ( <% $f->{'js_spawn_test'} %> ) {
+              // then go ahead and spawn
+            } else {
+              return;
+            }
+%         }
+
           // change the label on the last entry & add a remove button
           var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
           prev_label.innerHTML = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this <% lc($f->{'m2_label'}) %>" onClick="remove_<% $field %>(' + <%$field%>_fieldnum + ');" STYLE="color:#ff0000;font-weight:bold;padding-left:2px;padding-right:2px" >&nbsp;<% $f->{'m2_label'} || $field %>';
@@ -650,7 +676,7 @@ Example:
           var newrow =  <% include(@layer_opt, html_only=>1) |js_string %>;
 
 %         #until the rest have html/js_only
-%         if ( ($type eq 'selectlayers') || ($type eq 'selectlayersx') || ($type =~ /^select-cgp_rule_/) ) {
+%         if ( ($type eq 'selectlayers') || ($type eq 'selectlayersx') || ($type =~ /^select-cgp_rule_/) || ($type eq 'contact') ) {
             var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
 %         } else {
             var newfunc = '';
@@ -676,7 +702,7 @@ Example:
 
           var row = table.insertRow(<%$field%>_rownum++);
 
-          var label_cell = document.createElement('TD');
+          var label_cell = document.createElement('TH');
 
           label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
 
@@ -795,6 +821,18 @@ Example:
       : $opt{'html_bottom'}
 %>
 
+%     ## set extra field values for validation.  ie price plan fields
+%     my $extra_fields_to_validate = $opt{'extra_fields_validate'};
+%     my %validate_error_messages = (
+%       'digits: true' => 'Please only enter numbers here.',
+%       'email: true'  => 'Please enter a valid email here.',
+%     );
+%     foreach my $extra_fields (keys %$extra_fields_to_validate) {
+%       my $validate_type = $extra_fields_to_validate->{$extra_fields};
+%       $js_form_validate->{edit_topform}->{validate_fields}{$extra_fields} = $validate_type;
+%      $js_form_validate->{edit_topform}->{error_message}{$extra_fields} = $validate_error_messages{$validate_type};
+%     }
+
 % unless ($opt{'embed'}) {
 
   <BR>
@@ -833,13 +871,18 @@ Example:
         : $opt{'html_foot'}
   %>
 
-  <% include("/elements/footer.html") %>
+% my %footerdata = (
+%   'formvalidation' => $js_form_validate,
+% );  
+
+  <% include("/elements/footer.html", %footerdata) %>  
 
 % }
 <%init>
 
 my(%opt) = @_;
 
+my $conf = new FS::Conf;
 my $curuser = $FS::CurrentUser::CurrentUser;
 
 #false laziness w/process.html
@@ -849,7 +892,13 @@ 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 @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
+
+push @actualfields, $pkey;
+push @actualfields, 'ip_addr' if $table eq 'svc_broadband';
+push @actualfields, 'usergroup' if ($table eq 'svc_broadband' && $conf->exists('svc_broadband-radius'));
+
+my $js_form_validate = {};
 
 my( $mode, $object);
 my $clone = '';
@@ -890,7 +939,7 @@ if ( $opt{'embed'} ) {
     $mode = 'error';
 
     $object = $class->new( {
-      map { $_ => scalar($cgi->param($_)) } fields($table)
+      map { $_ => scalar($cgi->param($_)) } @actualfields
     });
 
     &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )