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