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);
77 failure : Pman.Login.show,
84 check: function(again) // called every so often to refresh cookie etc..
86 if (again) { // could be undefined..
87 Pman.Login.checkFails++;
89 Pman.Login.checkFails = 0;
94 if ( Pman.Login.checkFails > 4) {
95 Pman.Preview.disable();
96 Roo.MessageBox.alert("Error",
97 "Error getting authentication status. - try reloading, or wait a while", function() {
98 _this.sending = false;
103 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
109 url: baseURL + '/Login.js',
114 success: Pman.Login.success,
115 failure : Pman.Login.failure,
123 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
126 this.sending = false;
127 var res = Pman.processResponse(response);
129 if ( Pman.Login.checkFails > 2) {
130 Pman.Preview.disable();
131 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
132 "Error getting authentication status. - try reloading");
136 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
141 success : function(response, opts) // check successfull...
143 this.sending = false;
144 var res = Pman.processResponse(response);
146 return this.failure(response, opts);
148 if (!res.data || !res.data.id) {
149 return this.failure(response,opts);
152 this.fillAuth(res.data);
158 fillAuth: function(au) {
159 this.startAuthCheck();
160 this.authUserId = au.id;
162 this.lastChecked = new Date();
163 Pman.fireEvent('authrefreshed', au);
166 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
167 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
169 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
170 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
171 this.switchLang(au.lang);
174 // open system... - -on setyp..
175 if (this.authUserId < 0) {
176 Roo.MessageBox.alert("Warning",
177 "This is an open system - please set up a admin user with a password.");
180 //Pman.onload(); // which should do nothing if it's a re-auth result...
186 intervalID : false, /// the login refresher...
190 startAuthCheck : function() // starter for timeout checking..
192 if (Pman.Login.intervalID) { // timer already in place...
196 Pman.Login.intervalID = window.setInterval(function() {
197 Pman.Login.check(false);
198 }, 120000); // every 120 secs = 2mins..
211 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
212 { // the real end set is here...
229 // tabPosition: 'top',
232 alwaysShowTabs: false
239 this.dialog.addButton("Forgot Password", function()
242 var n = _this.form.findField('username').getValue();
244 Roo.MessageBox.alert("Error", "Fill in your email address");
248 url: baseURL + '/Login.js',
253 success: function(response, opts) { // check successfull...
255 var res = Pman.processResponse(response);
256 if (!res.success) { // error!
257 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
260 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
262 failure : function() {
263 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
269 this.dialog.addButton("Login", function()
271 Pman.Login.dialog.el.mask("Logging in");
272 Pman.Login.form.doAction('submit', {
273 url: baseURL + '/Login',
277 this.layout = this.dialog.getLayout();
278 this.layout.beginUpdate();
280 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
281 // generate some other tabs
282 this.form = new Roo.form.Form({
286 actionfailed : function(f, act) {
287 // form can return { errors: .... }
289 //act.result.errors // invalid form element list...
290 //act.result.errorMsg// invalid form element list...
292 Pman.Login.dialog.el.unmask();
293 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
294 "Login failed - communication error - try again.");
297 actioncomplete: function(re, act) {
299 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
300 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
301 Pman.Login.fillAuth(act.result.data);
303 Pman.Login.dialog.hide();
304 if (Roo.get('loading-mask')) {
305 //Roo.get('loading').show();
306 Roo.get('loading-mask').show();
325 new Roo.form.TextField({
326 fieldLabel: "Email Address",
329 autoCreate : {tag: "input", type: "text", size: "20"}
332 new Roo.form.TextField({
333 fieldLabel: "Password",
334 inputType: 'password',
337 autoCreate : {tag: "input", type: "text", size: "20"},
339 specialkey : function(e,ev) {
340 if (ev.keyCode == 13) {
341 Pman.Login.dialog.el.mask("Logging in");
342 Pman.Login.form.doAction('submit', {
343 url: baseURL + '/Login.json',
350 new Roo.form.ComboBox({
351 fieldLabel: "Language",
354 xtype : 'SimpleStore',
355 fields: ['lang', 'ldisp'],
358 [ 'zh_HK' , '\u7E41\u4E2D' ],
359 [ 'zh_CN', '\u7C21\u4E2D' ]
366 displayField:'ldisp',
370 triggerAction: 'all',
371 emptyText:'Select a Language...',
374 select : function(cb, rec, ix) {
377 Pman.Login.switchLang(rec.data.lang);
387 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
388 ef.dom.style.margin = 10;
390 this.form.render(ef.dom);
391 // logoprefix comes from base config.
392 Pman.Login.form.el.createChild({
394 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
395 style: 'margin-bottom: 10px;'
397 Pman.Login.form.el.dom.firstChild
400 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
402 //title: 'Org Details',
409 this.layout.endUpdate();
411 this.fireEvent('render', this);
418 resizeToLogo : function()
420 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
422 this.resizeToLogo.defer(1000,this);
425 var w = Ext.lib.Dom.getViewWidth() - 100;
426 var h = Ext.lib.Dom.getViewHeight() - 100;
427 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
428 Pman.Login.dialog.center();
433 show: function (modal)
438 modal = modal || false;
439 if (Pman.Login.authUserId < 0) { // logout!?
443 if (Pman.Login.intervalID) {
445 window.clearInterval(Pman.Login.intervalID);
446 Pman.Login.intervalID = false;
453 if (Roo.get('loading')) {
454 Roo.get('loading').remove();
456 if (Roo.get('loading-mask')) {
457 Roo.get('loading-mask').hide();
460 //incomming._node = tnode;
462 this.dialog.modal = !modal;
464 this.dialog.el.unmask();
465 this.resizeToLogo.defer(1000,this);
468 this.form.setValues({
469 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
470 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
472 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
473 if (this.form.findField('username').getValue().length > 0 ){
474 this.form.findField('password').focus();
476 this.form.findField('username').focus();
486 window.onbeforeunload = function() { }; // false does not work for IE..
487 Pman.Login.authUserId = -1;
489 url: baseURL + '/Login.html',
494 failure : function() {
495 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
496 document.location = baseURL + '?ts=' + Math.random();
500 success : function() {
501 Pman.Login.authUserId = -1;
502 Pman.Login.checkFails =0;
504 document.location = baseURL + '?ts=' + Math.random();
510 switchLang : function (lang) {
511 if (!lang || !lang.length) {
514 if (typeof(_T.en) == 'undefined') {
516 Roo.apply(_T.en, _T);
519 if (typeof(_T[lang]) == 'undefined') {
520 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
525 Roo.apply(_T, _T[lang]);
526 // just need to set the text values for everything...
530 function formLabel(name, val) {
532 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
533 if (lbl.getElementsByTagName('label').length) {
534 lbl = lbl.getElementsByTagName('label')[0];
536 lbl = lbl.parentNode.getElementsByTagName('label')[0];
542 formLabel('password', "Password"+':');
543 formLabel('username', "Email Address"+':');
544 formLabel('lang', "Language"+':');
545 this.dialog.setTitle("Login");
546 this.dialog.buttons[0].setText("Forgot Password");
547 this.dialog.buttons[1].setText("Login");
553 inGroup : function(g)
555 return this.authUser && this.authUser.groups &&
556 this.authUser.groups.indexOf(g) > -1;
560 return this.authUser && this.authUser.company_id_comptype &&
561 this.authUser.company_id_comptype == 'OWNER';
565 * Depreciated = use Pman.I18n
568 i18nList: function (type, codes)
571 return Pman.I18n.listToNames(type, codes);
573 i18n: function(type, code)
575 return Pman.I18n.toName(type, code);