Merge pull request #15834 from francescbassas/patch-16
[civicrm-core.git] / templates / CRM / Admin / Page / Navigation.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
9 *}
10 {if $action eq 1 or $action eq 2 or $action eq 8}
11 {include file="CRM/Admin/Form/Navigation.tpl"}
12 {else}
13 <div class="help">
14 {capture assign="displayPrefUrl"}href="{crmURL p='civicrm/admin/setting/preferences/display' q='reset=1'}"{/capture}
15 {capture assign="searchPrefUrl"}href="{crmURL p='civicrm/admin/setting/search' q='reset=1'}"{/capture}
16 <p>{ts}Customize the CiviCRM navigation menu bar for your users here.{/ts} {help id="id-navigation"}</p>
17 <p>{ts 1=$displayPrefUrl}The menu color and position can be adjusted on the <a %1>Display Preferences</a> screen.{/ts}</p>
18 <p>{ts 1=$searchPrefUrl}Quicksearch options can be edited on the <a %1>Search Preferences</a> screen.{/ts}</p>
19 </div>
20
21 <div class="crm-block crm-content-block">
22 <div id="new-menu-item">
23 {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}
24 </div>
25 <div class="spacer"></div>
26 <div style="padding-left: 48px;"><img src="{$config->resourceBase}i/logo_sm.png" /></div>
27 <div id="navigation-tree" class="navigation-tree" style="height:auto; border-collapse:separate; background-color:#FFFFFF;"></div>
28 <div class="spacer"></div>
29 <div>
30 <a href="#" class="nav-reset crm-hover-button">
31 {* TODO: fa-broom would be better, but not implemented yet. https://github.com/FortAwesome/Font-Awesome/issues/239 *}
32 <i class="crm-i fa-undo"></i> {ts}Cleanup reports menu{/ts}
33 </a>
34 </div>
35 <div class="spacer"></div>
36 </div>
37 {literal}
38 <script type="text/javascript">
39 CRM.$(function($) {
40 $("#navigation-tree").jstree({
41 plugins: ["dnd", "contextmenu"],
42 core: {
43 data: function(tree, callBack) {
44 CRM.api3('Navigation', 'get', {
45 domain_id: {/literal}{$config->domainID()}{literal},
46 options: {limit: 0, sort: 'weight'},
47 return: ['label', 'parent_id', 'icon'],
48 name: {'!=': 'Home'},
49 sequential: 1
50 }).then(function(data) {
51 var items = [];
52 $.each(data.values, function(key, value) {
53 items.push({
54 id: value.id,
55 text: value.label,
56 icon: value.icon || false,
57 parent: value.parent_id || '#'
58 });
59 });
60 callBack(items);
61 });
62 },
63 progressive_render: true,
64 check_callback: true
65 },
66 dnd: {
67 copy: false
68 },
69 contextmenu: {
70 items: function (node, callBack) {
71 var items = {
72 add: {
73 label: "{/literal}{ts escape='js'}Add{/ts}{literal}",
74 icon: 'crm-i fa-plus',
75 action: editForm
76 },
77 edit: {
78 label: "{/literal}{ts escape='js'}Edit{/ts}{literal}",
79 icon: 'crm-i fa-pencil',
80 action: editForm
81 },
82 delete: {
83 label: "{/literal}{ts escape='js'}Delete{/ts}{literal}",
84 icon: 'crm-i fa-trash',
85 action: function (menu) {
86 var nodeID = menu.reference.attr('id').replace('_anchor', ''),
87 node = $("#navigation-tree").jstree(true).get_node(nodeID),
88 menuName = node.text;
89 var deleteMsg = {/literal}"{ts escape='js'}Are you sure you want to delete this menu item:{/ts} " + '"'{literal} + menuName + {/literal}'"? {ts escape='js'}This action cannot be undone.{/ts}'{literal};
90 if (node.children.length) {
91 deleteMsg += {/literal}"<br /><br />" + ts('{ts escape='js' 1='<strong>%1</strong>'}%1 sub-menu items will also be deleted.{/ts}'{literal}, {1: node.children.length});
92 }
93 CRM.confirm({message: deleteMsg})
94 .on('crmConfirm:yes', function() {
95 CRM.api3('Navigation', 'delete', {id: nodeID}, true).then(refreshMenubar);
96 $("#navigation-tree").jstree(true).delete_node(menu.reference.closest('li'));
97 });
98 }
99 }
100 };
101 callBack(items);
102 }
103 }
104 }).on("move_node.jstree", function (e, data) {
105 var nodeID = data.node.id;
106 var refID = data.parent === '#' ? '' : data.parent;
107 var ps = data.position;
108 var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal};
109 CRM.status({}, $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps).then(refreshMenubar));
110 });
111
112 function editForm(menu) {
113 var nodeID = menu.reference.attr('id').replace('_anchor', ''),
114 action = menu.item.icon === 'crm-i fa-pencil' ? 'update' : 'add',
115 args = {reset: 1, action: action};
116 if (action === 'add') {
117 args.parent_id = nodeID;
118 } else {
119 args.id = nodeID;
120 }
121 CRM.loadForm(CRM.url('civicrm/admin/menu', args)).on('crmFormSuccess', function() {
122 $("#navigation-tree").jstree(true).refresh();
123 refreshMenubar();
124 });
125 }
126
127 $('#new-menu-item a.button')
128 .on('click', CRM.popup)
129 .on('crmPopupFormSuccess', function() {
130 $("#navigation-tree").jstree(true).refresh();
131 refreshMenubar();
132 });
133
134 $('a.nav-reset').on('click', function(e) {
135 e.preventDefault();
136 CRM.confirm({
137 title: $(this).text(),
138 message: '{/literal}{ts escape='js'}This will add links for all currently active reports to the "Reports" menu under the relevant component. If you have added report instances to other menus, they will be moved to "Reports". Are you sure?{/ts}{literal}'
139 })
140 .on('crmConfirm:yes', function() {
141 $('#crm-container').block();
142 CRM.api3('Navigation', 'reset', {'for': 'report'}, true)
143 .then(function() {
144 $('#crm-container').unblock();
145 $("#navigation-tree").jstree(true).refresh();
146 refreshMenubar();
147 });
148 });
149 });
150
151 // Force-refresh the menubar by resetting the cache code
152 function refreshMenubar() {
153 CRM.menubar.destroy();
154 CRM.menubar.cacheCode = Math.random();
155 CRM.menubar.initialize();
156 }
157 });
158 </script>
159 {/literal}
160 {/if}