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         'beforeload' : true, // fired after page ready, before module building.
34         'load' : true, // fired after module building
35         'authrefreshed' : true // fire on auth updated?? - should be on Login?!?!?
36     },
37
38     onBuildComplete : function ()
39     {
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         Roo.log('checking????');
49         
50         if (Pman.Login.authUser) {
51             (function() {
52                 if (typeof(FS) == 'undefined') {
53                     Roo.log("failed to initialize FS");
54                     return;
55                 }
56
57                 FS.identify(Pman.Login.authUser.id, {
58                     displayName: Pman.Login.authUser.firstname + ' ' + Pman.Login.authUser.lastname,
59                     email: Pman.Login.authUser.email
60                   });
61             }).defer(300);
62         }
63         
64         
65     },
66     listeners : {
67         'ready' : function()
68         {
69             
70
71             // kludge to fix firebug debugger
72             if (typeof(console) == 'undefined') {
73                 console = { log : function() {  } };
74             }
75             
76             // remove loader..
77             if (Roo.get('loading')) {
78                 Roo.get('loading').remove();
79             }
80             
81             Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
82             Roo.bootstrap.Tooltip.init(); 
83
84              
85             // reset password!!!!
86             /*
87             if (showNewPass.length) {
88                 Pman.PasswordChange.show(  { passwordReset : showNewPass },
89                     function(data) {
90                         // fail and success we do  a load...
91                         Pman.Login.onLoad();
92                     }
93                 );
94                 return;
95             }
96             */
97             Pman.Login.onLoad();
98             
99         },
100         'load' : function()
101         {
102             if (Roo.get('loading-logo-tile')) {
103                 Roo.get('loading-logo-tile').remove();
104             }
105             if (Roo.get('loading-logo-tile-top')) {
106                 Roo.get('loading-logo-tile-top').remove();
107             }
108             if (Roo.get('loading-logo-bottom')) {
109                 Roo.get('loading-logo-bottom').remove();
110             }
111             if (Roo.get('loading-logo-center')) {
112                 Roo.get('loading-logo-center').remove();
113             }
114         }   
115         
116     },
117     loadUserInterface : function()
118     {       
119         if (this.buildCompleted) { // it get's called from auth checking.. no need to build again..
120             return; 
121         }
122         // triggers after authentication verified...
123         
124         if(typeof(uiConfig.fullstory) != 'undefined'){
125             this.fullstory();
126         }
127         
128         if (Roo.get('loading')) {
129             Roo.get('loading').remove();
130         }
131         if (Roo.get('loading-mask')) {
132             Roo.get('loading-mask').show();
133         }
134         var au = Pman.Login.authUser;
135         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
136         
137         
138         if (Roo.isGecko) {
139            Roo.useShims = true;
140         }
141        
142         
143         Pman.building = true;
144         
145         Roo.XComponent.hideProgress = true;
146         Roo.XComponent.on('beforebuild',  this.onBeforeBuild, this);
147         
148         Roo.XComponent.on('buildcomplete',  this.onBuildComplete, this);
149         Roo.XComponent.build();
150          
151         
152     },
153     
154     finalize : function() {
155         
156       
157        
158         window.onbeforeunload = function(e) { 
159             e = e || window.event;
160             var r = "Closing this window will loose changes, are you sure you want to do that?";
161
162             // For IE and Firefox
163             if (e) {
164                 e.returnValue = r;
165             }
166
167             // For Safari
168             return r;
169             
170         };
171         
172         Roo.bootstrap.MessageBox.hide();
173         
174         if (Roo.get('loading-mask')) {
175            Roo.get('loading-mask').remove();
176         }
177         
178         
179         this.buildCompleted = true; // now we can force refreshes on everything..
180         
181         
182         // does the URL indicate we want to see a system..
183        
184         // Open system..
185         
186       
187         
188
189     }, 
190    genericDelete : function(tab,tbl) {
191         
192         var r = [];
193         
194             
195         var s = tab.grid.selModel.getSelections();
196         if (!s.length)  {
197             Roo.bootstrap.MessageBox.alert("Error", "Select at least one Row to delete" );
198             return '';
199         }
200         //var reader = tab.grid.reader || tab.grid.ds.reader;
201         for(var i = 0; i < s.length; i++) {
202             r.push(s[i].json.id);
203         }
204     
205         Roo.bootstrap.MessageBox.confirm("Confirm", "Are you sure you want to delete that?",
206             function(btn) {
207                 if (btn != 'yes') {
208                     return;
209                 }
210                 //tab.grid.mask("Deleting");
211                 new Pman.Request({
212                     url: baseURL + '/Roo/'+tbl+'.php',
213                     method: 'POST',
214                     mask: true,
215                     params: {
216                         _delete : r.join(',')
217                     },
218                     success: function(response) {
219                         //tab.grid.unmask();
220                         if ( tab.paging ) {
221                             tab.paging.onClick('refresh');   
222                         } else if (tab.grid.footer && tab.grid.footer.onClick) {
223                             // new xtype built grids
224                             tab.grid.footer.onClick('refresh');   
225                         } else if (tab.refresh) {
226                             tab.refresh(); // this might cause problems as panels have a refresh method?
227                         } else {
228                             tab.grid.store.load();
229                         }
230                         
231                         
232                         
233                     },
234                     failure: function(act) {
235                         Roo.log(act);
236                         var msg = '';
237                         try {
238                             msg = act.errorMsg;
239                         } catch(e) {
240                             msg = "Error deleting";
241                         }
242                         //tab.grid.unmask();
243                         Roo.bootstrap.MessageBox.alert("Error",  msg);
244                     }
245                     
246                 });
247             }
248             
249         );
250         return '';
251     },
252     /* fired before building - check permissions on a component.. */
253     onBeforeBuild : function(obj) 
254     {
255         if (typeof(obj.part) == 'undefined')  {
256             return;
257         }
258            
259         if (!obj.part[1].length) {
260             obj.part[1] = obj.part[0];
261         }
262         var permname = obj.part.join('.');
263             
264         Roo.log("CHECKING: "+ permname);
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 });