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