2012-02-23 07:05:32 +00:00
|
|
|
// ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
pscript['onload_profile-settings'] = function() {
|
2012-02-27 12:33:54 +00:00
|
|
|
var wrapper = wn.pages['profile-settings'];
|
2011-06-14 08:05:31 +00:00
|
|
|
wrapper.className = 'layout_wrapper';
|
2011-06-08 09:07:15 +00:00
|
|
|
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');
|
2012-02-29 13:08:18 +00:00
|
|
|
this.head.add_button('Change Password', this.change_password);
|
|
|
|
this.head.add_button('Change Background', this.change_background);
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
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);
|
|
|
|
|
2012-02-29 13:08:18 +00:00
|
|
|
$btn($a($td(this.tab, 0, 0), 'div', '', {marginTop:'11px'}), 'Change Image', this.change_image);
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
this.make_form();
|
|
|
|
this.load_details();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.load_details = function() {
|
2011-06-14 08:05:31 +00:00
|
|
|
$c_page('home','profile_settings','get_user_details','',function(r, rt) {
|
2011-06-08 09:07:15 +00:00
|
|
|
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},
|
2012-01-06 12:44:42 +00:00
|
|
|
{fieldname:'last_name', fieldtype:'Data',label:'Last Name'},
|
2011-06-08 09:07:15 +00:00
|
|
|
{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;
|
2011-06-14 08:05:31 +00:00
|
|
|
$c_page('home','profile_settings','set_user_details',v,function(r, rt) {
|
2011-06-08 09:07:15 +00:00
|
|
|
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();
|
2011-06-14 08:05:31 +00:00
|
|
|
$c_page('home','profile_settings','change_password',v,function(r,rt) {
|
2011-06-08 09:07:15 +00:00
|
|
|
if(!r.message && r.exc) { msgprint(r.exc); return; }
|
|
|
|
d.hide();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// change image
|
|
|
|
//
|
|
|
|
|
|
|
|
this.change_image = function() {
|
2012-02-29 13:08:18 +00:00
|
|
|
var d = new wn.widgets.Dialog({
|
|
|
|
title: 'Set your Profile'
|
|
|
|
})
|
|
|
|
me.uploader = new Uploader(d.body, {
|
|
|
|
modulename:'home.page.profile_settings.profile_settings',
|
|
|
|
method: 'set_user_image'
|
|
|
|
},
|
|
|
|
pscript.user_image_upload, 1)
|
|
|
|
d.show();
|
|
|
|
pscript.open_dialog = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.change_background = function() {
|
|
|
|
var d = new wn.widgets.Dialog({
|
|
|
|
title: 'Set Background Image'
|
|
|
|
})
|
|
|
|
me.uploader = new Uploader(d.body, {
|
|
|
|
modulename:'home.page.profile_settings.profile_settings',
|
|
|
|
method: 'set_user_background'
|
|
|
|
},
|
|
|
|
pscript.background_change, 1)
|
|
|
|
d.show();
|
|
|
|
pscript.open_dialog = d;
|
2011-06-08 09:07:15 +00:00
|
|
|
}
|
|
|
|
this.make();
|
|
|
|
}
|
|
|
|
|
2012-02-29 13:08:18 +00:00
|
|
|
pscript.background_change = function(fid) {
|
|
|
|
//erpnext.set_background_image(fid);
|
|
|
|
pscript.open_dialog.hide();
|
|
|
|
}
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
pscript.user_image_upload = function(fid) {
|
|
|
|
msgprint('File Uploaded');
|
|
|
|
if(fid) {
|
2012-02-29 13:08:18 +00:00
|
|
|
pscript.open_dialog.hide();
|
2011-06-08 09:07:15 +00:00
|
|
|
set_user_img(pscript.myprofile.img, user, null, fid);
|
|
|
|
}
|
2011-06-14 08:05:31 +00:00
|
|
|
}
|