Merge pull request #15971 from aydun/report#23
[civicrm-core.git] / templates / CRM / Admin / Page / Navigation.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
1188c7a8 3 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 4 | |
1188c7a8
TO
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 |
6a488035
TO
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}
f6eedce7 13 <div class="help">
5e69f428
CW
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>
6a488035
TO
19 </div>
20
21 <div class="crm-block crm-content-block">
22 <div id="new-menu-item">
5e69f428 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}
6a488035
TO
24 </div>
25 <div class="spacer"></div>
5e69f428 26 <div style="padding-left: 48px;"><img src="{$config->resourceBase}i/logo_sm.png" /></div>
6a488035
TO
27 <div id="navigation-tree" class="navigation-tree" style="height:auto; border-collapse:separate; background-color:#FFFFFF;"></div>
28 <div class="spacer"></div>
d353eb79 29 <div>
df1b6e34
CW
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>
d353eb79
AN
34 </div>
35 <div class="spacer"></div>
6a488035
TO
36 </div>
37 {literal}
38 <script type="text/javascript">
ae8f569f
CW
39 CRM.$(function($) {
40 $("#navigation-tree").jstree({
656e5c5b
CW
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'},
a2a3cc46 47 return: ['label', 'parent_id', 'icon'],
656e5c5b
CW
48 name: {'!=': 'Home'},
49 sequential: 1
5e69f428 50 }).then(function(data) {
656e5c5b
CW
51 var items = [];
52 $.each(data.values, function(key, value) {
53 items.push({
54 id: value.id,
55 text: value.label,
a2a3cc46 56 icon: value.icon || false,
656e5c5b
CW
57 parent: value.parent_id || '#'
58 });
59 });
60 callBack(items);
61 });
ae8f569f 62 },
656e5c5b
CW
63 progressive_render: true,
64 check_callback: true
ae8f569f 65 },
656e5c5b
CW
66 dnd: {
67 copy: false
ae8f569f
CW
68 },
69 contextmenu: {
656e5c5b
CW
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
ae8f569f 81 },
656e5c5b
CW
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() {
5e69f428 95 CRM.api3('Navigation', 'delete', {id: nodeID}, true).then(refreshMenubar);
656e5c5b 96 $("#navigation-tree").jstree(true).delete_node(menu.reference.closest('li'));
656e5c5b
CW
97 });
98 }
99 }
100 };
101 callBack(items);
6a488035 102 }
6a488035 103 }
656e5c5b
CW
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;
6a488035 108 var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal};
5e69f428 109 CRM.status({}, $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps).then(refreshMenubar));
656e5c5b 110 });
ae8f569f 111
656e5c5b
CW
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;
ae8f569f 118 } else {
656e5c5b 119 args.id = nodeID;
ae8f569f 120 }
656e5c5b
CW
121 CRM.loadForm(CRM.url('civicrm/admin/menu', args)).on('crmFormSuccess', function() {
122 $("#navigation-tree").jstree(true).refresh();
5e69f428 123 refreshMenubar();
ae8f569f 124 });
656e5c5b
CW
125 }
126
ae8f569f
CW
127 $('#new-menu-item a.button')
128 .on('click', CRM.popup)
129 .on('crmPopupFormSuccess', function() {
656e5c5b 130 $("#navigation-tree").jstree(true).refresh();
5e69f428 131 refreshMenubar();
ae8f569f 132 });
88ffbaaa
CW
133
134 $('a.nav-reset').on('click', function(e) {
135 e.preventDefault();
df1b6e34
CW
136 CRM.confirm({
137 title: $(this).text(),
533ccb95 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}'
df1b6e34
CW
139 })
140 .on('crmConfirm:yes', function() {
141 $('#crm-container').block();
88ffbaaa 142 CRM.api3('Navigation', 'reset', {'for': 'report'}, true)
5e69f428 143 .then(function() {
df1b6e34 144 $('#crm-container').unblock();
656e5c5b 145 $("#navigation-tree").jstree(true).refresh();
5e69f428
CW
146 refreshMenubar();
147 });
88ffbaaa
CW
148 });
149 });
5e69f428
CW
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 }
ae8f569f 157 });
6a488035
TO
158</script>
159{/literal}
160{/if}