Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 1 | // ERPNext - web based ERP (http://erpnext.com) |
| 2 | // Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | wn.provide('erpnext.login'); |
| 18 | |
| 19 | wn.pages["{{ name }}"].onload = function(wrapper) { |
| 20 | wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.appframe-area')); |
| 21 | wrapper.appframe.title('Login'); |
| 22 | wrapper.appframe.$w.find('.close').toggle(false); |
| 23 | |
| 24 | var lw = $i('login_wrapper'); |
| 25 | $bs(lw, '1px 1px 3px #888'); |
| 26 | |
| 27 | $('#login_btn').click(erpnext.login.doLogin) |
| 28 | |
| 29 | $('#password').keypress(function(ev){ |
| 30 | if(ev.which==13 && $('#password').val()) { |
| 31 | $('form').submit(function() { |
| 32 | erpnext.login.doLogin(); |
| 33 | return false; |
| 34 | }); |
| 35 | } |
| 36 | }); |
| 37 | $(document).trigger('login_rendered'); |
| 38 | } |
| 39 | |
| 40 | // Login Callback |
| 41 | erpnext.login.onLoginReply = function(r, rtext) { |
| 42 | $('#login_btn').done_working(); |
| 43 | if(r.message=="Logged In"){ |
| 44 | window.location.href='app.html' + (get_url_arg('page') ? ('?page='+get_url_arg('page')) : ''); |
| 45 | } else { |
| 46 | $i('login_message').innerHTML = '<span style="color: RED;">'+(r.message)+'</span>'; |
| 47 | //if(r.exc)alert(r.exc); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | |
| 52 | // Login |
| 53 | erpnext.login.doLogin = function(){ |
| 54 | |
| 55 | var args = {}; |
| 56 | args['usr']=$i("login_id").value; |
| 57 | args['pwd']=$i("password").value; |
| 58 | if($i('remember_me').checked) |
| 59 | args['remember_me'] = 1; |
| 60 | |
| 61 | $('#login_btn').set_working(); |
| 62 | |
| 63 | $c("login", args, erpnext.login.onLoginReply); |
| 64 | |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | erpnext.login.show_forgot_password = function(){ |
| 70 | // create dialog |
| 71 | var d = new wn.ui.Dialog({ |
| 72 | title:"Forgot Password", |
| 73 | fields: [ |
| 74 | {'label':'Email Id', 'fieldname':'email_id', 'fieldtype':'Data', 'reqd':true}, |
| 75 | {'label':'Email Me A New Password', 'fieldname':'run', 'fieldtype':'Button'} |
| 76 | ] |
| 77 | }); |
| 78 | |
| 79 | $(d.fields_dict.run.input).click(function() { |
| 80 | var values = d.get_values(); |
| 81 | if(!values) return; |
| 82 | wn.call({ |
| 83 | method:'reset_password', |
| 84 | args: { user: values.email_id }, |
| 85 | callback: function() { |
| 86 | d.hide(); |
| 87 | } |
| 88 | }) |
| 89 | }) |
| 90 | d.show(); |
| 91 | } |