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)
48 Roo.each(this.items, function(e) {
51 Roo.Document.on('ready', function() {
55 Roo.Login.superclass.constructor.call(this);
59 Roo.extend(Roo.Login, Roo.LayoutDialog, {
62 * @cfg {String} method
63 * Method used to query for login details.
69 * URL to query login data. - eg. baseURL + '/Login.php'
75 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
81 onLoad : function() // called on page load...
85 if (Roo.get('loading')) { // clear any loading indicator..
86 Roo.get('loading').remove();
89 //this.switchLang('en'); // set the language to english..
92 success: function(response, opts) { // check successfull...
94 var res = Pman.processResponse(response);
96 if (!res.success) { // error!
98 //console.log('call failure');
99 return this.failure(response,opts);
102 if (!res.data.id) { // id=0 == login failure.
103 return this.show(true);
107 //console.log(success);
108 this.fillAuth(res.data);
110 Roo.XComponent.build();
118 check: function(cfg) // called every so often to refresh cookie etc..
120 if (cfg.again) { // could be undefined..
127 if ( this.checkFails > 4) {
128 Roo.MessageBox.alert("Error",
129 "Error getting authentication status. - try reloading, or wait a while", function() {
130 _this.sending = false;
135 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
146 success: cfg.success || this.success,
147 failure : cfg.failure || this.failure,
157 window.onbeforeunload = function() { }; // false does not work for IE..
167 failure : function() {
168 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
169 document.location = document.location.toString() + '?ts=' + Math.random();
173 success : function() {
177 document.location = document.location.toString() + '?ts=' + Math.random();
186 success : function(response, opts) // check successfull...
188 this.sending = false;
189 var res = Pman.processResponse(response);
191 return this.failure(response, opts);
193 if (!res.data || !res.data.id) {
194 return this.failure(response,opts);
197 this.fillAuth(res.data);
204 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
207 this.sending = false;
208 var res = Pman.processResponse(response);
210 if ( Pman.Login.checkFails > 2) {
212 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
213 "Error getting authentication status. - try reloading");
216 opts.callCfg.again = true;
217 this.check.defer(1000, this, [ opts.callCfg ]);
223 fillAuth: function(au) {
224 this.startAuthCheck();
225 this.authUserId = au.id;
227 this.lastChecked = new Date();
228 this.fireEvent('refreshed', au);
229 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
230 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
232 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
233 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
234 this.switchLang(au.lang);
237 // open system... - -on setyp..
238 if (this.authUserId < 0) {
239 Roo.MessageBox.alert("Warning",
240 "This is an open system - please set up a admin user with a password.");
243 //Pman.onload(); // which should do nothing if it's a re-auth result...
248 startAuthCheck : function() // starter for timeout checking..
250 if (Pman.Login.intervalID) { // timer already in place...
254 Pman.Login.intervalID = window.setInterval(function() {
255 Pman.Login.check(false);
256 }, 120000); // every 120 secs = 2mins..
262 switchLang : function (lang)
264 if (!_T && lang != 'en') {
265 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
268 if (!_T || !lang.length) {
272 if (typeof(_T.en) == 'undefined') {
274 Roo.apply(_T.en, _T);
277 if (typeof(_T[lang]) == 'undefined') {
278 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
283 Roo.apply(_T, _T[lang]);
284 // just need to set the text values for everything...
286 /* this will not work ...
290 function formLabel(name, val) {
291 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
294 formLabel('password', "Password"+':');
295 formLabel('username', "Email Address"+':');
296 formLabel('lang', "Language"+':');
297 this.dialog.setTitle("Login");
298 this.dialog.buttons[0].setText("Forgot Password");
299 this.dialog.buttons[1].setText("Login");
319 center: { // needed??
322 // tabPosition: 'top',
325 alwaysShowTabs: false
329 rendered : function(dlg) {
330 this.form = this.items[0];
331 this.form.dialog = dlg;
332 this.buttons[0].form = this.form;
333 this.buttons[0].dialog = dlg
334 this.buttons[1].form = this.form;
335 this.buttons[1].dialog = dlg;
337 // logoprefix comes from base config.
338 //Pman.Login.form.el.createChild({
340 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
341 // style: 'margin-bottom: 10px;'
350 //this.resizeToLogo.defer(1000,this);
351 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
353 // this.resizeToLogo.defer(1000,this);
356 var w = Ext.lib.Dom.getViewWidth() - 100;
357 var h = Ext.lib.Dom.getViewHeight() - 100;
358 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
365 if (this.user.id < 0) { // used for inital setup situations.
369 if (this.intervalID) {
371 window.clearInterval(this.intervalID);
372 this.intervalID = false;
376 if (Roo.get('loading')) {
377 Roo.get('loading').remove();
379 if (Roo.get('loading-mask')) {
380 Roo.get('loading-mask').hide();
383 //incomming._node = tnode;
385 //this.dialog.modal = !modal;
386 //this.dialog.show();
387 this.dialog.el.unmask();
390 this.form.setValues({
391 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
392 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
395 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
396 if (this.form.findField('username').getValue().length > 0 ){
397 this.form.findField('password').focus();
399 this.form.findField('username').focus();
407 xtype : 'ContentPanel',
418 style : 'margin : 10px;',
420 actionfailed : function(f, act) {
421 // form can return { errors: .... }
423 //act.result.errors // invalid form element list...
424 //act.result.errorMsg// invalid form element list...
426 this.dialog.el.unmask();
427 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
428 "Login failed - communication error - try again.");
431 actioncomplete: function(re, act) {
433 Roo.state.Manager.set(
434 this.dialog.realm + '.username',
435 this.form.findField('username').getValue()
437 Roo.state.Manager.set(
438 this.dialog.realm + '.lang',
439 Pman.Login.form.findField('lang').getValue()
442 this.dialog.fillAuth(act.result.data);
446 if (Roo.get('loading-mask')) {
447 Roo.get('loading-mask').show();
449 Roo.XComponent.build();
459 fieldLabel: "Email Address",
462 autoCreate : {tag: "input", type: "text", size: "20"}
467 fieldLabel: "Password",
468 inputType: 'password',
471 autoCreate : {tag: "input", type: "text", size: "20"},
473 specialkey : function(e,ev) {
474 if (ev.keyCode == 13) {
475 this.form.dialog.el.mask("Logging in");
476 this.form.doAction('submit', {
477 url: this.form.dialog.url,
478 method: this.form.dialog.method,
487 fieldLabel: "Language",
490 xtype : 'SimpleStore',
491 fields: ['lang', 'ldisp'],
494 [ 'zh_HK' , '\u7E41\u4E2D' ],
495 [ 'zh_CN', '\u7C21\u4E2D' ]
502 displayField:'ldisp',
506 triggerAction: 'all',
507 emptyText:'Select a Language...',
510 select : function(cb, rec, ix) {
511 this.form.switchLang(rec.data.lang);
525 text : "Forgot Password",
529 var n = this.form.findField('username').getValue();
531 Roo.MessageBox.alert("Error", "Fill in your email address");
539 method: this.dialog.method,
540 success: function(response, opts) { // check successfull...
542 var res = Pman.processResponse(response);
543 if (!res.success) { // error!
544 Roo.MessageBox.alert("Error" ,
545 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
548 Roo.MessageBox.alert("Notice" ,
549 "Please check you email for the Password Reset message");
551 failure : function() {
552 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
565 this.dialog.el.mask("Logging in");
566 this.form.doAction('submit', {
568 method: this.dialog.method
577 Pman.Login = new Roo.util.Observable({
590 authUser: { id : false },
600 intervalID : false, /// the login refresher...