user background

This commit is contained in:
Rushabh Mehta 2012-02-29 18:38:18 +05:30
parent 79ae16506b
commit 412a65c23c
10 changed files with 91 additions and 36 deletions

View File

@ -14,7 +14,7 @@ erpnext.ActivityFeed = Class.extend({
init: function(row, data) {
this.scrub_data(data);
this.add_date_separator(row, data);
$(row).append(repl('<span %(onclick)s\
$(row).append(sprintf('<span %(onclick)s\
class="label %(add_class)s">%(feed_type)s</span>\
%(link)s %(subject)s <span class="user-info">%(by)s</span>', data));
},

View File

@ -26,13 +26,15 @@ MyProfile = function(wrapper) {
this.make = function() {
this.head = new PageHeader(this.wrapper, 'My Profile Settings');
this.head.add_button('Change Password', this.change_password)
this.head.add_button('Change Password', this.change_password);
this.head.add_button('Change Background', this.change_background);
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)
$btn($a($td(this.tab, 0, 0), 'div', '', {marginTop:'11px'}), 'Change Image', this.change_image);
this.make_form();
this.load_details();
@ -105,32 +107,42 @@ MyProfile = function(wrapper) {
//
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,
{
modulename:'home.page.profile_settings.profile_settings',
method: 'set_user_image'
},
pscript.user_image_upload, 1)
me.change_dialog = d;
}
me.change_dialog.show();
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;
}
this.make();
}
pscript.background_change = function(fid) {
//erpnext.set_background_image(fid);
pscript.open_dialog.hide();
}
pscript.user_image_upload = function(fid) {
msgprint('File Uploaded');
if(fid) {
pscript.myprofile.change_dialog.hide();
pscript.open_dialog.hide();
set_user_img(pscript.myprofile.img, user, null, fid);
}
}

View File

@ -63,6 +63,31 @@ def set_user_image(fid, fname):
"""
Set uploaded image as user image
"""
from webnotes.utils.file_manager import add_file_list, remove_all
remove_all('Profile', webnotes.session['user'])
add_file_list('Profile', webnotes.session['user'], fname, fid)
from webnotes.utils.file_manager import add_file_list, remove_file
user = webnotes.session['user']
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'user_image')
if old_image:
remove_file('Profile', user, old_image)
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'user_image', fid)
@webnotes.whitelist()
def set_user_background(fid, fname):
"""
Set uploaded image as user image
"""
from webnotes.utils.file_manager import add_file_list, remove_file
user = webnotes.session['user']
# remove old file
old_image = webnotes.conn.get_value('Profile', user, 'background_image')
if old_image:
remove_file('Profile', user, old_image)
# add new file
add_file_list('Profile', user, fname, fid)
webnotes.conn.set_value('Profile', user, 'background_image', fid)

View File

@ -35,6 +35,7 @@ def execute():
reload_doc('setup', 'page', 'modules_setup')
reload_doc('utilities', 'page', 'users')
reload_doc('home', 'page', 'activity')
reload_doc('core', 'doctype', 'profile')
webnotes.conn.set_value('Control Panel', 'Control Panel', 'home_page',
'desktop')

View File

@ -93,6 +93,8 @@ def boot_session(bootinfo):
# if no company, show a dialog box to create a new company
bootinfo['setup_complete'] = webnotes.conn.sql("""select name from
tabCompany limit 1""") and 'Yes' or 'No'
bootinfo['user_background'] = webnotes.conn.get_value("Profile", webnotes.session['user'], 'background_image') or ''
def get_letter_heads():
"""load letter heads with startup"""

View File

@ -50,6 +50,9 @@ erpnext.startup.start = function() {
if(wn.boot.custom_css) {
set_style(wn.boot.custom_css);
}
if(wn.boot.user_background) {
erpnext.set_user_background(wn.boot.user_background);
}
if(user == 'Guest'){
if(wn.boot.website_settings.title_prefix) {
@ -132,6 +135,10 @@ erpnext.startup.set_periodic_updates = function() {
wn.updates.id = setInterval(update_messages, 60000);
}
erpnext.set_user_background = function(src) {
set_style(repl('body { background: url("files/%(src)s") repeat !important;}', {src:src}))
}
// =======================================
// start

View File

@ -1,6 +1,6 @@
body {
{% if doc.background_image %}
background: url("files/{{ doc.background_image }}") repeat !important;
background: url("files/{{ doc.background_image }}") repeat;
{% elif doc.background_color %}
background-color: #{{ doc.background_color }};
{% endif %}

View File

@ -129,13 +129,13 @@ return output.join('');};str_format.cache={};str_format.parse=function(fmt){var
else if((match=/^\x25{2}/.exec(_fmt))!==null){parse_tree.push('%');}
else if((match=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt))!==null){if(match[2]){arg_names|=1;var field_list=[],replacement_field=match[2],field_match=[];if((field_match=/^([a-z_][a-z_\d]*)/i.exec(replacement_field))!==null){field_list.push(field_match[1]);while((replacement_field=replacement_field.substring(field_match[0].length))!==''){if((field_match=/^\.([a-z_][a-z_\d]*)/i.exec(replacement_field))!==null){field_list.push(field_match[1]);}
else if((field_match=/^\[(\d+)\]/.exec(replacement_field))!==null){field_list.push(field_match[1]);}
else{}}}
else{}
else{throw('[sprintf] huh?');}}}
else{throw('[sprintf] huh?');}
match[2]=field_list;}
else{arg_names|=2;}
if(arg_names===3){throw('[sprintf] mixing positional and named placeholders is not (yet) supported');}
parse_tree.push(match);}
else{}
else{throw('[sprintf] huh?');}
_fmt=_fmt.substring(match[0].length);}
return parse_tree;};return str_format;})();var vsprintf=function(fmt,argv){argv.unshift(fmt);return sprintf.apply(null,argv);};
/*
@ -280,7 +280,9 @@ var lstrip=function(s,chars){if(!chars)chars=['\n','\t',' '];var first_char=s.su
return s;}
var rstrip=function(s,chars){if(!chars)chars=['\n','\t',' '];var last_char=s.substr(s.length-1);while(in_list(chars,last_char)){var s=s.substr(0,this.length-1);last_char=s.substr(this.length-1);}
return s;}
function repl(s,dict){return sprintf(s,dict);}
function repl_all(s,s1,s2){var idx=s.indexOf(s1);while(idx!=-1){s=s.replace(s1,s2);idx=s.indexOf(s1);}
return s;}
function repl(s,dict){if(s==null)return'';for(key in dict)s=repl_all(s,'%('+key+')s',dict[key]);return s;}
function keys(obj){var mykeys=[];for(key in obj)mykeys[mykeys.length]=key;return mykeys;}
function values(obj){var myvalues=[];for(key in obj)myvalues[myvalues.length]=obj[key];return myvalues;}
function in_list(list,item){for(var i=0;i<list.length;i++)
@ -1677,7 +1679,7 @@ _f.Frm.prototype.setup=function(){var me=this;this.fields=[];this.fields_dict={}
_f.Frm.prototype.setup_print_layout=function(){this.print_wrapper=$a(this.wrapper,'div');this.print_head=$a(this.print_wrapper,'div');this.print_body=$a(this.print_wrapper,'div','layout_wrapper',{padding:'23px'});var t=make_table(this.print_head,1,2,'100%',[],{padding:'6px'});this.view_btn_wrapper=$a($td(t,0,0),'span','green_buttons');this.view_btn=$btn(this.view_btn_wrapper,'View Details',function(){cur_frm.edit_doc()},{marginRight:'4px'},'green');this.print_btn=$btn($td(t,0,0),'Print',function(){cur_frm.print_doc()});$y($td(t,0,1),{textAlign:'right'});this.print_close_btn=$btn($td(t,0,1),'Close',function(){nav_obj.show_last_open();});}
_f.Frm.prototype.onhide=function(){if(_f.cur_grid_cell)_f.cur_grid_cell.grid.cell_deselect();}
_f.Frm.prototype.setup_std_layout=function(){this.page_layout=new wn.PageLayout({parent:this.wrapper,main_width:this.in_dialog?'100%':'75%',sidebar_width:this.in_dialog?'0%':'25%'})
this.meta.section_style='Simple';this.layout=new Layout(this.page_layout.body,'100%');if(!this.in_dialog){this.setup_sidebar();}
this.meta.section_style='Simple';this.layout=new Layout(this.page_layout.body,'100%');if(this.in_dialog){$(this.page_layout.wrapper).removeClass('layout-wrapper-background');$(this.page_layout.main).removeClass('layout-main-section');$(this.page_layout.sidebar_area).toggle(false);}else{this.setup_sidebar();}
this.setup_footer();if(!(this.meta.istable||user=='Guest'))this.frm_head=new _f.FrmHeader(this.page_layout.head,this);if(this.frm_head&&this.meta.in_dialog)$dh(this.frm_head.page_head.close_btn);if(this.meta.colour)
this.layout.wrapper.style.backgroundColor='#'+this.meta.colour.split(':')[1];this.setup_fields_std();if(this.meta.description)
this.add_description();}
@ -2222,6 +2224,7 @@ var current_module;var is_system_manager=0;wn.provide('erpnext.startup');erpnext
erpnext.startup.set_globals=function(){pscript.is_erpnext_saas=cint(wn.control_panel.sync_with_gateway)
if(inList(user_roles,'System Manager'))is_system_manager=1;}
erpnext.startup.start=function(){$('#startup_div').html('Starting up...').toggle(true);erpnext.startup.set_globals();if(wn.boot.custom_css){set_style(wn.boot.custom_css);}
if(wn.boot.user_background){erpnext.set_user_background(wn.boot.user_background);}
if(user=='Guest'){if(wn.boot.website_settings.title_prefix){wn.title_prefix=wn.boot.website_settings.title_prefix;}}else{erpnext.toolbar.setup();erpnext.startup.set_periodic_updates();$('footer').html('<div class="web-footer erpnext-footer">\
Powered by <a href="https://erpnext.com">ERPNext</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("erpnext/startup/js/complete_setup.js");erpnext.complete_setup();}}
$('#startup_div').toggle(false);}
@ -2234,6 +2237,7 @@ $c_page('home','event_updates','get_unread_messages',null,function(r,rt){if(!r.e
if(circle){if(r.message.length){circle.find('span:first').text(r.message.length);circle.toggle(true);}else{circle.toggle(false);}}}else{clearInterval(wn.updates.id);}});}
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
wn.updates.id=setInterval(update_messages,60000);}
erpnext.set_user_background=function(src){set_style(repl('body { background: url("files/%(src)s") repeat !important;}',{src:src}))}
$(document).bind('startup',function(){erpnext.startup.start();});
/*
* erpnext/startup/js/modules.js

View File

@ -55,13 +55,13 @@ return output.join('');};str_format.cache={};str_format.parse=function(fmt){var
else if((match=/^\x25{2}/.exec(_fmt))!==null){parse_tree.push('%');}
else if((match=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt))!==null){if(match[2]){arg_names|=1;var field_list=[],replacement_field=match[2],field_match=[];if((field_match=/^([a-z_][a-z_\d]*)/i.exec(replacement_field))!==null){field_list.push(field_match[1]);while((replacement_field=replacement_field.substring(field_match[0].length))!==''){if((field_match=/^\.([a-z_][a-z_\d]*)/i.exec(replacement_field))!==null){field_list.push(field_match[1]);}
else if((field_match=/^\[(\d+)\]/.exec(replacement_field))!==null){field_list.push(field_match[1]);}
else{}}}
else{}
else{throw('[sprintf] huh?');}}}
else{throw('[sprintf] huh?');}
match[2]=field_list;}
else{arg_names|=2;}
if(arg_names===3){throw('[sprintf] mixing positional and named placeholders is not (yet) supported');}
parse_tree.push(match);}
else{}
else{throw('[sprintf] huh?');}
_fmt=_fmt.substring(match[0].length);}
return parse_tree;};return str_format;})();var vsprintf=function(fmt,argv){argv.unshift(fmt);return sprintf.apply(null,argv);};
/*
@ -206,7 +206,9 @@ var lstrip=function(s,chars){if(!chars)chars=['\n','\t',' '];var first_char=s.su
return s;}
var rstrip=function(s,chars){if(!chars)chars=['\n','\t',' '];var last_char=s.substr(s.length-1);while(in_list(chars,last_char)){var s=s.substr(0,this.length-1);last_char=s.substr(this.length-1);}
return s;}
function repl(s,dict){return sprintf(s,dict);}
function repl_all(s,s1,s2){var idx=s.indexOf(s1);while(idx!=-1){s=s.replace(s1,s2);idx=s.indexOf(s1);}
return s;}
function repl(s,dict){if(s==null)return'';for(key in dict)s=repl_all(s,'%('+key+')s',dict[key]);return s;}
function keys(obj){var mykeys=[];for(key in obj)mykeys[mykeys.length]=key;return mykeys;}
function values(obj){var myvalues=[];for(key in obj)myvalues[myvalues.length]=obj[key];return myvalues;}
function in_list(list,item){for(var i=0;i<list.length;i++)
@ -1070,6 +1072,7 @@ var current_module;var is_system_manager=0;wn.provide('erpnext.startup');erpnext
erpnext.startup.set_globals=function(){pscript.is_erpnext_saas=cint(wn.control_panel.sync_with_gateway)
if(inList(user_roles,'System Manager'))is_system_manager=1;}
erpnext.startup.start=function(){$('#startup_div').html('Starting up...').toggle(true);erpnext.startup.set_globals();if(wn.boot.custom_css){set_style(wn.boot.custom_css);}
if(wn.boot.user_background){erpnext.set_user_background(wn.boot.user_background);}
if(user=='Guest'){if(wn.boot.website_settings.title_prefix){wn.title_prefix=wn.boot.website_settings.title_prefix;}}else{erpnext.toolbar.setup();erpnext.startup.set_periodic_updates();$('footer').html('<div class="web-footer erpnext-footer">\
Powered by <a href="https://erpnext.com">ERPNext</a></div>');if(in_list(user_roles,'System Manager')&&(wn.boot.setup_complete=='No')){wn.require("erpnext/startup/js/complete_setup.js");erpnext.complete_setup();}}
$('#startup_div').toggle(false);}
@ -1082,6 +1085,7 @@ $c_page('home','event_updates','get_unread_messages',null,function(r,rt){if(!r.e
if(circle){if(r.message.length){circle.find('span:first').text(r.message.length);circle.toggle(true);}else{circle.toggle(false);}}}else{clearInterval(wn.updates.id);}});}
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
wn.updates.id=setInterval(update_messages,60000);}
erpnext.set_user_background=function(src){set_style(repl('body { background: url("files/%(src)s") repeat !important;}',{src:src}))}
$(document).bind('startup',function(){erpnext.startup.start();});
/*
* erpnext/website/js/topbar.js

View File

@ -1 +1 @@
762
768