Commit d6ffcbc8 authored by Mathieu Lutfy's avatar Mathieu Lutfy Committed by Aegir user

Update recentmenu extension

parent 8bb40fdf
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<url desc="Support">https://github.com/civicrm/org.civicrm.recentmenu</url> <url desc="Support">https://github.com/civicrm/org.civicrm.recentmenu</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2018-12-21</releaseDate> <releaseDate>2019-02-28</releaseDate>
<version>1.1</version> <version>1.2</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>5.8</ver> <ver>5.8</ver>
......
(function($) { (function($) {
$(document).on('crmLoad', '#civicrm-menu', function() { $(document)
if (CRM.vars && CRM.vars.recentmenu && !CRM.menubar.getItem('recent_items')) { .on('crmLoad', '#civicrm-menu', function() {
CRM.menubar.addItems(-1, null, [CRM.vars.recentmenu]); if (CRM.vars && CRM.vars.recentmenu && !CRM.menubar.getItem('recent_items')) {
} CRM.menubar.addItems(-1, null, [CRM.vars.recentmenu]);
}); }
})
.ajaxSuccess(function(event, xhr, settings) {
try {
if ((!settings.dataType || settings.dataType == 'json') && xhr.responseText) {
var response = $.parseJSON(xhr.responseText);
if (typeof(response.recentmenu_items) == 'object') {
CRM.vars.recentmenu = response.recentmenu_items;
CRM.menubar.updateItem(response.recentmenu_items);
}
}
}
// Ignore errors thrown by parseJSON and the menubar
catch (e) {}
});
})(CRM.$); })(CRM.$);
...@@ -134,67 +134,98 @@ function recentmenu_civicrm_entityTypes(&$entityTypes) { ...@@ -134,67 +134,98 @@ function recentmenu_civicrm_entityTypes(&$entityTypes) {
_recentmenu_civix_civicrm_entityTypes($entityTypes); _recentmenu_civix_civicrm_entityTypes($entityTypes);
} }
/**
* Implements hook_civicrm_pageRun().
*/
function recentmenu_civicrm_pageRun(&$page) {
if (!empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], ['json', 6])) {
$page->ajaxResponse['recentmenu_items'] = _get_recentmenu_items();
}
}
/**
* Implements hook_civicrm_preProcess().
*/
function recentmenu_civicrm_preProcess($formName, &$form) {
if (!empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], ['json', 6])) {
$form->ajaxResponse['recentmenu_items'] = _get_recentmenu_items();
}
}
/**
* Implements hook_civicrm_postProcess().
*/
function recentmenu_civicrm_postProcess($formName, &$form) {
if (!empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], ['json', 6])) {
$form->ajaxResponse['recentmenu_items'] = _get_recentmenu_items();
}
}
/** /**
* Implements hook_civicrm_coreResourceList(). * Implements hook_civicrm_coreResourceList().
*/ */
function recentmenu_civicrm_coreResourceList(&$list, $region) { function recentmenu_civicrm_coreResourceList(&$list, $region) {
if ($region == 'html-header' && CRM_Core_Permission::check('access CiviCRM')) { if ($region == 'html-header' && CRM_Core_Permission::check('access CiviCRM')) {
$icons = [ Civi::resources()
'Individual' => 'fa-user', ->addScriptFile('org.civicrm.recentmenu', 'js/recentmenu.js', 0, 'html-header')
'Household' => 'fa-home', ->addVars('recentmenu', _get_recentmenu_items());
'Organization' => 'fa-building', }
'Activity' => 'fa-tasks', }
'Case' => 'fa-folder-open',
'Contribution' => 'fa-credit-card', function _get_recentmenu_items() {
'Grant' => 'fa-money', $icons = [
'Group' => 'fa-users', 'Individual' => 'fa-user',
'Membership' => 'fa-id-badge', 'Household' => 'fa-home',
'Note' => 'fa-sticky-note', 'Organization' => 'fa-building',
'Participant' => 'fa-ticket', 'Activity' => 'fa-tasks',
'Pledge' => 'fa-paper-plane', 'Case' => 'fa-folder-open',
'Relationship' => 'fa-handshake-o', 'Contribution' => 'fa-credit-card',
]; 'Grant' => 'fa-money',
$recent = CRM_Utils_Recent::get(); 'Group' => 'fa-users',
$menu = [ 'Membership' => 'fa-id-badge',
'label' => E::ts('Recent (%1)', [1 => count($recent)]), 'Note' => 'fa-sticky-note',
'name' => 'recent_items', 'Participant' => 'fa-ticket',
'icon' => 'crm-i fa-history', 'Pledge' => 'fa-paper-plane',
'child' => [], 'Relationship' => 'fa-handshake-o',
]; ];
foreach ($recent as $i => $item) { $recent = CRM_Utils_Recent::get();
$node = [ $menu = [
'label' => $item['title'], 'label' => E::ts('Recent (%1)', [1 => count($recent)]),
'name' => 'recent_items',
'icon' => 'crm-i fa-history',
'child' => [],
];
foreach ($recent as $i => $item) {
$node = [
'label' => $item['title'],
'url' => $item['url'],
'name' => 'recent_items_' . $i,
'attr' => ['title' => $item['type']],
'icon' => 'crm-i fa-fw ' . CRM_Utils_Array::value($item['type'], $icons, 'fa-gear'),
'child' => [[
'label' => E::ts('View'),
'attr' => ['title' => E::ts('View %1', [1 => $item['type']])],
'url' => $item['url'], 'url' => $item['url'],
'name' => 'recent_items_' . $i, 'name' => 'recent_items_' . $i . '_view',
'attr' => ['title' => $item['type']], ]]
'icon' => 'crm-i fa-fw ' . CRM_Utils_Array::value($item['type'], $icons, 'fa-gear'), ];
'child' => [[ if (!empty($item['edit_url'])) {
'label' => E::ts('View'), $node['child'][] = [
'attr' => ['title' => E::ts('View %1', [1 => $item['type']])], 'label' => E::ts('Edit'),
'url' => $item['url'], 'attr' => ['title' => E::ts('Edit %1', [1 => $item['type']])],
'name' => 'recent_items_' . $i . '_view', 'url' => $item['edit_url'],
]] 'name' => 'recent_items_' . $i . '_edit',
]; ];
if (!empty($item['edit_url'])) {
$node['child'][] = [
'label' => E::ts('Edit'),
'attr' => ['title' => E::ts('Edit %1', [1 => $item['type']])],
'url' => $item['edit_url'],
'name' => 'recent_items_' . $i . '_edit',
];
}
if (!empty($item['delete_url'])) {
$node['child'][] = [
'label' => E::ts('Delete'),
'attr' => ['title' => E::ts('Delete %1', [1 => $item['type']])],
'url' => $item['delete_url'],
'name' => 'recent_items_' . $i . '_delete',
];
}
$menu['child'][] = $node;
} }
Civi::resources() if (!empty($item['delete_url'])) {
->addScriptFile('org.civicrm.recentmenu', 'js/recentmenu.js', 0, 'html-header') $node['child'][] = [
->addVars('recentmenu', $menu); 'label' => E::ts('Delete'),
'attr' => ['title' => E::ts('Delete %1', [1 => $item['type']])],
'url' => $item['delete_url'],
'name' => 'recent_items_' . $i . '_delete',
];
}
$menu['child'][] = $node;
} }
return $menu;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment