From c8d0fd4a50893535c7be0fb416e1f05a917e98d0 Mon Sep 17 00:00:00 2001 From: Dhaval Panchal Date: Tue, 13 Oct 2015 15:08:29 +0530 Subject: [PATCH] [IMP] website_forum: Change profile picture for forum users. --- addons/website_forum/controllers/main.py | 7 + .../static/src/js/website_forum.js | 27 ++++ addons/website_forum/views/website_forum.xml | 126 ++++++++++-------- 3 files changed, 101 insertions(+), 59 deletions(-) diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 2294daf73de..ca536bc28bd 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -705,6 +705,13 @@ class WebsiteForum(http.Controller): 'country_id': int(kwargs.get('country')) if kwargs.get('country') else False, 'website_description': kwargs.get('description'), } + + if 'clear_image' in kwargs: + values['image'] = False + elif kwargs.get('ufile'): + image = kwargs.get('ufile').read() + values['image'] = image.encode('base64') + if request.uid == user.id: # the controller allows to edit only its own privacy settings; use partner management for other cases values['website_published'] = kwargs.get('website_published') == 'True' user.write(values) diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 60073ffd70a..703e7cc61ea 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -40,6 +40,33 @@ if(!$('.website_forum').length) { $(this).find('.o_forum_tag_follow_box').stop().fadeOut().css('display','none'); }); + $('.o_forum_profile_pic_edit').on('click', function(ev) { + ev.preventDefault(); + $(this).closest('form').find('.o_forum_file_upload').trigger('click'); + }); + + $('.o_forum_file_upload').on('change', function() { + if (this.files.length) { + var $form = $(this).closest('form'); + var reader = new FileReader(); + reader.onload = function(ev) { + $form.find('.o_forum_avatar_img').attr('src', ev.target.result); + }; + reader.readAsDataURL(this.files[0]); + $form.find('#forum_clear_image').remove(); + } + }); + + $('.o_forum_profile_pic_clear').click(function() { + var $form = $(this).closest('form'); + $form.find('.o_forum_avatar_img').attr("src", "/web/static/src/img/placeholder.png"); + $form.append($('', { + name: 'clear_image', + id: 'forum_clear_image', + type: 'hidden', + })); + }); + // Extended user biography toogle $('.o_forum_user_info').hover( function () { diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 15d8c8f77e6..301bbb7e482 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -1261,74 +1261,80 @@

Edit Profile

-
- -
-
-
+ - -
- -
- -
+ + -
- -
- - +
+ +
+ +
+ +
-
-
- -
- +
+ +
+ + +
-
-
-
- -

Please enter a valid email address in order to receive notifications from answers or comments.

+
+ +
+ +
- -
- +
+
+ +

Please enter a valid email address in order to receive notifications from answers or comments.

+
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- -
- -
- + +
+ +
+ +
+
+
+
-
-
-
-
- @@ -1389,10 +1395,12 @@ + + +