Skip to content

Commit

Permalink
Make "share" link to go straight to share.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianloveswords committed May 17, 2012
1 parent d52fa26 commit 779efe4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
31 changes: 23 additions & 8 deletions controllers/share.js
Expand Up @@ -94,30 +94,45 @@ function makeLinkUrl(path, configuration) {
}

exports.show = function (request, response, next) {
var user = request.user;
var group = request.group;
var portfolio = group.get('portfolio');
var user, group, portfolio, owner, message;

if (!portfolio) return response.send('no portfolio :(', 404);
user = request.user;
group = request.group;
portfolio = group.get('portfolio');
owner = user && group.get('user_id') === user.get('id');

// If there is no portfolio and this is the owner, create and save a new
// portfolio object. Otherwise, kick the user out.
if (!portfolio) {
if (!owner) return response.send('no portfolio :(', 404);
portfolio = new Portfolio({
group_id: group.get('id'),
title: group.get('name'),
stories: {}
});
portfolio.save();
}

// if this is the user's page, show SocialShare button
if (user && group.get('user_id') === user.get('id')) {
var message = '<p style="float: left;">This is how your portfolio page looks like to the public.</p>'
if (owner)
message = '<p style="float: left;">This is how your portfolio page looks like to the public.</p>'
+ '<div class="socialshare" style="float: right;" data-type="small-bubbles" data-tweet-at="openbadges"></div>';
}


request.group.getBadgeObjects(function (err, badges) {
var badgesWithStories = _.map(badges, badgeModifierFactory(portfolio));
portfolio.badges = badgesWithStories;
portfolio.preamble = prepareText(portfolio.get('preamble'));

return response.render('portfolio', {
opengraph: [
{ property: 'title', content: portfolio.attributes.title },
{ property: 'type', content: 'openbadges:share' },
{ property: 'url', content: makeLinkUrl(request.url, configuration) }
],
portfolio: portfolio,
message: message || ''
message: message || null,
owner: owner
});
});
};
Expand Down
4 changes: 4 additions & 0 deletions static/css/style.css
Expand Up @@ -455,6 +455,10 @@ table.information {
margin-top: 16px;
}

.portfolio div.edit {
text-align: right;
}

.portfolio ul {
list-style: none;
margin: 20px auto;
Expand Down
2 changes: 1 addition & 1 deletion static/js/backpack.js
Expand Up @@ -124,7 +124,7 @@ Group.View = Backbone.View.extend({


share: function (event) {
window.location = '/share/' + this.model.get('url') + '/edit';
window.location = '/share/' + this.model.get('url') + '/';
return false;
},

Expand Down
5 changes: 5 additions & 0 deletions views/portfolio.hogan.js
Expand Up @@ -10,6 +10,11 @@
</div>
{{/message}}

{{#owner}}
<div class='edit'>
<a href="edit" class='edit btn btn-primary'>Edit this page</a>
</div>
{{/owner}}

<header>
{{#attributes.title}}<h1>{{attributes.title}}</h1>{{/attributes.title}}
Expand Down

0 comments on commit 779efe4

Please sign in to comment.