Merge pull request #12669 from eileenmcnaughton/dedupe_zero
[civicrm-core.git] / templates / CRM / Admin / Page / Navigation.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2019 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 *}
26 {if $action eq 1 or $action eq 2 or $action eq 8}
27 {include file="CRM/Admin/Form/Navigation.tpl"}
28 {else}
29 <div class="help">
30 {ts}Customize the CiviCRM navigation menu bar for your users here.{/ts} {help id="id-navigation"}
31 </div>
32
33 <div class="crm-block crm-content-block">
34 <div id="new-menu-item">
35 {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;
36 <span id="reset-menu" class="status" style="display:none">
37 {capture assign=rebuildURL}{crmURL p='civicrm/admin/menu' q="reset=1"}{/capture}
38 {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}
39 </span><br/><br/>
40 </div>
41 <div class="spacer"></div>
42 <div style="padding-left: 25px;"><div class="crm-logo-sm"></div></div>
43 <div id="navigation-tree" class="navigation-tree" style="height:auto; border-collapse:separate; background-color:#FFFFFF;"></div>
44 <div class="spacer"></div>
45 <div>
46 <a href="#" class="nav-reset crm-hover-button">
47 {* TODO: fa-broom would be better, but not implemented yet. https://github.com/FortAwesome/Font-Awesome/issues/239 *}
48 <i class="crm-i fa-undo"></i> {ts}Cleanup reports menu{/ts}
49 </a>
50 </div>
51 <div class="spacer"></div>
52 </div>
53 {literal}
54 <script type="text/javascript">
55 CRM.$(function($) {
56 $("#navigation-tree").jstree({
57 plugins: ["dnd", "contextmenu"],
58 core: {
59 data: function(tree, callBack) {
60 CRM.api3('Navigation', 'get', {
61 domain_id: {/literal}{$config->domainID()}{literal},
62 options: {limit: 0, sort: 'weight'},
63 return: ['label', 'parent_id', 'icon'],
64 name: {'!=': 'Home'},
65 sequential: 1
66 }).done(function(data) {
67 var items = [];
68 $.each(data.values, function(key, value) {
69 items.push({
70 id: value.id,
71 text: value.label,
72 icon: value.icon || false,
73 parent: value.parent_id || '#'
74 });
75 });
76 callBack(items);
77 });
78 },
79 progressive_render: true,
80 check_callback: true
81 },
82 dnd: {
83 copy: false
84 },
85 contextmenu: {
86 items: function (node, callBack) {
87 var items = {
88 add: {
89 label: "{/literal}{ts escape='js'}Add{/ts}{literal}",
90 icon: 'crm-i fa-plus',
91 action: editForm
92 },
93 edit: {
94 label: "{/literal}{ts escape='js'}Edit{/ts}{literal}",
95 icon: 'crm-i fa-pencil',
96 action: editForm
97 },
98 delete: {
99 label: "{/literal}{ts escape='js'}Delete{/ts}{literal}",
100 icon: 'crm-i fa-trash',
101 action: function (menu) {
102 var nodeID = menu.reference.attr('id').replace('_anchor', ''),
103 node = $("#navigation-tree").jstree(true).get_node(nodeID),
104 menuName = node.text;
105 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};
106 if (node.children.length) {
107 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});
108 }
109 CRM.confirm({message: deleteMsg})
110 .on('crmConfirm:yes', function() {
111 CRM.api3('Navigation', 'delete', {id: nodeID}, true);
112 $("#navigation-tree").jstree(true).delete_node(menu.reference.closest('li'));
113 $("#reset-menu").show();
114 });
115 }
116 }
117 };
118 callBack(items);
119 }
120 }
121 }).on("move_node.jstree", function (e, data) {
122 var nodeID = data.node.id;
123 var refID = data.parent === '#' ? '' : data.parent;
124 var ps = data.position;
125 var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal};
126 CRM.status({}, $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps));
127 $("#reset-menu").show();
128 });
129
130 function editForm(menu) {
131 var nodeID = menu.reference.attr('id').replace('_anchor', ''),
132 action = menu.item.icon === 'crm-i fa-pencil' ? 'update' : 'add',
133 args = {reset: 1, action: action};
134 if (action === 'add') {
135 args.parent_id = nodeID;
136 } else {
137 args.id = nodeID;
138 }
139 CRM.loadForm(CRM.url('civicrm/admin/menu', args)).on('crmFormSuccess', function() {
140 $("#navigation-tree").jstree(true).refresh();
141 $("#reset-menu").show();
142 });
143 }
144
145 $('#new-menu-item a.button')
146 .on('click', CRM.popup)
147 .on('crmPopupFormSuccess', function() {
148 $("#navigation-tree").jstree(true).refresh();
149 $("#reset-menu").show();
150 });
151
152 $('a.nav-reset').on('click', function(e) {
153 e.preventDefault();
154 CRM.confirm({
155 title: $(this).text(),
156 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}'
157 })
158 .on('crmConfirm:yes', function() {
159 $('#crm-container').block();
160 CRM.api3('Navigation', 'reset', {'for': 'report'}, true)
161 .done(function() {
162 $('#crm-container').unblock();
163 $("#navigation-tree").jstree(true).refresh();
164 $("#reset-menu").show();
165 })
166 });
167 });
168 });
169 </script>
170 {/literal}
171 {/if}