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 Pman.fireEvent('authrefreshed', au);
168 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
169 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
171 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
172 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
173 this.switchLang(au.lang);
176 // open system... - -on setyp..
177 if (this.authUserId < 0) {
178 Roo.MessageBox.alert("Warning",
179 "This is an open system - please set up a admin user with a password.");
182 //Pman.onload(); // which should do nothing if it's a re-auth result...
188 intervalID : false, /// the login refresher...
192 startAuthCheck : function() // starter for timeout checking..
194 if (Pman.Login.intervalID) { // timer already in place...
198 Pman.Login.intervalID = window.setInterval(function() {
199 Pman.Login.check(false);
200 }, 120000); // every 120 secs = 2mins..
213 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
214 { // the real end set is here...
231 // tabPosition: 'top',
234 alwaysShowTabs: false
241 this.dialog.addButton("Forgot Password", function()
244 var n = _this.form.findField('username').getValue();
246 Roo.MessageBox.alert("Error", "Fill in your email address");
250 url: baseURL + '/Login.js',
255 success: function(response, opts) { // check successfull...
257 var res = Pman.processResponse(response);
258 if (!res.success) { // error!
259 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
262 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
264 failure : function() {
265 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
271 this.dialog.addButton("Login", function()
273 Pman.Login.dialog.el.mask("Logging in");
274 Pman.Login.form.doAction('submit', {
275 url: baseURL + '/Login',
279 this.layout = this.dialog.getLayout();
280 this.layout.beginUpdate();
282 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
283 // generate some other tabs
284 this.form = new Roo.form.Form({
288 actionfailed : function(f, act) {
289 // form can return { errors: .... }
291 //act.result.errors // invalid form element list...
292 //act.result.errorMsg// invalid form element list...
294 Pman.Login.dialog.el.unmask();
295 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
296 "Login failed - communication error - try again.");
299 actioncomplete: function(re, act) {
301 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
302 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
303 Pman.Login.fillAuth(act.result.data);
305 Pman.Login.dialog.hide();
306 if (Roo.get('loading-mask')) {
307 //Roo.get('loading').show();
308 Roo.get('loading-mask').show();
327 new Roo.form.TextField({
328 fieldLabel: "Email Address",
331 autoCreate : {tag: "input", type: "text", size: "20"}
334 new Roo.form.TextField({
335 fieldLabel: "Password",
336 inputType: 'password',
339 autoCreate : {tag: "input", type: "text", size: "20"},
341 specialkey : function(e,ev) {
342 if (ev.keyCode == 13) {
343 Pman.Login.dialog.el.mask("Logging in");
344 Pman.Login.form.doAction('submit', {
345 url: baseURL + '/Login.json',
352 new Roo.form.ComboBox({
353 fieldLabel: "Language",
356 xtype : 'SimpleStore',
357 fields: ['lang', 'ldisp'],
360 [ 'zh_HK' , '\u7E41\u4E2D' ],
361 [ 'zh_CN', '\u7C21\u4E2D' ]
368 displayField:'ldisp',
372 triggerAction: 'all',
373 emptyText:'Select a Language...',
376 select : function(cb, rec, ix) {
379 Pman.Login.switchLang(rec.data.lang);
389 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
390 ef.dom.style.margin = 10;
392 this.form.render(ef.dom);
393 // logoprefix comes from base config.
394 Pman.Login.form.el.createChild({
396 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
397 style: 'margin-bottom: 10px;'
399 Pman.Login.form.el.dom.firstChild
402 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
404 //title: 'Org Details',
411 this.layout.endUpdate();
413 this.fireEvent('render', this);
420 resizeToLogo : function()
422 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
424 this.resizeToLogo.defer(1000,this);
427 var w = Ext.lib.Dom.getViewWidth() - 100;
428 var h = Ext.lib.Dom.getViewHeight() - 100;
429 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
430 Pman.Login.dialog.center();
435 show: function (modal)
440 modal = modal || false;
441 if (Pman.Login.authUserId < 0) { // logout!?
445 if (Pman.Login.intervalID) {
447 window.clearInterval(Pman.Login.intervalID);
448 Pman.Login.intervalID = false;
455 if (Roo.get('loading')) {
456 Roo.get('loading').remove();
458 if (Roo.get('loading-mask')) {
459 Roo.get('loading-mask').hide();
462 //incomming._node = tnode;
464 this.dialog.modal = !modal;
466 this.dialog.el.unmask();
467 this.resizeToLogo.defer(1000,this);
470 this.form.setValues({
471 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
472 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
474 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
475 if (this.form.findField('username').getValue().length > 0 ){
476 this.form.findField('password').focus();
478 this.form.findField('username').focus();
488 window.onbeforeunload = function() { }; // false does not work for IE..
489 Pman.Login.authUserId = -1;
491 url: baseURL + '/Login.html',
496 failure : function() {
497 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
498 document.location = baseURL + '?ts=' + Math.random();
502 success : function() {
503 Pman.Login.authUserId = -1;
504 Pman.Login.checkFails =0;
506 document.location = baseURL + '?ts=' + Math.random();
512 switchLang : function (lang) {
513 if (!lang || !lang.length) {
516 if (typeof(_T.en) == 'undefined') {
518 Roo.apply(_T.en, _T);
521 if (typeof(_T[lang]) == 'undefined') {
522 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
527 Roo.apply(_T, _T[lang]);
528 // just need to set the text values for everything...
532 function formLabel(name, val) {
534 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
535 if (lbl.getElementsByTagName('label').length) {
536 lbl = lbl.getElementsByTagName('label')[0];
538 lbl = lbl.parentNode.getElementsByTagName('label')[0];
544 formLabel('password', "Password"+':');
545 formLabel('username', "Email Address"+':');
546 formLabel('lang', "Language"+':');
547 this.dialog.setTitle("Login");
548 this.dialog.buttons[0].setText("Forgot Password");
549 this.dialog.buttons[1].setText("Login");
555 inGroup : function(g)
557 return this.authUser && this.authUser.groups &&
558 this.authUser.groups.indexOf(g) > -1;
562 return this.authUser && this.authUser.company_id_comptype &&
563 this.authUser.company_id_comptype == 'OWNER';
567 * Depreciated = use Pman.I18n
570 i18nList: function (type, codes)
573 return Pman.I18n.listToNames(type, codes);
575 i18n: function(type, code)
577 return Pman.I18n.toName(type, code);