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({
39 * Ext.apply(_T, _T[lang]);
43 Roo.Login = function(cfg)
51 Roo.onReady(function() {
57 Roo.Login.superclass.constructor.call(this, this);
58 //this.addxtype(this.items[0]);
64 Roo.extend(Roo.Login, Roo.LayoutDialog, {
67 * @cfg {String} method
68 * Method used to query for login details.
74 * URL to query login data. - eg. baseURL + '/Login.php'
80 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
85 * @property checkFails
86 * Number of times we have attempted to get authentication check, and failed.
91 * @property intervalID
92 * The window interval that does the constant login checking.
98 onLoad : function() // called on page load...
102 if (Roo.get('loading')) { // clear any loading indicator..
103 Roo.get('loading').remove();
106 //this.switchLang('en'); // set the language to english..
109 success: function(response, opts) { // check successfull...
111 var res = this.processResponse(response);
113 if (!res.success) { // error!
115 //console.log('call failure');
116 return this.failure(response,opts);
119 if (!res.data.id) { // id=0 == login failure.
124 //console.log(success);
125 this.fillAuth(res.data);
127 Roo.XComponent.build();
135 check: function(cfg) // called every so often to refresh cookie etc..
137 if (cfg.again) { // could be undefined..
144 if ( this.checkFails > 4) {
145 Roo.MessageBox.alert("Error",
146 "Error getting authentication status. - try reloading, or wait a while", function() {
147 _this.sending = false;
152 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
163 success: cfg.success || this.success,
164 failure : cfg.failure || this.failure,
174 window.onbeforeunload = function() { }; // false does not work for IE..
184 failure : function() {
185 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
186 document.location = document.location.toString() + '?ts=' + Math.random();
190 success : function() {
194 document.location = document.location.toString() + '?ts=' + Math.random();
201 processResponse : function (response)
205 res = Roo.decode(response.responseText);
207 if (typeof(res) != 'object') {
208 res = { success : false, errorMsg : res, errors : true };
210 if (typeof(res.success) == 'undefined') {
215 res = { success : false, errorMsg : response.responseText, errors : true };
220 success : function(response, opts) // check successfull...
222 this.sending = false;
223 var res = this.processResponse(response);
225 return this.failure(response, opts);
227 if (!res.data || !res.data.id) {
228 return this.failure(response,opts);
231 this.fillAuth(res.data);
238 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
241 this.sending = false;
242 var res = this.processResponse(response);
244 if ( this.checkFails > 2) {
246 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
247 "Error getting authentication status. - try reloading");
250 opts.callCfg.again = true;
251 this.check.defer(1000, this, [ opts.callCfg ]);
257 fillAuth: function(au) {
258 this.startAuthCheck();
259 this.authUserId = au.id;
261 this.lastChecked = new Date();
262 this.fireEvent('refreshed', au);
263 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
264 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
265 au.lang = au.lang || 'en';
266 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
267 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
268 this.switchLang(au.lang );
271 // open system... - -on setyp..
272 if (this.authUserId < 0) {
273 Roo.MessageBox.alert("Warning",
274 "This is an open system - please set up a admin user with a password.");
277 //Pman.onload(); // which should do nothing if it's a re-auth result...
282 startAuthCheck : function() // starter for timeout checking..
284 if (this.intervalID) { // timer already in place...
288 this.intervalID = window.setInterval(function() {
290 }, 120000); // every 120 secs = 2mins..
296 switchLang : function (lang)
298 _T = typeof(_T) == 'undefined' ? false : _T;
299 if (!_T || !lang.length) {
303 if (!_T && lang != 'en') {
304 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
308 if (typeof(_T.en) == 'undefined') {
310 Roo.apply(_T.en, _T);
313 if (typeof(_T[lang]) == 'undefined') {
314 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
319 Roo.apply(_T, _T[lang]);
320 // just need to set the text values for everything...
322 /* this will not work ...
326 function formLabel(name, val) {
327 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
330 formLabel('password', "Password"+':');
331 formLabel('username', "Email Address"+':');
332 formLabel('lang', "Language"+':');
333 this.dialog.setTitle("Login");
334 this.dialog.buttons[0].setText("Forgot Password");
335 this.dialog.buttons[1].setText("Login");
356 center: { // needed??
359 // tabPosition: 'top',
362 alwaysShowTabs: false
369 this.form = this.layout.getRegion('center').activePanel.form;
370 this.form.dialog = dlg;
371 this.buttons[0].form = this.form;
372 this.buttons[0].dialog = dlg
373 this.buttons[1].form = this.form;
374 this.buttons[1].dialog = dlg;
376 //this.resizeToLogo.defer(1000,this);
377 // this is all related to resizing for logos..
378 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
380 // this.resizeToLogo.defer(1000,this);
383 //var w = Ext.lib.Dom.getViewWidth() - 100;
384 //var h = Ext.lib.Dom.getViewHeight() - 100;
385 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
392 if (this.user.id < 0) { // used for inital setup situations.
396 if (this.intervalID) {
398 window.clearInterval(this.intervalID);
399 this.intervalID = false;
403 if (Roo.get('loading')) {
404 Roo.get('loading').remove();
406 if (Roo.get('loading-mask')) {
407 Roo.get('loading-mask').hide();
410 //incomming._node = tnode;
412 //this.dialog.modal = !modal;
413 //this.dialog.show();
417 this.form.setValues({
418 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
419 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
422 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', 'en'));
423 if (this.form.findField('username').getValue().length > 0 ){
424 this.form.findField('password').focus();
426 this.form.findField('username').focus();
434 xtype : 'ContentPanel',
446 style : 'margin: 10px;',
449 actionfailed : function(f, act) {
450 // form can return { errors: .... }
452 //act.result.errors // invalid form element list...
453 //act.result.errorMsg// invalid form element list...
455 this.dialog.el.unmask();
456 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
457 "Login failed - communication error - try again.");
460 actioncomplete: function(re, act) {
462 Roo.state.Manager.set(
463 this.dialog.realm + '.username',
464 this.findField('username').getValue()
466 Roo.state.Manager.set(
467 this.dialog.realm + '.lang',
468 this.findField('lang').getValue()
471 this.dialog.fillAuth(act.result.data);
475 if (Roo.get('loading-mask')) {
476 Roo.get('loading-mask').show();
478 Roo.XComponent.build();
488 fieldLabel: "Email Address",
491 autoCreate : {tag: "input", type: "text", size: "20"}
496 fieldLabel: "Password",
497 inputType: 'password',
500 autoCreate : {tag: "input", type: "text", size: "20"},
502 specialkey : function(e,ev) {
503 if (ev.keyCode == 13) {
504 this.form.dialog.el.mask("Logging in");
505 this.form.doAction('submit', {
506 url: this.form.dialog.url,
507 method: this.form.dialog.method,
516 fieldLabel: "Language",
519 xtype : 'SimpleStore',
520 fields: ['lang', 'ldisp'],
523 [ 'zh_HK' , '\u7E41\u4E2D' ],
524 [ 'zh_CN', '\u7C21\u4E2D' ]
531 displayField:'ldisp',
535 triggerAction: 'all',
536 emptyText:'Select a Language...',
539 select : function(cb, rec, ix) {
540 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