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, cfg);
54 this.addxtype(this.items[0]);
60 Roo.extend(Roo.Login, Roo.LayoutDialog, {
63 * @cfg {String} method
64 * Method used to query for login details.
70 * URL to query login data. - eg. baseURL + '/Login.php'
76 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
81 * @property checkFails
82 * Number of times we have attempted to get authentication check, and failed.
87 * @property intervalID
88 * The window interval that does the constant login checking.
94 onLoad : function() // called on page load...
98 if (Roo.get('loading')) { // clear any loading indicator..
99 Roo.get('loading').remove();
102 //this.switchLang('en'); // set the language to english..
105 success: function(response, opts) { // check successfull...
107 var res = this.processResponse(response);
109 if (!res.success) { // error!
111 //console.log('call failure');
112 return this.failure(response,opts);
115 if (!res.data.id) { // id=0 == login failure.
120 //console.log(success);
121 this.fillAuth(res.data);
123 Roo.XComponent.build();
131 check: function(cfg) // called every so often to refresh cookie etc..
133 if (cfg.again) { // could be undefined..
140 if ( this.checkFails > 4) {
141 Roo.MessageBox.alert("Error",
142 "Error getting authentication status. - try reloading, or wait a while", function() {
143 _this.sending = false;
148 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
159 success: cfg.success || this.success,
160 failure : cfg.failure || this.failure,
170 window.onbeforeunload = function() { }; // false does not work for IE..
180 failure : function() {
181 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
182 document.location = document.location.toString() + '?ts=' + Math.random();
186 success : function() {
190 document.location = document.location.toString() + '?ts=' + Math.random();
197 processResponse : function (response)
201 res = Roo.decode(response.responseText);
203 if (typeof(res) != 'object') {
204 res = { success : false, errorMsg : res, errors : true };
206 if (typeof(res.success) == 'undefined') {
211 res = { success : false, errorMsg : response.responseText, errors : true };
216 success : function(response, opts) // check successfull...
218 this.sending = false;
219 var res = this.processResponse(response);
221 return this.failure(response, opts);
223 if (!res.data || !res.data.id) {
224 return this.failure(response,opts);
227 this.fillAuth(res.data);
234 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
237 this.sending = false;
238 var res = this.processResponse(response);
240 if ( this.checkFails > 2) {
242 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
243 "Error getting authentication status. - try reloading");
246 opts.callCfg.again = true;
247 this.check.defer(1000, this, [ opts.callCfg ]);
253 fillAuth: function(au) {
254 this.startAuthCheck();
255 this.authUserId = au.id;
257 this.lastChecked = new Date();
258 this.fireEvent('refreshed', au);
259 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
260 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
262 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
263 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
264 this.switchLang(au.lang);
267 // open system... - -on setyp..
268 if (this.authUserId < 0) {
269 Roo.MessageBox.alert("Warning",
270 "This is an open system - please set up a admin user with a password.");
273 //Pman.onload(); // which should do nothing if it's a re-auth result...
278 startAuthCheck : function() // starter for timeout checking..
280 if (this.intervalID) { // timer already in place...
284 this.intervalID = window.setInterval(function() {
286 }, 120000); // every 120 secs = 2mins..
292 switchLang : function (lang)
294 if (!_T && lang != 'en') {
295 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
298 if (!_T || !lang.length) {
302 if (typeof(_T.en) == 'undefined') {
304 Roo.apply(_T.en, _T);
307 if (typeof(_T[lang]) == 'undefined') {
308 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
313 Roo.apply(_T, _T[lang]);
314 // just need to set the text values for everything...
316 /* this will not work ...
320 function formLabel(name, val) {
321 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
324 formLabel('password', "Password"+':');
325 formLabel('username', "Email Address"+':');
326 formLabel('lang', "Language"+':');
327 this.dialog.setTitle("Login");
328 this.dialog.buttons[0].setText("Forgot Password");
329 this.dialog.buttons[1].setText("Login");
349 center: { // needed??
352 // tabPosition: 'top',
355 alwaysShowTabs: false
359 rendered : function(dlg) {
360 this.form = this.items[0];
361 this.form.dialog = dlg;
362 this.buttons[0].form = this.form;
363 this.buttons[0].dialog = dlg
364 this.buttons[1].form = this.form;
365 this.buttons[1].dialog = dlg;
367 // logoprefix comes from base config.
368 //Pman.Login.form.el.createChild({
370 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
371 // style: 'margin-bottom: 10px;'
380 //this.resizeToLogo.defer(1000,this);
381 // this is all related to resizing for logos..
382 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
384 // this.resizeToLogo.defer(1000,this);
387 //var w = Ext.lib.Dom.getViewWidth() - 100;
388 //var h = Ext.lib.Dom.getViewHeight() - 100;
389 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
396 if (this.user.id < 0) { // used for inital setup situations.
400 if (this.intervalID) {
402 window.clearInterval(this.intervalID);
403 this.intervalID = false;
407 if (Roo.get('loading')) {
408 Roo.get('loading').remove();
410 if (Roo.get('loading-mask')) {
411 Roo.get('loading-mask').hide();
414 //incomming._node = tnode;
416 //this.dialog.modal = !modal;
417 //this.dialog.show();
418 this.dialog.el.unmask();
421 this.form.setValues({
422 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
423 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
426 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
427 if (this.form.findField('username').getValue().length > 0 ){
428 this.form.findField('password').focus();
430 this.form.findField('username').focus();
438 xtype : 'ContentPanel',
449 style : 'margin : 10px;',
451 actionfailed : function(f, act) {
452 // form can return { errors: .... }
454 //act.result.errors // invalid form element list...
455 //act.result.errorMsg// invalid form element list...
457 this.dialog.el.unmask();
458 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
459 "Login failed - communication error - try again.");
462 actioncomplete: function(re, act) {
464 Roo.state.Manager.set(
465 this.dialog.realm + '.username',
466 this.findField('username').getValue()
468 Roo.state.Manager.set(
469 this.dialog.realm + '.lang',
470 this.findField('lang').getValue()
473 this.dialog.fillAuth(act.result.data);
477 if (Roo.get('loading-mask')) {
478 Roo.get('loading-mask').show();
480 Roo.XComponent.build();
490 fieldLabel: "Email Address",
493 autoCreate : {tag: "input", type: "text", size: "20"}
498 fieldLabel: "Password",
499 inputType: 'password',
502 autoCreate : {tag: "input", type: "text", size: "20"},
504 specialkey : function(e,ev) {
505 if (ev.keyCode == 13) {
506 this.form.dialog.el.mask("Logging in");
507 this.form.doAction('submit', {
508 url: this.form.dialog.url,
509 method: this.form.dialog.method,
518 fieldLabel: "Language",
521 xtype : 'SimpleStore',
522 fields: ['lang', 'ldisp'],
525 [ 'zh_HK' , '\u7E41\u4E2D' ],
526 [ 'zh_CN', '\u7C21\u4E2D' ]
533 displayField:'ldisp',
537 triggerAction: 'all',
538 emptyText:'Select a Language...',
541 select : function(cb, rec, ix) {
542 this.form.switchLang(rec.data.lang);
556 text : "Forgot Password",
560 var n = this.form.findField('username').getValue();
562 Roo.MessageBox.alert("Error", "Fill in your email address");
566 url: this.dialog.url,
570 method: this.dialog.method,
571 success: function(response, opts) { // check successfull...
573 var res = this.dialog.processResponse(response);
574 if (!res.success) { // error!
575 Roo.MessageBox.alert("Error" ,
576 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
579 Roo.MessageBox.alert("Notice" ,
580 "Please check you email for the Password Reset message");
582 failure : function() {
583 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
596 click : function () {
598 this.dialog.el.mask("Logging in");
599 this.form.doAction('submit', {
600 url: this.dialog.url,
601 method: this.dialog.method