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() {
58 Roo.Login.superclass.constructor.call(this, this);
59 //this.addxtype(this.items[0]);
65 Roo.extend(Roo.Login, Roo.LayoutDialog, {
68 * @cfg {String} method
69 * Method used to query for login details.
75 * URL to query login data. - eg. baseURL + '/Login.php'
81 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
86 * @property checkFails
87 * Number of times we have attempted to get authentication check, and failed.
92 * @property intervalID
93 * The window interval that does the constant login checking.
99 onLoad : function() // called on page load...
103 if (Roo.get('loading')) { // clear any loading indicator..
104 Roo.get('loading').remove();
107 //this.switchLang('en'); // set the language to english..
110 success: function(response, opts) { // check successfull...
112 var res = this.processResponse(response);
114 if (!res.success) { // error!
116 //console.log('call failure');
117 return this.failure(response,opts);
120 if (!res.data.id) { // id=0 == login failure.
125 //console.log(success);
126 this.fillAuth(res.data);
128 Roo.XComponent.build();
136 check: function(cfg) // called every so often to refresh cookie etc..
138 if (cfg.again) { // could be undefined..
145 if ( this.checkFails > 4) {
146 Roo.MessageBox.alert("Error",
147 "Error getting authentication status. - try reloading, or wait a while", function() {
148 _this.sending = false;
153 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
164 success: cfg.success || this.success,
165 failure : cfg.failure || this.failure,
175 window.onbeforeunload = function() { }; // false does not work for IE..
185 failure : function() {
186 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
187 document.location = document.location.toString() + '?ts=' + Math.random();
191 success : function() {
195 document.location = document.location.toString() + '?ts=' + Math.random();
202 processResponse : function (response)
206 res = Roo.decode(response.responseText);
208 if (typeof(res) != 'object') {
209 res = { success : false, errorMsg : res, errors : true };
211 if (typeof(res.success) == 'undefined') {
216 res = { success : false, errorMsg : response.responseText, errors : true };
221 success : function(response, opts) // check successfull...
223 this.sending = false;
224 var res = this.processResponse(response);
226 return this.failure(response, opts);
228 if (!res.data || !res.data.id) {
229 return this.failure(response,opts);
232 this.fillAuth(res.data);
239 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
242 this.sending = false;
243 var res = this.processResponse(response);
245 if ( this.checkFails > 2) {
247 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
248 "Error getting authentication status. - try reloading");
251 opts.callCfg.again = true;
252 this.check.defer(1000, this, [ opts.callCfg ]);
258 fillAuth: function(au) {
259 this.startAuthCheck();
260 this.authUserId = au.id;
262 this.lastChecked = new Date();
263 this.fireEvent('refreshed', au);
264 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
265 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
267 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
268 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
269 this.switchLang(au.lang);
272 // open system... - -on setyp..
273 if (this.authUserId < 0) {
274 Roo.MessageBox.alert("Warning",
275 "This is an open system - please set up a admin user with a password.");
278 //Pman.onload(); // which should do nothing if it's a re-auth result...
283 startAuthCheck : function() // starter for timeout checking..
285 if (this.intervalID) { // timer already in place...
289 this.intervalID = window.setInterval(function() {
291 }, 120000); // every 120 secs = 2mins..
297 switchLang : function (lang)
299 if (!_T && lang != 'en') {
300 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
303 if (!_T || !lang.length) {
307 if (typeof(_T.en) == 'undefined') {
309 Roo.apply(_T.en, _T);
312 if (typeof(_T[lang]) == 'undefined') {
313 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
318 Roo.apply(_T, _T[lang]);
319 // just need to set the text values for everything...
321 /* this will not work ...
325 function formLabel(name, val) {
326 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
329 formLabel('password', "Password"+':');
330 formLabel('username', "Email Address"+':');
331 formLabel('lang', "Language"+':');
332 this.dialog.setTitle("Login");
333 this.dialog.buttons[0].setText("Forgot Password");
334 this.dialog.buttons[1].setText("Login");
354 center: { // needed??
357 // tabPosition: 'top',
360 alwaysShowTabs: false
364 rendered : function(dlg) {
365 this.form = this.items[0];
366 this.form.dialog = dlg;
367 this.buttons[0].form = this.form;
368 this.buttons[0].dialog = dlg
369 this.buttons[1].form = this.form;
370 this.buttons[1].dialog = dlg;
372 // logoprefix comes from base config.
373 //Pman.Login.form.el.createChild({
375 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
376 // style: 'margin-bottom: 10px;'
385 //this.resizeToLogo.defer(1000,this);
386 // this is all related to resizing for logos..
387 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
389 // this.resizeToLogo.defer(1000,this);
392 //var w = Ext.lib.Dom.getViewWidth() - 100;
393 //var h = Ext.lib.Dom.getViewHeight() - 100;
394 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
401 if (this.user.id < 0) { // used for inital setup situations.
405 if (this.intervalID) {
407 window.clearInterval(this.intervalID);
408 this.intervalID = false;
412 if (Roo.get('loading')) {
413 Roo.get('loading').remove();
415 if (Roo.get('loading-mask')) {
416 Roo.get('loading-mask').hide();
419 //incomming._node = tnode;
421 //this.dialog.modal = !modal;
422 //this.dialog.show();
423 this.dialog.el.unmask();
426 this.form.setValues({
427 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
428 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
431 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
432 if (this.form.findField('username').getValue().length > 0 ){
433 this.form.findField('password').focus();
435 this.form.findField('username').focus();
443 xtype : 'ContentPanel',
454 style : 'margin : 10px;',
456 actionfailed : function(f, act) {
457 // form can return { errors: .... }
459 //act.result.errors // invalid form element list...
460 //act.result.errorMsg// invalid form element list...
462 this.dialog.el.unmask();
463 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
464 "Login failed - communication error - try again.");
467 actioncomplete: function(re, act) {
469 Roo.state.Manager.set(
470 this.dialog.realm + '.username',
471 this.findField('username').getValue()
473 Roo.state.Manager.set(
474 this.dialog.realm + '.lang',
475 this.findField('lang').getValue()
478 this.dialog.fillAuth(act.result.data);
482 if (Roo.get('loading-mask')) {
483 Roo.get('loading-mask').show();
485 Roo.XComponent.build();
495 fieldLabel: "Email Address",
498 autoCreate : {tag: "input", type: "text", size: "20"}
503 fieldLabel: "Password",
504 inputType: 'password',
507 autoCreate : {tag: "input", type: "text", size: "20"},
509 specialkey : function(e,ev) {
510 if (ev.keyCode == 13) {
511 this.form.dialog.el.mask("Logging in");
512 this.form.doAction('submit', {
513 url: this.form.dialog.url,
514 method: this.form.dialog.method,
523 fieldLabel: "Language",
526 xtype : 'SimpleStore',
527 fields: ['lang', 'ldisp'],
530 [ 'zh_HK' , '\u7E41\u4E2D' ],
531 [ 'zh_CN', '\u7C21\u4E2D' ]
538 displayField:'ldisp',
542 triggerAction: 'all',
543 emptyText:'Select a Language...',
546 select : function(cb, rec, ix) {
547 this.form.switchLang(rec.data.lang);
561 text : "Forgot Password",
565 var n = this.form.findField('username').getValue();
567 Roo.MessageBox.alert("Error", "Fill in your email address");
571 url: this.dialog.url,
575 method: this.dialog.method,
576 success: function(response, opts) { // check successfull...
578 var res = this.dialog.processResponse(response);
579 if (!res.success) { // error!
580 Roo.MessageBox.alert("Error" ,
581 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
584 Roo.MessageBox.alert("Notice" ,
585 "Please check you email for the Password Reset message");
587 failure : function() {
588 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
601 click : function () {
603 this.dialog.el.mask("Logging in");
604 this.form.doAction('submit', {
605 url: this.dialog.url,
606 method: this.dialog.method