blob: 6e6fcc7f73f7d7b05a142e33e2ca9bcb39b4963a [file] [log] [blame]
Anand Doshi51146c02012-07-12 18:41:12 +05301// 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
17wn.provide('erpnext.login');
18
19wn.pages["{{ name }}"].onload = function(wrapper) {
Anand Doshi51146c02012-07-12 18:41:12 +053020 var lw = $i('login_wrapper');
21 $bs(lw, '1px 1px 3px #888');
22
23 $('#login_btn').click(erpnext.login.doLogin)
24
25 $('#password').keypress(function(ev){
26 if(ev.which==13 && $('#password').val()) {
27 $('form').submit(function() {
28 erpnext.login.doLogin();
29 return false;
30 });
31 }
32 });
33 $(document).trigger('login_rendered');
34}
35
36// Login Callback
37erpnext.login.onLoginReply = function(r, rtext) {
38 $('#login_btn').done_working();
39 if(r.message=="Logged In"){
40 window.location.href='app.html' + (get_url_arg('page') ? ('?page='+get_url_arg('page')) : '');
41 } else {
42 $i('login_message').innerHTML = '<span style="color: RED;">'+(r.message)+'</span>';
43 //if(r.exc)alert(r.exc);
44 }
45}
46
47
48// Login
49erpnext.login.doLogin = function(){
50
51 var args = {};
52 args['usr']=$i("login_id").value;
53 args['pwd']=$i("password").value;
Rushabh Mehta3009c462012-10-03 11:56:38 +053054 //if($i('remember_me').checked)
55 //args['remember_me'] = 1;
Anand Doshi51146c02012-07-12 18:41:12 +053056
57 $('#login_btn').set_working();
Rushabh Mehta91ba3462012-07-13 14:54:40 +053058 $('#login_message').empty();
Anand Doshi51146c02012-07-12 18:41:12 +053059
60 $c("login", args, erpnext.login.onLoginReply);
61
62 return false;
63}
64
65
66erpnext.login.show_forgot_password = function(){
67 // create dialog
68 var d = new wn.ui.Dialog({
69 title:"Forgot Password",
70 fields: [
71 {'label':'Email Id', 'fieldname':'email_id', 'fieldtype':'Data', 'reqd':true},
72 {'label':'Email Me A New Password', 'fieldname':'run', 'fieldtype':'Button'}
73 ]
74 });
75
76 $(d.fields_dict.run.input).click(function() {
77 var values = d.get_values();
78 if(!values) return;
79 wn.call({
80 method:'reset_password',
81 args: { user: values.email_id },
82 callback: function() {
83 d.hide();
84 }
85 })
86 })
87 d.show();
88}