1 //<script type="text/javascript">
5 * fires Pman 'authrefreshed' event on every poll to server..
10 re-arrange language code...
11 * flipping language should be like this:
13 * Ext.apply(_T, _T[lang]);
19 Pman.Login = new Roo.util.Observable({
33 authUser: { id : false },
39 checkConnection : false, // the Roo.data.Connection for checking if still authenticated.
41 onLoad : function() // called on page load...
46 if (Roo.get('loading')) {
47 Roo.get('loading').remove();
49 this.switchLang('en');
51 // check if we are logged in..
53 url: baseURL + '/Login.js',
58 success: function(response, opts) { // check successfull...
60 var res = Pman.processResponse(response);
62 if (!res.success) { // error!
64 //console.log('call failure');
65 return Pman.Login.failure(response,opts);
69 if (!res.data.id) { // id=0 == login failure.
70 return this.show(true);
72 Roo.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1');
75 //console.log(success);
76 this.fillAuth(res.data);
81 failure : Pman.Login.show,
88 check: function(again) // called every so often to refresh cookie etc..
90 if (again) { // could be undefined..
91 Pman.Login.checkFails++;
93 Pman.Login.checkFails = 0;
98 if ( Pman.Login.checkFails > 4) {
99 Pman.Preview.disable();
100 Roo.MessageBox.alert("Error",
101 "Error getting authentication status. - try reloading, or wait a while", function() {
102 _this.sending = false;
107 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
111 if (!this.checkConnection) {
112 this.checkConnection = new Roo.data.Connection();
114 this.checkConnection.request({
115 url: baseURL + '/Login.js',
120 success: Pman.Login.success,
121 failure : Pman.Login.failure,
129 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
132 this.sending = false;
133 var res = Pman.processResponse(response);
135 if ( Pman.Login.checkFails > 2) {
136 Pman.Preview.disable();
137 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
138 "Error getting authentication status. - try reloading");
142 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
147 success : function(response, opts) // check successfull...
149 this.sending = false;
150 var res = Pman.processResponse(response);
152 return this.failure(response, opts);
154 if (!res.data || !res.data.id) {
155 return this.failure(response,opts);
158 this.fillAuth(res.data);
166 if (Pman.Login.callback) {
167 Pman.Login.callback();
173 fillAuth: function(au) {
174 this.startAuthCheck();
175 this.authUserId = au.id;
177 this.lastChecked = new Date();
178 // if login is used on other applicaitons..
179 if (Pman.fireEvent) { Pman.fireEvent('authrefreshed', au); }
182 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
183 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
185 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
186 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
187 this.switchLang(au.lang);
190 // open system... - -on setyp..
191 if (this.authUserId < 0) {
192 Roo.MessageBox.alert("Warning",
193 "This is an open system - please set up a admin user with a password.");
196 //Pman.onload(); // which should do nothing if it's a re-auth result...
202 intervalID : false, /// the login refresher...
206 startAuthCheck : function() // starter for timeout checking..
208 if (Pman.Login.intervalID) { // timer already in place...
212 Pman.Login.intervalID = window.setInterval(function() {
213 Pman.Login.check(false);
214 }, 120000); // every 120 secs = 2mins..
227 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
228 { // the real end set is here...
245 // tabPosition: 'top',
248 alwaysShowTabs: false
255 this.dialog.addButton("Forgot Password", function()
258 var n = _this.form.findField('username').getValue();
260 Roo.MessageBox.alert("Error", "Fill in your email address");
264 url: baseURL + '/Login.js',
269 success: function(response, opts) { // check successfull...
271 var res = Pman.processResponse(response);
272 if (!res.success) { // error!
273 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
276 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
278 failure : function() {
279 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
285 this.dialog.addButton("Login", function()
287 Pman.Login.dialog.el.mask("Logging in");
288 Pman.Login.form.doAction('submit', {
289 url: baseURL + '/Login',
293 this.layout = this.dialog.getLayout();
294 this.layout.beginUpdate();
296 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
297 // generate some other tabs
298 this.form = new Roo.form.Form({
302 actionfailed : function(f, act) {
303 // form can return { errors: .... }
305 //act.result.errors // invalid form element list...
306 //act.result.errorMsg// invalid form element list...
308 Pman.Login.dialog.el.unmask();
309 var msg = act.result.errorMsg || act.result.message;
310 msg = msg || "Login failed - communication error - try again.";
311 Roo.MessageBox.alert("Error", msg);
314 actioncomplete: function(re, act) {
316 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
317 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
318 Pman.Login.fillAuth(act.result.data);
320 Pman.Login.dialog.hide();
321 if (Roo.get('loading-mask')) {
322 //Roo.get('loading').show();
323 Roo.get('loading-mask').show();
328 if (Pman.Login.callback) {
329 Pman.Login.callback();
345 new Roo.form.TextField({
346 fieldLabel: "Email Address",
349 autoCreate : {tag: "input", type: "text", size: "20"}
352 new Roo.form.TextField({
353 fieldLabel: "Password",
354 inputType: 'password',
357 autoCreate : {tag: "input", type: "text", size: "20"},
359 specialkey : function(e,ev) {
360 if (ev.keyCode == 13) {
361 Pman.Login.dialog.el.mask("Logging in");
362 Pman.Login.form.doAction('submit', {
363 url: baseURL + '/Login',
370 new Roo.form.ComboBox({
371 fieldLabel: "Language",
374 xtype : 'SimpleStore',
375 fields: ['lang', 'ldisp'],
378 [ 'zh_HK' , '\u7E41\u4E2D' ],
379 [ 'zh_CN', '\u7C21\u4E2D' ]
386 displayField:'ldisp',
390 triggerAction: 'all',
391 emptyText:'Select a Language...',
394 select : function(cb, rec, ix) {
397 Pman.Login.switchLang(rec.data.lang);
407 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
408 ef.dom.style.margin = 10;
410 this.form.render(ef.dom);
411 // logoprefix comes from base config.
413 var img = typeof(appLogo) != 'undefined' && appLogo.length ? appLogo :
414 rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif' ;
416 Pman.Login.form.el.createChild({
419 style: 'margin-bottom: 10px;'
421 Pman.Login.form.el.dom.firstChild
424 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
426 //title: 'Org Details',
433 this.layout.endUpdate();
435 this.fireEvent('render', this);
442 resizeToLogo : function()
444 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
446 this.resizeToLogo.defer(1000,this);
449 var w = Roo.lib.Dom.getViewWidth() - 100;
450 var h = Roo.lib.Dom.getViewHeight() - 100;
451 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
452 Pman.Login.dialog.center();
457 show: function (modal, cb)
465 this.callback = cb; // used for non-pman usage..
466 modal = modal || false;
467 if (Pman.Login.authUserId < 0) { // logout!?
471 if (Pman.Login.intervalID) {
473 window.clearInterval(Pman.Login.intervalID);
474 Pman.Login.intervalID = false;
481 if (Roo.get('loading')) {
482 Roo.get('loading').remove();
484 if (Roo.get('loading-mask')) {
485 Roo.get('loading-mask').hide();
488 //incomming._node = tnode;
489 // why we want this non-modal????
491 this.dialog.modal = !modal;
493 this.dialog.el.unmask();
494 this.resizeToLogo.defer(1000,this);
496 // if we have not created a provider.. do it now...
497 if (!Roo.state.Manager.getProvider().expires) {
498 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
502 this.form.setValues({
503 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
504 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
506 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
507 if (this.form.findField('username').getValue().length > 0 ){
508 this.form.findField('password').focus();
510 this.form.findField('username').focus();
520 window.onbeforeunload = function() { }; // false does not work for IE..
521 Pman.Login.authUserId = -1;
523 url: baseURL + '/Login.html',
528 failure : function() {
529 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
530 document.location = baseURL + '?ts=' + Math.random();
534 success : function() {
535 Pman.Login.authUserId = -1;
536 Pman.Login.checkFails =0;
538 document.location = baseURL + '?ts=' + Math.random();
544 switchLang : function (lang) {
545 if (!lang || !lang.length) {
548 if (typeof(_T.en) == 'undefined') {
550 Roo.apply(_T.en, _T);
553 if (typeof(_T[lang]) == 'undefined') {
554 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
559 Roo.apply(_T, _T[lang]);
560 // just need to set the text values for everything...
564 function formLabel(name, val) {
566 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
567 if (lbl.getElementsByTagName('label').length) {
568 lbl = lbl.getElementsByTagName('label')[0];
570 lbl = lbl.parentNode.getElementsByTagName('label')[0];
576 formLabel('password', "Password"+':');
577 formLabel('username', "Email Address"+':');
578 formLabel('lang', "Language"+':');
579 this.dialog.setTitle("Login");
580 this.dialog.buttons[0].setText("Forgot Password");
581 this.dialog.buttons[1].setText("Login");
587 inGroup : function(g)
589 return this.authUser && this.authUser.groups &&
590 this.authUser.groups.indexOf(g) > -1;
594 return this.authUser && this.authUser.company_id_comptype &&
595 this.authUser.company_id_comptype == 'OWNER';
599 * Depreciated = use Pman.I18n
602 i18nList: function (type, codes)
605 return Pman.I18n.listToNames(type, codes);
607 i18n: function(type, code)
609 return Pman.I18n.toName(type, code);