Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
39de6fd5 | 3 | | CiviCRM version 4.6 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 id="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"> | |
52604b19 | 35 | <a href="{crmURL p="civicrm/admin/menu" q="action=add&reset=1"}" class="button" style="margin-left: 6px;"><span><div class="icon ui-icon-circle-plus"></div>{ts}Add Menu Item{/ts}</span></a> |
22b67281 | 36 | <span id="reset-menu" class="status" style="display:none"> |
6a488035 TO |
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 id="navigation-tree" class="navigation-tree" style="height:auto; border-collapse:separate; background-color:#FFFFFF;"></div> | |
43 | <div class="spacer"></div> | |
44 | </div> | |
45 | {literal} | |
4441df69 CW |
46 | <style type="text/css"> |
47 | #navigation-tree li { | |
48 | font-weight: normal; | |
49 | } | |
50 | #navigation-tree > ul > li { | |
51 | font-weight: bold; | |
52 | } | |
53 | </style> | |
6a488035 | 54 | <script type="text/javascript"> |
ae8f569f CW |
55 | CRM.$(function($) { |
56 | $("#navigation-tree").jstree({ | |
57 | plugins: [ "themes", "json_data", "dnd","ui", "crrm","contextmenu" ], | |
58 | json_data: { | |
59 | ajax:{ | |
60 | dataType: "json", | |
61 | url: {/literal}"{crmURL p='civicrm/ajax/menu' h=0 q='key='}{crmKey name='civicrm/ajax/menu'}"{literal} | |
62 | }, | |
63 | progressive_render: true | |
64 | }, | |
65 | themes: { | |
66 | "theme": 'classic', | |
67 | "dots": true, | |
68 | "icons": false, | |
69 | "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css' | |
70 | }, | |
71 | rules: { | |
72 | droppable: [ "tree-drop" ], | |
73 | multiple: true, | |
74 | deletable: "all", | |
75 | draggable: "all" | |
76 | }, | |
77 | crrm: { | |
78 | move: { | |
79 | check_move: function(m) { | |
80 | var homeMenuId = {/literal}"{$homeMenuId}"{literal}; | |
81 | if ( $( m.r[0] ).attr('id').replace("node_","") == homeMenuId || | |
82 | $( m.o[0] ).attr('id').replace("node_","") == homeMenuId ) { | |
83 | return false; | |
84 | } else { | |
85 | return true; | |
86 | } | |
87 | } | |
6a488035 | 88 | } |
ae8f569f CW |
89 | }, |
90 | contextmenu: { | |
91 | items: { | |
92 | create: false, | |
93 | ccp: { | |
94 | label : "{/literal}{ts escape='js'}Edit{/ts}{literal}", | |
95 | visible: function (node, obj) { if(node.length != 1) return false; | |
96 | return obj.check("renameable", node); }, | |
97 | action: function (node, obj) { | |
98 | var nid = $(node).prop('id'); | |
99 | var nodeID = nid.substr( 5 ); | |
100 | var editURL = {/literal}"{crmURL p='civicrm/admin/menu' h=0 q='action=update&reset=1&id='}"{literal} + nodeID; | |
101 | CRM.loadForm(editURL).on('crmFormSuccess', function() { | |
102 | $("#navigation-tree").jstree('refresh'); | |
103 | $("#reset-menu").show( ); | |
104 | }); | |
105 | }, | |
106 | submenu: false | |
107 | } | |
6a488035 | 108 | } |
6a488035 | 109 | } |
6a488035 | 110 | |
ae8f569f CW |
111 | }).bind("rename.jstree", function ( e,node ) { |
112 | var nodeID = node.rslt.obj.attr('id').replace("node_",""); | |
113 | var newName = node.rslt.new_name; | |
6a488035 | 114 | var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal}; |
ae8f569f | 115 | $.get( postURL + '&type=rename&id=' + nodeID + '&data=' + newName, |
6a488035 | 116 | function (data) { |
ae8f569f | 117 | $("#reset-menu").show( ); |
6a488035 TO |
118 | } |
119 | ); | |
6a488035 | 120 | |
ae8f569f CW |
121 | }).bind("remove.jstree", function( e,node ) { |
122 | var menuName = node.rslt.obj.find('a').first( ).text( ); | |
123 | var nodeID = node.rslt.obj.attr('id').replace("node_",""); | |
124 | ||
125 | // don't allow deleting of home | |
126 | var homeMenuId = {/literal}"{$homeMenuId}"{literal}; | |
127 | if ( nodeID == homeMenuId ) { | |
128 | var cannotDeleteMsg = {/literal}"{ts escape='js'}You cannot delete this menu item:{/ts}" + " "{literal} + menuName; | |
129 | CRM.alert( cannotDeleteMsg, {/literal}"{ts escape='js'}Cannot Delete{/ts}"{literal} ); | |
130 | $("#navigation-tree").jstree('refresh'); | |
131 | return false; | |
132 | } | |
6d07c262 | 133 | var deleteMsg = {/literal}"{ts escape='js'}Are you sure you want to delete this menu item:{/ts}" + " "{literal} + menuName + {/literal}" ? {ts}This action cannot be undone.{/ts}"{literal}; |
ae8f569f CW |
134 | var isDelete = confirm( deleteMsg ); |
135 | if ( isDelete ) { | |
136 | var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal}; | |
137 | $.get( postURL + '&type=delete&id=' + nodeID, | |
138 | function (data) { | |
139 | $("#reset-menu").show( ); | |
140 | } | |
141 | ); | |
142 | } else { | |
143 | $("#navigation-tree").jstree('refresh'); | |
144 | } | |
145 | ||
146 | }).bind("move_node.jstree", function ( e,node ) { | |
147 | node.rslt.o.each(function (i) { | |
148 | var nodeID = node.rslt.o.attr('id').replace("node_",""); | |
149 | var refID = node.rslt.np.attr('id').replace("node_",""); | |
150 | if (isNaN( refID ) ){ refID =''; } | |
151 | var ps = node.rslt.cp+i; | |
152 | var postURL = {/literal}"{crmURL p='civicrm/ajax/menutree' h=0 q='key='}{crmKey name='civicrm/ajax/menutree'}"{literal}; | |
153 | $.get( postURL + '&type=move&id=' + nodeID + '&ref_id=' + refID + '&ps='+ps, | |
154 | function (data) { | |
155 | $("#reset-menu").show( ); | |
156 | }); | |
157 | }); | |
6a488035 | 158 | }); |
ae8f569f CW |
159 | $('#new-menu-item a.button') |
160 | .on('click', CRM.popup) | |
161 | .on('crmPopupFormSuccess', function() { | |
1a62cf90 CW |
162 | $("#navigation-tree").jstree('refresh'); |
163 | $("#reset-menu").show(); | |
ae8f569f CW |
164 | }); |
165 | }); | |
6a488035 TO |
166 | </script> |
167 | {/literal} | |
168 | {/if} |