1 //<script type="text/javascript">
5 * fires Pman 'authrefreshed' event on every poll to server..
10 re-arrange language code...
11 * flipping language should be like this:
13 * Ext.apply(_T, _T[lang]);
19 Pman.Login = new Roo.util.Observable({
33 authUser: { id : false },
39 checkConnection : false, // the Roo.data.Connection for checking if still authenticated.
41 onLoad : function() // called on page load...
46 if (Roo.get('loading')) {
47 Roo.get('loading').remove();
49 this.switchLang('en');
51 // check if we are logged in..
53 url: baseURL + '/Login.js',
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 Pman.Login.failure(response,opts);
69 if (!res.data.id) { // id=0 == login failure.
70 return this.show(true);
74 //console.log(success);
75 this.fillAuth(res.data);
80 failure : Pman.Login.show,
87 check: function(again) // called every so often to refresh cookie etc..
89 if (again) { // could be undefined..
90 Pman.Login.checkFails++;
92 Pman.Login.checkFails = 0;
97 if ( Pman.Login.checkFails > 4) {
98 Pman.Preview.disable();
99 Roo.MessageBox.alert("Error",
100 "Error getting authentication status. - try reloading, or wait a while", function() {
101 _this.sending = false;
106 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
110 if (!this.checkConnection) {
111 this.checkConnection = new Roo.data.Connection();
113 this.checkConnection.request({
114 url: baseURL + '/Login.js',
119 success: Pman.Login.success,
120 failure : Pman.Login.failure,
128 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
131 this.sending = false;
132 var res = Pman.processResponse(response);
134 if ( Pman.Login.checkFails > 2) {
135 if (typeof(Pman.Preview) != 'undefined') {
136 Pman.Preview.disable(); // not sure why this was added - but MO chrome does not have it.
138 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
139 "Error getting authentication status. - try reloading");
143 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
148 success : function(response, opts) // check successfull...
150 this.sending = false;
151 var res = Pman.processResponse(response);
153 return this.failure(response, opts);
155 if (!res.data || !res.data.id) {
156 return this.failure(response,opts);
159 this.fillAuth(res.data);
167 if (Pman.Login.callback) {
168 Pman.Login.callback();
174 fillAuth: function(au) {
175 this.startAuthCheck();
176 this.authUserId = au.id;
178 this.lastChecked = new Date();
179 // if login is used on other applicaitons..
180 if (Pman.fireEvent) { Pman.fireEvent('authrefreshed', au); }
183 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
184 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
186 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
187 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
188 this.switchLang(au.lang);
191 // open system... - -on setyp..
192 if (this.authUserId < 0) {
193 Roo.MessageBox.alert("Warning",
194 "This is an open system - please set up a admin user with a password.");
197 //Pman.onload(); // which should do nothing if it's a re-auth result...
203 intervalID : false, /// the login refresher...
207 startAuthCheck : function() // starter for timeout checking..
209 if (Pman.Login.intervalID) { // timer already in place...
213 Pman.Login.intervalID = window.setInterval(function() {
214 Pman.Login.check(false);
215 }, 120000); // every 120 secs = 2mins..
228 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
229 { // the real end set is here...
246 // tabPosition: 'top',
249 alwaysShowTabs: false
256 this.dialog.addButton("Forgot Password", function()
259 var n = _this.form.findField('username').getValue();
261 Roo.MessageBox.alert("Error", "Fill in your email address");
265 url: baseURL + '/Login.js',
266 mask : "Sending Password Reset email",
271 success: function(res) { // check successfull...
273 if (!res.success) { // error!
274 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
277 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
279 failure : function() {
280 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
286 this.dialog.addButton("Login", function()
288 Pman.Login.dialog.el.mask("Logging in");
289 Pman.Login.form.doAction('submit', {
290 url: baseURL + '/Login',
294 this.layout = this.dialog.getLayout();
295 this.layout.beginUpdate();
297 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
298 // generate some other tabs
299 this.form = new Roo.form.Form({
303 actionfailed : function(f, act) {
304 // form can return { errors: .... }
306 //act.result.errors // invalid form element list...
307 //act.result.errorMsg// invalid form element list...
309 Pman.Login.dialog.el.unmask();
310 var msg = act.result.errorMsg || act.result.message;
311 msg = msg || "Login failed - communication error - try again.";
312 Roo.MessageBox.alert("Error", msg);
315 actioncomplete: function(re, act) {
317 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
318 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
319 Pman.Login.fillAuth(act.result.data);
321 Pman.Login.dialog.hide();
322 if (Roo.get('loading-mask')) {
323 //Roo.get('loading').show();
324 Roo.get('loading-mask').show();
329 if (Pman.Login.callback) {
330 Pman.Login.callback();
346 new Roo.form.TextField({
347 fieldLabel: "Email Address",
350 autoCreate : {tag: "input", type: "text", size: "20"}
353 new Roo.form.Password({
354 fieldLabel: "Password",
357 autoCreate : {tag: "input", type: "text", size: "20"},
359 specialkey : function(e,ev) {
360 if (ev.keyCode == 13) {
361 Pman.Login.dialog.el.mask("Logging in");
362 Pman.Login.form.doAction('submit', {
363 url: baseURL + '/Login',
370 new Roo.form.ComboBox({
371 fieldLabel: "Language",
374 xtype : 'SimpleStore',
375 fields: ['lang', 'ldisp'],
378 [ 'zh_HK' , '\u7E41\u4E2D' ],
379 [ 'zh_CN', '\u7C21\u4E2D' ]
386 displayField:'ldisp',
390 triggerAction: 'all',
391 emptyText:'Select a Language...',
394 select : function(cb, rec, ix) {
397 Pman.Login.switchLang(rec.data.lang);
407 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
408 ef.dom.style.margin = 10;
410 this.form.render(ef.dom);
411 // logoprefix comes from base config - normally the owner company logo...
414 var img = typeof(appLogo) != 'undefined' && appLogo.length ? appLogo :
415 rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif' ;
417 Pman.Login.form.el.createChild({
420 style: 'margin-bottom: 10px;'
422 Pman.Login.form.el.dom.firstChild
423 ).on('error', function() {
424 this.dom.style.visibility = 'hidden';
425 this.dom.style.height = '10px';
428 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
430 //title: 'Org Details',
437 this.layout.endUpdate();
439 this.fireEvent('render', this);
446 resizeToLogo : function()
448 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
450 this.resizeToLogo.defer(1000,this);
453 var w = Roo.lib.Dom.getViewWidth() - 100;
454 var h = Roo.lib.Dom.getViewHeight() - 100;
455 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
456 Pman.Login.dialog.center();
461 show: function (modal, cb)
469 this.callback = cb; // used for non-pman usage..
470 modal = modal || false;
471 if (Pman.Login.authUserId < 0) { // logout!?
475 if (Pman.Login.intervalID) {
477 window.clearInterval(Pman.Login.intervalID);
478 Pman.Login.intervalID = false;
485 if (Roo.get('loading')) {
486 Roo.get('loading').remove();
488 if (Roo.get('loading-mask')) {
489 Roo.get('loading-mask').hide();
492 //incomming._node = tnode;
493 // why we want this non-modal????
495 this.dialog.modal = !modal;
497 this.dialog.el.unmask();
498 this.resizeToLogo.defer(1000,this);
500 // if we have not created a provider.. do it now...
501 if (!Roo.state.Manager.getProvider().expires) {
502 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
506 this.form.setValues({
507 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
508 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
510 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
511 if (this.form.findField('username').getValue().length > 0 ){
512 this.form.findField('password').focus();
514 this.form.findField('username').focus();
524 window.onbeforeunload = function() { }; // false does not work for IE..
525 Pman.Login.authUserId = -1;
527 url: baseURL + '/Login.html',
532 failure : function() {
533 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
534 document.location = baseURL + '?ts=' + Math.random();
538 success : function() {
539 Pman.Login.authUserId = -1;
540 Pman.Login.checkFails =0;
542 document.location = baseURL + '?ts=' + Math.random();
548 switchLang : function (lang) {
549 if (!lang || !lang.length) {
552 if (typeof(_T.en) == 'undefined') {
554 Roo.apply(_T.en, _T);
557 if (typeof(_T[lang]) == 'undefined') {
558 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
563 Roo.apply(_T, _T[lang]);
564 // just need to set the text values for everything...
568 function formLabel(name, val) {
570 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
571 if (lbl.getElementsByTagName('label').length) {
572 lbl = lbl.getElementsByTagName('label')[0];
574 lbl = lbl.parentNode.getElementsByTagName('label')[0];
580 formLabel('password', "Password"+':');
581 formLabel('username', "Email Address"+':');
582 formLabel('lang', "Language"+':');
583 this.dialog.setTitle("Login");
584 this.dialog.buttons[0].setText("Forgot Password");
585 this.dialog.buttons[1].setText("Login");
591 inGroup : function(g)
593 return this.authUser && this.authUser.groups &&
594 this.authUser.groups.indexOf(g) > -1;
598 return this.authUser && this.authUser.company_id_comptype &&
599 this.authUser.company_id_comptype == 'OWNER';
603 * Depreciated = use Pman.I18n
606 i18nList: function (type, codes)
609 return Pman.I18n.listToNames(type, codes);
611 i18n: function(type, code)
613 return Pman.I18n.toName(type, code);