1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Toolbar
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Renders a standard button
14 *
15 * @since 3.0
16 */
17 class JToolbarButtonStandard extends JToolbarButton
18 {
19 /**
20 * Button type
21 *
22 * @var string
23 */
24 protected $_name = 'Standard';
25
26 /**
27 * Fetch the HTML for the button
28 *
29 * @param string $type Unused string.
30 * @param string $name The name of the button icon class.
31 * @param string $text Button text.
32 * @param string $task Task associated with the button.
33 * @param boolean $list True to allow lists
34 *
35 * @return string HTML string for the button
36 *
37 * @since 3.0
38 */
39 public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true)
40 {
41 // Store all data to the options array for use with JLayout
42 $options = array();
43 $options['text'] = JText::_($text);
44 $options['class'] = $this->fetchIconClass($name);
45 $options['doTask'] = $this->_getCommand($options['text'], $task, $list);
46 $options['btnClass'] = 'btn btn-small button-' . $name;
47
48 if ($name === 'apply' || $name === 'new')
49 {
50 $options['btnClass'] .= ' btn-success';
51 $options['class'] .= ' icon-white';
52 }
53
54 // Instantiate a new JLayoutFile instance and render the layout
55 $layout = new JLayoutFile('joomla.toolbar.standard');
56
57 return $layout->render($options);
58 }
59
60 /**
61 * Get the button CSS Id
62 *
63 * @param string $type Unused string.
64 * @param string $name Name to be used as apart of the id
65 * @param string $text Button text
66 * @param string $task The task associated with the button
67 * @param boolean $list True to allow use of lists
68 * @param boolean $hideMenu True to hide the menu on click
69 *
70 * @return string Button CSS Id
71 *
72 * @since 3.0
73 */
74 public function fetchId($type = 'Standard', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
75 {
76 return $this->_parent->getName() . '-' . $name;
77 }
78
79 /**
80 * Get the JavaScript command for the button
81 *
82 * @param string $name The task name as seen by the user
83 * @param string $task The task used by the application
84 * @param boolean $list True is requires a list confirmation.
85 *
86 * @return string JavaScript command string
87 *
88 * @since 3.0
89 */
90 protected function _getCommand($name, $task, $list)
91 {
92 JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
93
94 $cmd = "Joomla.submitbutton('" . $task . "');";
95
96 if ($list)
97 {
98 $alert = "alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'));";
99 $cmd = "if (document.adminForm.boxchecked.value == 0) { " . $alert . " } else { " . $cmd . " }";
100 }
101
102 return $cmd;
103 }
104 }
105