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 with a confirm dialog
14 *
15 * @since 3.0
16 */
17 class JToolbarButtonConfirm extends JToolbarButton
18 {
19 /**
20 * Button type
21 *
22 * @var string
23 */
24 protected $_name = 'Confirm';
25
26 /**
27 * Fetch the HTML for the button
28 *
29 * @param string $type Unused string.
30 * @param string $msg Message to render
31 * @param string $name Name to be used as apart of the id
32 * @param string $text Button text
33 * @param string $task The task associated with the button
34 * @param boolean $list True to allow use of lists
35 * @param boolean $hideMenu True to hide the menu on click
36 *
37 * @return string HTML string for the button
38 *
39 * @since 3.0
40 */
41 public function fetchButton($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
42 {
43 // Store all data to the options array for use with JLayout
44 $options = array();
45 $options['text'] = JText::_($text);
46 $options['msg'] = JText::_($msg, true);
47 $options['class'] = $this->fetchIconClass($name);
48 $options['doTask'] = $this->_getCommand($options['msg'], $name, $task, $list);
49
50 // Instantiate a new JLayoutFile instance and render the layout
51 $layout = new JLayoutFile('joomla.toolbar.confirm');
52
53 return $layout->render($options);
54 }
55
56 /**
57 * Get the button CSS Id
58 *
59 * @param string $type Button type
60 * @param string $msg Message to display
61 * @param string $name Name to be used as apart of the id
62 * @param string $text Button text
63 * @param string $task The task associated with the button
64 * @param boolean $list True to allow use of lists
65 * @param boolean $hideMenu True to hide the menu on click
66 *
67 * @return string Button CSS Id
68 *
69 * @since 3.0
70 */
71 public function fetchId($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
72 {
73 return $this->_parent->getName() . '-' . $name;
74 }
75
76 /**
77 * Get the JavaScript command for the button
78 *
79 * @param object $msg The message to display.
80 * @param string $name Not used.
81 * @param string $task The task used by the application
82 * @param boolean $list True is requires a list confirmation.
83 *
84 * @return string JavaScript command string
85 *
86 * @since 3.0
87 */
88 protected function _getCommand($msg, $name, $task, $list)
89 {
90 JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
91
92 $cmd = "if (confirm('" . $msg . "')) { Joomla.submitbutton('" . $task . "'); }";
93
94 if ($list)
95 {
96 $alert = "alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'));";
97 $cmd = "if (document.adminForm.boxchecked.value == 0) { " . $alert . " } else { " . $cmd . " }";
98
99 }
100
101 return $cmd;
102 }
103 }
104