Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu config screen improvements #14002

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CRM/Admin/Form/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function buildQuickForm() {

$permissions = [];
foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) {
$permissions[] = ['id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals)];
$permissions[] = ['id' => $id, 'text' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals)];
}
$this->add('text', 'permission', ts('Permission'),
['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(['data' => ['results' => $permissions, 'text' => 'label']])]
$this->add('select2', 'permission', ts('Permission'), $permissions, FALSE,
['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'multiple' => TRUE]
);

$operators = ['AND' => ts('AND'), 'OR' => ts('OR')];
Expand Down Expand Up @@ -123,6 +123,10 @@ public function setDefaultValues() {
// its ok if there is no element called is_active
$defaults['is_active'] = ($this->_id) ? $this->_defaults['is_active'] : 1;

if (!empty($defaults['icon'])) {
$defaults['icon'] = trim(str_replace('crm-i', '', $defaults['icon']));
}

return $defaults;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function &add(
if ($inputType == 'select2') {
$type = 'text';
$options = $attributes;
$attributes = $attributes = ($extra ? $extra : []) + ['class' => ''];
$attributes = ($extra ? $extra : []) + ['class' => ''];
$attributes['class'] = ltrim($attributes['class'] . " crm-select2 crm-form-select2");
$attributes['data-select-params'] = json_encode(['data' => $options, 'multiple' => !empty($attributes['multiple'])]);
unset($attributes['multiple']);
Expand Down
7 changes: 1 addition & 6 deletions templates/CRM/Admin/Form/Navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@
.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
});
.change();
});
</script>
{/literal}
2 changes: 1 addition & 1 deletion templates/CRM/Admin/Page/Navigation.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
<li>{ts}Change the permissions for a menu item. Right-click and select 'Edit'.{/ts}</li>
<li>{ts}Re-order menu items (including moving them from one branch of the menu 'tree' to another. Simply use your mouse to 'drag and drop' the menu item to the new location.{/ts}</li>
</ul>
<p><em>{ts}Changes you make to the menu are saved immediately. However, you will need reload this page to see your changes in the menu bar above.{/ts}</em></p>
<p><em>{ts}Changes you make to the menu are saved immediately.{/ts}</em></p>
{/htxt}
39 changes: 22 additions & 17 deletions templates/CRM/Admin/Page/Navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
{include file="CRM/Admin/Form/Navigation.tpl"}
{else}
<div class="help">
{ts}Customize the CiviCRM navigation menu bar for your users here.{/ts} {help id="id-navigation"}
{capture assign="displayPrefUrl"}href="{crmURL p='civicrm/admin/setting/preferences/display' q='reset=1'}"{/capture}
{capture assign="searchPrefUrl"}href="{crmURL p='civicrm/admin/setting/search' q='reset=1'}"{/capture}
<p>{ts}Customize the CiviCRM navigation menu bar for your users here.{/ts} {help id="id-navigation"}</p>
<p>{ts 1=$displayPrefUrl}The menu color and position can be adjusted on the <a %1>Display Preferences</a> screen.{/ts}</p>
<p>{ts 1=$searchPrefUrl}Quicksearch options can be edited on the <a %1>Search Preferences</a> screen.{/ts}</p>
</div>

<div class="crm-block crm-content-block">
<div id="new-menu-item">
{crmButton p="civicrm/admin/menu" q="action=add&reset=1" id="newMenuItem" icon="crm-i fa-plus-circle" style="margin-left: 6px;"}{ts}Add Menu Item{/ts}{/crmButton}&nbsp;&nbsp;&nbsp;&nbsp;
<span id="reset-menu" class="status" style="display:none">
{capture assign=rebuildURL}{crmURL p='civicrm/admin/menu' q="reset=1"}{/capture}
{ts 1=$rebuildURL}<a href='%1' title="Reload page"><strong>Click here</strong></a> to reload the page and see your changes in the menu bar above.{/ts}
</span><br/><br/>
{crmButton p="civicrm/admin/menu" q="action=add&reset=1" id="newMenuItem" icon="crm-i fa-plus-circle" style="margin-left: 6px;"}{ts}Add Menu Item{/ts}{/crmButton}
</div>
<div class="spacer"></div>
<div style="padding-left: 25px;"><div class="crm-logo-sm"></div></div>
<div style="padding-left: 48px;"><img src="{$config->resourceBase}i/logo_sm.png" /></div>
<div id="navigation-tree" class="navigation-tree" style="height:auto; border-collapse:separate; background-color:#FFFFFF;"></div>
<div class="spacer"></div>
<div>
Expand All @@ -63,7 +63,7 @@
return: ['label', 'parent_id', 'icon'],
name: {'!=': 'Home'},
sequential: 1
}).done(function(data) {
}).then(function(data) {
var items = [];
$.each(data.values, function(key, value) {
items.push({
Expand Down Expand Up @@ -108,9 +108,8 @@
}
CRM.confirm({message: deleteMsg})
.on('crmConfirm:yes', function() {
CRM.api3('Navigation', 'delete', {id: nodeID}, true);
CRM.api3('Navigation', 'delete', {id: nodeID}, true).then(refreshMenubar);
$("#navigation-tree").jstree(true).delete_node(menu.reference.closest('li'));
$("#reset-menu").show();
});
}
}
Expand All @@ -123,8 +122,7 @@
var refID = data.parent === '#' ? '' : data.parent;
var ps = data.position;
var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal};
CRM.status({}, $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps));
$("#reset-menu").show();
CRM.status({}, $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps).then(refreshMenubar));
});

function editForm(menu) {
Expand All @@ -138,15 +136,15 @@
}
CRM.loadForm(CRM.url('civicrm/admin/menu', args)).on('crmFormSuccess', function() {
$("#navigation-tree").jstree(true).refresh();
$("#reset-menu").show();
refreshMenubar();
});
}

$('#new-menu-item a.button')
.on('click', CRM.popup)
.on('crmPopupFormSuccess', function() {
$("#navigation-tree").jstree(true).refresh();
$("#reset-menu").show();
refreshMenubar();
});

$('a.nav-reset').on('click', function(e) {
Expand All @@ -158,13 +156,20 @@
.on('crmConfirm:yes', function() {
$('#crm-container').block();
CRM.api3('Navigation', 'reset', {'for': 'report'}, true)
.done(function() {
.then(function() {
$('#crm-container').unblock();
$("#navigation-tree").jstree(true).refresh();
$("#reset-menu").show();
})
refreshMenubar();
});
});
});

// Force-refresh the menubar by resetting the cache code
function refreshMenubar() {
CRM.menubar.destroy();
CRM.menubar.cacheCode = Math.random();
CRM.menubar.initialize();
}
});
</script>
{/literal}
Expand Down