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.
108 var c = new Roo.data.Connection();
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);
161 if (Pman.Login.callback) {
162 Pman.Login.callback();
168 fillAuth: function(au) {
169 this.startAuthCheck();
170 this.authUserId = au.id;
172 this.lastChecked = new Date();
173 // if login is used on other applicaitons..
174 if (Pman.fireEvent) { Pman.fireEvent('authrefreshed', au); }
177 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
178 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
180 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
181 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
182 this.switchLang(au.lang);
185 // open system... - -on setyp..
186 if (this.authUserId < 0) {
187 Roo.MessageBox.alert("Warning",
188 "This is an open system - please set up a admin user with a password.");
191 //Pman.onload(); // which should do nothing if it's a re-auth result...
197 intervalID : false, /// the login refresher...
201 startAuthCheck : function() // starter for timeout checking..
203 if (Pman.Login.intervalID) { // timer already in place...
207 Pman.Login.intervalID = window.setInterval(function() {
208 Pman.Login.check(false);
209 }, 120000); // every 120 secs = 2mins..
222 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
223 { // the real end set is here...
240 // tabPosition: 'top',
243 alwaysShowTabs: false
250 this.dialog.addButton("Forgot Password", function()
253 var n = _this.form.findField('username').getValue();
255 Roo.MessageBox.alert("Error", "Fill in your email address");
259 url: baseURL + '/Login.js',
264 success: function(response, opts) { // check successfull...
266 var res = Pman.processResponse(response);
267 if (!res.success) { // error!
268 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
271 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
273 failure : function() {
274 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
280 this.dialog.addButton("Login", function()
282 Pman.Login.dialog.el.mask("Logging in");
283 Pman.Login.form.doAction('submit', {
284 url: baseURL + '/Login',
288 this.layout = this.dialog.getLayout();
289 this.layout.beginUpdate();
291 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
292 // generate some other tabs
293 this.form = new Roo.form.Form({
297 actionfailed : function(f, act) {
298 // form can return { errors: .... }
300 //act.result.errors // invalid form element list...
301 //act.result.errorMsg// invalid form element list...
303 Pman.Login.dialog.el.unmask();
304 var msg = act.result.errorMsg || act.result.message;
305 msg = msg || "Login failed - communication error - try again.";
306 Roo.MessageBox.alert("Error", msg);
309 actioncomplete: function(re, act) {
311 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
312 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
313 Pman.Login.fillAuth(act.result.data);
315 Pman.Login.dialog.hide();
316 if (Roo.get('loading-mask')) {
317 //Roo.get('loading').show();
318 Roo.get('loading-mask').show();
323 if (Pman.Login.callback) {
324 Pman.Login.callback();
340 new Roo.form.TextField({
341 fieldLabel: "Email Address",
344 autoCreate : {tag: "input", type: "text", size: "20"}
347 new Roo.form.TextField({
348 fieldLabel: "Password",
349 inputType: 'password',
352 autoCreate : {tag: "input", type: "text", size: "20"},
354 specialkey : function(e,ev) {
355 if (ev.keyCode == 13) {
356 Pman.Login.dialog.el.mask("Logging in");
357 Pman.Login.form.doAction('submit', {
358 url: baseURL + '/Login',
365 new Roo.form.ComboBox({
366 fieldLabel: "Language",
369 xtype : 'SimpleStore',
370 fields: ['lang', 'ldisp'],
373 [ 'zh_HK' , '\u7E41\u4E2D' ],
374 [ 'zh_CN', '\u7C21\u4E2D' ]
381 displayField:'ldisp',
385 triggerAction: 'all',
386 emptyText:'Select a Language...',
389 select : function(cb, rec, ix) {
392 Pman.Login.switchLang(rec.data.lang);
402 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
403 ef.dom.style.margin = 10;
405 this.form.render(ef.dom);
406 // logoprefix comes from base config.
408 var img = typeof(appLogo) != 'undefined' && appLogo.length ? appLogo :
409 rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif' ;
411 Pman.Login.form.el.createChild({
414 style: 'margin-bottom: 10px;'
416 Pman.Login.form.el.dom.firstChild
419 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
421 //title: 'Org Details',
428 this.layout.endUpdate();
430 this.fireEvent('render', this);
437 resizeToLogo : function()
439 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
441 this.resizeToLogo.defer(1000,this);
444 var w = Roo.lib.Dom.getViewWidth() - 100;
445 var h = Roo.lib.Dom.getViewHeight() - 100;
446 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
447 Pman.Login.dialog.center();
452 show: function (modal, cb)
460 this.callback = cb; // used for non-pman usage..
461 modal = modal || false;
462 if (Pman.Login.authUserId < 0) { // logout!?
466 if (Pman.Login.intervalID) {
468 window.clearInterval(Pman.Login.intervalID);
469 Pman.Login.intervalID = false;
476 if (Roo.get('loading')) {
477 Roo.get('loading').remove();
479 if (Roo.get('loading-mask')) {
480 Roo.get('loading-mask').hide();
483 //incomming._node = tnode;
484 // why we want this non-modal????
486 this.dialog.modal = !modal;
488 this.dialog.el.unmask();
489 this.resizeToLogo.defer(1000,this);
491 // if we have not created a provider.. do it now...
492 if (!Roo.state.Manager.getProvider().expires) {
493 Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
497 this.form.setValues({
498 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
499 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
501 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
502 if (this.form.findField('username').getValue().length > 0 ){
503 this.form.findField('password').focus();
505 this.form.findField('username').focus();
515 window.onbeforeunload = function() { }; // false does not work for IE..
516 Pman.Login.authUserId = -1;
518 url: baseURL + '/Login.html',
523 failure : function() {
524 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
525 document.location = baseURL + '?ts=' + Math.random();
529 success : function() {
530 Pman.Login.authUserId = -1;
531 Pman.Login.checkFails =0;
533 document.location = baseURL + '?ts=' + Math.random();
539 switchLang : function (lang) {
540 if (!lang || !lang.length) {
543 if (typeof(_T.en) == 'undefined') {
545 Roo.apply(_T.en, _T);
548 if (typeof(_T[lang]) == 'undefined') {
549 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
554 Roo.apply(_T, _T[lang]);
555 // just need to set the text values for everything...
559 function formLabel(name, val) {
561 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
562 if (lbl.getElementsByTagName('label').length) {
563 lbl = lbl.getElementsByTagName('label')[0];
565 lbl = lbl.parentNode.getElementsByTagName('label')[0];
571 formLabel('password', "Password"+':');
572 formLabel('username', "Email Address"+':');
573 formLabel('lang', "Language"+':');
574 this.dialog.setTitle("Login");
575 this.dialog.buttons[0].setText("Forgot Password");
576 this.dialog.buttons[1].setText("Login");
582 inGroup : function(g)
584 return this.authUser && this.authUser.groups &&
585 this.authUser.groups.indexOf(g) > -1;
589 return this.authUser && this.authUser.company_id_comptype &&
590 this.authUser.company_id_comptype == 'OWNER';
594 * Depreciated = use Pman.I18n
597 i18nList: function (type, codes)
600 return Pman.I18n.listToNames(type, codes);
602 i18n: function(type, code)
604 return Pman.I18n.toName(type, code);