1 //<script type="text/javascript">
5 * A generic Login Dialog..... - only one needed in theory!?!?
7 * Fires XComponent builder on success...
10 * username,password, lang = for login actions.
11 * check = 1 for periodic checking that sesion is valid.
12 * passwordRequest = email request password
14 * Affects: (this id="????" elements)
15 * loading (removed) (used to indicate application is loading)
16 * loading-mask (hides) (used to hide application when it's building loading)
22 * Myapp.login = Roo.Login({
36 * Ext.apply(_T, _T[lang]);
40 Roo.Login = function(cfg)
47 Roo.each(this.items, function(e) {
50 Roo.Document.on('ready', function() {
54 Roo.Login.superclass.constructor.call(this);
58 Roo.extend(Roo.Login, Roo.LayoutDialog, {
61 * @cfg {String} method
62 * Method used to query for login details.
68 * URL to query login data. - eg. baseURL + '/Login.php'
74 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
80 onLoad : function() // called on page load...
84 if (Roo.get('loading')) { // clear any loading indicator..
85 Roo.get('loading').remove();
88 this.switchLang('en'); // set the language to english..
91 success: function(response, opts) { // check successfull...
93 var res = Pman.processResponse(response);
95 if (!res.success) { // error!
97 //console.log('call failure');
98 return this.failure(response,opts);
101 if (!res.data.id) { // id=0 == login failure.
102 return this.show(true);
106 //console.log(success);
107 this.fillAuth(res.data);
109 Roo.XComponent.build();
117 check: function(cfg) // called every so often to refresh cookie etc..
119 if (cfg.again) { // could be undefined..
126 if ( this.checkFails > 4) {
127 Roo.MessageBox.alert("Error",
128 "Error getting authentication status. - try reloading, or wait a while", function() {
129 _this.sending = false;
134 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
145 success: cfg.success || this.success,
146 failure : cfg.failure || this.failure,
154 success : function(response, opts) // check successfull...
156 this.sending = false;
157 var res = Pman.processResponse(response);
159 return this.failure(response, opts);
161 if (!res.data || !res.data.id) {
162 return this.failure(response,opts);
165 this.fillAuth(res.data);
172 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
175 this.sending = false;
176 var res = Pman.processResponse(response);
178 if ( Pman.Login.checkFails > 2) {
180 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
181 "Error getting authentication status. - try reloading");
184 opts.callCfg.again = true;
185 this.check.defer(1000, this, [ opts.callCfg ]);
191 fillAuth: function(au) {
192 this.startAuthCheck();
193 this.authUserId = au.id;
195 this.lastChecked = new Date();
196 this.fireEvent('refreshed', au);
197 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
198 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
200 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
201 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
202 this.switchLang(au.lang);
205 // open system... - -on setyp..
206 if (this.authUserId < 0) {
207 Roo.MessageBox.alert("Warning",
208 "This is an open system - please set up a admin user with a password.");
211 //Pman.onload(); // which should do nothing if it's a re-auth result...
216 startAuthCheck : function() // starter for timeout checking..
218 if (Pman.Login.intervalID) { // timer already in place...
222 Pman.Login.intervalID = window.setInterval(function() {
223 Pman.Login.check(false);
224 }, 120000); // every 120 secs = 2mins..
241 center: { // needed??
244 // tabPosition: 'top',
247 alwaysShowTabs: false
251 rendered : function(dlg) {
252 this.form = this.items[0];
253 this.form.dialog = dlg;
254 this.buttons[0].form = this.form;
255 this.buttons[0].dialog = dlg
256 this.buttons[1].form = this.form;
257 this.buttons[1].dialog = dlg
261 //this.resizeToLogo.defer(1000,this);
262 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
264 // this.resizeToLogo.defer(1000,this);
267 var w = Ext.lib.Dom.getViewWidth() - 100;
268 var h = Ext.lib.Dom.getViewHeight() - 100;
269 this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
276 if (this.user.id < 0) { // used for inital setup situations.
280 if (this.intervalID) {
282 window.clearInterval(this.intervalID);
283 this.intervalID = false;
287 if (Roo.get('loading')) {
288 Roo.get('loading').remove();
290 if (Roo.get('loading-mask')) {
291 Roo.get('loading-mask').hide();
294 //incomming._node = tnode;
296 //this.dialog.modal = !modal;
297 //this.dialog.show();
298 this.dialog.el.unmask();
301 this.form.setValues({
302 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
303 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
306 Pman.Login.switchLang(Roo.state.Manager.get(this.realm + '.lang', ''));
307 if (this.form.findField('username').getValue().length > 0 ){
308 this.form.findField('password').focus();
310 this.form.findField('username').focus();
318 xtype : 'ContentPanel',
329 style : 'margin : 10px;',
331 actionfailed : function(f, act) {
332 // form can return { errors: .... }
334 //act.result.errors // invalid form element list...
335 //act.result.errorMsg// invalid form element list...
337 this.dialog.el.unmask();
338 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
339 "Login failed - communication error - try again.");
342 actioncomplete: function(re, act) {
344 Roo.state.Manager.set(
345 this.dialog.realm + '.' + this.dialog.params.username,
346 this.form.findField(this.dialog.params.username).getValue()
348 Roo.state.Manager.set(
349 this.dialog.realm + '.lang',
350 Pman.Login.form.findField('lang').getValue()
353 this.dialog.fillAuth(act.result.data);
357 if (Roo.get('loading-mask')) {
358 Roo.get('loading-mask').show();
360 Roo.XComponent.build();
370 fieldLabel: "Email Address",
373 autoCreate : {tag: "input", type: "text", size: "20"}
378 fieldLabel: "Password",
379 inputType: 'password',
382 autoCreate : {tag: "input", type: "text", size: "20"},
384 specialkey : function(e,ev) {
385 if (ev.keyCode == 13) {
386 this.form.dialog.el.mask("Logging in");
387 this.form.doAction('submit', {
388 url: this.form.dialog.url,
389 method: this.form.dialog.method,
398 fieldLabel: "Language",
401 xtype : 'SimpleStore',
402 fields: ['lang', 'ldisp'],
405 [ 'zh_HK' , '\u7E41\u4E2D' ],
406 [ 'zh_CN', '\u7C21\u4E2D' ]
413 displayField:'ldisp',
417 triggerAction: 'all',
418 emptyText:'Select a Language...',
421 select : function(cb, rec, ix) {
422 this.form.switchLang(rec.data.lang);
436 text : "Forgot Password",
440 var n = this.form.findField('username').getValue();
442 Roo.MessageBox.alert("Error", "Fill in your email address");
450 method: this.dialog.method,
451 success: function(response, opts) { // check successfull...
453 var res = Pman.processResponse(response);
454 if (!res.success) { // error!
455 Roo.MessageBox.alert("Error" ,
456 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
459 Roo.MessageBox.alert("Notice" ,
460 "Please check you email for the Password Reset message");
462 failure : function() {
463 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
476 this.dialog.el.mask("Logging in");
477 this.form.doAction('submit', {
479 method: this.dialog.method
488 Pman.Login = new Roo.util.Observable({
501 authUser: { id : false },
511 intervalID : false, /// the login refresher...
519 // logoprefix comes from base config.
520 Pman.Login.form.el.createChild({
522 src: rootURL + '/Pman/'+appNameShort + '/templates/images/logo.gif',
523 style: 'margin-bottom: 10px;'
525 Pman.Login.form.el.dom.firstChild
528 var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
530 //title: 'Org Details',
537 this.layout.endUpdate();
539 this.fireEvent('render', this);
551 window.onbeforeunload = function() { }; // false does not work for IE..
552 Pman.Login.authUserId = -1;
554 url: baseURL + '/Login.html',
559 failure : function() {
560 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
561 document.location = baseURL + '?ts=' + Math.random();
565 success : function() {
566 Pman.Login.authUserId = -1;
567 Pman.Login.checkFails =0;
569 document.location = baseURL + '?ts=' + Math.random();
575 switchLang : function (lang) {
579 if (typeof(_T.en) == 'undefined') {
581 Roo.apply(_T.en, _T);
584 if (typeof(_T[lang]) == 'undefined') {
585 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
590 Roo.apply(_T, _T[lang]);
591 // just need to set the text values for everything...
595 function formLabel(name, val) {
597 var lbl = Pman.Login.form.findField( name ).el.dom.parentNode.parentNode;
598 if (lbl.getElementsByTagName('label').length) {
599 lbl = lbl.getElementsByTagName('label')[0];
601 lbl = lbl.parentNode.getElementsByTagName('label')[0];
607 formLabel('password', "Password"+':');
608 formLabel('username', "Email Address"+':');
609 formLabel('lang', "Language"+':');
610 this.dialog.setTitle("Login");
611 this.dialog.buttons[0].setText("Forgot Password");
612 this.dialog.buttons[1].setText("Login");
618 inGroup : function(g)
620 return this.authUser && this.authUser.groups &&
621 this.authUser.groups.indexOf(g) > -1;
625 return this.authUser && this.authUser.company_id_comptype &&
626 this.authUser.company_id_comptype == 'OWNER';
630 * Depreciated = use Pman.I18n
633 i18nList: function (type, codes)
636 return Pman.I18n.listToNames(type, codes);
638 i18n: function(type, code)
640 return Pman.I18n.toName(type, code);