Pman.js
[Pman.BAdmin] / Pman.js
1 /**
2  * 
3  *  
4  *  This is the main Pman class [for bootstrap]
5  *
6  *  In theory it's lighter than the original, as no BC concerns..
7  */
8  
9 // translation..
10
11 Roo.namespace('_T');
12
13 //??
14     
15
16 Pman = new Roo.Document(
17 {
18     Dialog : {},
19     // Tab not needed, as that's now our top level UI element..
20
21     subMenuItems : [],
22     topMenuItems : [],
23     rightNames: { }, /// register right names here - so they can be translated and rendered.
24     /**
25      * @property {Roo.menu.Menu} pulldownMenu - the 'add menu pulldown, you can use it to add items..
26      *
27      */
28     pulldownMenu : false, 
29     
30     
31     buildCompleted : false, // flag to say if we are building interface..
32     events : {
33         'beforeauth' : true, // fired after page ready, before authentication check
34         'beforeload' : true, // fired after page ready, before module building.
35         'load' : true, // fired after module building
36         'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
37     },
38
39     onBuildComplete : function ()
40     {
41         this.building = false;   
42         //this.layout.getRegion('center').showPanel(0);
43         //this.layout.endUpdate(); 
44         //this.addTopToolbar();  
45         this.finalize();
46         this.fireEvent('load',this);
47         
48         if (Pman.Login.authUser) {
49             (function() {
50                 if (typeof(FS) == 'undefined') {
51                     Roo.log("failed to initialize FS");
52                     return;
53                 }
54
55                 FS.identify(Pman.Login.authUser.id, {
56                     displayName: Pman.Login.authUser.firstname + ' ' + Pman.Login.authUser.lastname,
57                     email: Pman.Login.authUser.email
58                   });
59             }).defer(300);
60         }
61         
62         
63     },
64     listeners : {
65         'ready' : function()
66         {
67             
68
69             // kludge to fix firebug debugger
70             if (typeof(console) == 'undefined') {
71                 console = { log : function() {  } };
72             }
73             
74             // remove loader..
75             if (Roo.get('loading')) {
76                 Roo.get('loading').remove();
77             }
78             
79             Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
80             Roo.bootstrap.Tooltip.init(); 
81
82             if(window.location.pathname.substr(baseURL.length).match(/\/PasswordReset\//)){
83                 Pman.Dialog.BAdminPasswordReset.show({}, function(){
84                     window.location.href = baseURL;
85                 });
86                 
87                 return;
88             }
89              
90             Pman.Login.onLoad();
91             
92         },
93         'load' : function()
94         {
95             if (Roo.get('loading-logo-tile')) {
96                 Roo.get('loading-logo-tile').remove();
97             }
98             if (Roo.get('loading-logo-tile-top')) {
99                 Roo.get('loading-logo-tile-top').remove();
100             }
101             if (Roo.get('loading-logo-bottom')) {
102                 Roo.get('loading-logo-bottom').remove();
103             }
104             if (Roo.get('loading-logo-center')) {
105                 Roo.get('loading-logo-center').remove();
106             }
107         }   
108         
109     },
110     loadUserInterface : function()
111     {       
112         if (this.buildCompleted) { // it get's called from auth checking.. no need to build again..
113             return; 
114         }
115         // triggers after authentication verified...
116         
117         if(typeof(uiConfig.fullstory) != 'undefined'){
118             this.fullstory();
119         }
120         
121         if (Roo.get('loading')) {
122             Roo.get('loading').remove();
123         }
124         if (Roo.get('loading-mask')) {
125             Roo.get('loading-mask').show();
126         }
127         var au = Pman.Login.authUser;
128         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
129         
130         
131         if (Roo.isGecko) {
132            Roo.useShims = true;
133         }
134        
135         
136         Pman.building = true;
137         
138         Roo.XComponent.hideProgress = true;
139         Roo.XComponent.on('beforebuild',  this.onBeforeBuild, this);
140         
141         Roo.XComponent.on('buildcomplete',  this.onBuildComplete, this);
142         Roo.XComponent.build();
143          
144         
145     },
146     
147     finalize : function() {
148         
149       
150        
151         window.onbeforeunload = function(e) { 
152             e = e || window.event;
153             var r = "Closing this window will loose changes, are you sure you want to do that?";
154
155             // For IE and Firefox
156             if (e) {
157                 e.returnValue = r;
158             }
159
160             // For Safari
161             return r;
162             
163         };
164         
165         Roo.bootstrap.MessageBox.hide();
166         
167         if (Roo.get('loading-mask')) {
168            Roo.get('loading-mask').remove();
169         }
170         
171         
172         this.buildCompleted = true; // now we can force refreshes on everything..
173         
174         
175         // does the URL indicate we want to see a system..
176        
177         // Open system..
178         
179       
180         
181
182     }, 
183     genericDelete : function(tab,tbl) {
184         
185         var r = [];
186         
187             
188         var s = tab.grid.selModel.getSelections();
189         if (!s.length)  {
190             Roo.bootstrap.MessageBox.alert("Error", "Select at least one Row to delete" );
191             return '';
192         }
193         //var reader = tab.grid.reader || tab.grid.ds.reader;
194         for(var i = 0; i < s.length; i++) {
195             r.push(s[i].json.id);
196         }
197         
198         Roo.bootstrap.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
199             function(btn) {
200                 if (btn != 'yes') {
201                     return;
202                 }
203                 
204                 //tab.grid.mask("Deleting");
205                 new Pman.Request({
206                     url: baseURL + '/Roo/'+tbl+'.php',
207                     method: 'POST',
208                     mask: true,
209                     params: {
210                         _delete : r.join(',')
211                     },
212                     success: function(response) {
213                         //tab.grid.unmask();
214                         if ( tab.paging ) {
215                             tab.paging.onClick('refresh');   
216                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
217                             // new xtype built grids
218                             tab.grid.footer.onClick('refresh');   
219                         } else if (tab.refresh) {
220                             tab.refresh(); // this might cause problems as panels have a refresh method?
221                         } else {
222                             tab.grid.store.load();
223                         }
224                         
225                         
226                         
227                     },
228                     failure: function(act) {
229                         Roo.bootstrap.MessageBox.hide();
230                         
231                         //Roo.log(act);
232                         var msg = '';
233                         try {
234                             msg = act.errorMsg;
235                         } catch(e) {
236                             msg = "Error deleting";
237                         }
238                         //tab.grid.unmask();
239                         Roo.bootstrap.MessageBox.alert("Error",  msg);
240                         
241                     }
242                     
243                 });
244             }
245             
246         );
247         return '';
248     },
249     /* fired before building - check permissions on a component.. */
250     onBeforeBuild : function(obj) 
251     {
252         if (typeof(obj.part) == 'undefined')  {
253             return;
254         }
255            
256         if (!obj.part[1].length) {
257             obj.part[1] = obj.part[0];
258         }
259         var permname = obj.part.join('.');
260             
261         Roo.log("CHECKING: "+ permname);
262         
263         if (typeof(appDisabled) != 'undefined' && appDisabled.indexOf(permname)> -1)  {
264             obj.disabled = true;
265         }
266         // we now have permission...
267         // obj.moduleOwner '.' lname
268      
269         if (Pman.Login.hasPermExists(permname) && !Pman.Login.hasPerm(permname,'S')) {
270             // it's a turned off permission...
271             Roo.log(permname + " is Disabled for this user");
272             obj.disabled = true;
273             return;
274         }
275         
276         if (obj.permname && obj.permname.length &&
277             Pman.Login.hasPermExists(obj.permname) && !Pman.Login.hasPerm(obj.permname,'S')) {
278             // it's a turned off permission...
279             Roo.log(obj.permname + " is Disabled for this user");
280             obj.disabled = true;
281             return;
282         }
283             
284         
285     },
286     
287     fullstory : function()
288     {
289         if(uiConfig.fullstory.domains.indexOf(location.host) < 0){
290             return;
291         }
292
293         window['_fs_debug'] = false;
294         window['_fs_host'] = 'fullstory.com';
295         window['_fs_org'] = uiConfig.fullstory.account;
296         window['_fs_namespace'] = 'FS';
297         (function(m,n,e,t,l,o,g,y){
298             if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}
299             g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[];
300             o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
301             y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
302             g.identify=function(i,v){g(l,{uid:i});if(v){g(l,v)}};g.setUserVars=function(v){g(l,v)};
303             g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
304             g.clearUserCookie=function(c,d,i){if(!c || document.cookie.match('fs_uid=[`;`]*`[`;`]*`[`;`]*`')){
305             d=n.domain;while(1){n.cookie='fs_uid=;domain='+d+
306             ';path=/;expires='+new Date(0).toUTCString();i=d.indexOf('.');if(i<0){break;}d=d.slice(i+1)}}};
307         })(window,document,window['_fs_namespace'],'script','user');
308     }
309 });