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({
28 authUser: { id : false },
34 onLoad : function() // called on page load...
39 if (Roo.get('loading')) {
40 Roo.get('loading').remove();
42 this.switchLang('en');
44 // check if we are logged in..
46 url: baseURL + '/Login.js',
51 success: function(response, opts) { // check successfull...
53 var res = Pman.processResponse(response);
55 if (!res.success) { // error!
57 //console.log('call failure');
58 return Pman.Login.failure(response,opts);
62 if (!res.data.id) { // id=0 == login failure.
63 return this.show(true);
67 //console.log(success);
68 this.fillAuth(res.data);
72 failure : Pman.Login.show,
79 check: function(again) // called every so often to refresh cookie etc..
81 if (again) { // could be undefined..
82 Pman.Login.checkFails++;
84 Pman.Login.checkFails = 0;
89 if ( Pman.Login.checkFails > 4) {
90 Pman.Preview.disable();
91 Roo.MessageBox.alert("Error",
92 "Error getting authentication status. - try reloading, or wait a while", function() {
93 _this.sending = false;
98 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
104 url: baseURL + '/Login.js',
109 success: Pman.Login.success,
110 failure : Pman.Login.failure,
118 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
121 this.sending = false;
122 var res = Pman.processResponse(response);
124 if ( Pman.Login.checkFails > 2) {
125 Pman.Preview.disable();
126 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
127 "Error getting authentication status. - try reloading");
131 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
136 success : function(response, opts) // check successfull...
138 this.sending = false;
139 var res = Pman.processResponse(response);
141 return this.failure(response, opts);
143 if (!res.data || !res.data.id) {
144 return this.failure(response,opts);
147 this.fillAuth(res.data);
153 fillAuth: function(au) {
154 this.startAuthCheck();
155 this.authUserId = au.id;
157 this.lastChecked = new Date();
158 Pman.fireEvent('authrefreshed', au);
159 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
160 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
162 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
163 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
164 this.switchLang(au.lang);
167 // open system... - -on setyp..
168 if (this.authUserId < 0) {
169 Roo.MessageBox.alert("Warning",
170 "This is an open system - please set up a admin user with a password.");
173 //Pman.onload(); // which should do nothing if it's a re-auth result...
179 intervalID : false, /// the login refresher...
183 startAuthCheck : function() // starter for timeout checking..
185 if (Pman.Login.intervalID) { // timer already in place...
189 Pman.Login.intervalID = window.setInterval(function() {
190 Pman.Login.check(false);
191 }, 120000); // every 120 secs = 2mins..
204 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
205 { // the real end set is here...
222 // tabPosition: 'top',
225 alwaysShowTabs: false
232 this.dialog.addButton("Forgot Password", function()
235 var n = _this.form.findField('username').getValue();
237 Roo.MessageBox.alert("Error", "Fill in your email address");
241 url: baseURL + '/Login.js',
246 success: function(response, opts) { // check successfull...
248 var res = Pman.processResponse(response);
249 if (!res.success) { // error!
250 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
253 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
255 failure : function() {
256 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
262 this.dialog.addButton("Login", function()
264 Pman.Login.dialog.el.mask("Logging in");
265 Pman.Login.form.doAction('submit', {
266 url: baseURL + '/Login',
270 this.layout = this.dialog.getLayout();
271 this.layout.beginUpdate();
273 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
274 // generate some other tabs
275 this.form = new Roo.form.Form({
279 actionfailed : function(f, act) {
280 // form can return { errors: .... }
282 //act.result.errors // invalid form element list...
283 //act.result.errorMsg// invalid form element list...
285 Pman.Login.dialog.el.unmask();
286 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
287 "Login failed - communication error - try again.");
290 actioncomplete: function(re, act) {
292 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
293 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
294 Pman.Login.fillAuth(act.result.data);
296 Pman.Login.dialog.hide();
297 if (Roo.get('loading-mask')) {
298 //Roo.get('loading').show();
299 Roo.get('loading-mask').show();
318 new Roo.form.TextField({
319 fieldLabel: "Email Address",
322 autoCreate : {tag: "input", type: "text", size: "20"}
325 new Roo.form.TextField({
326 fieldLabel: "Password",
327 inputType: 'password',
330 autoCreate : {tag: "input", type: "text", size: "20"},
332 specialkey : function(e,ev) {
333 if (ev.keyCode == 13) {
334 Pman.Login.dialog.el.mask("Logging in");
335 Pman.Login.form.doAction('submit', {
336 url: baseURL + '/Login.json',
343 new Roo.form.ComboBox({
344 fieldLabel: "Language",
347 xtype : 'SimpleStore',
348 fields: ['lang', 'ldisp'],
351 [ 'zh_HK' , '\u7E41\u4E2D' ],
352 [ 'zh_CN', '\u7C21\u4E2D' ]
359 displayField:'ldisp',
363 triggerAction: 'all',
364 emptyText:'Select a Language...',
367 select : function(cb, rec, ix) {
370 Pman.Login.switchLang(rec.data.lang);
380 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
381 ef.dom.style.margin = 10;
383 this.form.render(ef.dom);
384 // logoprefix comes from base config.
385 Pman.Login.form.el.createChild({
387 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
388 style: 'margin-bottom: 10px;'
390 Pman.Login.form.el.dom.firstChild
393 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
395 //title: 'Org Details',
402 this.layout.endUpdate();
404 this.fireEvent('render', this);
411 resizeToLogo : function()
413 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
415 this.resizeToLogo.defer(1000,this);
418 var w = Ext.lib.Dom.getViewWidth() - 100;
419 var h = Ext.lib.Dom.getViewHeight() - 100;
420 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
421 Pman.Login.dialog.center();
426 show: function (modal)
431 modal = modal || false;
432 if (Pman.Login.authUserId < 0) { // logout!?
436 if (Pman.Login.intervalID) {
438 window.clearInterval(Pman.Login.intervalID);
439 Pman.Login.intervalID = false;
446 if (Roo.get('loading')) {
447 Roo.get('loading').remove();
449 if (Roo.get('loading-mask')) {
450 Roo.get('loading-mask').hide();
453 //incomming._node = tnode;
455 this.dialog.modal = !modal;
457 this.dialog.el.unmask();
458 this.resizeToLogo.defer(1000,this);
461 this.form.setValues({
462 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
463 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
465 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
466 if (this.form.findField('username').getValue().length > 0 ){
467 this.form.findField('password').focus();
469 this.form.findField('username').focus();
479 window.onbeforeunload = function() { }; // false does not work for IE..
480 Pman.Login.authUserId = -1;
482 url: baseURL + '/Login.html',
487 failure : function() {
488 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
489 document.location = baseURL + '?ts=' + Math.random();
493 success : function() {
494 Pman.Login.authUserId = -1;
495 Pman.Login.checkFails =0;
497 document.location = baseURL + '?ts=' + Math.random();
503 switchLang : function (lang) {
504 if (!lang || !lang.length) {
507 if (typeof(_T.en) == 'undefined') {
509 Roo.apply(_T.en, _T);
512 if (typeof(_T[lang]) == 'undefined') {
513 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
518 Roo.apply(_T, _T[lang]);
519 // just need to set the text values for everything...
523 function formLabel(name, val) {
525 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
526 if (lbl.getElementsByTagName('label').length) {
527 lbl = lbl.getElementsByTagName('label')[0];
529 lbl = lbl.parentNode.getElementsByTagName('label')[0];
535 formLabel('password', "Password"+':');
536 formLabel('username', "Email Address"+':');
537 formLabel('lang', "Language"+':');
538 this.dialog.setTitle("Login");
539 this.dialog.buttons[0].setText("Forgot Password");
540 this.dialog.buttons[1].setText("Login");
546 inGroup : function(g)
548 return this.authUser && this.authUser.groups &&
549 this.authUser.groups.indexOf(g) > -1;
553 return this.authUser && this.authUser.company_id_comptype &&
554 this.authUser.company_id_comptype == 'OWNER';
558 * Depreciated = use Pman.I18n
561 i18nList: function (type, codes)
564 return Pman.I18n.listToNames(type, codes);
566 i18n: function(type, code)
568 return Pman.I18n.toName(type, code);