mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
added home files
This commit is contained in:
0
home/page/profile_settings/__init__.py
Normal file
0
home/page/profile_settings/__init__.py
Normal file
115
home/page/profile_settings/profile_settings.js
Normal file
115
home/page/profile_settings/profile_settings.js
Normal file
@@ -0,0 +1,115 @@
|
||||
pscript['onload_profile-settings'] = function() {
|
||||
var wrapper = page_body.pages['profile-settings'];
|
||||
wrapper.className = 'layout_wrapper';
|
||||
pscript.myprofile = new MyProfile(wrapper)
|
||||
}
|
||||
|
||||
MyProfile = function(wrapper) {
|
||||
this.wrapper = wrapper;
|
||||
var me = this;
|
||||
|
||||
this.make = function() {
|
||||
this.head = new PageHeader(this.wrapper, 'My Profile Settings');
|
||||
this.head.add_button('Change Password', this.change_password)
|
||||
this.tab = make_table($a(this.wrapper, 'div', '', {marginTop:'19px'}),
|
||||
1, 2, '90%', ['50%', '50%'], {padding:'11px'})
|
||||
this.img = $a($td(this.tab, 0, 0), 'img');
|
||||
set_user_img(this.img, user);
|
||||
|
||||
$btn($a($td(this.tab, 0, 0), 'div', '', {marginTop:'11px'}), 'Change Image', this.change_image)
|
||||
|
||||
this.make_form();
|
||||
this.load_details();
|
||||
}
|
||||
|
||||
this.load_details = function() {
|
||||
$c_page('event_updates','profile_settings','get_user_details','',function(r, rt) {
|
||||
me.form.set_values(r.message);
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
// form
|
||||
//
|
||||
this.make_form = function() {
|
||||
var div = $a($td(this.tab, 0, 1), 'div');
|
||||
this.form = new wn.widgets.FieldGroup()
|
||||
this.form.make_fields(div, [
|
||||
{fieldname:'first_name', fieldtype:'Data',label:'First Name',reqd:1},
|
||||
{fieldname:'last_name', fieldtype:'Data',label:'Last Name',reqd:1},
|
||||
{fieldname:'bio', fieldtype:'Text',label:'Bio'},
|
||||
{fieldname:'update', fieldtype:'Button',label:'Update'}
|
||||
]);
|
||||
|
||||
this.form.fields_dict.update.input.onclick = function() {
|
||||
var v = me.form.get_values();
|
||||
if(v) {
|
||||
this.set_working();
|
||||
var btn = this;
|
||||
$c_page('event_updates','profile_settings','set_user_details',v,function(r, rt) {
|
||||
btn.done_working();
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// change password
|
||||
//
|
||||
this.change_password = function() {
|
||||
var d = new wn.widgets.Dialog({
|
||||
title:'Change Password',
|
||||
width: 400,
|
||||
fields: [
|
||||
{fieldname:'old_password', fieldtype:'Password', label:'Old Password', reqd:1 },
|
||||
{fieldname:'new_password', fieldtype:'Password', label:'New Password', reqd:1 },
|
||||
{fieldname:'new_password1', fieldtype:'Password', label:'Re-type New Password', reqd:1 },
|
||||
{fieldname:'change', fieldtype:'Button', label:'Change'}
|
||||
]
|
||||
})
|
||||
d.make();
|
||||
d.fields_dict.change.input.onclick = function() {
|
||||
var v = d.get_values();
|
||||
if(v) {
|
||||
if(v.new_password != v.new_password1) {
|
||||
msgprint('Passwords must match'); return;
|
||||
}
|
||||
this.set_working();
|
||||
$c_page('event_updates','profile_settings','change_password',v,function(r,rt) {
|
||||
if(!r.message && r.exc) { msgprint(r.exc); return; }
|
||||
d.hide();
|
||||
})
|
||||
}
|
||||
}
|
||||
d.show();
|
||||
}
|
||||
|
||||
//
|
||||
// change image
|
||||
//
|
||||
|
||||
this.change_image = function() {
|
||||
if(!me.change_dialog) {
|
||||
|
||||
var d = new Dialog(400,200,'Set Your Profile Image');
|
||||
d.make_body([
|
||||
['HTML','wrapper']
|
||||
]);
|
||||
|
||||
var w = d.widgets['wrapper'];
|
||||
me.uploader = new Uploader(w, {thumbnail:'80px', server_obj:'Company Control', method:'update_profile_image'}, pscript.user_image_upload)
|
||||
me.change_dialog = d;
|
||||
}
|
||||
me.change_dialog.show();
|
||||
}
|
||||
this.make();
|
||||
}
|
||||
|
||||
pscript.user_image_upload = function(fid) {
|
||||
msgprint('File Uploaded');
|
||||
|
||||
if(fid) {
|
||||
pscript.myprofile.change_dialog.hide();
|
||||
set_user_img(pscript.myprofile.img, user, null, fid);
|
||||
}
|
||||
}
|
||||
34
home/page/profile_settings/profile_settings.py
Normal file
34
home/page/profile_settings/profile_settings.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import load_json, cint, nowdate
|
||||
|
||||
#
|
||||
# change profile (remote)
|
||||
#
|
||||
def change_password(arg):
|
||||
arg = load_json(arg)
|
||||
|
||||
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
|
||||
import server_tools.server_tools.gateway_utils
|
||||
webnotes.msgprint(server_tools.server_tools.gateway_utils.change_password(arg['old_password'], arg['new_password'])['message'])
|
||||
else:
|
||||
if not webnotes.conn.sql('select name from tabProfile where name=%s and password=password(%s)', (webnotes.session['user'], arg['old_password'])):
|
||||
webnotes.msgprint('Old password is not correct', raise_exception=1)
|
||||
|
||||
from webnotes.utils import nowdate
|
||||
webnotes.conn.sql("update tabProfile set password=password(%s), password_last_updated=%s where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
|
||||
webnotes.msgprint('Password Updated');
|
||||
|
||||
def get_user_details(arg=None):
|
||||
"Returns user first name, last name and bio"
|
||||
|
||||
return webnotes.conn.sql("select first_name, last_name, bio from tabProfile where name=%s", webnotes.user.name, as_dict=1)[0]
|
||||
|
||||
def set_user_details(arg=None):
|
||||
"updates user details given in argument"
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
p = Document('Profile', webnotes.user.name)
|
||||
p.fields.update(load_json(arg))
|
||||
p.save()
|
||||
webnotes.msgprint('Updated')
|
||||
36
home/page/profile_settings/profile_settings.txt
Normal file
36
home/page/profile_settings/profile_settings.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
[
|
||||
{
|
||||
'author': None,
|
||||
'category': 'Standard',
|
||||
'content': None,
|
||||
'creation': '2011-04-13 12:08:59',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Page',
|
||||
'file_list': None,
|
||||
'icon': None,
|
||||
'idx': None,
|
||||
'keywords': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-04-13 12:08:59',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Home',
|
||||
'name': 'profile-settings',
|
||||
'owner': 'Administrator',
|
||||
'page_name': 'Profile Settings',
|
||||
'page_title': None,
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'publish': None,
|
||||
'script': None,
|
||||
'show_in_menu': None,
|
||||
'site_description': None,
|
||||
'standard': 'Yes',
|
||||
'static_content': None,
|
||||
'style': None,
|
||||
'stylesheet': None,
|
||||
'template': None,
|
||||
'write_content': None
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user