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..
273 center: { // needed??
276 // tabPosition: 'top',
279 alwaysShowTabs: false
283 rendered : function(dlg) {
284 this.form = this.items[0];
285 this.form.dialog = dlg;
286 this.buttons[0].form = this.form;
287 this.buttons[0].dialog = dlg
288 this.buttons[1].form = this.form;
289 this.buttons[1].dialog = dlg;
291 // logoprefix comes from base config.
292 //Pman.Login.form.el.createChild({
294 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
295 // style: 'margin-bottom: 10px;'
304 //this.resizeToLogo.defer(1000,this);
305 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
307 // this.resizeToLogo.defer(1000,this);
310 var w = Ext.lib.Dom.getViewWidth() - 100;
311 var h = Ext.lib.Dom.getViewHeight() - 100;
312 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
319 if (this.user.id < 0) { // used for inital setup situations.
323 if (this.intervalID) {
325 window.clearInterval(this.intervalID);
326 this.intervalID = false;
330 if (Roo.get('loading')) {
331 Roo.get('loading').remove();
333 if (Roo.get('loading-mask')) {
334 Roo.get('loading-mask').hide();
337 //incomming._node = tnode;
339 //this.dialog.modal = !modal;
340 //this.dialog.show();
341 this.dialog.el.unmask();
344 this.form.setValues({
345 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
346 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
349 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
350 if (this.form.findField('username').getValue().length > 0 ){
351 this.form.findField('password').focus();
353 this.form.findField('username').focus();
361 xtype : 'ContentPanel',
372 style : 'margin : 10px;',
374 actionfailed : function(f, act) {
375 // form can return { errors: .... }
377 //act.result.errors // invalid form element list...
378 //act.result.errorMsg// invalid form element list...
380 this.dialog.el.unmask();
381 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
382 "Login failed - communication error - try again.");
385 actioncomplete: function(re, act) {
387 Roo.state.Manager.set(
388 this.dialog.realm + '.' + this.dialog.params.username,
389 this.form.findField(this.dialog.params.username).getValue()
391 Roo.state.Manager.set(
392 this.dialog.realm + '.lang',
393 Pman.Login.form.findField('lang').getValue()
396 this.dialog.fillAuth(act.result.data);
400 if (Roo.get('loading-mask')) {
401 Roo.get('loading-mask').show();
403 Roo.XComponent.build();
413 fieldLabel: "Email Address",
416 autoCreate : {tag: "input", type: "text", size: "20"}
421 fieldLabel: "Password",
422 inputType: 'password',
425 autoCreate : {tag: "input", type: "text", size: "20"},
427 specialkey : function(e,ev) {
428 if (ev.keyCode == 13) {
429 this.form.dialog.el.mask("Logging in");
430 this.form.doAction('submit', {
431 url: this.form.dialog.url,
432 method: this.form.dialog.method,
441 fieldLabel: "Language",
444 xtype : 'SimpleStore',
445 fields: ['lang', 'ldisp'],
448 [ 'zh_HK' , '\u7E41\u4E2D' ],
449 [ 'zh_CN', '\u7C21\u4E2D' ]
456 displayField:'ldisp',
460 triggerAction: 'all',
461 emptyText:'Select a Language...',
464 select : function(cb, rec, ix) {
465 this.form.switchLang(rec.data.lang);
479 text : "Forgot Password",
483 var n = this.form.findField('username').getValue();
485 Roo.MessageBox.alert("Error", "Fill in your email address");
493 method: this.dialog.method,
494 success: function(response, opts) { // check successfull...
496 var res = Pman.processResponse(response);
497 if (!res.success) { // error!
498 Roo.MessageBox.alert("Error" ,
499 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
502 Roo.MessageBox.alert("Notice" ,
503 "Please check you email for the Password Reset message");
505 failure : function() {
506 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
519 this.dialog.el.mask("Logging in");
520 this.form.doAction('submit', {
522 method: this.dialog.method
531 Pman.Login = new Roo.util.Observable({
544 authUser: { id : false },
554 intervalID : false, /// the login refresher...
565 switchLang : function (lang)
567 if (!_T && lang != 'en') {
568 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
571 if (!_T || !lang.length) {
575 if (typeof(_T.en) == 'undefined') {
577 Roo.apply(_T.en, _T);
580 if (typeof(_T[lang]) == 'undefined') {
581 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
586 Roo.apply(_T, _T[lang]);
587 // just need to set the text values for everything...
591 function formLabel(name, val) {
593 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
594 if (lbl.getElementsByTagName('label').length) {
595 lbl = lbl.getElementsByTagName('label')[0];
597 lbl = lbl.parentNode.getElementsByTagName('label')[0];
603 formLabel('password', "Password"+':');
604 formLabel('username', "Email Address"+':');
605 formLabel('lang', "Language"+':');
606 this.dialog.setTitle("Login");
607 this.dialog.buttons[0].setText("Forgot Password");
608 this.dialog.buttons[1].setText("Login");
616 * Depreciated = use Pman.I18n