removed related phpmyadmin links and globals
[openemr.git] / interface / main / tabs / js / menu_analysis.js
blobc4c959868ef78522a3de84ebc7038775095c696e
1 /**
2  * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
3  *
4  * LICENSE: This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
14  *
15  * @package OpenEMR
16  * @author  Kevin Yeh <kevin.y@integralemr.com>
17  * @link    http://www.open-emr.org
18  */
20 var targets={};
21 targets['Calendar']='lst';
22 targets['Flow Board']='lst';
23 targets['Messages ']='pat';
24 targets['Administration']='adm';
25 targets['Reports']='rep';
26 targets['Miscellaneous']='msc';
28 targets['Patients']='lst';
30 var acl_reqs={};
31 var global_reqs={};
33 //Billing Menu Restrictions
34 acl_reqs['EDI History']=['acct','eob'];
35 global_reqs['EDI History']='enable_edihistory_in_left_menu'
37 // Administration Menu restrictions
38 acl_reqs['Globals']=['admin','super'];
39 acl_reqs['Facilities']=['admin','users'];
40 acl_reqs['Users']=['admin','users'];
41 acl_reqs['Addr Book']=['admin','practice'];
42 acl_reqs['Practice']=['admin','practice'];
43 acl_reqs['Codes']=['admin','superbill'];
44 acl_reqs['Layouts']=['admin','super'];
45 acl_reqs['Lists']=['admin','super'];
46 acl_reqs['ACL']=['admin','acl'];
47 acl_reqs['Files']=['admin','super'];
48 acl_reqs['Backup']=['admin','super'];
51 acl_reqs['Rules']=['admin','super'];
52 global_reqs['Rules']='enable_cdr'
54 acl_reqs['Alerts']=['admin','super'];
55 global_reqs['Alerts']='enable_cdr'
57 acl_reqs['Patient Reminders']=['admin','super'];
58 global_reqs['Patient Reminders']='enable_cdr'
61 acl_reqs['Language']=['admin','language'];
62 acl_reqs['Forms']=['admin','forms'];
64 acl_reqs['Calendar']=['admin','calendar','main/calendar/index.php?module=PostCalendar&type=admin&func=modifyconfig']
66 acl_reqs['Logs']=['admin','users'];
68 acl_reqs['Certificates']=['admin','users'];
70 acl_reqs['Native Data Loads']=['admin','super'];
71 acl_reqs['External Data Loads']=['admin','super'];
72 acl_reqs['Merge Patient']=['admin','super'];
74 global_reqs['Fax/Scan']=['enable_hylafax','enable_scanner'];
77 function set_acl_reqs(entry)
79     if('url' in entry)
80     {
81         if(entry.label in acl_reqs)
82         {
83             var reqs=acl_reqs[entry.label];
84             if(reqs.length===3)
85             {
86                 if(entry.url.indexOf(reqs[2])!==-1)
87                 {
88                     entry.acl_req=[reqs[0],reqs[1]];
89                 }
90             }
91             else
92             {
93                 entry.acl_req=acl_reqs[entry.label];
94             }
95         }
96         if(entry.label in global_reqs)
97         {
98             entry.global_req=global_reqs[entry.label];
99         }
100     }
103 function setTarget(entry,target)
105     if('url' in entry)
106     {
107         entry.target=target
108     }
109     else
110     {
111         for(var idx=0;idx<entry.children.length;idx++)
112         {
113             setTarget(entry.children[idx],target);
114         }
115     }
117 function post_process(menu_entries)
119     for(var idx=0;idx<menu_entries.length;idx++)
120     {
121         var curEntry=menu_entries[idx];
122         set_acl_reqs(curEntry);
123         if(curEntry.label in targets)
124         {
125             setTarget(curEntry,targets[curEntry.label]);
126         }
127         post_process(curEntry.children);
128     }
130 function parse_link(link,entry)
132     if(link)
133     {
134         var parameters=link.substring(link.indexOf('(')+1,link.indexOf(')'));
135         if(parameters==='')
136         {
137             parameters=link;
138         }
139         if(link.indexOf("loadFrame2")===-1)
140         {
141             var url=parameters.replace(/\'/g,"").replace(/\"/g,"").replace("../","/interface/");
142             entry.url=url;
143             entry.target="report";
144         }
145         else
146         {
147             parameters=parameters.replace(/\'/g,"").replace(/\"/g,"");
148             var params=parameters.split(",");
149             entry.target=params[1];
150             if(entry.target==='RTop')
151             {
152                 entry.target='pat';
153             }
154             if(entry.target==='RBot')
155             {
156                 entry.target='enc';
157             }
160             entry.url=params[2].replace("../","/");
161             if(entry.url.indexOf("/")>0)
162             {
163                 entry.url="/interface/"+entry.url;
164             }
166         }
167     }
170 function menu_entry(label,link,menu_id)
172     var self=this;
173     self.label=label;
174     self.menu_id=menu_id;
175     parse_link(link,self);
176     self.children=[];
177     self.icon=icon;
178     self.helperText=helperText;
179     self.requirement=0;
180     if(menu_id)
181     {
182         if(menu_id.charAt(3)==='1')
183         {
184             if(self.label==='Summary')
185             {
186                 self.target="pat";
187             }
188             else
189             {
190                 self.target="enc";
191             }
192             self.requirement=1;
193         } else
194         if(menu_id.charAt(3)==='2')
195         {
196             self.target="enc";
197             self.requirement=2;
198             // Special case for "Current" visit entry
199             if(self.label==="Current")
200             {
201                 self.requirement=3;
202             }
203         }
204     }
207     return this;
210 function menu_entry_from_jq(elem)
212     return new menu_entry(elem.text(),elem.attr("onClick"),elem.attr("id"));
214 var menu_entries=[];
215 function analyze_menu()
217     alert('I think you will never see this. --Rod'); // debugging
219     if(!top.left_nav)
220     {
221         setTimeout(analyze_menu,1000);
222         return;
223     }
224     else
225     {
226         if(!top.left_nav.$)
227         {
228             alert("no jq!");
229             setTimeout(analyze_menu,1000);
230             return;
231         }
232     }
233     var jqLeft=top.left_nav.$(top.left_nav.document)
234     var $=top.left_nav.$;
235     jqLeft.ready(function(){
237         var menuTop=jqLeft.find("#navigation-slide");
238         menuTop.children().each(
239                 function(idx,elem)
240                 {
241                     // Header or content
242                     var jqElem=$(elem);
243                     var anchor=jqElem.children("a");
244                     var subMenu = jqElem.children("ul");
246                     var newEntry=menu_entry_from_jq(anchor);
247                     if(subMenu.length>0)
248                     {
249                         // 2 (Second) level menu items
250                         subMenu.children("li").each(function(idx,elem)
251                         {
252                             var sub_anchor=$(elem).children("a");
253                             var sub_entry=menu_entry_from_jq(sub_anchor);
254                             if(sub_anchor.length!==1)
255                             {
256                                 alert(sub_anchor.text());
257                             }
258                             var subSubMenu=$(elem).children("ul");
259                             //Third Level Menu Items
260                             if(subSubMenu.length>0 && sub_entry.label !=="Visit Forms")
261                             {
262                                 subSubMenu.children("li").each(function(idx,elem)
263                                 {
264                                     var sub_sub_anchor=$(elem).children("a");
265                                     var sub_sub_entry=menu_entry_from_jq(sub_sub_anchor);
266                                     sub_entry.children.push(sub_sub_entry);
268                                 });
270                             }
271                             //End Third Level Menu Items
272                             newEntry.children.push(sub_entry);
273                         });
274                         // End Second level menu items
275                     }
276                     else
277                     {
280                     };
281                     menu_entries.push(newEntry);
284                 }
285         );
286         // Scan popup select
287         var popups = jqLeft.find("select[name='popups'] option");
288         var popups_menu_header=new menu_entry("Popups","","popup");
289         menu_entries.push(popups_menu_header);
290         popups.each(function(idx,elem)
291             {
292                 var jqElem=$(elem);
293                 if(jqElem.val()!=='')
294                 {
295                     var popup_entry=new menu_entry(jqElem.text(),jqElem.val(),"Popup:"+jqElem.text());
296                     popup_entry.target="pop";
297                     popup_entry.requirement=1;
298                     popups_menu_header.children.push(popup_entry);
299                 }
300             });
301         // Process Complete
303         post_process(menu_entries);
304         var data=$("<div id='#menuData'></div>");
305         data.text("$menu_json=\""+JSON.stringify(menu_entries).replace(/\"/g,"\\\"")+"\";");
306         $("body").append(data);
307     });
309 var toID=setTimeout(analyze_menu,1000);