1 <?php
2
3 namespace Brickrouge;
4
5 class Modal extends Element
6 {
7 const ACTIONS = '#modal-actions';
8
9 static protected function add_assets(Document $document)
10 {
11 $document->js->add('modal.js');
12 }
13
14 public function __construct(array $attributes=array())
15 {
16 parent::__construct('div', $attributes);
17 }
18
19 protected function alter_class_names(array $class_names)
20 {
21 return parent::alter_class_names($class_names) + array
22 (
23 'modal' => true,
24 'hide' => true,
25 'fade' => true
26 );
27 }
28
29 protected function render_inner_html()
30 {
31 $html = '';
32
33 $header = $this->render_modal_header();
34
35 if ($header)
36 {
37 $header = '<h3>' . $header . '</h3>';
38 }
39
40 $html .= <<<EOT
41 <div class="modal-header">
42 <button class="close" data-dismiss="modal" aria-hidden="true">×</button>
43 {$header}
44 </div>
45 EOT;
46
47 $body = $this->render_modal_body();
48
49 if ($body === null)
50 {
51 throw new ElementIsEmpty();
52 }
53
54 $html .= <<<EOT
55 <div class="modal-body">
56 {$body}
57 </div>
58 EOT;
59
60 $footer = $this->render_modal_footer();
61
62 if ($footer)
63 {
64 $html .= <<<EOT
65 <div class="modal-footer">
66 {$footer}
67 </div>
68 EOT;
69 }
70
71 return $html;
72 }
73
74 protected function decorate_with_legend($html, $legend)
75 {
76 return $html;
77 }
78
79 protected function ()
80 {
81 return $this[self::LEGEND];
82 }
83
84 protected function render_modal_body()
85 {
86 return parent::render_inner_html();
87 }
88
89 protected function ()
90 {
91 $actions = $this[self::ACTIONS];
92
93 if ($actions && !($actions instanceof Actions))
94 {
95 $actions = new Actions($actions);
96 }
97
98 return $actions;
99 }
100 }
101