From 0f179c9ab60ac22c697027cadc9f4bdb9c515ce5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 17 Oct 2012 15:58:46 +0200 Subject: [PATCH] stylesheet/javascript handling verbessert --- SL/Controller/BackgroundJobHistory.pm | 2 +- SL/Controller/Layout/Base.pm | 70 +++++++++++++++++++++++- SL/Controller/Layout/Classic.pm | 20 +++---- SL/Controller/Layout/MenuLeft.pm | 10 +++- SL/Drafts.pm | 2 +- SL/Form.pm | 77 +++++++++------------------ SL/User.pm | 1 - bin/mozilla/admin.pl | 4 +- bin/mozilla/am.pl | 2 +- bin/mozilla/drafts.pl | 6 +-- bin/mozilla/is.pl | 2 +- bin/mozilla/oe.pl | 2 +- 12 files changed, 121 insertions(+), 77 deletions(-) diff --git a/SL/Controller/BackgroundJobHistory.pm b/SL/Controller/BackgroundJobHistory.pm index fbee5c028..29f2bc79a 100644 --- a/SL/Controller/BackgroundJobHistory.pm +++ b/SL/Controller/BackgroundJobHistory.pm @@ -79,7 +79,7 @@ sub check_task_server { } sub add_stylesheet { - $::form->use_stylesheet('lx-office-erp/background_jobs.css'); + $::request->{layout}->use_stylesheet('lx-office-erp/background_jobs.css'); } 1; diff --git a/SL/Controller/Layout/Base.pm b/SL/Controller/Layout/Base.pm index cbd5088d3..1a27174b5 100644 --- a/SL/Controller/Layout/Base.pm +++ b/SL/Controller/Layout/Base.pm @@ -21,6 +21,10 @@ sub init_menu { Menu->new('menu.ini'); } +########################################## +# inheritable/overridable +########################################## + sub pre_content { } @@ -33,13 +37,75 @@ sub end_content { sub post_content { } +sub stylesheets_inline { +} + +sub javascript_inline { +} + +######################################### +# Interface +######################################## + +sub use_stylesheet { + my $self = shift; + push @{ $self->{stylesheets} ||= [] }, @_ if @_; + @{ $self->{stylesheets} ||= [] }; +} + sub stylesheets { + my ($self) = @_; + my $css_path = $self->get_stylesheet_for_user; + + return grep { $_ } map { $self->_find_stylesheet($_, $css_path) } $self->use_stylesheet; } -sub stylesheets_inline { +sub _find_stylesheet { + my ($self, $stylesheet, $css_path) = @_; + + return "$css_path/$stylesheet" if -f "$css_path/$stylesheet"; + return "css/$stylesheet" if -f "css/$stylesheet"; + return $stylesheet if -f $stylesheet; } -sub javascript_inline { +sub get_stylesheet_for_user { + my $css_path = 'css'; + if (my $user_style = $::myconfig{stylesheet}) { + $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling + if (-d "$css_path/$user_style" && + -f "$css_path/$user_style/main.css") { + $css_path = "$css_path/$user_style"; + } else { + $css_path = "$css_path/lx-office-erp"; + } + } else { + $css_path = "$css_path/lx-office-erp"; + } + $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here + + return $css_path; +} + + +sub use_javascript { + my $self = shift; + $::lxdebug->dump(0, "class", \@_); + push @{ $self->{javascripts} ||= [] }, @_ if @_; + @{ $self->{javascripts} ||= [] }; +} + +sub javascripts { + my ($self) = @_; + + $::lxdebug->dump(0, "called", [ map { $self->find_javascript($_) } $self->use_javascript ]); + return map { $self->_find_javascript($_) } $self->use_javascript; +} + +sub _find_javascript { + my ($self, $javascript) = @_; + + return "js/$javascript" if -f "js/$javascript"; + return $javascript if -f $javascript; } 1; diff --git a/SL/Controller/Layout/Classic.pm b/SL/Controller/Layout/Classic.pm index 514db7947..6aac3e574 100644 --- a/SL/Controller/Layout/Classic.pm +++ b/SL/Controller/Layout/Classic.pm @@ -14,6 +14,16 @@ sub new { $self->{top} = SL::Controller::Layout::Top->new; $self->{left} = SL::Controller::Layout::MenuLeft->new; + $self->use_stylesheet( + $self->{top}->stylesheets, + $self->{left}->stylesheets, + ); + + $self->use_javascript( + $self->{top}->javascripts, + $self->{left}->javascripts, + ); + $self; } @@ -30,14 +40,4 @@ sub end_content { "\n"; } -sub stylesheets { - $_[0]{top}->stylesheets, - $_[0]{left}->stylesheets; -} - -sub javascripts { - $_[0]{top}->javascripts, - $_[0]{left}->javascripts; -} - 1; diff --git a/SL/Controller/Layout/MenuLeft.pm b/SL/Controller/Layout/MenuLeft.pm index c79905269..ed4c5e9d3 100644 --- a/SL/Controller/Layout/MenuLeft.pm +++ b/SL/Controller/Layout/MenuLeft.pm @@ -7,8 +7,14 @@ use URI; use List::MoreUtils qw(apply); -sub stylesheets { - qw(css/icons16.css css/icons24.css); +sub new { + my ($class, @slurp) = @_; + + my $self = $class->SUPER::new(@slurp); + + $self->use_stylesheet(qw(css/icons16.css css/icons24.css)); + + $self; } sub render { diff --git a/SL/Drafts.pm b/SL/Drafts.pm index 7298f5c1d..16111af9c 100644 --- a/SL/Drafts.pm +++ b/SL/Drafts.pm @@ -36,7 +36,7 @@ sub get_module { return ($module, $submodule); } -my @dont_save = qw(login password stylesheet action); +my @dont_save = qw(login password action); sub save { $main::lxdebug->enter_sub(); diff --git a/SL/Form.pm b/SL/Form.pm index b25fe6a2d..59815ebde 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -447,53 +447,30 @@ sub create_http_response { return $output; } -sub use_stylesheet { - my $self = shift; - - $self->{stylesheet} = [ $self->{stylesheet} ] unless ref $self->{stylesheet} eq 'ARRAY'; - - if (@_) { - $self->{stylesheet} = - [ grep { -f } - map { m:^css/: ? $_ : "css/$_" } - grep { $_ } - (@{ $self->{stylesheet} }, @_) - ]; - } - - return @{ $self->{stylesheet} }; -} - -sub get_stylesheet_for_user { - my $css_path = 'css'; - if (my $user_style = $::myconfig{stylesheet}) { - $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling - if (-d "$css_path/$user_style" && - -f "$css_path/$user_style/main.css") { - $css_path = "$css_path/$user_style"; - } else { - $css_path = "$css_path/lx-office-erp"; - } - } else { - $css_path = "$css_path/lx-office-erp"; - } - $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here - - return $css_path; -} - sub header { $::lxdebug->enter_sub; - # extra code is currently only used by menuv3 and menuv4 to set their css. - # it is strongly deprecated, and will be changed in a future version. my ($self, %params) = @_; my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; my @header; + my $layout = $::request->{layout}; + $::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++; - my $css_path = $self->get_stylesheet_for_user; + # standard css for all + $layout->use_stylesheet("$_.css") for qw( + main menu tabcontent list_accounts jquery.autocomplete + jquery.multiselect2side frame_header/header + ui-lightness/jquery-ui-1.8.12.custom + js/jscalendar/calendar-win2k-1 + ); + + $layout->use_javascript("$_.js") for qw( + jquery common jscalendar/calendar jscalendar/lang/calendar-de + jscalendar/calendar-setup part_selection jquery-ui jquery.cookie jqModal + switchmenuframe + ); $self->{favicon} ||= "favicon.ico"; $self->{titlebar} = join ' - ', grep $_, $self->{title}, $self->{login}, $::myconfig{dbname}, $self->{version} if $self->{title}; @@ -505,16 +482,11 @@ sub header { push @header, ""; } - push @header, map { qq|| } $self->use_stylesheet, $::request->{layout}->stylesheets; - - push @header, "" if $self->{landscape}; - push @header, "" if -f $self->{favicon}; - push @header, map { qq|| } - qw(jquery common jscalendar/calendar jscalendar/lang/calendar-de jscalendar/calendar-setup part_selection jquery-ui jquery.cookie jqModal switchmenuframe); + push @header, map { qq|| } $layout->stylesheets; + push @header, " " if $self->{landscape}; + push @header, "" if -f $self->{favicon}; + push @header, map { qq|| } $layout->javascripts; push @header, $self->{javascript} if $self->{javascript}; - push @header, map { qq|| } - qw(main menu tabcontent list_accounts jquery.autocomplete jquery.multiselect2side frame_header/header ui-lightness/jquery-ui-1.8.12.custom); - push @header, map { qq|| } push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] }; push @header, "" if $self->{fokus}; @@ -522,6 +494,7 @@ sub header { strict => qq||, transitional => qq||, frameset => qq||, + html5 => qq||, ); # output @@ -545,7 +518,6 @@ EOT ***********************************************/ - $params{extra_code} @@ -559,11 +531,12 @@ EOT sub footer { # TODO: fix abort conditions + print $::request->{layout}->end_content; print $::request->{layout}->post_content; - print "\n" for $::request->{layout}->javascripts; - if (my @inline_scripts = $::request->{layout}->javascript_inline) { - print "\n" for @inline_scripts; - } +# print "\n" for $::request->{layout}->javascripts; +# if (my @inline_scripts = $::request->{layout}->javascript_inline) { +# print "\n" for @inline_scripts; +# } print < diff --git a/SL/User.pm b/SL/User.pm index 2de54ee5e..5255c8eee 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -136,7 +136,6 @@ sub login { $dbh->disconnect; if ($update_available) { - $form->{"stylesheet"} = "lx-office-erp.css"; $form->{"title"} = $main::locale->text("Dataset upgrade"); $form->header(); print $form->parse_html_template("dbupgrade/header"); diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index c704174c8..a9dbd050e 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -91,7 +91,7 @@ sub run { $locale = $::locale; $auth = $::auth; - $form->{stylesheet} = "lx-office-erp.css"; + $request->{layout}->use_stylesheet("lx-office-erp.css"); $form->{favicon} = "favicon.ico"; if ($form->{action}) { @@ -703,7 +703,7 @@ sub dbupdate { my $form = $main::form; my $locale = $main::locale; - $form->{stylesheet} = "lx-office-erp.css"; + $::request->{layout}->use_stylesheet("lx-office-erp.css"); $form->{title} = $locale->text("Dataset upgrade"); $form->header(); diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index c84772813..f967c7975 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -466,7 +466,7 @@ sub list_account { $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id}); } - $form->use_stylesheet("list_accounts.css"); + $::request->{layout}->use_stylesheet("list_accounts.css"); $form->{title} = $locale->text('Chart of Accounts'); $form->header; diff --git a/bin/mozilla/drafts.pl b/bin/mozilla/drafts.pl index c471d009b..cac7bea36 100644 --- a/bin/mozilla/drafts.pl +++ b/bin/mozilla/drafts.pl @@ -26,7 +26,7 @@ sub save_draft { restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM}); delete $form->{SAVED_FORM}; - $form->{SAVED_FORM} = save_form(qw(stylesheet login password)); + $form->{SAVED_FORM} = save_form(qw(login password)); $form->{remove_draft} = 1; $form->header(); @@ -79,7 +79,7 @@ sub load_draft_maybe { $draft_nextsub = "add" unless ($draft_nextsub); delete $form->{action}; - my $saved_form = save_form(qw(stylesheet login password)); + my $saved_form = save_form(qw(login password)); $form->header(); print($form->parse_html_template("drafts/load", @@ -129,7 +129,7 @@ sub load_draft { $form->{draft_description} = $description; $form->{remove_draft} = 'checked'; } - # Ich vergesse bei Rechnungsentwürfe das Rechnungsdatum zu ändern. Dadurch entstehen + # Ich vergesse bei Rechnungsentwürfe das Rechnungsdatum zu ändern. Dadurch entstehen # ungültige Belege. Vielleicht geht es anderen ähnlich jan 19.2.2011 $form->{invdate} = $form->current_date(\%myconfig); # Aktuelles Rechnungsdatum ... $form->{duedate} = $form->current_date(\%myconfig); # Aktuelles Fälligkeitsdatum ... diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index b08e5dbe0..8aed4918c 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -835,7 +835,7 @@ sub storno { $form->error($locale->text("Invoice has already been storno'd!")); } - map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form })); + map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password type))); } keys(%{ $form })); invoice_links(); prepare_invoice(); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 9508f736f..a5feea84a 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1225,7 +1225,7 @@ sub save { $form->{simple_save} = 1; if(!$form->{print_and_save}) { - delete @{$form}{ary_diff([keys %{ $form }], [qw(login stylesheet id script type cursor_fokus)])}; + delete @{$form}{ary_diff([keys %{ $form }], [qw(login id script type cursor_fokus)])}; edit(); ::end_of_request(); } -- 2.20.1