1 //<script type="text/javascript">
5 * A generic Login Dialog..... - only one needed in theory!?!?
7 * Fires XComponent builder on success...
10 * username,password, lang = for login actions.
11 * check = 1 for periodic checking that sesion is valid.
12 * passwordRequest = email request password
13 * logout = 1 = to logout
15 * Affects: (this id="????" elements)
16 * loading (removed) (used to indicate application is loading)
17 * loading-mask (hides) (used to hide application when it's building loading)
23 * Myapp.login = Roo.Login({
37 * Ext.apply(_T, _T[lang]);
41 Roo.Login = function(cfg)
49 Roo.onReady(function() {
53 Roo.Login.superclass.constructor.call(this, {});
54 Roo.each(this.items, function(e) {
62 Roo.extend(Roo.Login, Roo.LayoutDialog, {
65 * @cfg {String} method
66 * Method used to query for login details.
72 * URL to query login data. - eg. baseURL + '/Login.php'
78 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
84 onLoad : function() // called on page load...
88 if (Roo.get('loading')) { // clear any loading indicator..
89 Roo.get('loading').remove();
92 //this.switchLang('en'); // set the language to english..
95 success: function(response, opts) { // check successfull...
97 var res = Pman.processResponse(response);
99 if (!res.success) { // error!
101 //console.log('call failure');
102 return this.failure(response,opts);
105 if (!res.data.id) { // id=0 == login failure.
106 return this.show(true);
110 //console.log(success);
111 this.fillAuth(res.data);
113 Roo.XComponent.build();
121 check: function(cfg) // called every so often to refresh cookie etc..
123 if (cfg.again) { // could be undefined..
130 if ( this.checkFails > 4) {
131 Roo.MessageBox.alert("Error",
132 "Error getting authentication status. - try reloading, or wait a while", function() {
133 _this.sending = false;
138 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
149 success: cfg.success || this.success,
150 failure : cfg.failure || this.failure,
160 window.onbeforeunload = function() { }; // false does not work for IE..
170 failure : function() {
171 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
172 document.location = document.location.toString() + '?ts=' + Math.random();
176 success : function() {
180 document.location = document.location.toString() + '?ts=' + Math.random();
189 success : function(response, opts) // check successfull...
191 this.sending = false;
192 var res = Pman.processResponse(response);
194 return this.failure(response, opts);
196 if (!res.data || !res.data.id) {
197 return this.failure(response,opts);
200 this.fillAuth(res.data);
207 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
210 this.sending = false;
211 var res = Pman.processResponse(response);
213 if ( Pman.Login.checkFails > 2) {
215 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
216 "Error getting authentication status. - try reloading");
219 opts.callCfg.again = true;
220 this.check.defer(1000, this, [ opts.callCfg ]);
226 fillAuth: function(au) {
227 this.startAuthCheck();
228 this.authUserId = au.id;
230 this.lastChecked = new Date();
231 this.fireEvent('refreshed', au);
232 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
233 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
235 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
236 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
237 this.switchLang(au.lang);
240 // open system... - -on setyp..
241 if (this.authUserId < 0) {
242 Roo.MessageBox.alert("Warning",
243 "This is an open system - please set up a admin user with a password.");
246 //Pman.onload(); // which should do nothing if it's a re-auth result...
251 startAuthCheck : function() // starter for timeout checking..
253 if (Pman.Login.intervalID) { // timer already in place...
257 Pman.Login.intervalID = window.setInterval(function() {
258 Pman.Login.check(false);
259 }, 120000); // every 120 secs = 2mins..
265 switchLang : function (lang)
267 if (!_T && lang != 'en') {
268 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
271 if (!_T || !lang.length) {
275 if (typeof(_T.en) == 'undefined') {
277 Roo.apply(_T.en, _T);
280 if (typeof(_T[lang]) == 'undefined') {
281 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
286 Roo.apply(_T, _T[lang]);
287 // just need to set the text values for everything...
289 /* this will not work ...
293 function formLabel(name, val) {
294 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
297 formLabel('password', "Password"+':');
298 formLabel('username', "Email Address"+':');
299 formLabel('lang', "Language"+':');
300 this.dialog.setTitle("Login");
301 this.dialog.buttons[0].setText("Forgot Password");
302 this.dialog.buttons[1].setText("Login");
322 center: { // needed??
325 // tabPosition: 'top',
328 alwaysShowTabs: false
332 rendered : function(dlg) {
333 this.form = this.items[0];
334 this.form.dialog = dlg;
335 this.buttons[0].form = this.form;
336 this.buttons[0].dialog = dlg
337 this.buttons[1].form = this.form;
338 this.buttons[1].dialog = dlg;
340 // logoprefix comes from base config.
341 //Pman.Login.form.el.createChild({
343 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
344 // style: 'margin-bottom: 10px;'
353 //this.resizeToLogo.defer(1000,this);
354 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
356 // this.resizeToLogo.defer(1000,this);
359 var w = Ext.lib.Dom.getViewWidth() - 100;
360 var h = Ext.lib.Dom.getViewHeight() - 100;
361 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
368 if (this.user.id < 0) { // used for inital setup situations.
372 if (this.intervalID) {
374 window.clearInterval(this.intervalID);
375 this.intervalID = false;
379 if (Roo.get('loading')) {
380 Roo.get('loading').remove();
382 if (Roo.get('loading-mask')) {
383 Roo.get('loading-mask').hide();
386 //incomming._node = tnode;
388 //this.dialog.modal = !modal;
389 //this.dialog.show();
390 this.dialog.el.unmask();
393 this.form.setValues({
394 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
395 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
398 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
399 if (this.form.findField('username').getValue().length > 0 ){
400 this.form.findField('password').focus();
402 this.form.findField('username').focus();
410 xtype : 'ContentPanel',
421 style : 'margin : 10px;',
423 actionfailed : function(f, act) {
424 // form can return { errors: .... }
426 //act.result.errors // invalid form element list...
427 //act.result.errorMsg// invalid form element list...
429 this.dialog.el.unmask();
430 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
431 "Login failed - communication error - try again.");
434 actioncomplete: function(re, act) {
436 Roo.state.Manager.set(
437 this.dialog.realm + '.username',
438 this.form.findField('username').getValue()
440 Roo.state.Manager.set(
441 this.dialog.realm + '.lang',
442 Pman.Login.form.findField('lang').getValue()
445 this.dialog.fillAuth(act.result.data);
449 if (Roo.get('loading-mask')) {
450 Roo.get('loading-mask').show();
452 Roo.XComponent.build();
462 fieldLabel: "Email Address",
465 autoCreate : {tag: "input", type: "text", size: "20"}
470 fieldLabel: "Password",
471 inputType: 'password',
474 autoCreate : {tag: "input", type: "text", size: "20"},
476 specialkey : function(e,ev) {
477 if (ev.keyCode == 13) {
478 this.form.dialog.el.mask("Logging in");
479 this.form.doAction('submit', {
480 url: this.form.dialog.url,
481 method: this.form.dialog.method,
490 fieldLabel: "Language",
493 xtype : 'SimpleStore',
494 fields: ['lang', 'ldisp'],
497 [ 'zh_HK' , '\u7E41\u4E2D' ],
498 [ 'zh_CN', '\u7C21\u4E2D' ]
505 displayField:'ldisp',
509 triggerAction: 'all',
510 emptyText:'Select a Language...',
513 select : function(cb, rec, ix) {
514 this.form.switchLang(rec.data.lang);
528 text : "Forgot Password",
532 var n = this.form.findField('username').getValue();
534 Roo.MessageBox.alert("Error", "Fill in your email address");
542 method: this.dialog.method,
543 success: function(response, opts) { // check successfull...
545 var res = Pman.processResponse(response);
546 if (!res.success) { // error!
547 Roo.MessageBox.alert("Error" ,
548 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
551 Roo.MessageBox.alert("Notice" ,
552 "Please check you email for the Password Reset message");
554 failure : function() {
555 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
568 this.dialog.el.mask("Logging in");
569 this.form.doAction('submit', {
571 method: this.dialog.method
580 Pman.Login = new Roo.util.Observable({
593 authUser: { id : false },
603 intervalID : false, /// the login refresher...