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);
74 //console.log(success);
75 this.fillAuth(res.data);
80 failure : Pman.Login.show,
87 check: function(again) // called every so often to refresh cookie etc..
89 if (again) { // could be undefined..
90 Pman.Login.checkFails++;
92 Pman.Login.checkFails = 0;
97 if ( Pman.Login.checkFails > 4) {
98 Pman.Preview.disable();
99 Roo.MessageBox.alert("Error",
100 "Error getting authentication status. - try reloading, or wait a while", function() {
101 _this.sending = false;
106 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
110 if (!this.checkConnection) {
111 this.checkConnection = new Roo.data.Connection();
113 this.checkConnection.request({
114 url: baseURL + '/Login.js',
119 success: Pman.Login.success,
120 failure : Pman.Login.failure,
128 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
131 this.sending = false;
132 var res = Pman.processResponse(response);
134 if ( Pman.Login.checkFails > 2) {
135 Pman.Preview.disable();
136 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
137 "Error getting authentication status. - try reloading");
141 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
146 success : function(response, opts) // check successfull...
148 this.sending = false;
149 var res = Pman.processResponse(response);
151 return this.failure(response, opts);
153 if (!res.data || !res.data.id) {
154 return this.failure(response,opts);
157 this.fillAuth(res.data);
165 if (Pman.Login.callback) {
166 Pman.Login.callback();
172 fillAuth: function(au) {
173 this.startAuthCheck();
174 this.authUserId = au.id;
176 this.lastChecked = new Date();
177 // if login is used on other applicaitons..
178 if (Pman.fireEvent) { Pman.fireEvent('authrefreshed', au); }
181 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
182 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
184 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
185 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
186 this.switchLang(au.lang);
189 // open system... - -on setyp..
190 if (this.authUserId < 0) {
191 Roo.MessageBox.alert("Warning",
192 "This is an open system - please set up a admin user with a password.");
195 //Pman.onload(); // which should do nothing if it's a re-auth result...
201 intervalID : false, /// the login refresher...
205 startAuthCheck : function() // starter for timeout checking..
207 if (Pman.Login.intervalID) { // timer already in place...
211 Pman.Login.intervalID = window.setInterval(function() {
212 Pman.Login.check(false);
213 }, 120000); // every 120 secs = 2mins..
226 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
227 { // the real end set is here...
244 // tabPosition: 'top',
247 alwaysShowTabs: false
254 this.dialog.addButton("Forgot Password", function()
257 var n = _this.form.findField('username').getValue();
259 Roo.MessageBox.alert("Error", "Fill in your email address");
263 url: baseURL + '/Login.js',
268 success: function(response, opts) { // check successfull...
270 var res = Pman.processResponse(response);
271 if (!res.success) { // error!
272 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
275 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
277 failure : function() {
278 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
284 this.dialog.addButton("Login", function()
286 Pman.Login.dialog.el.mask("Logging in");
287 Pman.Login.form.doAction('submit', {
288 url: baseURL + '/Login',
292 this.layout = this.dialog.getLayout();
293 this.layout.beginUpdate();
295 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
296 // generate some other tabs
297 this.form = new Roo.form.Form({
301 actionfailed : function(f, act) {
302 // form can return { errors: .... }
304 //act.result.errors // invalid form element list...
305 //act.result.errorMsg// invalid form element list...
307 Pman.Login.dialog.el.unmask();
308 var msg = act.result.errorMsg || act.result.message;
309 msg = msg || "Login failed - communication error - try again.";
310 Roo.MessageBox.alert("Error", msg);
313 actioncomplete: function(re, act) {
315 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
316 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
317 Pman.Login.fillAuth(act.result.data);
319 Pman.Login.dialog.hide();
320 if (Roo.get('loading-mask')) {
321 //Roo.get('loading').show();
322 Roo.get('loading-mask').show();
327 if (Pman.Login.callback) {
328 Pman.Login.callback();
344 new Roo.form.TextField({
345 fieldLabel: "Email Address",
348 autoCreate : {tag: "input", type: "text", size: "20"}
351 new Roo.form.TextField({
352 fieldLabel: "Password",
353 inputType: 'password',
356 autoCreate : {tag: "input", type: "text", size: "20"},
358 specialkey : function(e,ev) {
359 if (ev.keyCode == 13) {
360 Pman.Login.dialog.el.mask("Logging in");
361 Pman.Login.form.doAction('submit', {
362 url: baseURL + '/Login',
369 new Roo.form.ComboBox({
370 fieldLabel: "Language",
373 xtype : 'SimpleStore',
374 fields: ['lang', 'ldisp'],
377 [ 'zh_HK' , '\u7E41\u4E2D' ],
378 [ 'zh_CN', '\u7C21\u4E2D' ]
385 displayField:'ldisp',
389 triggerAction: 'all',
390 emptyText:'Select a Language...',
393 select : function(cb, rec, ix) {
396 Pman.Login.switchLang(rec.data.lang);
406 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
407 ef.dom.style.margin = 10;
409 this.form.render(ef.dom);
410 // logoprefix comes from base config - normally the owner company logo...
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
422 ).on('error', function() {
423 this.dom.style.visibility = 'hidden';
424 this.dom.style.height = '10px';
427 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
429 //title: 'Org Details',
436 this.layout.endUpdate();
438 this.fireEvent('render', this);
445 resizeToLogo : function()
447 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
449 this.resizeToLogo.defer(1000,this);
452 var w = Roo.lib.Dom.getViewWidth() - 100;
453 var h = Roo.lib.Dom.getViewHeight() - 100;
454 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
455 Pman.Login.dialog.center();
460 show: function (modal, cb)
468 this.callback = cb; // used for non-pman usage..
469 modal = modal || false;
470 if (Pman.Login.authUserId < 0) { // logout!?
474 if (Pman.Login.intervalID) {
476 window.clearInterval(Pman.Login.intervalID);
477 Pman.Login.intervalID = false;
484 if (Roo.get('loading')) {
485 Roo.get('loading').remove();
487 if (Roo.get('loading-mask')) {
488 Roo.get('loading-mask').hide();
491 //incomming._node = tnode;
492 // why we want this non-modal????
494 this.dialog.modal = !modal;
496 this.dialog.el.unmask();
497 this.resizeToLogo.defer(1000,this);
499 // if we have not created a provider.. do it now...
500 if (!Roo.state.Manager.getProvider().expires) {
501 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
505 this.form.setValues({
506 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
507 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
509 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
510 if (this.form.findField('username').getValue().length > 0 ){
511 this.form.findField('password').focus();
513 this.form.findField('username').focus();
523 window.onbeforeunload = function() { }; // false does not work for IE..
524 Pman.Login.authUserId = -1;
526 url: baseURL + '/Login.html',
531 failure : function() {
532 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
533 document.location = baseURL + '?ts=' + Math.random();
537 success : function() {
538 Pman.Login.authUserId = -1;
539 Pman.Login.checkFails =0;
541 document.location = baseURL + '?ts=' + Math.random();
547 switchLang : function (lang) {
548 if (!lang || !lang.length) {
551 if (typeof(_T.en) == 'undefined') {
553 Roo.apply(_T.en, _T);
556 if (typeof(_T[lang]) == 'undefined') {
557 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
562 Roo.apply(_T, _T[lang]);
563 // just need to set the text values for everything...
567 function formLabel(name, val) {
569 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
570 if (lbl.getElementsByTagName('label').length) {
571 lbl = lbl.getElementsByTagName('label')[0];
573 lbl = lbl.parentNode.getElementsByTagName('label')[0];
579 formLabel('password', "Password"+':');
580 formLabel('username', "Email Address"+':');
581 formLabel('lang', "Language"+':');
582 this.dialog.setTitle("Login");
583 this.dialog.buttons[0].setText("Forgot Password");
584 this.dialog.buttons[1].setText("Login");
590 inGroup : function(g)
592 return this.authUser && this.authUser.groups &&
593 this.authUser.groups.indexOf(g) > -1;
597 return this.authUser && this.authUser.company_id_comptype &&
598 this.authUser.company_id_comptype == 'OWNER';
602 * Depreciated = use Pman.I18n
605 i18nList: function (type, codes)
608 return Pman.I18n.listToNames(type, codes);
610 i18n: function(type, code)
612 return Pman.I18n.toName(type, code);