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);
60 if (!res.data.id) { // id=0 == login failure.
61 return this.show(true);
65 //console.log(success);
66 this.fillAuth(res.data);
70 failure : Pman.Login.show,
77 check: function(again) // called every so often to refresh cookie etc..
79 if (again) { // could be undefined..
80 Pman.Login.checkFails++;
82 Pman.Login.checkFails = 0;
87 if ( Pman.Login.checkFails > 4) {
88 Pman.Preview.disable();
89 Roo.MessageBox.alert("Error",
90 "Error getting authentication status. - try reloading, or wait a while", function() {
91 _this.sending = false;
96 _this.check.defer(10000, _this, [ true ]); // check in 10 secs.
102 url: baseURL + '/Login.js',
107 success: Pman.Login.success,
108 failure : Pman.Login.failure,
116 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
119 this.sending = false;
120 var res = Pman.processResponse(response);
122 if ( Pman.Login.checkFails > 2) {
123 Pman.Preview.disable();
124 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
125 "Error getting authentication status. - try reloading");
129 Pman.Login.check.defer(1000, Pman.Login, [ true ]);
134 success : function(response, opts) // check successfull...
136 this.sending = false;
137 var res = Pman.processResponse(response);
139 return this.failure(response, opts);
141 if (!res.data || !res.data.id) {
142 return this.failure(response,opts);
145 this.fillAuth(res.data);
151 fillAuth: function(au) {
152 this.startAuthCheck();
153 this.authUserId = au.id;
155 this.lastChecked = new Date();
156 Pman.fireEvent('authrefreshed', au);
157 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
158 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
160 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
161 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, au.lang);
162 this.switchLang(au.lang);
165 // open system... - -on setyp..
166 if (this.authUserId < 0) {
167 Roo.MessageBox.alert("Warning",
168 "This is an open system - please set up a admin user with a password.");
171 //Pman.onload(); // which should do nothing if it's a re-auth result...
177 intervalID : false, /// the login refresher...
181 startAuthCheck : function() // starter for timeout checking..
183 if (Pman.Login.intervalID) { // timer already in place...
187 Pman.Login.intervalID = window.setInterval(function() {
188 Pman.Login.check(false);
189 }, 120000); // every 120 secs = 2mins..
202 this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),
203 { // the real end set is here...
220 // tabPosition: 'top',
223 alwaysShowTabs: false
230 this.dialog.addButton("Forgot Password", function()
233 var n = _this.form.findField('username').getValue();
235 Roo.MessageBox.alert("Error", "Fill in your email address");
239 url: baseURL + '/Login.js',
244 success: function(response, opts) { // check successfull...
246 var res = Pman.processResponse(response);
247 if (!res.success) { // error!
248 Roo.MessageBox.alert("Error" , res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
251 Roo.MessageBox.alert("Notice" , "Please check you email for the Password Reset message");
253 failure : function() {
254 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
260 this.dialog.addButton("Login", function()
262 Pman.Login.dialog.el.mask("Logging in");
263 Pman.Login.form.doAction('submit', {
264 url: baseURL + '/Login',
268 this.layout = this.dialog.getLayout();
269 this.layout.beginUpdate();
271 //layout.add('center', new Roo.ContentPanel('center', {title: 'The First Tab'}));
272 // generate some other tabs
273 this.form = new Roo.form.Form({
277 actionfailed : function(f, act) {
278 // form can return { errors: .... }
280 //act.result.errors // invalid form element list...
281 //act.result.errorMsg// invalid form element list...
283 Pman.Login.dialog.el.unmask();
284 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
285 "Login failed - communication error - try again.");
288 actioncomplete: function(re, act) {
290 Roo.state.Manager.set('Pman.Login.username.'+appNameShort, Pman.Login.form.findField('username').getValue() );
291 Roo.state.Manager.set('Pman.Login.lang.'+appNameShort, Pman.Login.form.findField('lang').getValue() );
292 Pman.Login.fillAuth(act.result.data);
294 Pman.Login.dialog.hide();
295 if (Roo.get('loading-mask')) {
296 //Roo.get('loading').show();
297 Roo.get('loading-mask').show();
316 new Roo.form.TextField({
317 fieldLabel: "Email Address",
320 autoCreate : {tag: "input", type: "text", size: "20"}
323 new Roo.form.TextField({
324 fieldLabel: "Password",
325 inputType: 'password',
328 autoCreate : {tag: "input", type: "text", size: "20"},
330 specialkey : function(e,ev) {
331 if (ev.keyCode == 13) {
332 Pman.Login.dialog.el.mask("Logging in");
333 Pman.Login.form.doAction('submit', {
334 url: baseURL + '/Login.json',
341 new Roo.form.ComboBox({
342 fieldLabel: "Language",
345 xtype : 'SimpleStore',
346 fields: ['lang', 'ldisp'],
349 [ 'zh_HK' , '\u7E41\u4E2D' ],
350 [ 'zh_CN', '\u7C21\u4E2D' ]
357 displayField:'ldisp',
361 triggerAction: 'all',
362 emptyText:'Select a Language...',
365 select : function(cb, rec, ix) {
368 Pman.Login.switchLang(rec.data.lang);
378 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
379 ef.dom.style.margin = 10;
381 this.form.render(ef.dom);
382 // logoprefix comes from base config.
383 Pman.Login.form.el.createChild({
385 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
386 style: 'margin-bottom: 10px;'
388 Pman.Login.form.el.dom.firstChild
391 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
393 //title: 'Org Details',
400 this.layout.endUpdate();
402 this.fireEvent('render', this);
409 resizeToLogo : function()
411 var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
413 this.resizeToLogo.defer(1000,this);
416 var w = Ext.lib.Dom.getViewWidth() - 100;
417 var h = Ext.lib.Dom.getViewHeight() - 100;
418 Pman.Login.dialog.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
419 Pman.Login.dialog.center();
424 show: function (modal)
429 modal = modal || false;
430 if (Pman.Login.authUserId < 0) { // logout!?
434 if (Pman.Login.intervalID) {
436 window.clearInterval(Pman.Login.intervalID);
437 Pman.Login.intervalID = false;
444 if (Roo.get('loading')) {
445 Roo.get('loading').remove();
447 if (Roo.get('loading-mask')) {
448 Roo.get('loading-mask').hide();
451 //incomming._node = tnode;
453 this.dialog.modal = !modal;
455 this.dialog.el.unmask();
456 this.resizeToLogo.defer(1000,this);
459 this.form.setValues({
460 'username' : Roo.state.Manager.get('Pman.Login.username.'+appNameShort, ''),
461 'lang' : Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, 'en')
463 Pman.Login.switchLang(Roo.state.Manager.get('Pman.Login.lang.'+appNameShort, ''));
464 if (this.form.findField('username').getValue().length > 0 ){
465 this.form.findField('password').focus();
467 this.form.findField('username').focus();
477 window.onbeforeunload = function() { }; // false does not work for IE..
478 Pman.Login.authUserId = -1;
480 url: baseURL + '/Login.html',
485 failure : function() {
486 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
487 document.location = baseURL + '?ts=' + Math.random();
491 success : function() {
492 Pman.Login.authUserId = -1;
493 Pman.Login.checkFails =0;
495 document.location = baseURL + '?ts=' + Math.random();
501 switchLang : function (lang) {
502 if (!lang || !lang.length) {
505 if (typeof(_T.en) == 'undefined') {
507 Roo.apply(_T.en, _T);
510 if (typeof(_T[lang]) == 'undefined') {
511 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
516 Roo.apply(_T, _T[lang]);
517 // just need to set the text values for everything...
521 function formLabel(name, val) {
523 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
524 if (lbl.getElementsByTagName('label').length) {
525 lbl = lbl.getElementsByTagName('label')[0];
527 lbl = lbl.parentNode.getElementsByTagName('label')[0];
533 formLabel('password', "Password"+':');
534 formLabel('username', "Email Address"+':');
535 formLabel('lang', "Language"+':');
536 this.dialog.setTitle("Login");
537 this.dialog.buttons[0].setText("Forgot Password");
538 this.dialog.buttons[1].setText("Login");
544 inGroup : function(g)
546 return this.authUser && this.authUser.groups &&
547 this.authUser.groups.indexOf(g) > -1;
551 return this.authUser && this.authUser.company_id_comptype &&
552 this.authUser.company_id_comptype == 'OWNER';
556 * Depreciated = use Pman.I18n
559 i18nList: function (type, codes)
562 return Pman.I18n.listToNames(type, codes);
564 i18n: function(type, code)
566 return Pman.I18n.toName(type, code);