1 //<script type="text/javascript">
6 * @extends Roo.LayoutDialog
7 * A generic Login Dialog..... - only one needed in theory!?!?
9 * Fires XComponent builder on success...
12 * username,password, lang = for login actions.
13 * check = 1 for periodic checking that sesion is valid.
14 * passwordRequest = email request password
15 * logout = 1 = to logout
17 * Affects: (this id="????" elements)
18 * loading (removed) (used to indicate application is loading)
19 * loading-mask (hides) (used to hide application when it's building loading)
25 * Myapp.login = Roo.Login({
41 Roo.Login = function(cfg)
49 Roo.onReady(function() {
55 Roo.Login.superclass.constructor.call(this, this);
56 //this.addxtype(this.items[0]);
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.
83 * @property checkFails
84 * Number of times we have attempted to get authentication check, and failed.
89 * @property intervalID
90 * The window interval that does the constant login checking.
96 onLoad : function() // called on page load...
100 if (Roo.get('loading')) { // clear any loading indicator..
101 Roo.get('loading').remove();
104 //this.switchLang('en'); // set the language to english..
107 success: function(response, opts) { // check successfull...
109 var res = this.processResponse(response);
111 if (!res.success) { // error!
113 //console.log('call failure');
114 return this.failure(response,opts);
117 if (!res.data.id) { // id=0 == login failure.
122 //console.log(success);
123 this.fillAuth(res.data);
125 Roo.XComponent.build();
133 check: function(cfg) // called every so often to refresh cookie etc..
135 if (cfg.again) { // could be undefined..
142 if ( this.checkFails > 4) {
143 Roo.MessageBox.alert("Error",
144 "Error getting authentication status. - try reloading, or wait a while", function() {
145 _this.sending = false;
150 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
161 success: cfg.success || this.success,
162 failure : cfg.failure || this.failure,
172 window.onbeforeunload = function() { }; // false does not work for IE..
182 failure : function() {
183 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
184 document.location = document.location.toString() + '?ts=' + Math.random();
188 success : function() {
192 document.location = document.location.toString() + '?ts=' + Math.random();
199 processResponse : function (response)
203 res = Roo.decode(response.responseText);
205 if (typeof(res) != 'object') {
206 res = { success : false, errorMsg : res, errors : true };
208 if (typeof(res.success) == 'undefined') {
213 res = { success : false, errorMsg : response.responseText, errors : true };
218 success : function(response, opts) // check successfull...
220 this.sending = false;
221 var res = this.processResponse(response);
223 return this.failure(response, opts);
225 if (!res.data || !res.data.id) {
226 return this.failure(response,opts);
229 this.fillAuth(res.data);
236 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
239 this.sending = false;
240 var res = this.processResponse(response);
242 if ( this.checkFails > 2) {
244 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
245 "Error getting authentication status. - try reloading");
248 opts.callCfg.again = true;
249 this.check.defer(1000, this, [ opts.callCfg ]);
255 fillAuth: function(au) {
256 this.startAuthCheck();
257 this.authUserId = au.id;
259 this.lastChecked = new Date();
260 this.fireEvent('refreshed', au);
261 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
262 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
263 au.lang = au.lang || 'en';
264 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
265 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
266 this.switchLang(au.lang );
269 // open system... - -on setyp..
270 if (this.authUserId < 0) {
271 Roo.MessageBox.alert("Warning",
272 "This is an open system - please set up a admin user with a password.");
275 //Pman.onload(); // which should do nothing if it's a re-auth result...
280 startAuthCheck : function() // starter for timeout checking..
282 if (this.intervalID) { // timer already in place...
286 this.intervalID = window.setInterval(function() {
288 }, 120000); // every 120 secs = 2mins..
294 switchLang : function (lang)
296 _T = typeof(_T) == 'undefined' ? false : _T;
297 if (!_T || !lang.length) {
301 if (!_T && lang != 'en') {
302 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
306 if (typeof(_T.en) == 'undefined') {
308 Roo.apply(_T.en, _T);
311 if (typeof(_T[lang]) == 'undefined') {
312 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
317 Roo.apply(_T, _T[lang]);
318 // just need to set the text values for everything...
320 /* this will not work ...
324 function formLabel(name, val) {
325 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
328 formLabel('password', "Password"+':');
329 formLabel('username', "Email Address"+':');
330 formLabel('lang', "Language"+':');
331 this.dialog.setTitle("Login");
332 this.dialog.buttons[0].setText("Forgot Password");
333 this.dialog.buttons[1].setText("Login");
354 center: { // needed??
357 // tabPosition: 'top',
360 alwaysShowTabs: false
367 this.form = this.layout.getRegion('center').activePanel.form;
368 this.form.dialog = dlg;
369 this.buttons[0].form = this.form;
370 this.buttons[0].dialog = dlg;
371 this.buttons[1].form = this.form;
372 this.buttons[1].dialog = dlg;
374 //this.resizeToLogo.defer(1000,this);
375 // this is all related to resizing for logos..
376 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
378 // this.resizeToLogo.defer(1000,this);
381 //var w = Ext.lib.Dom.getViewWidth() - 100;
382 //var h = Ext.lib.Dom.getViewHeight() - 100;
383 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
390 if (this.user.id < 0) { // used for inital setup situations.
394 if (this.intervalID) {
396 window.clearInterval(this.intervalID);
397 this.intervalID = false;
401 if (Roo.get('loading')) {
402 Roo.get('loading').remove();
404 if (Roo.get('loading-mask')) {
405 Roo.get('loading-mask').hide();
408 //incomming._node = tnode;
410 //this.dialog.modal = !modal;
411 //this.dialog.show();
415 this.form.setValues({
416 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
417 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
420 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', 'en'));
421 if (this.form.findField('username').getValue().length > 0 ){
422 this.form.findField('password').focus();
424 this.form.findField('username').focus();
432 xtype : 'ContentPanel',
444 style : 'margin: 10px;',
447 actionfailed : function(f, act) {
448 // form can return { errors: .... }
450 //act.result.errors // invalid form element list...
451 //act.result.errorMsg// invalid form element list...
453 this.dialog.el.unmask();
454 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
455 "Login failed - communication error - try again.");
458 actioncomplete: function(re, act) {
460 Roo.state.Manager.set(
461 this.dialog.realm + '.username',
462 this.findField('username').getValue()
464 Roo.state.Manager.set(
465 this.dialog.realm + '.lang',
466 this.findField('lang').getValue()
469 this.dialog.fillAuth(act.result.data);
473 if (Roo.get('loading-mask')) {
474 Roo.get('loading-mask').show();
476 Roo.XComponent.build();
486 fieldLabel: "Email Address",
489 autoCreate : {tag: "input", type: "text", size: "20"}
494 fieldLabel: "Password",
495 inputType: 'password',
498 autoCreate : {tag: "input", type: "text", size: "20"},
500 specialkey : function(e,ev) {
501 if (ev.keyCode == 13) {
502 this.form.dialog.el.mask("Logging in");
503 this.form.doAction('submit', {
504 url: this.form.dialog.url,
505 method: this.form.dialog.method
514 fieldLabel: "Language",
517 xtype : 'SimpleStore',
518 fields: ['lang', 'ldisp'],
521 [ 'zh_HK' , '\u7E41\u4E2D' ],
522 [ 'zh_CN', '\u7C21\u4E2D' ]
529 displayField:'ldisp',
533 triggerAction: 'all',
534 emptyText:'Select a Language...',
537 select : function(cb, rec, ix) {
538 this.form.switchLang(rec.data.lang);
554 text : "Forgot Password",
558 var n = this.form.findField('username').getValue();
560 Roo.MessageBox.alert("Error", "Fill in your email address");
564 url: this.dialog.url,
568 method: this.dialog.method,
569 success: function(response, opts) { // check successfull...
571 var res = this.dialog.processResponse(response);
572 if (!res.success) { // error!
573 Roo.MessageBox.alert("Error" ,
574 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
577 Roo.MessageBox.alert("Notice" ,
578 "Please check you email for the Password Reset message");
580 failure : function() {
581 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
594 click : function () {
596 this.dialog.el.mask("Logging in");
597 this.form.doAction('submit', {
598 url: this.dialog.url,
599 method: this.dialog.method