1 //<script type="text/javascript">
5 * A generic Login Dialog..... - only one needed in theory!?!?
7 * Fires XComponent builder on success...
12 * Myapp.login = Roo.Login({
15 password' : 'password',
23 * Ext.apply(_T, _T[lang]);
27 Roo.Login = function(cfg)
30 Roo.each(this.items, function(e) {
33 Roo.Document.on('ready', function() {
37 Roo.Login.superclass.constructor.call(this);
39 Roo.extend(Roo.Login, Roo.LayoutDialog, {
47 onLoad : function() // called on page load...
51 if (Roo.get('loading')) { // clear any loading indicator..
52 Roo.get('loading').remove();
55 this.switchLang('en'); // set the language to english..
58 success: function(response, opts) { // check successfull...
60 var res = Pman.processResponse(response);
62 if (!res.success) { // error!
64 //console.log('call failure');
65 return this.failure(response,opts);
68 if (!res.data.id) { // id=0 == login failure.
69 return this.show(true);
73 //console.log(success);
74 this.fillAuth(res.data);
76 Roo.XComponent.build();
84 check: function(cfg) // called every so often to refresh cookie etc..
86 if (again) { // could be undefined..
93 if ( this.checkFails > 4) {
94 Roo.MessageBox.alert("Error",
95 "Error getting authentication status. - try reloading, or wait a while", function() {
96 _this.sending = false;
101 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
112 success: cfg.success || this.success,
113 failure : cfg.failure || this.failure,
128 Pman.Login = new Roo.util.Observable({
141 authUser: { id : false },
148 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
151 this.sending = false;
152 var res = Pman.processResponse(response);
154 if ( Pman.Login.checkFails > 2) {
155 Pman.Preview.disable();
156 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
157 "Error getting authentication status. - try reloading");
161 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
166 success : function(response, opts) // check successfull...
168 this.sending = false;
169 var res = Pman.processResponse(response);
171 return this.failure(response, opts);
173 if (!res.data || !res.data.id) {
174 return this.failure(response,opts);
177 this.fillAuth(res.data);
183 fillAuth: function(au) {
184 this.startAuthCheck();
185 this.authUserId = au.id;
187 this.lastChecked = new Date();
188 Pman.fireEvent('authrefreshed', au);
189 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
190 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
192 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
193 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
194 this.switchLang(au.lang);
197 // open system... - -on setyp..
198 if (this.authUserId < 0) {
199 Roo.MessageBox.alert("Warning",
200 "This is an open system - please set up a admin user with a password.");
203 //Pman.onload(); // which should do nothing if it's a re-auth result...
209 intervalID : false, /// the login refresher...
213 startAuthCheck : function() // starter for timeout checking..
215 if (Pman.Login.intervalID) { // timer already in place...
219 Pman.Login.intervalID = window.setInterval(function() {
220 Pman.Login.check(false);
221 }, 120000); // every 120 secs = 2mins..
234 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
235 { // the real end set is here...
252 // tabPosition: 'top',
255 alwaysShowTabs: false
262 this.dialog.addButton("Forgot Password", function()
265 var n = _this.form.findField('username').getValue();
267 Roo.MessageBox.alert("Error", "Fill in your email address");
271 url: baseURL + '/Login.js',
276 success: function(response, opts) { // check successfull...
278 var res = Pman.processResponse(response);
279 if (!res.success) { // error!
280 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
283 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
285 failure : function() {
286 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
292 this.dialog.addButton("Login", function()
294 Pman.Login.dialog.el.mask("Logging in");
295 Pman.Login.form.doAction('submit', {
296 url: baseURL + '/Login',
300 this.layout = this.dialog.getLayout();
301 this.layout.beginUpdate();
303 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
304 // generate some other tabs
305 this.form = new Roo.form.Form({
309 actionfailed : function(f, act) {
310 // form can return { errors: .... }
312 //act.result.errors // invalid form element list...
313 //act.result.errorMsg// invalid form element list...
315 Pman.Login.dialog.el.unmask();
316 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
317 "Login failed - communication error - try again.");
320 actioncomplete: function(re, act) {
322 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
323 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
324 Pman.Login.fillAuth(act.result.data);
326 Pman.Login.dialog.hide();
327 if (Roo.get('loading-mask')) {
328 //Roo.get('loading').show();
329 Roo.get('loading-mask').show();
348 new Roo.form.TextField({
349 fieldLabel: "Email Address",
352 autoCreate : {tag: "input", type: "text", size: "20"}
355 new Roo.form.TextField({
356 fieldLabel: "Password",
357 inputType: 'password',
360 autoCreate : {tag: "input", type: "text", size: "20"},
362 specialkey : function(e,ev) {
363 if (ev.keyCode == 13) {
364 Pman.Login.dialog.el.mask("Logging in");
365 Pman.Login.form.doAction('submit', {
366 url: baseURL + '/Login.json',
373 new Roo.form.ComboBox({
374 fieldLabel: "Language",
377 xtype : 'SimpleStore',
378 fields: ['lang', 'ldisp'],
381 [ 'zh_HK' , '\u7E41\u4E2D' ],
382 [ 'zh_CN', '\u7C21\u4E2D' ]
389 displayField:'ldisp',
393 triggerAction: 'all',
394 emptyText:'Select a Language...',
397 select : function(cb, rec, ix) {
400 Pman.Login.switchLang(rec.data.lang);
410 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
411 ef.dom.style.margin = 10;
413 this.form.render(ef.dom);
414 // logoprefix comes from base config.
415 Pman.Login.form.el.createChild({
417 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
418 style: 'margin-bottom: 10px;'
420 Pman.Login.form.el.dom.firstChild
423 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
425 //title: 'Org Details',
432 this.layout.endUpdate();
434 this.fireEvent('render', this);
441 resizeToLogo : function()
443 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
445 this.resizeToLogo.defer(1000,this);
448 var w = Ext.lib.Dom.getViewWidth() - 100;
449 var h = Ext.lib.Dom.getViewHeight() - 100;
450 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
451 Pman.Login.dialog.center();
456 show: function (modal)
461 modal = modal || false;
462 if (Pman.Login.authUserId < 0) { // logout!?
466 if (Pman.Login.intervalID) {
468 window.clearInterval(Pman.Login.intervalID);
469 Pman.Login.intervalID = false;
476 if (Roo.get('loading')) {
477 Roo.get('loading').remove();
479 if (Roo.get('loading-mask')) {
480 Roo.get('loading-mask').hide();
483 //incomming._node = tnode;
485 this.dialog.modal = !modal;
487 this.dialog.el.unmask();
488 this.resizeToLogo.defer(1000,this);
491 this.form.setValues({
492 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
493 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
495 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
496 if (this.form.findField('username').getValue().length > 0 ){
497 this.form.findField('password').focus();
499 this.form.findField('username').focus();
509 window.onbeforeunload = function() { }; // false does not work for IE..
510 Pman.Login.authUserId = -1;
512 url: baseURL + '/Login.html',
517 failure : function() {
518 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
519 document.location = baseURL + '?ts=' + Math.random();
523 success : function() {
524 Pman.Login.authUserId = -1;
525 Pman.Login.checkFails =0;
527 document.location = baseURL + '?ts=' + Math.random();
533 switchLang : function (lang) {
537 if (typeof(_T.en) == 'undefined') {
539 Roo.apply(_T.en, _T);
542 if (typeof(_T[lang]) == 'undefined') {
543 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
548 Roo.apply(_T, _T[lang]);
549 // just need to set the text values for everything...
553 function formLabel(name, val) {
555 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
556 if (lbl.getElementsByTagName('label').length) {
557 lbl = lbl.getElementsByTagName('label')[0];
559 lbl = lbl.parentNode.getElementsByTagName('label')[0];
565 formLabel('password', "Password"+':');
566 formLabel('username', "Email Address"+':');
567 formLabel('lang', "Language"+':');
568 this.dialog.setTitle("Login");
569 this.dialog.buttons[0].setText("Forgot Password");
570 this.dialog.buttons[1].setText("Login");
576 inGroup : function(g)
578 return this.authUser && this.authUser.groups &&
579 this.authUser.groups.indexOf(g) > -1;
583 return this.authUser && this.authUser.company_id_comptype &&
584 this.authUser.company_id_comptype == 'OWNER';
588 * Depreciated = use Pman.I18n
591 i18nList: function (type, codes)
594 return Pman.I18n.listToNames(type, codes);
596 i18n: function(type, code)
598 return Pman.I18n.toName(type, code);