added pertinent author/copyright to files modified in tabs
[openemr.git] / interface / main / tabs / js / tabs_view_model.js
blob86266d2faf1f372476772a0791d9255d14769cf9
1 /**
2  * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
3  * Copyright (C) 2016 Brady Miller <brady.g.miller@gmail.com>
4  *
5  * LICENSE: This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 3
8  * of the License, or (at your option) any later version.
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
15  *
16  * @package OpenEMR
17  * @author  Kevin Yeh <kevin.y@integralemr.com>
18  * @author  Brady Miller <brady.g.miller@gmail.com>
19  * @link    http://www.open-emr.org
20  */
22 function tabStatus(title,url,name,closable,visible,locked)
24     var self=this;
25     self.visible=ko.observable(visible);
26     self.locked=ko.observable(locked);
27     self.closable=ko.observable(closable);
28     self.title=ko.observable(title);
29     self.url=ko.observable(url);
30     self.name=ko.observable(name);
31     self.window=null;
32     return this;
35 function tabs_view_model()
37     this.tabsList=ko.observableArray();
38     this.tabsList.push(new tabStatus("One",webroot_url+"/interface/main/main_info.php","cal",true,true,false));
39     this.tabsList.push(new tabStatus("Two",webroot_url+"/interface/main/messages/messages.php?form_active=1","msg",true,false,false));
40 //    this.tabsList.push(new tabStatus("Three"));
41     this.text=ko.observable("Test");
42     return this;
45 function activateTab(data)
47     for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
48     {
49         var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
50         if(data!==curTab)
51         {
52             if(!curTab.locked())
53             {
54                 curTab.visible(false);
55             }
56         }
57         else
58         {
59             curTab.visible(true);
60         }
61     }    
64 function activateTabByName(name,hideOthers)
66     for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
67     {
68         var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
69         if(curTab.name()===name)
70         {
71             curTab.visible(true);
72         }
73         else if(hideOthers)
74         {
75             if(!curTab.locked())
76             {
77                 curTab.visible(false);
78             }
79         }
80     }
83 function tabClicked(data,evt)
85     activateTab(data);
88 function tabRefresh(data,evt)
90     // To do: Consider modification if part of frame.
91     data.window.location=data.window.location;
92     activateTab(data);
95 function tabClose(data,evt)
97         app_view_model.application_data.tabs.tabsList.remove(data);
100 function tabCloseByName(name)
102     for(var tabIdx=0;tabIdx<app_view_model.application_data.tabs.tabsList().length;tabIdx++)
103     {
104         var curTab=app_view_model.application_data.tabs.tabsList()[tabIdx];
105         if(curTab.name()===name)
106         {
107             tabClose(curTab);
108         }
109     }    
112 function navigateTab(url,name)
114     top.restoreSession();
115     var curTab;
116     if($("iframe[name='"+name+"']").length>0)
117     {            
118        $("iframe[name='"+name+"']").get(0).contentWindow.location=url; 
119     }
120     else
121     {
122         curTab=new tabStatus("New",url,name,true,false,false);
123         app_view_model.application_data.tabs.tabsList.push(curTab);
124     }
127 function tabLockToggle(data,evt)
129     data.locked(!data.locked());
130     if(data.locked())
131     {
132         activateTab(data);
133     }
134     else
135     {
136         data.visible(false);
137     }
140 function refreshPatient(data,evt)
142     loadCurrentPatient();
146 function setEncounter(id)
148     app_view_model.application_data.patient().selectedEncounterID(id);
151 function chooseEncounterEvent(data,evt)
153     setEncounter(data.id());
154     goToEncounter(data.id());
157 function goToEncounter(encId)
159     var url=webroot_url+'/interface/patient_file/encounter/encounter_top.php?set_encounter=' + encId;
160     navigateTab(url,"enc");
161     activateTabByName("enc",true);
164 function reviewEncounter(encId)
166     var url=webroot_url+'/interface/patient_file/encounter/forms.php?review_id=' + encId;
167     navigateTab(url,"rev");
168     activateTabByName("rev",true);
171 function reviewEncounterEvent(data,evt)
173     reviewEncounter(data.id());
175 function clickNewEncounter(data,evt)
177     newEncounter();
180 function newEncounter()
182     var url=webroot_url+'/interface/forms/newpatient/new.php?autoloaded=1&calenc='
183     navigateTab(url,"enc");
184     activateTabByName("enc",true);    
188 function clickEncounterList(data,evt)
190     encounterList();
192 function encounterList()
194     var url=webroot_url+'/interface/patient_file/history/encounters.php'
195     navigateTab(url,"enc");
196     activateTabByName("enc",true);    
197     
200 function loadCurrentPatient()
202     var url=webroot_url+'/interface/patient_file/summary/demographics.php'
203     navigateTab(url,"pat");
204     activateTabByName("pat",true);    
205     
208 function menuActionClick(data,evt)
210     if(data.enabled())
211     {
212         if(data.requirement===2)
213         {
214             var encounterID=app_view_model.application_data.patient().selectedEncounterID();
215             if(isEncounterLocked(encounterID))
216             {
217                 alert("This encounter is locked. No new forms can be added.");
218                 return;
219             }
220         }        
221         navigateTab(webroot_url+data.url(),data.target);
222         activateTabByName(data.target,true);        
223     }
224     else
225     {
226         if(data.requirement===1)
227         {
228             alert('You must first select or add a patient.');        
229         }
230         else if((data.requirement===2)||data.requirement===3)
231         {
232             alert('You must first select or create an encounter.');                    
233         }
234     }    
235        
238 function clearPatient()
240     top.restoreSession();    
241     app_view_model.application_data.patient(null);
242     tabCloseByName('enc');
243     tabCloseByName('rev');
244     tabCloseByName('pop');
245     tabCloseByName('pat');
246     navigateTab(webroot_url+'/interface/main/finder/dynamic_finder.php','fin');
247     activateTabByName('fin',true);
248     //Ajax call to clear active patient in session
249     $.ajax({
250         type: "POST",
251         url: webroot_url+"/library/ajax/unset_session_ajax.php",
252           data: { func: "unset_pid"},
253           success:function( msg ) {
255     
256           }
257         });