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         
49     },
50     listeners : {
51         'ready' : function()
52         {
53             
54
55             // kludge to fix firebug debugger
56             if (typeof(console) == 'undefined') {
57                 console = { log : function() {  } };
58             }
59             
60             // remove loader..
61             if (Roo.get('loading')) {
62                 Roo.get('loading').remove();
63             }
64             
65             Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
66             Roo.QuickTips.init(); 
67
68              
69             // reset password!!!!
70             /*
71             if (showNewPass.length) {
72                 Pman.PasswordChange.show(  { passwordReset : showNewPass },
73                     function(data) {
74                         // fail and success we do  a load...
75                         Pman.Login.onLoad();
76                     }
77                 );
78                 return;
79             }
80             */
81             Pman.Login.onLoad();
82             
83         },
84         'load' : function()
85         {
86             if (Roo.get('loading-logo-tile')) {
87                 Roo.get('loading-logo-tile').remove();
88             }
89             if (Roo.get('loading-logo-tile-top')) {
90                 Roo.get('loading-logo-tile-top').remove();
91             }
92             if (Roo.get('loading-logo-bottom')) {
93                 Roo.get('loading-logo-bottom').remove();
94             }
95             if (Roo.get('loading-logo-center')) {
96                 Roo.get('loading-logo-center').remove();
97             }
98         }   
99         
100     },
101     loadUserInterface : function()
102     {
103         // triggers after authentication verified...
104         
105         if (Roo.get('loading')) {
106             Roo.get('loading').remove();
107         }
108         if (Roo.get('loading-mask')) {
109             Roo.get('loading-mask').show();
110         }
111         
112         document.title = appName + ' v' + AppVersion + ' - ' + au.company_id_name;
113         
114         
115         if (Roo.isGecko) {
116            Roo.useShims = true;
117         }
118        
119         
120         Pman.building = true;
121         
122         Roo.XComponent.on('buildcomplete',  this.onBuildComplete, this);
123         Roo.XComponent.build();
124          
125         
126     },
127     
128     finalize : function() {
129         
130       
131        
132         window.onbeforeunload = function(e) { 
133             e = e || window.event;
134             var r = "Closing this window will loose changes, are you sure you want to do that?";
135
136             // For IE and Firefox
137             if (e) {
138                 e.returnValue = r;
139             }
140
141             // For Safari
142             return r;
143             
144         };
145         
146         Roo.bootstrap.MessageBox.hide();
147         
148         if (Roo.get('loading-mask')) {
149            Roo.get('loading-mask').remove();
150         }
151         
152         
153         this.buildCompleted = true; // now we can force refreshes on everything..
154         
155         
156         // does the URL indicate we want to see a system..
157        
158         // Open system..
159         
160         var forceAdmin = function(data)
161         {
162             if (!data || !data.id) {
163                 //Roo.log("Force Admin");
164                 Pman.Dialog.PersonStaff.show( 
165                     { 
166                         id : 0, 
167                         company_id : Pman.Login.authUser.company_id_id * 1, 
168                         company_id_name : Pman.Login.authUser.company_id_name
169                     }, function(data) {
170                         forceAdmin(data);
171                     }
172                 );
173                 return;
174             }
175             Roo.state.Manager.set('Pman.Login.username', data.email),
176             window.onbeforeunload = false;
177             document.location = baseURL + '?ts=' + Math.random();
178         }
179         
180         var forceCompany = function(data) {
181             if (Pman.Login.authUser.company_id * 1 > 0) {
182                 forceAdmin();
183                 return;
184             }
185             if (!data || !data.id) {
186                 Pman.Dialog.CoreCompanies.show( { id : 0, comptype: 'OWNER' }, function(data) {
187                     Roo.log("company dialog returned");
188                     Roo.log(data);
189                     forceCompany(data);
190                 });
191                 return;
192             }
193             Pman.Login.authUser.company_id_id  = data.id;
194             Pman.Login.authUser.company_id  = data.id;
195             Pman.Login.authUser.company_id_name  = data.name;
196             Roo.log("forcing admin");
197             forceAdmin();
198         }
199         
200         if (Pman.Login.authUser.id < 0) {
201             // admin company has been created - create the user..
202             if (Pman.Login.authUser.company_id_id* 1 > 0) {
203                 forceAdmin();
204                 return;
205             }
206             
207             forceCompany();
208             /// create account..
209             
210             
211         }
212         
213
214     }
215 });