Javascript Layout: ActionBar
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 27 Oct 2016 14:27:15 +0000 (16:27 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 28 Feb 2017 09:04:33 +0000 (10:04 +0100)
SL/Layout/Javascript.pm

index 76728ef..3b170a4 100644 (file)
@@ -5,12 +5,15 @@ use parent qw(SL::Layout::Base);
 
 use SL::Layout::None;
 use SL::Layout::Top;
+use SL::Layout::ActionBar;
 use SL::Layout::Content;
 
 use List::Util qw(max);
+use List::MoreUtils qw(uniq);
 use URI;
 
 sub init_sub_layouts {
+  $_[0]->sub_layouts_by_name->{actionbar} = SL::Layout::ActionBar->new;
   [
     SL::Layout::None->new,
     SL::Layout::Top->new,
@@ -18,17 +21,19 @@ sub init_sub_layouts {
   ]
 }
 
-sub use_javascript {
-  my $self = shift;
-  qw(
-    js/dhtmlsuite/menu-for-applications.js
-  ),
-  $self->SUPER::use_javascript(@_);
+sub javascripts {
+  my ($self) = @_;
+
+  return uniq grep { $_ } map { $self->_find_javascript($_)  }
+    map({ $_->javascripts } $self->sub_layouts),
+    qw(dhtmlsuite/menu-for-applications.js),
+    $_[0]->sub_layouts_by_name->{actionbar}->javascripts,
+    $self->use_javascript;
 }
 
 sub javascripts_inline {
   $_[0]->SUPER::javascripts_inline,
-<<'EOJS'
+<<'EOJS',
   DHTMLSuite.createStandardObjects();
   DHTMLSuite.configObj.setImagePath('image/dhtmlsuite/');
   var menu_model = new DHTMLSuite.menuModel();
@@ -39,6 +44,7 @@ sub javascripts_inline {
   menu_bar.setTarget('main_menu_div');
   menu_bar.init();
 EOJS
+  $_[0]->sub_layouts_by_name->{actionbar}->javascripts_inline,
 }
 
 sub pre_content {
@@ -48,17 +54,27 @@ sub pre_content {
     menu            => $_[0]->menu,
     icon_path       => sub { my $simg = "image/icons/svg/$_[0].svg";  my $pimg="image/icons/16x16/$_[0].png"; -f $simg ? $simg : ( -f $pimg ? $pimg : ()) },
     max_width       => sub { 10 * max map { length $::locale->text($_->{name}) } @{ $_[0]{children} || [] } },
-  );
+  ) .
+  $_[0]->sub_layouts_by_name->{actionbar}->pre_content;
 }
 
 sub stylesheets {
-  $_[0]->add_stylesheets(qw(
-    dhtmlsuite/menu-item.css
-    dhtmlsuite/menu-bar.css
-    icons16.css
-    menu.css
-  ));
-  $_[0]->SUPER::stylesheets;
+  my ($self) = @_;
+  my $css_path = $self->get_stylesheet_for_user;
+
+  return
+    uniq
+    grep { $_ }
+    map { $self->_find_stylesheet($_, $css_path)  }
+    qw(
+      dhtmlsuite/menu-item.css
+      dhtmlsuite/menu-bar.css
+      icons16.css
+      menu.css
+    ),
+    ( map { $_->stylesheets } $_[0]->sub_layouts ),
+    $_[0]->sub_layouts_by_name->{actionbar}->stylesheets,
+    $_[0]->use_stylesheet;
 }
 
 1;