From 412a65c23cef7e3afc763d89fa833738521e3308 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 29 Feb 2012 18:38:18 +0530 Subject: [PATCH] user background --- erpnext/home/page/activity/activity.js | 2 +- .../page/profile_settings/profile_settings.js | 54 +++++++++++-------- .../page/profile_settings/profile_settings.py | 31 +++++++++-- erpnext/patches/jan_mar_2012/navupdate.py | 1 + erpnext/startup/event_handlers.py | 2 + erpnext/startup/startup.js | 7 +++ .../style_settings/custom_template.css | 2 +- js/all-app.js | 14 +++-- js/all-web.js | 12 +++-- version.num | 2 +- 10 files changed, 91 insertions(+), 36 deletions(-) diff --git a/erpnext/home/page/activity/activity.js b/erpnext/home/page/activity/activity.js index b14f1f87ba..d72c7aeab4 100644 --- a/erpnext/home/page/activity/activity.js +++ b/erpnext/home/page/activity/activity.js @@ -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('%(feed_type)s\ %(link)s %(subject)s %(by)s', data)); }, diff --git a/erpnext/home/page/profile_settings/profile_settings.js b/erpnext/home/page/profile_settings/profile_settings.js index 9dac7f6f1d..8ce94f8439 100644 --- a/erpnext/home/page/profile_settings/profile_settings.js +++ b/erpnext/home/page/profile_settings/profile_settings.js @@ -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); } } diff --git a/erpnext/home/page/profile_settings/profile_settings.py b/erpnext/home/page/profile_settings/profile_settings.py index f614c75ff4..fb633fdb19 100644 --- a/erpnext/home/page/profile_settings/profile_settings.py +++ b/erpnext/home/page/profile_settings/profile_settings.py @@ -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) diff --git a/erpnext/patches/jan_mar_2012/navupdate.py b/erpnext/patches/jan_mar_2012/navupdate.py index 18338dd1ed..29939e5aa7 100644 --- a/erpnext/patches/jan_mar_2012/navupdate.py +++ b/erpnext/patches/jan_mar_2012/navupdate.py @@ -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') diff --git a/erpnext/startup/event_handlers.py b/erpnext/startup/event_handlers.py index 79fd60312a..dca9e0c6f6 100644 --- a/erpnext/startup/event_handlers.py +++ b/erpnext/startup/event_handlers.py @@ -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""" diff --git a/erpnext/startup/startup.js b/erpnext/startup/startup.js index aef298cbd2..ad8289e9d5 100644 --- a/erpnext/startup/startup.js +++ b/erpnext/startup/startup.js @@ -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 diff --git a/erpnext/website/doctype/style_settings/custom_template.css b/erpnext/website/doctype/style_settings/custom_template.css index e6eeeb34fa..8eb3d6396f 100644 --- a/erpnext/website/doctype/style_settings/custom_template.css +++ b/erpnext/website/doctype/style_settings/custom_template.css @@ -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 %} diff --git a/js/all-app.js b/js/all-app.js index 09e92a504f..e5e796783e 100644 --- a/js/all-app.js +++ b/js/all-app.js @@ -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\ Powered by ERPNext');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 diff --git a/js/all-web.js b/js/all-web.js index 98e1a7ab9b..1df96396ca 100644 --- a/js/all-web.js +++ b/js/all-web.js @@ -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\ Powered by ERPNext');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 diff --git a/version.num b/version.num index d6ee760bad..988e00fe6b 100644 --- a/version.num +++ b/version.num @@ -1 +1 @@ -762 \ No newline at end of file +768 \ No newline at end of file