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();
187 success : function(response, opts) // check successfull...
189 this.sending = false;
190 var res = Pman.processResponse(response);
192 return this.failure(response, opts);
194 if (!res.data || !res.data.id) {
195 return this.failure(response,opts);
198 this.fillAuth(res.data);
205 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
208 this.sending = false;
209 var res = Pman.processResponse(response);
211 if ( Pman.Login.checkFails > 2) {
213 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
214 "Error getting authentication status. - try reloading");
217 opts.callCfg.again = true;
218 this.check.defer(1000, this, [ opts.callCfg ]);
224 fillAuth: function(au) {
225 this.startAuthCheck();
226 this.authUserId = au.id;
228 this.lastChecked = new Date();
229 this.fireEvent('refreshed', au);
230 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
231 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
233 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
234 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
235 this.switchLang(au.lang);
238 // open system... - -on setyp..
239 if (this.authUserId < 0) {
240 Roo.MessageBox.alert("Warning",
241 "This is an open system - please set up a admin user with a password.");
244 //Pman.onload(); // which should do nothing if it's a re-auth result...
249 startAuthCheck : function() // starter for timeout checking..
251 if (Pman.Login.intervalID) { // timer already in place...
255 Pman.Login.intervalID = window.setInterval(function() {
256 Pman.Login.check(false);
257 }, 120000); // every 120 secs = 2mins..
263 switchLang : function (lang)
265 if (!_T && lang != 'en') {
266 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
269 if (!_T || !lang.length) {
273 if (typeof(_T.en) == 'undefined') {
275 Roo.apply(_T.en, _T);
278 if (typeof(_T[lang]) == 'undefined') {
279 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
284 Roo.apply(_T, _T[lang]);
285 // just need to set the text values for everything...
287 /* this will not work ...
291 function formLabel(name, val) {
292 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
295 formLabel('password', "Password"+':');
296 formLabel('username', "Email Address"+':');
297 formLabel('lang', "Language"+':');
298 this.dialog.setTitle("Login");
299 this.dialog.buttons[0].setText("Forgot Password");
300 this.dialog.buttons[1].setText("Login");
320 center: { // needed??
323 // tabPosition: 'top',
326 alwaysShowTabs: false
330 rendered : function(dlg) {
331 this.form = this.items[0];
332 this.form.dialog = dlg;
333 this.buttons[0].form = this.form;
334 this.buttons[0].dialog = dlg
335 this.buttons[1].form = this.form;
336 this.buttons[1].dialog = dlg;
338 // logoprefix comes from base config.
339 //Pman.Login.form.el.createChild({
341 // src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
342 // style: 'margin-bottom: 10px;'
351 //this.resizeToLogo.defer(1000,this);
352 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
354 // this.resizeToLogo.defer(1000,this);
357 var w = Ext.lib.Dom.getViewWidth() - 100;
358 var h = Ext.lib.Dom.getViewHeight() - 100;
359 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
366 if (this.user.id < 0) { // used for inital setup situations.
370 if (this.intervalID) {
372 window.clearInterval(this.intervalID);
373 this.intervalID = false;
377 if (Roo.get('loading')) {
378 Roo.get('loading').remove();
380 if (Roo.get('loading-mask')) {
381 Roo.get('loading-mask').hide();
384 //incomming._node = tnode;
386 //this.dialog.modal = !modal;
387 //this.dialog.show();
388 this.dialog.el.unmask();
391 this.form.setValues({
392 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
393 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
396 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
397 if (this.form.findField('username').getValue().length > 0 ){
398 this.form.findField('password').focus();
400 this.form.findField('username').focus();
408 xtype : 'ContentPanel',
419 style : 'margin : 10px;',
421 actionfailed : function(f, act) {
422 // form can return { errors: .... }
424 //act.result.errors // invalid form element list...
425 //act.result.errorMsg// invalid form element list...
427 this.dialog.el.unmask();
428 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
429 "Login failed - communication error - try again.");
432 actioncomplete: function(re, act) {
434 Roo.state.Manager.set(
435 this.dialog.realm + '.username',
436 this.form.findField('username').getValue()
438 Roo.state.Manager.set(
439 this.dialog.realm + '.lang',
440 Pman.Login.form.findField('lang').getValue()
443 this.dialog.fillAuth(act.result.data);
447 if (Roo.get('loading-mask')) {
448 Roo.get('loading-mask').show();
450 Roo.XComponent.build();
460 fieldLabel: "Email Address",
463 autoCreate : {tag: "input", type: "text", size: "20"}
468 fieldLabel: "Password",
469 inputType: 'password',
472 autoCreate : {tag: "input", type: "text", size: "20"},
474 specialkey : function(e,ev) {
475 if (ev.keyCode == 13) {
476 this.form.dialog.el.mask("Logging in");
477 this.form.doAction('submit', {
478 url: this.form.dialog.url,
479 method: this.form.dialog.method,
488 fieldLabel: "Language",
491 xtype : 'SimpleStore',
492 fields: ['lang', 'ldisp'],
495 [ 'zh_HK' , '\u7E41\u4E2D' ],
496 [ 'zh_CN', '\u7C21\u4E2D' ]
503 displayField:'ldisp',
507 triggerAction: 'all',
508 emptyText:'Select a Language...',
511 select : function(cb, rec, ix) {
512 this.form.switchLang(rec.data.lang);
526 text : "Forgot Password",
530 var n = this.form.findField('username').getValue();
532 Roo.MessageBox.alert("Error", "Fill in your email address");
536 url: this.dialog.url,
540 method: this.dialog.method,
541 success: function(response, opts) { // check successfull...
543 var res = Pman.processResponse(response);
544 if (!res.success) { // error!
545 Roo.MessageBox.alert("Error" ,
546 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
549 Roo.MessageBox.alert("Notice" ,
550 "Please check you email for the Password Reset message");
552 failure : function() {
553 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
566 click : function () {
568 this.dialog.el.mask("Logging in");
569 this.form.doAction('submit', {
570 url: this.dialog.url,
571 method: this.dialog.method