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 onLoad : function() // called on page load...
44 if (Roo.get('loading')) {
45 Roo.get('loading').remove();
47 this.switchLang('en');
49 // check if we are logged in..
51 url: baseURL + '/Login.js',
56 success: function(response, opts) { // check successfull...
58 var res = Pman.processResponse(response);
60 if (!res.success) { // error!
62 //console.log('call failure');
63 return Pman.Login.failure(response,opts);
67 if (!res.data.id) { // id=0 == login failure.
68 return this.show(true);
72 //console.log(success);
73 this.fillAuth(res.data);
78 failure : Pman.Login.show,
85 check: function(again) // called every so often to refresh cookie etc..
87 if (again) { // could be undefined..
88 Pman.Login.checkFails++;
90 Pman.Login.checkFails = 0;
95 if ( Pman.Login.checkFails > 4) {
96 Pman.Preview.disable();
97 Roo.MessageBox.alert("Error",
98 "Error getting authentication status. - try reloading, or wait a while", function() {
99 _this.sending = false;
104 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
110 url: baseURL + '/Login.js',
115 success: Pman.Login.success,
116 failure : Pman.Login.failure,
124 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
127 this.sending = false;
128 var res = Pman.processResponse(response);
130 if ( Pman.Login.checkFails > 2) {
131 Pman.Preview.disable();
132 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
133 "Error getting authentication status. - try reloading");
137 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
142 success : function(response, opts) // check successfull...
144 this.sending = false;
145 var res = Pman.processResponse(response);
147 return this.failure(response, opts);
149 if (!res.data || !res.data.id) {
150 return this.failure(response,opts);
153 this.fillAuth(res.data);
160 fillAuth: function(au) {
161 this.startAuthCheck();
162 this.authUserId = au.id;
164 this.lastChecked = new Date();
165 // if login is used on other applicaitons..
166 if (Pman.fireEvent) { Pman.fireEvent('authrefreshed', au); }
169 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
170 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
172 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
173 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
174 this.switchLang(au.lang);
177 // open system... - -on setyp..
178 if (this.authUserId < 0) {
179 Roo.MessageBox.alert("Warning",
180 "This is an open system - please set up a admin user with a password.");
183 //Pman.onload(); // which should do nothing if it's a re-auth result...
189 intervalID : false, /// the login refresher...
193 startAuthCheck : function() // starter for timeout checking..
195 if (Pman.Login.intervalID) { // timer already in place...
199 Pman.Login.intervalID = window.setInterval(function() {
200 Pman.Login.check(false);
201 }, 120000); // every 120 secs = 2mins..
214 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
215 { // the real end set is here...
232 // tabPosition: 'top',
235 alwaysShowTabs: false
242 this.dialog.addButton("Forgot Password", function()
245 var n = _this.form.findField('username').getValue();
247 Roo.MessageBox.alert("Error", "Fill in your email address");
251 url: baseURL + '/Login.js',
256 success: function(response, opts) { // check successfull...
258 var res = Pman.processResponse(response);
259 if (!res.success) { // error!
260 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
263 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
265 failure : function() {
266 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
272 this.dialog.addButton("Login", function()
274 Pman.Login.dialog.el.mask("Logging in");
275 Pman.Login.form.doAction('submit', {
276 url: baseURL + '/Login',
280 this.layout = this.dialog.getLayout();
281 this.layout.beginUpdate();
283 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
284 // generate some other tabs
285 this.form = new Roo.form.Form({
289 actionfailed : function(f, act) {
290 // form can return { errors: .... }
292 //act.result.errors // invalid form element list...
293 //act.result.errorMsg// invalid form element list...
295 Pman.Login.dialog.el.unmask();
296 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
297 "Login failed - communication error - try again.");
300 actioncomplete: function(re, act) {
302 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
303 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
304 Pman.Login.fillAuth(act.result.data);
306 Pman.Login.dialog.hide();
307 if (Roo.get('loading-mask')) {
308 //Roo.get('loading').show();
309 Roo.get('loading-mask').show();
328 new Roo.form.TextField({
329 fieldLabel: "Email Address",
332 autoCreate : {tag: "input", type: "text", size: "20"}
335 new Roo.form.TextField({
336 fieldLabel: "Password",
337 inputType: 'password',
340 autoCreate : {tag: "input", type: "text", size: "20"},
342 specialkey : function(e,ev) {
343 if (ev.keyCode == 13) {
344 Pman.Login.dialog.el.mask("Logging in");
345 Pman.Login.form.doAction('submit', {
346 url: baseURL + '/Login.json',
353 new Roo.form.ComboBox({
354 fieldLabel: "Language",
357 xtype : 'SimpleStore',
358 fields: ['lang', 'ldisp'],
361 [ 'zh_HK' , '\u7E41\u4E2D' ],
362 [ 'zh_CN', '\u7C21\u4E2D' ]
369 displayField:'ldisp',
373 triggerAction: 'all',
374 emptyText:'Select a Language...',
377 select : function(cb, rec, ix) {
380 Pman.Login.switchLang(rec.data.lang);
390 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
391 ef.dom.style.margin = 10;
393 this.form.render(ef.dom);
394 // logoprefix comes from base config.
395 Pman.Login.form.el.createChild({
397 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
398 style: 'margin-bottom: 10px;'
400 Pman.Login.form.el.dom.firstChild
403 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
405 //title: 'Org Details',
412 this.layout.endUpdate();
414 this.fireEvent('render', this);
421 resizeToLogo : function()
423 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
425 this.resizeToLogo.defer(1000,this);
428 var w = Roo.lib.Dom.getViewWidth() - 100;
429 var h = Roo.lib.Dom.getViewHeight() - 100;
430 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
431 Pman.Login.dialog.center();
436 show: function (modal)
441 modal = modal || false;
442 if (Pman.Login.authUserId < 0) { // logout!?
446 if (Pman.Login.intervalID) {
448 window.clearInterval(Pman.Login.intervalID);
449 Pman.Login.intervalID = false;
456 if (Roo.get('loading')) {
457 Roo.get('loading').remove();
459 if (Roo.get('loading-mask')) {
460 Roo.get('loading-mask').hide();
463 //incomming._node = tnode;
465 this.dialog.modal = !modal;
467 this.dialog.el.unmask();
468 this.resizeToLogo.defer(1000,this);
471 this.form.setValues({
472 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
473 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
475 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
476 if (this.form.findField('username').getValue().length > 0 ){
477 this.form.findField('password').focus();
479 this.form.findField('username').focus();
489 window.onbeforeunload = function() { }; // false does not work for IE..
490 Pman.Login.authUserId = -1;
492 url: baseURL + '/Login.html',
497 failure : function() {
498 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
499 document.location = baseURL + '?ts=' + Math.random();
503 success : function() {
504 Pman.Login.authUserId = -1;
505 Pman.Login.checkFails =0;
507 document.location = baseURL + '?ts=' + Math.random();
513 switchLang : function (lang) {
514 if (!lang || !lang.length) {
517 if (typeof(_T.en) == 'undefined') {
519 Roo.apply(_T.en, _T);
522 if (typeof(_T[lang]) == 'undefined') {
523 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
528 Roo.apply(_T, _T[lang]);
529 // just need to set the text values for everything...
533 function formLabel(name, val) {
535 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
536 if (lbl.getElementsByTagName('label').length) {
537 lbl = lbl.getElementsByTagName('label')[0];
539 lbl = lbl.parentNode.getElementsByTagName('label')[0];
545 formLabel('password', "Password"+':');
546 formLabel('username', "Email Address"+':');
547 formLabel('lang', "Language"+':');
548 this.dialog.setTitle("Login");
549 this.dialog.buttons[0].setText("Forgot Password");
550 this.dialog.buttons[1].setText("Login");
556 inGroup : function(g)
558 return this.authUser && this.authUser.groups &&
559 this.authUser.groups.indexOf(g) > -1;
563 return this.authUser && this.authUser.company_id_comptype &&
564 this.authUser.company_id_comptype == 'OWNER';
568 * Depreciated = use Pman.I18n
571 i18nList: function (type, codes)
574 return Pman.I18n.listToNames(type, codes);
576 i18n: function(type, code)
578 return Pman.I18n.toName(type, code);