PHP8
[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            
83             Pman.Login.onLoad();
84             
85         },
86         'load' : function()
87         {
88             if (Roo.get('loading-logo-tile')) {
89                 Roo.get('loading-logo-tile').remove();
90             }
91             if (Roo.get('loading-logo-tile-top')) {
92                 Roo.get('loading-logo-tile-top').remove();
93             }
94             if (Roo.get('loading-logo-bottom')) {
95                 Roo.get('loading-logo-bottom').remove();
96             }
97             if (Roo.get('loading-logo-center')) {
98                 Roo.get('loading-logo-center').remove();
99             }
100         }   
101         
102     },
103     loadUserInterface : function()
104     {       
105         if (this.buildCompleted) { // it get's called from auth checking.. no need to build again..
106             return; 
107         }
108         // triggers after authentication verified...
109         
110         if(typeof(uiConfig.fullstory) != 'undefined'){
111             this.fullstory();
112         }
113         
114         if (Roo.get('loading')) {
115             Roo.get('loading').remove();
116         }
117         if (Roo.get('loading-mask')) {
118             Roo.get('loading-mask').show();
119         }
120         var au = Pman.Login.authUser;
121         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
122         
123         
124         if (Roo.isGecko) {
125            Roo.useShims = true;
126         }
127        
128         
129         Pman.building = true;
130         
131         Roo.XComponent.hideProgress = true;
132         Roo.XComponent.on('beforebuild',  this.onBeforeBuild, this);
133         
134         Roo.XComponent.on('buildcomplete',  this.onBuildComplete, this);
135         Roo.XComponent.build();
136          
137         
138     },
139     
140     finalize : function() {
141         
142       
143        
144         window.onbeforeunload = function(e) { 
145             e = e || window.event;
146             var r = "Closing this window will loose changes, are you sure you want to do that?";
147
148             // For IE and Firefox
149             if (e) {
150                 e.returnValue = r;
151             }
152
153             // For Safari
154             return r;
155             
156         };
157         
158         Roo.bootstrap.MessageBox.hide();
159         
160         if (Roo.get('loading-mask')) {
161            Roo.get('loading-mask').remove();
162         }
163         
164         
165         this.buildCompleted = true; // now we can force refreshes on everything..
166         
167         
168         // does the URL indicate we want to see a system..
169        
170         // Open system..
171         
172       
173         
174
175     }, 
176     genericDelete : function(tab,tbl) {
177         
178         var r = [];
179         
180             
181         var s = tab.grid.selModel.getSelections();
182         if (!s.length)  {
183             Roo.bootstrap.MessageBox.alert("Error", "Select at least one Row to delete" );
184             return '';
185         }
186         //var reader = tab.grid.reader || tab.grid.ds.reader;
187         for(var i = 0; i < s.length; i++) {
188             r.push(s[i].json.id);
189         }
190         
191         Roo.bootstrap.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
192             function(btn) {
193                 if (btn != 'yes') {
194                     return;
195                 }
196                 
197                 //tab.grid.mask("Deleting");
198                 new Pman.Request({
199                     url: baseURL + '/Roo/'+tbl+'.php',
200                     method: 'POST',
201                     mask: true,
202                     params: {
203                         _delete : r.join(',')
204                     },
205                     success: function(response) {
206                         //tab.grid.unmask();
207                         if ( tab.paging ) {
208                             tab.paging.onClick('refresh');   
209                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
210                             // new xtype built grids
211                             tab.grid.footer.onClick('refresh');   
212                         } else if (tab.refresh) {
213                             tab.refresh(); // this might cause problems as panels have a refresh method?
214                         } else {
215                             tab.grid.store.load();
216                         }
217                         
218                         
219                         
220                     },
221                     failure: function(act) {
222                         Roo.bootstrap.MessageBox.hide();
223                         
224                         //Roo.log(act);
225                         var msg = '';
226                         try {
227                             msg = act.errorMsg;
228                         } catch(e) {
229                             msg = "Error deleting";
230                         }
231                         //tab.grid.unmask();
232                         Roo.bootstrap.MessageBox.alert("Error",  msg);
233                         
234                     }
235                     
236                 });
237             }
238             
239         );
240         return '';
241     },
242     /* fired before building - check permissions on a component.. */
243     onBeforeBuild : function(obj) 
244     {
245         if (typeof(obj.part) == 'undefined')  {
246             return;
247         }
248            
249         if (!obj.part[1].length) {
250             obj.part[1] = obj.part[0];
251         }
252         var permname = obj.part.join('.');
253             
254         Roo.log("CHECKING: "+ permname);
255         
256         if (typeof(appDisabled) != 'undefined' && appDisabled.indexOf(permname)> -1)  {
257             obj.disabled = true;
258         }
259         // we now have permission...
260         // obj.moduleOwner '.' lname
261      
262         if (Pman.Login.hasPermExists(permname) && !Pman.Login.hasPerm(permname,'S')) {
263             // it's a turned off permission...
264             Roo.log(permname + " is Disabled for this user");
265             obj.disabled = true;
266             return;
267         }
268         
269         if (obj.permname && obj.permname.length &&
270             Pman.Login.hasPermExists(obj.permname) && !Pman.Login.hasPerm(obj.permname,'S')) {
271             // it's a turned off permission...
272             Roo.log(obj.permname + " is Disabled for this user");
273             obj.disabled = true;
274             return;
275         }
276             
277         
278     },
279     
280     fullstory : function()
281     {
282         if(uiConfig.fullstory.domains.indexOf(location.host) < 0){
283             return;
284         }
285
286         window['_fs_debug'] = false;
287         window['_fs_host'] = 'fullstory.com';
288         window['_fs_org'] = uiConfig.fullstory.account;
289         window['_fs_namespace'] = 'FS';
290         (function(m,n,e,t,l,o,g,y){
291             if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}
292             g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[];
293             o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
294             y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
295             g.identify=function(i,v){g(l,{uid:i});if(v){g(l,v)}};g.setUserVars=function(v){g(l,v)};
296             g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
297             g.clearUserCookie=function(c,d,i){if(!c || document.cookie.match('fs_uid=[`;`]*`[`;`]*`[`;`]*`')){
298             d=n.domain;while(1){n.cookie='fs_uid=;domain='+d+
299             ';path=/;expires='+new Date(0).toUTCString();i=d.indexOf('.');if(i<0){break;}d=d.slice(i+1)}}};
300         })(window,document,window['_fs_namespace'],'script','user');
301     }
302 });