From 0d5b61161be04616973495ba39822e1af60a6f0b Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 15 Apr 2013 05:25:59 -0400 Subject: added basic UI for auto-tweeting --- askbot/deps/django_authopenid/util.py | 15 ++-- askbot/media/js/user.js | 82 ++++++++++++++++++++++ askbot/media/style/style.css | 7 ++ askbot/media/style/style.less | 12 +++- .../user_profile/twitter_sharing_controls.html | 12 ++-- askbot/urls.py | 15 ++++ askbot/views/__init__.py | 1 + askbot/views/sharing.py | 53 ++++++++++++++ 8 files changed, 186 insertions(+), 11 deletions(-) create mode 100644 askbot/views/sharing.py diff --git a/askbot/deps/django_authopenid/util.py b/askbot/deps/django_authopenid/util.py index 7e78da16..03e70922 100644 --- a/askbot/deps/django_authopenid/util.py +++ b/askbot/deps/django_authopenid/util.py @@ -757,11 +757,8 @@ class OAuthConnection(object): def get_token(self): return self.request_token - def get_user_id(self, oauth_token = None, oauth_verifier = None): - """Returns user ID within the OAuth provider system, - based on ``oauth_token`` and ``oauth_verifier`` - """ - + def get_access_token(self, oauth_token=None, oauth_verifier=None): + """returns data as returned upon visiting te access_token_url""" token = oauth.Token( oauth_token['oauth_token'], oauth_token['oauth_token_secret'] @@ -770,7 +767,13 @@ class OAuthConnection(object): client = oauth.Client(self.consumer, token = token) url = self.parameters['access_token_url'] #there must be some provider-specific post-processing - data = self.send_request(client = client, url=url, method='GET') + return self.send_request(client = client, url=url, method='GET') + + def get_user_id(self, oauth_token = None, oauth_verifier = None): + """Returns user ID within the OAuth provider system, + based on ``oauth_token`` and ``oauth_verifier`` + """ + data = self.get_access_token(oauth_token, oauth_verifier) data['consumer_key'] = self.parameters['consumer_key'] data['consumer_secret'] = self.parameters['consumer_secret'] return self.parameters['get_user_id_function'](data) diff --git a/askbot/media/js/user.js b/askbot/media/js/user.js index 251ee004..a1ea840b 100644 --- a/askbot/media/js/user.js +++ b/askbot/media/js/user.js @@ -993,6 +993,82 @@ UserGroupsEditor.prototype.decorate = function(element){ //todo - add group deleters }; +/** + * controls that set up automatic tweeting to the user account + */ +var Tweeting = function() { + WrappedElement.call(this); +}; +inherits(Tweeting, WrappedElement); + +Tweeting.prototype.getStartHandler = function() { + var url = this._startUrl; + return function() { + window.location.href = url; + }; +}; + +Tweeting.prototype.getMode = function() { + return this._modeSelector.val(); +}; + +Tweeting.prototype.getModeSelectorHandler = function() { + var me = this; + var url = this._changeModeUrl; + return function() { + $.ajax({ + type: 'POST', + dataType: 'json', + url: url, + data: {'mode': me.getMode() }, + cache: false + }); + }; +}; + +Tweeting.prototype.getAccount = function() { + return this._accountSelector.val(); +}; + +Tweeting.prototype.getAccountSelectorHandler = function() { + var selectAccountUrl = this._changeModeUrl; + var startUrl = this._startUrl; + var me = this; + return function() { + var account = me.getAccount(); + if (account === 'existing-handle') { + $.ajax({ + type: 'POST', + dataType: 'json', + url: selectAccountUrl, + data: {'mode': 'share-my-posts' }, + cache: false + }); + } else if (account === 'new-handle') { + window.location.href = startUrl; + } + } +}; + +Tweeting.prototype.decorate = function(element) { + this._element = element; + this._changeModeUrl = element.data('changeModeUrl'); + this._startUrl = element.data('startUrl'); + if (element.hasClass('disabled')) { + this._startButton = element.find('.start-tweeting'); + this._startUrl = this._startButton.data('url'); + setupButtonEventHandlers(this._startButton, this.getStartHandler()); + } else if (element.hasClass('inactive')) { + //decorate choose account selector + this._accountSelector = element.find('select'); + this._accountSelector.change(this.getAccountSelectorHandler()); + } else if (element.hasClass('enabled')) { + //decorate choose mode selector + this._modeSelector = element.find('select'); + this._modeSelector.change(this.getModeSelectorHandler()); + } +}; + (function(){ var fbtn = $('.follow-user-toggle'); if (fbtn.length === 1){ @@ -1010,4 +1086,10 @@ UserGroupsEditor.prototype.decorate = function(element){ } else { $('#add-group').remove(); } + + var tweeting = $('.auto-tweeting'); + if (tweeting.length) { + var tweetingControl = new Tweeting(); + tweetingControl.decorate(tweeting); + } })(); diff --git a/askbot/media/style/style.css b/askbot/media/style/style.css index e818c493..7e60afd2 100644 --- a/askbot/media/style/style.css +++ b/askbot/media/style/style.css @@ -2980,6 +2980,9 @@ a:hover.medal { .user-details h3 { font-size: 16px; } +.user-details td { + padding-right: 10px; +} .user-about { background-color: #EEEEEE; height: 200px; @@ -4345,3 +4348,7 @@ textarea.tipped-input { .tag-subscriptions ul.tags li { margin: 2px 5px; } +.auto-tweeting select { + width: auto; + margin-bottom: 0; +} diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less index f3f70679..6e622311 100644 --- a/askbot/media/style/style.less +++ b/askbot/media/style/style.less @@ -3088,9 +3088,12 @@ a:hover.medal { .user-details { font-size: 13px; - h3{ + h3 { font-size:16px; } + td { + padding-right: 10px; + } } .user-about { @@ -4535,3 +4538,10 @@ textarea.tipped-input { margin: 2px 5px; } } + +.auto-tweeting { + select { + width: auto; + margin-bottom: 0; + } +} diff --git a/askbot/templates/user_profile/twitter_sharing_controls.html b/askbot/templates/user_profile/twitter_sharing_controls.html index 1e3c3879..bb44ea0c 100644 --- a/askbot/templates/user_profile/twitter_sharing_controls.html +++ b/askbot/templates/user_profile/twitter_sharing_controls.html @@ -1,14 +1,17 @@ {% set auto_tweeting_status = view_user.get_social_sharing_status('twitter') %} - +{% set handle = view_user.twitter_handle|escape %} + {% if auto_tweeting_status == 'enabled' %} - {% set handle = view_user.twitter_handle|escape %} {% trans %}Auto-tweeting to @{{ handle }}{% endtrans %}