public function buildQuickForm() {
parent::buildQuickForm();
+ $this->setPageTitle(ts('Menu Item'));
+
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
);
$this->add('text', 'url', ts('Url'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'url'));
- $permissions = CRM_Core_Permission::basicPermissions(TRUE);
- $include = &$this->addElement('advmultiselect', 'permission',
- ts('Permission') . ' ', $permissions,
- array(
- 'size' => 5,
- 'style' => 'width:auto',
- 'class' => 'advmultiselect',
- )
+ $permissions = array();
+ foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) {
+ $permissions[] = array('id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals));
+ }
+ $this->add('text', 'permission', ts('Permission'),
+ array('placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(array('data' => $permissions)))
);
- $include->setButtonAttributes('add', array('value' => ts('Add >>')));
- $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
-
- $operators = array('AND' => 'AND', 'OR' => 'OR');
- $this->add('select', 'permission_operator', ts('Operator'), $operators);
+ $operators = array('AND' => ts('AND'), 'OR' => ts('OR'));
+ $this->add('select', 'permission_operator', NULL, $operators);
//make separator location configurable
- $separator = array(0 => 'None', 1 => 'After Menu Element', 2 => 'Before Menu Element');
- $this->add('select', 'has_separator', ts('Separator?'), $separator);
+ $separator = array(ts('None'), ts('After menu element'), ts('Before menu element'));
+ $this->add('select', 'has_separator', ts('Separator'), $separator);
- $active = $this->add('advcheckbox', 'is_active', ts('Enabled?'));
+ $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
if (CRM_Utils_Array::value('name', $this->_defaults) == 'Home') {
$active->freeze();
$homeMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
unset($parentMenu[$homeMenuId]);
- $parent = $this->add('select', 'parent_id', ts('Parent'), array('' => ts('- select -')) + $parentMenu);
+ $this->add('select', 'parent_id', ts('Parent'), array('' => ts('Top level')) + $parentMenu, FALSE, array('class' => 'crm-select2'));
}
}
public function setDefaultValues() {
$defaults = $this->_defaults;
if (isset($this->_id)) {
- if (!empty($this->_defaults['permission'])) {
- foreach (explode(',', $this->_defaults['permission']) as $value) {
- $components[$value] = $value;
- }
- $defaults['permission'] = $components;
- }
//Take parent id in object variable to calculate the menu
//weight if menu parent id changed
$this->_currentParentID = CRM_Utils_Array::value('parent_id', $this->_defaults);
{* this template is used for adding/editing CiviCRM Menu *}
<div class="crm-block crm-form-block crm-navigation-form-block">
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
-<fieldset><legend>{if $action eq 1}{ts}New Menu{/ts}{elseif $action eq 2}{ts}Edit Menu{/ts}{else}{ts}Delete Menu{/ts}{/if}</legend>
<table class="form-layout-compressed">
<tr class="crm-navigation-form-block-label">
<td class="label">{$form.label.label}</td><td>{$form.label.html}</td>
</tr>
<tr class="crm-navigation-form-block-url">
- <td class="label">{$form.url.label}</td><td>{$form.url.html} {help id="id-menu_url" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td class="label">{$form.url.label} {help id="id-menu_url" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td>{$form.url.html} </td>
</tr>
- { if $form.parent_id.html }
+ {if $form.parent_id.html}
<tr class="crm-navigation-form-block-parent_id">
- <td class="label">{$form.parent_id.label}</td><td>{$form.parent_id.html} {help id="id-parent" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td class="label">{$form.parent_id.label} {help id="id-parent" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td>{$form.parent_id.html}</td>
</tr>
{/if}
<tr class="crm-navigation-form-block-has_separator">
- <td class="label">{$form.has_separator.label}</td><td>{$form.has_separator.html} {help id="id-has_separator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td class="label">{$form.has_separator.label} {help id="id-has_separator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td>{$form.has_separator.html} </td>
</tr>
<tr class="crm-navigation-form-block-permission">
- <td class="label">{$form.permission.label}{help id="id-menu_permission" file="CRM/Admin/Form/Navigation.hlp"}</td><td>{$form.permission.html}</td>
- </tr>
- <tr class="crm-navigation-form-block-permission_operator">
- <td class="label"> </td><td>{$form.permission_operator.html} {$form.permission_operator.label} {help id="id-permission_operator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td class="label">{$form.permission.label}{help id="id-menu_permission" file="CRM/Admin/Form/Navigation.hlp"}</td>
+ <td>{$form.permission.html} <span class="permission_operator_wrapper">{$form.permission_operator.html} {help id="id-permission_operator" file="CRM/Admin/Form/Navigation.hlp"}</span></td>
</tr>
<tr class="crm-navigation-form-block-is_active">
<td class="label">{$form.is_active.label}</td><td>{$form.is_active.html}</td>
</tr>
</table>
-</fieldset>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
+{literal}
+<script type="text/javascript">
+ CRM.$(function($) {
+ var $form = $('form.{/literal}{$form.formClass}{literal}');
+ $('input[name=permission]', $form)
+ .on('change', function() {
+ $('span.permission_operator_wrapper').toggle(CRM._.includes($(this).val(), ','));
+ })
+ .change()
+ .crmSelect2({
+ formatResult: CRM.utils.formatSelect2Result,
+ formatSelection: function(row) {return row.label},
+ multiple: true
+ });
+ });
+</script>
+{/literal}