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, {});
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.
82 onLoad : function() // called on page load...
86 if (Roo.get('loading')) { // clear any loading indicator..
87 Roo.get('loading').remove();
90 //this.switchLang('en'); // set the language to english..
93 success: function(response, opts) { // check successfull...
95 var res = Pman.processResponse(response);
97 if (!res.success) { // error!
99 //console.log('call failure');
100 return this.failure(response,opts);
103 if (!res.data.id) { // id=0 == login failure.
104 return this.show(true);
108 //console.log(success);
109 this.fillAuth(res.data);
111 Roo.XComponent.build();
119 check: function(cfg) // called every so often to refresh cookie etc..
121 if (cfg.again) { // could be undefined..
128 if ( this.checkFails > 4) {
129 Roo.MessageBox.alert("Error",
130 "Error getting authentication status. - try reloading, or wait a while", function() {
131 _this.sending = false;
136 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
147 success: cfg.success || this.success,
148 failure : cfg.failure || this.failure,
158 window.onbeforeunload = function() { }; // false does not work for IE..
168 failure : function() {
169 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
170 document.location = document.location.toString() + '?ts=' + Math.random();
174 success : function() {
178 document.location = document.location.toString() + '?ts=' + Math.random();
185 processResponse : function (response)
189 res = Roo.decode(response.responseText);
191 if (typeof(res) != 'object') {
192 res = { success : false, errorMsg : res, errors : true };
194 if (typeof(res.success) == 'undefined') {
199 res = { success : false, errorMsg : response.responseText, errors : true };
204 success : function(response, opts) // check successfull...
206 this.sending = false;
207 var res = Pman.processResponse(response);
209 return this.failure(response, opts);
211 if (!res.data || !res.data.id) {
212 return this.failure(response,opts);
215 this.fillAuth(res.data);
222 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
225 this.sending = false;
226 var res = Pman.processResponse(response);
228 if ( Pman.Login.checkFails > 2) {
230 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
231 "Error getting authentication status. - try reloading");
234 opts.callCfg.again = true;
235 this.check.defer(1000, this, [ opts.callCfg ]);
241 fillAuth: function(au) {
242 this.startAuthCheck();
243 this.authUserId = au.id;
245 this.lastChecked = new Date();
246 this.fireEvent('refreshed', au);
247 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
248 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
250 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
251 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
252 this.switchLang(au.lang);
255 // open system... - -on setyp..
256 if (this.authUserId < 0) {
257 Roo.MessageBox.alert("Warning",
258 "This is an open system - please set up a admin user with a password.");
261 //Pman.onload(); // which should do nothing if it's a re-auth result...
266 startAuthCheck : function() // starter for timeout checking..
268 if (Pman.Login.intervalID) { // timer already in place...
272 Pman.Login.intervalID = window.setInterval(function() {
273 Pman.Login.check(false);
274 }, 120000); // every 120 secs = 2mins..
280 switchLang : function (lang)
282 if (!_T && lang != 'en') {
283 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
286 if (!_T || !lang.length) {
290 if (typeof(_T.en) == 'undefined') {
292 Roo.apply(_T.en, _T);
295 if (typeof(_T[lang]) == 'undefined') {
296 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
301 Roo.apply(_T, _T[lang]);
302 // just need to set the text values for everything...
304 /* this will not work ...
308 function formLabel(name, val) {
309 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
312 formLabel('password', "Password"+':');
313 formLabel('username', "Email Address"+':');
314 formLabel('lang', "Language"+':');
315 this.dialog.setTitle("Login");
316 this.dialog.buttons[0].setText("Forgot Password");
317 this.dialog.buttons[1].setText("Login");
337 center: { // needed??
340 // tabPosition: 'top',
343 alwaysShowTabs: false
347 rendered : function(dlg) {
348 this.form = this.items[0];
349 this.form.dialog = dlg;
350 this.buttons[0].form = this.form;
351 this.buttons[0].dialog = dlg
352 this.buttons[1].form = this.form;
353 this.buttons[1].dialog = dlg;
355 // logoprefix comes from base config.
356 //Pman.Login.form.el.createChild({
358 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
359 // style: 'margin-bottom: 10px;'
368 //this.resizeToLogo.defer(1000,this);
369 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
371 // this.resizeToLogo.defer(1000,this);
374 var w = Ext.lib.Dom.getViewWidth() - 100;
375 var h = Ext.lib.Dom.getViewHeight() - 100;
376 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
383 if (this.user.id < 0) { // used for inital setup situations.
387 if (this.intervalID) {
389 window.clearInterval(this.intervalID);
390 this.intervalID = false;
394 if (Roo.get('loading')) {
395 Roo.get('loading').remove();
397 if (Roo.get('loading-mask')) {
398 Roo.get('loading-mask').hide();
401 //incomming._node = tnode;
403 //this.dialog.modal = !modal;
404 //this.dialog.show();
405 this.dialog.el.unmask();
408 this.form.setValues({
409 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
410 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
413 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
414 if (this.form.findField('username').getValue().length > 0 ){
415 this.form.findField('password').focus();
417 this.form.findField('username').focus();
425 xtype : 'ContentPanel',
436 style : 'margin : 10px;',
438 actionfailed : function(f, act) {
439 // form can return { errors: .... }
441 //act.result.errors // invalid form element list...
442 //act.result.errorMsg// invalid form element list...
444 this.dialog.el.unmask();
445 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
446 "Login failed - communication error - try again.");
449 actioncomplete: function(re, act) {
451 Roo.state.Manager.set(
452 this.dialog.realm + '.username',
453 this.form.findField('username').getValue()
455 Roo.state.Manager.set(
456 this.dialog.realm + '.lang',
457 Pman.Login.form.findField('lang').getValue()
460 this.dialog.fillAuth(act.result.data);
464 if (Roo.get('loading-mask')) {
465 Roo.get('loading-mask').show();
467 Roo.XComponent.build();
477 fieldLabel: "Email Address",
480 autoCreate : {tag: "input", type: "text", size: "20"}
485 fieldLabel: "Password",
486 inputType: 'password',
489 autoCreate : {tag: "input", type: "text", size: "20"},
491 specialkey : function(e,ev) {
492 if (ev.keyCode == 13) {
493 this.form.dialog.el.mask("Logging in");
494 this.form.doAction('submit', {
495 url: this.form.dialog.url,
496 method: this.form.dialog.method,
505 fieldLabel: "Language",
508 xtype : 'SimpleStore',
509 fields: ['lang', 'ldisp'],
512 [ 'zh_HK' , '\u7E41\u4E2D' ],
513 [ 'zh_CN', '\u7C21\u4E2D' ]
520 displayField:'ldisp',
524 triggerAction: 'all',
525 emptyText:'Select a Language...',
528 select : function(cb, rec, ix) {
529 this.form.switchLang(rec.data.lang);
543 text : "Forgot Password",
547 var n = this.form.findField('username').getValue();
549 Roo.MessageBox.alert("Error", "Fill in your email address");
553 url: this.dialog.url,
557 method: this.dialog.method,
558 success: function(response, opts) { // check successfull...
560 var res = Pman.processResponse(response);
561 if (!res.success) { // error!
562 Roo.MessageBox.alert("Error" ,
563 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
566 Roo.MessageBox.alert("Notice" ,
567 "Please check you email for the Password Reset message");
569 failure : function() {
570 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
583 click : function () {
585 this.dialog.el.mask("Logging in");
586 this.form.doAction('submit', {
587 url: this.dialog.url,
588 method: this.dialog.method