1 //<script type="text/javascript">
5 re-arrange language code...
7 * flipping language should be like this:
9 * Ext.apply(_T, _T[lang]);
15 Pman.Login = new Roo.util.Observable({
21 * @event poll fired after server has been polled for login information
22 * which may also contain extra user info.
36 authUser: { id : false },
42 onLoad : function() // called on page load...
47 if (Roo.get('loading')) {
48 Roo.get('loading').remove();
50 this.switchLang('en');
52 // check if we are logged in..
54 url: baseURL + '/Login.js',
59 success: function(response, opts) { // check successfull...
61 var res = Pman.processResponse(response);
63 if (!res.success) { // error!
65 //console.log('call failure');
66 return Pman.Login.failure(response,opts);
70 if (!res.data.id) { // id=0 == login failure.
71 return this.show(true);
75 //console.log(success);
76 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.
112 url: baseURL + '/Login.js',
117 success: Pman.Login.success,
118 failure : Pman.Login.failure,
126 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
129 this.sending = false;
130 var res = Pman.processResponse(response);
132 if ( Pman.Login.checkFails > 2) {
133 Pman.Preview.disable();
134 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
135 "Error getting authentication status. - try reloading");
139 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
144 success : function(response, opts) // check successfull...
146 this.sending = false;
147 var res = Pman.processResponse(response);
149 return this.failure(response, opts);
151 if (!res.data || !res.data.id) {
152 return this.failure(response,opts);
155 this.fillAuth(res.data);
161 fillAuth: function(au) {
162 this.startAuthCheck();
163 this.authUserId = au.id;
165 this.lastChecked = new Date();
166 Pman.fireEvent('authrefreshed', au);
167 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
168 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
170 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
171 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
172 this.switchLang(au.lang);
175 // open system... - -on setyp..
176 if (this.authUserId < 0) {
177 Roo.MessageBox.alert("Warning",
178 "This is an open system - please set up a admin user with a password.");
181 //Pman.onload(); // which should do nothing if it's a re-auth result...
187 intervalID : false, /// the login refresher...
191 startAuthCheck : function() // starter for timeout checking..
193 if (Pman.Login.intervalID) { // timer already in place...
197 Pman.Login.intervalID = window.setInterval(function() {
198 Pman.Login.check(false);
199 }, 120000); // every 120 secs = 2mins..
212 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
213 { // the real end set is here...
230 // tabPosition: 'top',
233 alwaysShowTabs: false
240 this.dialog.addButton("Forgot Password", function()
243 var n = _this.form.findField('username').getValue();
245 Roo.MessageBox.alert("Error", "Fill in your email address");
249 url: baseURL + '/Login.js',
254 success: function(response, opts) { // check successfull...
256 var res = Pman.processResponse(response);
257 if (!res.success) { // error!
258 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
261 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
263 failure : function() {
264 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
270 this.dialog.addButton("Login", function()
272 Pman.Login.dialog.el.mask("Logging in");
273 Pman.Login.form.doAction('submit', {
274 url: baseURL + '/Login',
278 this.layout = this.dialog.getLayout();
279 this.layout.beginUpdate();
281 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
282 // generate some other tabs
283 this.form = new Roo.form.Form({
287 actionfailed : function(f, act) {
288 // form can return { errors: .... }
290 //act.result.errors // invalid form element list...
291 //act.result.errorMsg// invalid form element list...
293 Pman.Login.dialog.el.unmask();
294 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
295 "Login failed - communication error - try again.");
298 actioncomplete: function(re, act) {
300 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
301 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
302 Pman.Login.fillAuth(act.result.data);
304 Pman.Login.dialog.hide();
305 if (Roo.get('loading-mask')) {
306 //Roo.get('loading').show();
307 Roo.get('loading-mask').show();
326 new Roo.form.TextField({
327 fieldLabel: "Email Address",
330 autoCreate : {tag: "input", type: "text", size: "20"}
333 new Roo.form.TextField({
334 fieldLabel: "Password",
335 inputType: 'password',
338 autoCreate : {tag: "input", type: "text", size: "20"},
340 specialkey : function(e,ev) {
341 if (ev.keyCode == 13) {
342 Pman.Login.dialog.el.mask("Logging in");
343 Pman.Login.form.doAction('submit', {
344 url: baseURL + '/Login.json',
351 new Roo.form.ComboBox({
352 fieldLabel: "Language",
355 xtype : 'SimpleStore',
356 fields: ['lang', 'ldisp'],
359 [ 'zh_HK' , '\u7E41\u4E2D' ],
360 [ 'zh_CN', '\u7C21\u4E2D' ]
367 displayField:'ldisp',
371 triggerAction: 'all',
372 emptyText:'Select a Language...',
375 select : function(cb, rec, ix) {
378 Pman.Login.switchLang(rec.data.lang);
388 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
389 ef.dom.style.margin = 10;
391 this.form.render(ef.dom);
392 // logoprefix comes from base config.
393 Pman.Login.form.el.createChild({
395 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
396 style: 'margin-bottom: 10px;'
398 Pman.Login.form.el.dom.firstChild
401 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
403 //title: 'Org Details',
410 this.layout.endUpdate();
412 this.fireEvent('render', this);
419 resizeToLogo : function()
421 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
423 this.resizeToLogo.defer(1000,this);
426 var w = Ext.lib.Dom.getViewWidth() - 100;
427 var h = Ext.lib.Dom.getViewHeight() - 100;
428 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
429 Pman.Login.dialog.center();
434 show: function (modal)
439 modal = modal || false;
440 if (Pman.Login.authUserId < 0) { // logout!?
444 if (Pman.Login.intervalID) {
446 window.clearInterval(Pman.Login.intervalID);
447 Pman.Login.intervalID = false;
454 if (Roo.get('loading')) {
455 Roo.get('loading').remove();
457 if (Roo.get('loading-mask')) {
458 Roo.get('loading-mask').hide();
461 //incomming._node = tnode;
463 this.dialog.modal = !modal;
465 this.dialog.el.unmask();
466 this.resizeToLogo.defer(1000,this);
469 this.form.setValues({
470 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
471 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
473 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
474 if (this.form.findField('username').getValue().length > 0 ){
475 this.form.findField('password').focus();
477 this.form.findField('username').focus();
487 window.onbeforeunload = function() { }; // false does not work for IE..
488 Pman.Login.authUserId = -1;
490 url: baseURL + '/Login.html',
495 failure : function() {
496 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
497 document.location = baseURL + '?ts=' + Math.random();
501 success : function() {
502 Pman.Login.authUserId = -1;
503 Pman.Login.checkFails =0;
505 document.location = baseURL + '?ts=' + Math.random();
511 switchLang : function (lang) {
512 if (!lang || !lang.length) {
515 if (typeof(_T.en) == 'undefined') {
517 Roo.apply(_T.en, _T);
520 if (typeof(_T[lang]) == 'undefined') {
521 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
526 Roo.apply(_T, _T[lang]);
527 // just need to set the text values for everything...
531 function formLabel(name, val) {
533 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
534 if (lbl.getElementsByTagName('label').length) {
535 lbl = lbl.getElementsByTagName('label')[0];
537 lbl = lbl.parentNode.getElementsByTagName('label')[0];
543 formLabel('password', "Password"+':');
544 formLabel('username', "Email Address"+':');
545 formLabel('lang', "Language"+':');
546 this.dialog.setTitle("Login");
547 this.dialog.buttons[0].setText("Forgot Password");
548 this.dialog.buttons[1].setText("Login");
554 inGroup : function(g)
556 return this.authUser && this.authUser.groups &&
557 this.authUser.groups.indexOf(g) > -1;
561 return this.authUser && this.authUser.company_id_comptype &&
562 this.authUser.company_id_comptype == 'OWNER';
566 * Depreciated = use Pman.I18n
569 i18nList: function (type, codes)
572 return Pman.I18n.listToNames(type, codes);
574 i18n: function(type, code)
576 return Pman.I18n.toName(type, code);