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() {
54 Roo.Login.superclass.constructor.call(this);
55 //this.addxtype(this.items[0]);
61 Roo.extend(Roo.Login, Roo.LayoutDialog, {
64 * @cfg {String} method
65 * Method used to query for login details.
71 * URL to query login data. - eg. baseURL + '/Login.php'
77 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
82 * @property checkFails
83 * Number of times we have attempted to get authentication check, and failed.
88 * @property intervalID
89 * The window interval that does the constant login checking.
95 onLoad : function() // called on page load...
99 if (Roo.get('loading')) { // clear any loading indicator..
100 Roo.get('loading').remove();
103 //this.switchLang('en'); // set the language to english..
106 success: function(response, opts) { // check successfull...
108 var res = this.processResponse(response);
110 if (!res.success) { // error!
112 //console.log('call failure');
113 return this.failure(response,opts);
116 if (!res.data.id) { // id=0 == login failure.
121 //console.log(success);
122 this.fillAuth(res.data);
124 Roo.XComponent.build();
132 check: function(cfg) // called every so often to refresh cookie etc..
134 if (cfg.again) { // could be undefined..
141 if ( this.checkFails > 4) {
142 Roo.MessageBox.alert("Error",
143 "Error getting authentication status. - try reloading, or wait a while", function() {
144 _this.sending = false;
149 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
160 success: cfg.success || this.success,
161 failure : cfg.failure || this.failure,
171 window.onbeforeunload = function() { }; // false does not work for IE..
181 failure : function() {
182 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
183 document.location = document.location.toString() + '?ts=' + Math.random();
187 success : function() {
191 document.location = document.location.toString() + '?ts=' + Math.random();
198 processResponse : function (response)
202 res = Roo.decode(response.responseText);
204 if (typeof(res) != 'object') {
205 res = { success : false, errorMsg : res, errors : true };
207 if (typeof(res.success) == 'undefined') {
212 res = { success : false, errorMsg : response.responseText, errors : true };
217 success : function(response, opts) // check successfull...
219 this.sending = false;
220 var res = this.processResponse(response);
222 return this.failure(response, opts);
224 if (!res.data || !res.data.id) {
225 return this.failure(response,opts);
228 this.fillAuth(res.data);
235 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
238 this.sending = false;
239 var res = this.processResponse(response);
241 if ( this.checkFails > 2) {
243 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
244 "Error getting authentication status. - try reloading");
247 opts.callCfg.again = true;
248 this.check.defer(1000, this, [ opts.callCfg ]);
254 fillAuth: function(au) {
255 this.startAuthCheck();
256 this.authUserId = au.id;
258 this.lastChecked = new Date();
259 this.fireEvent('refreshed', au);
260 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
261 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
263 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
264 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
265 this.switchLang(au.lang);
268 // open system... - -on setyp..
269 if (this.authUserId < 0) {
270 Roo.MessageBox.alert("Warning",
271 "This is an open system - please set up a admin user with a password.");
274 //Pman.onload(); // which should do nothing if it's a re-auth result...
279 startAuthCheck : function() // starter for timeout checking..
281 if (this.intervalID) { // timer already in place...
285 this.intervalID = window.setInterval(function() {
287 }, 120000); // every 120 secs = 2mins..
293 switchLang : function (lang)
295 if (!_T && lang != 'en') {
296 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
299 if (!_T || !lang.length) {
303 if (typeof(_T.en) == 'undefined') {
305 Roo.apply(_T.en, _T);
308 if (typeof(_T[lang]) == 'undefined') {
309 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
314 Roo.apply(_T, _T[lang]);
315 // just need to set the text values for everything...
317 /* this will not work ...
321 function formLabel(name, val) {
322 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
325 formLabel('password', "Password"+':');
326 formLabel('username', "Email Address"+':');
327 formLabel('lang', "Language"+':');
328 this.dialog.setTitle("Login");
329 this.dialog.buttons[0].setText("Forgot Password");
330 this.dialog.buttons[1].setText("Login");
350 center: { // needed??
353 // tabPosition: 'top',
356 alwaysShowTabs: false
360 rendered : function(dlg) {
361 this.form = this.items[0];
362 this.form.dialog = dlg;
363 this.buttons[0].form = this.form;
364 this.buttons[0].dialog = dlg
365 this.buttons[1].form = this.form;
366 this.buttons[1].dialog = dlg;
368 // logoprefix comes from base config.
369 //Pman.Login.form.el.createChild({
371 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
372 // style: 'margin-bottom: 10px;'
381 //this.resizeToLogo.defer(1000,this);
382 // this is all related to resizing for logos..
383 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
385 // this.resizeToLogo.defer(1000,this);
388 //var w = Ext.lib.Dom.getViewWidth() - 100;
389 //var h = Ext.lib.Dom.getViewHeight() - 100;
390 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
397 if (this.user.id < 0) { // used for inital setup situations.
401 if (this.intervalID) {
403 window.clearInterval(this.intervalID);
404 this.intervalID = false;
408 if (Roo.get('loading')) {
409 Roo.get('loading').remove();
411 if (Roo.get('loading-mask')) {
412 Roo.get('loading-mask').hide();
415 //incomming._node = tnode;
417 //this.dialog.modal = !modal;
418 //this.dialog.show();
419 this.dialog.el.unmask();
422 this.form.setValues({
423 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
424 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
427 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
428 if (this.form.findField('username').getValue().length > 0 ){
429 this.form.findField('password').focus();
431 this.form.findField('username').focus();
439 xtype : 'ContentPanel',
450 style : 'margin : 10px;',
452 actionfailed : function(f, act) {
453 // form can return { errors: .... }
455 //act.result.errors // invalid form element list...
456 //act.result.errorMsg// invalid form element list...
458 this.dialog.el.unmask();
459 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
460 "Login failed - communication error - try again.");
463 actioncomplete: function(re, act) {
465 Roo.state.Manager.set(
466 this.dialog.realm + '.username',
467 this.findField('username').getValue()
469 Roo.state.Manager.set(
470 this.dialog.realm + '.lang',
471 this.findField('lang').getValue()
474 this.dialog.fillAuth(act.result.data);
478 if (Roo.get('loading-mask')) {
479 Roo.get('loading-mask').show();
481 Roo.XComponent.build();
491 fieldLabel: "Email Address",
494 autoCreate : {tag: "input", type: "text", size: "20"}
499 fieldLabel: "Password",
500 inputType: 'password',
503 autoCreate : {tag: "input", type: "text", size: "20"},
505 specialkey : function(e,ev) {
506 if (ev.keyCode == 13) {
507 this.form.dialog.el.mask("Logging in");
508 this.form.doAction('submit', {
509 url: this.form.dialog.url,
510 method: this.form.dialog.method,
519 fieldLabel: "Language",
522 xtype : 'SimpleStore',
523 fields: ['lang', 'ldisp'],
526 [ 'zh_HK' , '\u7E41\u4E2D' ],
527 [ 'zh_CN', '\u7C21\u4E2D' ]
534 displayField:'ldisp',
538 triggerAction: 'all',
539 emptyText:'Select a Language...',
542 select : function(cb, rec, ix) {
543 this.form.switchLang(rec.data.lang);
557 text : "Forgot Password",
561 var n = this.form.findField('username').getValue();
563 Roo.MessageBox.alert("Error", "Fill in your email address");
567 url: this.dialog.url,
571 method: this.dialog.method,
572 success: function(response, opts) { // check successfull...
574 var res = this.dialog.processResponse(response);
575 if (!res.success) { // error!
576 Roo.MessageBox.alert("Error" ,
577 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
580 Roo.MessageBox.alert("Notice" ,
581 "Please check you email for the Password Reset message");
583 failure : function() {
584 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
597 click : function () {
599 this.dialog.el.mask("Logging in");
600 this.form.doAction('submit', {
601 url: this.dialog.url,
602 method: this.dialog.method