[freeside-commits] freeside/httemplate/edit/elements edit.html, 1.18, 1.19
Ivan,,,
ivan at wavetail.420.am
Tue Apr 15 06:42:41 PDT 2008
Update of /home/cvs/cvsroot/freeside/httemplate/edit/elements
In directory wavetail.420.am:/tmp/cvs-serv418/edit/elements
Modified Files:
edit.html
Log Message:
new package editor
Index: edit.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/elements/edit.html,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- edit.html 6 Apr 2008 16:12:46 -0000 1.18
+++ edit.html 15 Apr 2008 13:42:39 -0000 1.19
@@ -22,9 +22,12 @@
#percentage
#checkbox
#select
- #selectlayers (can't use after a tablebreak-tr-title yet... grep "OneTrueTable")
+ #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
@@ -32,29 +35,32 @@
'value' => 'Y', #for checkbox, title, fixed, fixedhidden
'disabled' => 0,
'onchange' => 'javascript_function',
- 'm2name_table' => 'table_name', #only tested w/
- # selectlayers so far
- # might work w/select
- # dunno others
- 'm2name_namecol' => 'name_column', #
- 'm2name_label' => 'Label', #
- 'm2name_new_default' => \@table_name_objects, #default
- #m2name
- #objects for
- #new records
- 'm2name_error_callback' => sub { my($cgi, $object) = @_; },
- 'm2name_remove_warnings' => \%warnings, #hashref of warning
- #messages for
- #m2name removal
- 'm2name_new_js' => 'function_name', #javascript function
- #called on spawned rows
- #(one arg: new_element)
- 'm2name_remove_js' => 'function_name', #js function called
- #when a row is
- #deleted
- #(three args:
- # value, text,
- # 'no_match')
+
+ #m2 stuff only tested w/selectlayers so far
+ #might work w/select too, dunno others
+ 'm2name_table' => 'table_name',
+ 'm2name_namecol' => 'name_column',
+ #OR#
+ 'm2m_table' =>
+ 'm2m_target_table' =>
+ 'm2m_srccol' => #opt, if not the same as this table
+ 'm2m_dstcol' => #opt, if not the same as target 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',
@@ -93,6 +99,9 @@
# returns a hashref for the new object
'new_hashref_callback'
+
+ # returns the new object iself (otherwise, ->new is called)
+ 'new_object_callback'
#run when adding
'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
@@ -103,18 +112,24 @@
#XXX describe
'field_callback' => sub { },
+ 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
+
+ 'html_init' => '', #after the header/menubar
+
#string or coderef of additional HTML to add before </TABLE>
'html_table_bottom' => '',
-
- 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
-
+
+ #after </TABLE> but before the submit
'html_bottom' => '', #string
'html_bottom' => sub {
my $object = shift;
# ...
"html_string";
},
-
+
+ #at the very bottom (well, as low as you can go from here)
+ 'html_foot' => '',
+
# overrides default popurl(1)."process/$table.html"
'post_url' => popurl(1).'process/something',
@@ -131,6 +146,14 @@
)
%>
+<% defined($opt{'html_init'})
+ ? ( ref($opt{'html_init'})
+ ? &{$opt{'html_init'}}()
+ : $opt{'html_init'}
+ )
+ : ''
+%>
+
<% include('/elements/error.html') %>
% my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
@@ -148,10 +171,11 @@
</B></FONT>
#<% $object->$pkey() || "(NEW)" %>
-%# <% ntable("#cccccc",0) %>
-<TABLE ID="OneTrueTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
+% my $tablenum = 0;
+<TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
% my $g_row = 0;
+% my @g_row_stack = ();
% foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
% @$fields
% ) {
@@ -169,9 +193,11 @@
% my $onchange = $f->{'onchange'};
%
% my $layer_values = {};
-% if ( $f->{'layer_values_callback'} && ! $f->{'m2name_table'} ) {
-% $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object );
-% }
+% $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
+% if $f->{'layer_values_callback'}
+% && ! $f->{'m2name_table'}
+% && ! $f->{'m2m_table'};
+%
% warn "layer values: ". Dumper($layer_values)
% if $opt{'debug'};
%
@@ -196,8 +222,19 @@
% 'layer_fields' => $f->{'layer_fields'},
% 'layer_values' => $layer_values,
% 'html_between' => $f->{'html_between'},
+%
+% #umm.
+% 'disabled' => $f->{'disabled'},
% );
%
+% #select-table
+% $include_common{$_} = $f->{$_}
+% foreach grep exists($f->{$_}), qw( table name_col );
+%
+% if ( $type eq 'tablebreak-tr-title' ) {
+% $include_common{'table_id'} = 'TableNumber'. $tablenum++
+% }
+%
% my $layer_prefix_on = '';
%
% my $include_sub = sub {
@@ -207,7 +244,7 @@
%
% my $include = $type;
% $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
-% $include = "tr-$include" unless $include =~ /^(hidden|tablebreak)/;
+% $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
%
% $include_common{'layer_prefix'} = "$field$fieldnum."
% if $layer_prefix_on;
@@ -223,33 +260,56 @@
% @include;
% };
%
-% $g_row++;
-% $g_row++ if $type eq 'title';
+% unless ( $type =~ /^column/ ) {
+% $g_row = 1 if $type eq 'tablebreak-tr-title';
+% $g_row++;
+% $g_row++ if $type eq 'title';
+% } else {
+% if ( $type eq 'columnstart' ) {
+% push @g_row_stack, $g_row++;
+% $g_row = 0;
+% #} elsif ( $type eq 'columnnext' ) {
+% } elsif ( $type eq 'columnend' ) {
+% $g_row = pop @g_row_stack;
+% }
+%
+% }
%
% my $fieldnum = '';
% my $curr_value = '';
-% if ( $f->{'m2name_table'} ) { #XXX test this for all types of fields
-% my $table = $f->{'m2name_table'};
-% my $col = $f->{'m2name_namecol'};
+% if ( $f->{'m2name_table'} || $f->{'m2m_table'} ) { #XXX test this for all
+% #types of fields
+% my($table, $col);
+% if ( $f->{'m2name_table'} ) {
+% $table = $f->{'m2name_table'};
+% $col = $f->{'m2name_namecol'};
+% } elsif ( $f->{'m2m_table'} ) {
+% $table = $f->{'m2m_table'}; #XXX method name
+% $col = $f->{'m2m_dstcol'}; #XXX or get it from schema, defualt to
+% #same name as primary key of
+% #m2m_target_table
+% }
% $fieldnum = 0;
% $layer_prefix_on = 1;
-% #print out the fields for the existing m2names
+% #print out the fields for the existing m2s
% my @existing = ();
% if ( $mode eq 'error' ) {
-% @existing = &{ $f->{'m2name_error_callback'} }( $cgi, $object );
+% @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
% } elsif ( $object->$pkey() ) { # $mode eq 'edit'
% @existing = $object->$table();
-% } elsif ( $f->{'m2name_new_default'} ) { # && $mode eq 'new'
-% @existing = @{ $f->{'m2name_new_default'} };
+% warn scalar(@existing). " from $object->$table: ". join('/', @existing)
+% if $opt{'debug'};
+% } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
+% @existing = @{ $f->{'m2_new_default'} };
% }
% foreach my $name_obj ( @existing ) {
%
% my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
-% lc($f->{'m2name_label'}).
+% lc($f->{'m2_label'}).
% qq(" onClick="remove_$field($fieldnum);").
% ' STYLE="color:#ff0000;font-weight:bold;'.
% 'padding-left:2px;padding-right:2px"'.
-% '> '. ($f->{'m2name_label'} || $field ). ' ';
+% '> '. ($f->{'m2_label'} || $field ). ' ';
%
% if ( $f->{'layer_values_callback'} ) {
% my %switches = ( 'mode' => $mode );
@@ -276,10 +336,13 @@
% #$field .= $fieldnum;
% $onchange .= "\nspawn_$field(what);";
% } else {
-% $curr_value =
-% ($opt{'value_callback'} && $mode ne 'error')
-% ? &{ $opt{'value_callback'} }( $f->{'field'}, $object->$field() )
-% : $object->$field();
+% if ( $f->{curr_value_callback} ) {
+% $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
+% } else {
+% $curr_value = $object->$field();
+% }
+% $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
+% if $opt{'value_callback'} && $mode ne 'error';
% }
%
% my @include = &{ $include_sub }(
@@ -287,18 +350,19 @@
% 'fieldnum' => $fieldnum,
% 'curr_value' => $curr_value,
% 'object' => $object,
+% 'cgi' => $cgi,
% 'onchange' => $onchange,
% 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
% );
<% include( @include ) %>
-% if ( $f->{'m2name_table'} ) {
+% if ( $f->{'m2name_table'} || $f->{'m2m_table'} ) {
<SCRIPT TYPE="text/javascript">
- var rownum = <% $g_row %>;
- var fieldnum = <% $fieldnum %>;
+ var <%$field%>_rownum = <% $g_row %>;
+ var <%$field%>_fieldnum = <% $fieldnum %>;
function spawn_<%$field%>(what) {
@@ -310,23 +374,25 @@
alert(what.name + " didn't match?!");
return;
}
- if ( match[1] != fieldnum ) {
+ if ( match[1] != <%$field%>_fieldnum ) {
return;
}
// change the label on the last entry & add a remove button
- var prev_label = document.getElementById('<% $field %>_label' + fieldnum );
- prev_label.innerHTML = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this <% lc($f->{'m2name_label'}) %>" onClick="remove_<% $field %>(' + fieldnum + ');" STYLE="color:#ff0000;font-weight:bold;padding-left:2px;padding-right:2px" > <% $f->{'m2name_label'} || $field %>';
+ 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" > <% $f->{'m2_label'} || $field %>';
- fieldnum++;
+ <%$field%>_fieldnum++;
//get the new widget
% $include[0] =~ s(^/elements/tr-)(/elements/);
% my @layer_opt = ( @include,
% 'field' => $field."MAGIC_NUMBER",
+% 'id' => $field."MAGIC_NUMBER",
% 'layer_prefix' => $field."MAGIC_NUMBER.",
% );
+% warn @layer_opt if $opt{'debug'};
var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
@@ -338,8 +404,8 @@
// substitute in the new field name
var magic_regex = /MAGIC_NUMBER/g;
- newrow = newrow.replace( magic_regex, fieldnum );
- newfunc = newfunc.replace( magic_regex, fieldnum );
+ newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
+ newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
// evaluate new_func
if (window.ActiveXObject) {
@@ -352,13 +418,13 @@
// add new row
//hmm, can't use selectlayers after a tablebreak-title for now
- var table = document.getElementById('OneTrueTable');
+ var table = document.getElementById('TableNumber<% $tablenum-1 %>');
- var row = table.insertRow(rownum++);
+ var row = table.insertRow(<%$field%>_rownum++);
var label_cell = document.createElement('TD');
- label_cell.id = '<% $field %>_label' + fieldnum;
+ label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
label_cell.style.textAlign = "right";
label_cell.style.verticalAlign = "top";
@@ -378,10 +444,10 @@
row.appendChild(widget_cell);
-% if ( $f->{'m2name_new_js'} ) {
+% if ( $f->{'m2_new_js'} ) {
// take out items selected in previous dropdowns
- var new_element = document.getElementById("<%$field%>" + fieldnum );
- <% $f->{'m2name_new_js'} %>(new_element);
+ var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
+ <% $f->{'m2_new_js'} %>(new_element);
if ( new_element.length < 2 ) {
//just the ** Select new **, so don't display the row
@@ -395,7 +461,12 @@
//alert("remove <%$field%> " + remove_fieldnum);
var select = document.getElementById('<%$field%>' + remove_fieldnum);
-% my $warnings = $f->{'m2name_remove_warnings'};
+ if ( ! select ) {
+ alert("can't find element <%$field%>" + remove_fieldnum);
+ return;
+ }
+
+% my $warnings = $f->{'m2_remove_warnings'};
% if ( $warnings ) {
var sel_value = select.options[select.selectedIndex].value;
% foreach my $value ( keys %$warnings ) {
@@ -411,9 +482,9 @@
var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
label_td.parentNode.style.display = 'none';
-% if ( $f->{m2name_remove_js} ) {
+% if ( $f->{m2_remove_js} ) {
var opt = select.options[select.selectedIndex];
- <% $f->{m2name_remove_js} %>( opt.value, opt.text, 'no_match');
+ <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
% }
}
@@ -442,6 +513,11 @@
</FORM>
+<% ref( $opt{'html_foot'} )
+ ? &{ $opt{'html_foot'} }( $object )
+ : $opt{'html_foot'}
+%>
+
<% include("/elements/footer.html") %>
<%init>
@@ -471,7 +547,6 @@
$mode = 'error';
-
$object = $class->new( {
map { $_ => scalar($cgi->param($_)) } fields($table)
});
@@ -515,16 +590,18 @@
? &{$opt{'new_hashref_callback'}}
: {};
- $object = $class->new( $hashref );
+ $object = $opt{'new_object_callback'}
+ ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
+ : $class->new( $hashref );
&{$opt{'new_callback'}}($cgi, $object, $fields)
if $opt{'new_callback'};
}
-my $action = $object->$pkey() ? 'Edit' : 'Add';
+$opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';
-my $title = "$action $opt{'name'}";
+my $title = $opt{action}. ' '. $opt{name};
my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
$viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
More information about the freeside-commits
mailing list