0d432db148aeedb2e12453739661060fd8fc90ca
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Core_ShowHideBlocks
{
38 * The icons prefixed to block show and hide links.
42 static $_showIcon, $_hideIcon;
45 * The array of ids of blocks that will be shown
52 * The array of ids of blocks that will be hidden
61 * @param array $show initial value of show array
62 * @param array $hide initial value of hide array
64 * @return \CRM_Core_ShowHideBlocks the newly created object@access public
66 function __construct($show = NULL, $hide = NULL) {
71 $this->_show
= array();
78 $this->_hide
= array();
83 * load icon vars used in hide and show links
89 static function setIcons() {
90 if (!isset(self
::$_showIcon)) {
91 $config = CRM_Core_Config
::singleton();
92 self
::$_showIcon = '<img src="' . $config->resourceBase
. 'i/TreePlus.gif" class="action-icon" alt="' . ts('show field or section') . '"/>';
93 self
::$_hideIcon = '<img src="' . $config->resourceBase
. 'i/TreeMinus.gif" class="action-icon" alt="' . ts('hide field or section') . '"/>';
98 * add the values from this class to the template
103 function addToTemplate() {
107 foreach (array_keys($this->_hide
) as $h) {
116 foreach (array_keys($this->_show
) as $s) {
124 $template = CRM_Core_Smarty
::singleton();
125 $template->assign_by_ref('hideBlocks', $hide);
126 $template->assign_by_ref('showBlocks', $show);
130 * Add a value to the show array
132 * @param string $name id to be added
137 function addShow($name) {
138 $this->_show
[$name] = 1;
139 if (array_key_exists($name, $this->_hide
)) {
140 unset($this->_hide
[$name]);
145 * Add a value to the hide array
147 * @param string $name id to be added
152 function addHide($name) {
153 $this->_hide
[$name] = 1;
154 if (array_key_exists($name, $this->_show
)) {
155 unset($this->_show
[$name]);
160 * create a well formatted html link from the smaller pieces
162 * @param string $name name of the link
163 * @param string $href
164 * @param string $text
167 * @return string the formatted html link
170 static function linkHtml($name, $href, $text, $js) {
171 return '<a name="' . $name . '" id="' . $name . '" href="' . $href . '" ' . $js . ">$text</a>";
175 * Create links that we can use in the form
177 * @param CRM_Core_Form $form the form object
178 * @param string $prefix the attribute that we are referencing
179 * @param string $showLinkText the text to be shown for the show link
180 * @param string $hideLinkText the text to be shown for the hide link
187 static function links(&$form, $prefix, $showLinkText, $hideLinkText, $assign = TRUE) {
188 $showCode = "cj('#id_{$prefix}').show(); cj('#id_{$prefix}_show').hide();";
189 $hideCode = "cj('#id_{$prefix}').hide(); cj('#id_{$prefix}_show').show(); return false;";
193 $values['show'] = self
::linkHtml("${prefix}_show", "#${prefix}_hide", self
::$_showIcon . $showLinkText, "onclick=\"$showCode\"");
194 $values['hide'] = self
::linkHtml("${prefix}_hide", "#${prefix}", self
::$_hideIcon . $hideLinkText, "onclick=\"$hideCode\"");
197 $form->assign($prefix, $values);
205 * Create html link elements that we can use in the form
207 * @param CRM_Core_Form $form the form object
208 * @param int $index the current index of the element being processed
209 * @param int $maxIndex the max number of elements that will be processed
210 * @param string $prefix the attribute that we are referencing
211 * @param string $showLinkText the text to be shown for the show link
212 * @param string $hideLinkText the text to be shown for the hide link
213 * @param string $elementType the set the class
214 * @param string $hideLink the hide block string
219 function linksForArray(&$form, $index, $maxIndex, $prefix, $showLinkText, $hideLinkText, $elementType = NULL, $hideLink = NULL) {
220 $showHidePrefix = str_replace(array("]", "["), array("", "_"), $prefix);
221 $showHidePrefix = "id_" . $showHidePrefix;
222 if ($index == $maxIndex) {
223 $showCode = $hideCode = "return false;";
228 $showCode = "cj('#${prefix}_${next}_show').show(); return false;";
230 $hideCode = $hideLink;
233 $hideCode = "cj('#${prefix}_${next}_show, #${prefix}_${next}').hide(); return false;";
237 $showCode = "cj('#{$showHidePrefix}_{$next}_show').show(); return false;";
238 $hideCode = "cj('#{$showHidePrefix}_{$next}_show, #{$showHidePrefix}_{$next}').hide(); return false;";
244 $form->addElement('link', "${prefix}[${index}][show]", NULL, "#${prefix}_${index}", self
::$_showIcon . $showLinkText,
245 array('onclick' => "cj('#${prefix}_${index}_show').hide(); cj('#${prefix}_${index}').show();" . $showCode)
247 $form->addElement('link', "${prefix}[${index}][hide]", NULL, "#${prefix}_${index}", self
::$_hideIcon . $hideLinkText,
248 array('onclick' => "cj('#${prefix}_${index}').hide(); cj('#${prefix}_${index}_show').show();" . $hideCode)
252 $form->addElement('link', "${prefix}[${index}][show]", NULL, "#${prefix}_${index}", self
::$_showIcon . $showLinkText,
253 array('onclick' => "cj('#{$showHidePrefix}_{$index}_show').hide(); cj('#{$showHidePrefix}_{$index}').show();" . $showCode)
255 $form->addElement('link', "${prefix}[${index}][hide]", NULL, "#${prefix}_${index}", self
::$_hideIcon . $hideLinkText,
256 array('onclick' => "cj('#{$showHidePrefix}_{$index}').hide(); cj('#{$showHidePrefix}_{$index}_show').show();" . $hideCode)