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