From 41ab1bbaf58292688e1e84ab153059896f17a5d4 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 31 Mar 2008 21:11:02 +0000 Subject: [PATCH] fix safari weirdness with caching iframes and auto-submitting them (in tax editor at least) --- httemplate/browse/cust_main_county.cgi | 38 ++++++++++++++------ httemplate/elements/popup_link.html | 21 ++--------- httemplate/elements/popup_link_onclick.html | 55 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 httemplate/elements/popup_link_onclick.html diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index 12bdeb333..ff3a475c7 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -85,17 +85,31 @@ my $edit_link = [ 'javascript:void(0);', sub { ''; } ]; my $edit_onclick = sub { my $row = shift; my $taxnum = $row->taxnum; - my $color = '#333399'; - qq!overlib( OLiframeContent('${p}edit/cust_main_county.html?$taxnum', 540, 420, 'edit_cust_main_county_popup' ), CAPTION, 'Edit tax rate', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;!; + include( '/elements/popup_link_onclick.html', + 'action' => "${p}edit/cust_main_county.html?$taxnum", + 'actionlabel' => 'Edit tax rate', + 'height' => 420, + #default# 'width' => 540, + #default# 'color' => '#333399', + ); }; sub expand_link { - my( $row, $desc ) = @_; - my $taxnum = $row->taxnum; + my %param = @_; + + my $taxnum = $param{'row'}->taxnum; my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum"; - my $color = '#333399'; - qq!!; + ''. + include( '/elements/popup_link.html', + 'label' => $param{'label'}, + 'action' => $url, + 'actionlabel' => $param{'desc'}, + 'height' => 420, + #default# 'width' => 540, + #default# 'color' => '#333399', + ). + ''; } sub separate_taxclasses_link { @@ -227,13 +241,17 @@ my @fields = ( sub { state_label($_[0]->state, $_[0]->country). ( $_[0]->state ? '' - : ' '. expand_link($_[0], 'Add States'). - 'add states' + : ' '. expand_link( desc => 'Add States', + row => $_[0], + label => 'add states', + ) ) }, sub { $_[0]->county || '(all) '. - expand_link($_[0], 'Add Counties'). - 'add counties' + expand_link( desc => 'Add Counties', + row => $_[0], + label => 'add counties', + ) }, ); diff --git a/httemplate/elements/popup_link.html b/httemplate/elements/popup_link.html index 556e19ebe..0915bfa68 100644 --- a/httemplate/elements/popup_link.html +++ b/httemplate/elements/popup_link.html @@ -21,16 +21,11 @@ Example: } ) -% if ($action && $label) { +% if ($params->{'action'} && $label) { <% $label %>\ % } <%init> -my($action, $label, $actionlabel) = ( '', '', '' ); -my $closetext = 'Close'; -my $width = 540; -my $color = '#333399'; - my $params; if (ref($_[0]) eq 'HASH') { #$params = { %$params, %{ $_[0] } }; @@ -40,17 +35,7 @@ if (ref($_[0]) eq 'HASH') { $params = { @_ }; } -$action = $params->{'action'} if exists $params->{'action'}; -$label = $params->{'label'} if exists $params->{'label'}; -$actionlabel = $params->{'actionlabel'} if exists $params->{'actionlabel'}; -$width = $params->{'width'} if exists $params->{'width'}; -$color = $params->{'color'} if exists $params->{'color'}; -$closetext = $params->{'closetext'} if exists $params->{'closetext'}; - -#stupid safari is caching the "location" of popup iframs, and submitting them -#instead of displaying them. this should prevent that. -my $popup_name = 'popup-'.time. "-$$-". rand() * 2**32; - -my $onclick = "overlib( OLiframeContent('$action', $width, 336, '$popup_name' ), CAPTION, '$actionlabel', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color', CLOSETEXT, '$closetext' ); return false;"; +my $label = $params->{'label'}; +my $onclick = include('/elements/popup_link_onclick.html', $params); diff --git a/httemplate/elements/popup_link_onclick.html b/httemplate/elements/popup_link_onclick.html new file mode 100644 index 000000000..41383fdf6 --- /dev/null +++ b/httemplate/elements/popup_link_onclick.html @@ -0,0 +1,55 @@ +<%doc> + +Example: + + + + + include( '/elements/popup_link_onclick.html', { #hashref or a list, either way + + #required + 'action' => 'content.html', # uri for content of popup + + #strongly recommended + 'actionlabel => 'You clicked', # popup title + + #opt + 'width' => '540', + 'color' => '#ff0000', + 'closetext' => 'Go Away', # the value '' removes the link + } ) + + +% if ($action) { +<% $onclick %>\ +% } +<%init> + +my($action, $actionlabel) = ( '', '' ); +my( $width, $height ) = ( 540, 336 ); +my $closetext = 'Close'; +my $color = '#333399'; + +my $params; +if (ref($_[0]) eq 'HASH') { + #$params = { %$params, %{ $_[0] } }; + $params = shift; +} else { + #$params = { %$params, @_ }; + $params = { @_ }; +} + +$action = $params->{'action'} if exists $params->{'action'}; +$actionlabel = $params->{'actionlabel'} if exists $params->{'actionlabel'}; +$width = $params->{'width'} if exists $params->{'width'}; +$height = $params->{'height'} if exists $params->{'height'}; +$color = $params->{'color'} if exists $params->{'color'}; +$closetext = $params->{'closetext'} if exists $params->{'closetext'}; + +#stupid safari is caching the "location" of popup iframs, and submitting them +#instead of displaying them. this should prevent that. +my $popup_name = 'popup-'.time. "-$$-". rand() * 2**32; + +my $onclick = "overlib( OLiframeContent('$action', $width, $height, '$popup_name' ), CAPTION, '$actionlabel', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color', CLOSETEXT, '$closetext' ); return false;"; + + -- 2.11.0