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() {
56 Roo.Login.superclass.constructor.call(this, this);
57 //this.addxtype(this.items[0]);
63 Roo.extend(Roo.Login, Roo.LayoutDialog, {
66 * @cfg {String} method
67 * Method used to query for login details.
73 * URL to query login data. - eg. baseURL + '/Login.php'
79 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
84 * @property checkFails
85 * Number of times we have attempted to get authentication check, and failed.
90 * @property intervalID
91 * The window interval that does the constant login checking.
97 onLoad : function() // called on page load...
101 if (Roo.get('loading')) { // clear any loading indicator..
102 Roo.get('loading').remove();
105 //this.switchLang('en'); // set the language to english..
108 success: function(response, opts) { // check successfull...
110 var res = this.processResponse(response);
112 if (!res.success) { // error!
114 //console.log('call failure');
115 return this.failure(response,opts);
118 if (!res.data.id) { // id=0 == login failure.
123 //console.log(success);
124 this.fillAuth(res.data);
126 Roo.XComponent.build();
134 check: function(cfg) // called every so often to refresh cookie etc..
136 if (cfg.again) { // could be undefined..
143 if ( this.checkFails > 4) {
144 Roo.MessageBox.alert("Error",
145 "Error getting authentication status. - try reloading, or wait a while", function() {
146 _this.sending = false;
151 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
162 success: cfg.success || this.success,
163 failure : cfg.failure || this.failure,
173 window.onbeforeunload = function() { }; // false does not work for IE..
183 failure : function() {
184 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
185 document.location = document.location.toString() + '?ts=' + Math.random();
189 success : function() {
193 document.location = document.location.toString() + '?ts=' + Math.random();
200 processResponse : function (response)
204 res = Roo.decode(response.responseText);
206 if (typeof(res) != 'object') {
207 res = { success : false, errorMsg : res, errors : true };
209 if (typeof(res.success) == 'undefined') {
214 res = { success : false, errorMsg : response.responseText, errors : true };
219 success : function(response, opts) // check successfull...
221 this.sending = false;
222 var res = this.processResponse(response);
224 return this.failure(response, opts);
226 if (!res.data || !res.data.id) {
227 return this.failure(response,opts);
230 this.fillAuth(res.data);
237 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
240 this.sending = false;
241 var res = this.processResponse(response);
243 if ( this.checkFails > 2) {
245 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
246 "Error getting authentication status. - try reloading");
249 opts.callCfg.again = true;
250 this.check.defer(1000, this, [ opts.callCfg ]);
256 fillAuth: function(au) {
257 this.startAuthCheck();
258 this.authUserId = au.id;
260 this.lastChecked = new Date();
261 this.fireEvent('refreshed', au);
262 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
263 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
265 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
266 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
267 this.switchLang(au.lang);
270 // open system... - -on setyp..
271 if (this.authUserId < 0) {
272 Roo.MessageBox.alert("Warning",
273 "This is an open system - please set up a admin user with a password.");
276 //Pman.onload(); // which should do nothing if it's a re-auth result...
281 startAuthCheck : function() // starter for timeout checking..
283 if (this.intervalID) { // timer already in place...
287 this.intervalID = window.setInterval(function() {
289 }, 120000); // every 120 secs = 2mins..
295 switchLang : function (lang)
297 if (!_T && lang != 'en') {
298 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
301 if (!_T || !lang.length) {
305 if (typeof(_T.en) == 'undefined') {
307 Roo.apply(_T.en, _T);
310 if (typeof(_T[lang]) == 'undefined') {
311 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
316 Roo.apply(_T, _T[lang]);
317 // just need to set the text values for everything...
319 /* this will not work ...
323 function formLabel(name, val) {
324 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
327 formLabel('password', "Password"+':');
328 formLabel('username', "Email Address"+':');
329 formLabel('lang', "Language"+':');
330 this.dialog.setTitle("Login");
331 this.dialog.buttons[0].setText("Forgot Password");
332 this.dialog.buttons[1].setText("Login");
352 center: { // needed??
355 // tabPosition: 'top',
358 alwaysShowTabs: false
362 rendered : function(dlg) {
363 this.form = this.items[0];
364 this.form.dialog = dlg;
365 this.buttons[0].form = this.form;
366 this.buttons[0].dialog = dlg
367 this.buttons[1].form = this.form;
368 this.buttons[1].dialog = dlg;
370 // logoprefix comes from base config.
371 //Pman.Login.form.el.createChild({
373 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
374 // style: 'margin-bottom: 10px;'
383 //this.resizeToLogo.defer(1000,this);
384 // this is all related to resizing for logos..
385 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
387 // this.resizeToLogo.defer(1000,this);
390 //var w = Ext.lib.Dom.getViewWidth() - 100;
391 //var h = Ext.lib.Dom.getViewHeight() - 100;
392 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
399 if (this.user.id < 0) { // used for inital setup situations.
403 if (this.intervalID) {
405 window.clearInterval(this.intervalID);
406 this.intervalID = false;
410 if (Roo.get('loading')) {
411 Roo.get('loading').remove();
413 if (Roo.get('loading-mask')) {
414 Roo.get('loading-mask').hide();
417 //incomming._node = tnode;
419 //this.dialog.modal = !modal;
420 //this.dialog.show();
421 this.dialog.el.unmask();
424 this.form.setValues({
425 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
426 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
429 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
430 if (this.form.findField('username').getValue().length > 0 ){
431 this.form.findField('password').focus();
433 this.form.findField('username').focus();
441 xtype : 'ContentPanel',
452 style : 'margin : 10px;',
454 actionfailed : function(f, act) {
455 // form can return { errors: .... }
457 //act.result.errors // invalid form element list...
458 //act.result.errorMsg// invalid form element list...
460 this.dialog.el.unmask();
461 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
462 "Login failed - communication error - try again.");
465 actioncomplete: function(re, act) {
467 Roo.state.Manager.set(
468 this.dialog.realm + '.username',
469 this.findField('username').getValue()
471 Roo.state.Manager.set(
472 this.dialog.realm + '.lang',
473 this.findField('lang').getValue()
476 this.dialog.fillAuth(act.result.data);
480 if (Roo.get('loading-mask')) {
481 Roo.get('loading-mask').show();
483 Roo.XComponent.build();
493 fieldLabel: "Email Address",
496 autoCreate : {tag: "input", type: "text", size: "20"}
501 fieldLabel: "Password",
502 inputType: 'password',
505 autoCreate : {tag: "input", type: "text", size: "20"},
507 specialkey : function(e,ev) {
508 if (ev.keyCode == 13) {
509 this.form.dialog.el.mask("Logging in");
510 this.form.doAction('submit', {
511 url: this.form.dialog.url,
512 method: this.form.dialog.method,
521 fieldLabel: "Language",
524 xtype : 'SimpleStore',
525 fields: ['lang', 'ldisp'],
528 [ 'zh_HK' , '\u7E41\u4E2D' ],
529 [ 'zh_CN', '\u7C21\u4E2D' ]
536 displayField:'ldisp',
540 triggerAction: 'all',
541 emptyText:'Select a Language...',
544 select : function(cb, rec, ix) {
545 this.form.switchLang(rec.data.lang);
559 text : "Forgot Password",
563 var n = this.form.findField('username').getValue();
565 Roo.MessageBox.alert("Error", "Fill in your email address");
569 url: this.dialog.url,
573 method: this.dialog.method,
574 success: function(response, opts) { // check successfull...
576 var res = this.dialog.processResponse(response);
577 if (!res.success) { // error!
578 Roo.MessageBox.alert("Error" ,
579 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
582 Roo.MessageBox.alert("Notice" ,
583 "Please check you email for the Password Reset message");
585 failure : function() {
586 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
599 click : function () {
601 this.dialog.el.mask("Logging in");
602 this.form.doAction('submit', {
603 url: this.dialog.url,
604 method: this.dialog.method