Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
require login to write a review (bug 871871)
Browse files Browse the repository at this point in the history
  • Loading branch information
spasovski committed May 16, 2013
1 parent ea3c7da commit c9afb32
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hearth/media/js/ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ define('ratings',
// If the user isn't logged in, prompt them to do so.
if (!user.logged_in()) {
login.login().done(function() {
addReview(e, $senderEl);
// TODO: This should be more graceful than a page reload.
require('views').reload();
});
return;
}
Expand Down
10 changes: 10 additions & 0 deletions hearth/media/js/views/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ define('views/app',
function(caps, l10n, utils, requests, _, urls, z, nunjucks, overflow) {
'use strict';

var login = require('login');

z.page.on('click', '#product-rating-status .toggle', utils._pd(function() {
// Show/hide scary content-rating disclaimers to developers.
$(this).closest('.toggle').siblings('div').toggleClass('hidden');
Expand Down Expand Up @@ -58,6 +60,14 @@ define('views/app',
}
}).onload('ratings', function() {
var reviews = $('.detail .reviews li');
if (!require('user').logged_in()) {
$('#add-review').text(gettext('Sign in to Review')).on('click', function(e) {
e.preventDefault();
e.stopPropagation();
login.login();
});
}

if (reviews.length < 3) return;

for (var i = 0; i < reviews.length - 2; i += 2) {
Expand Down
11 changes: 10 additions & 1 deletion hearth/media/js/views/app/ratings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
define('views/app/ratings', ['l10n', 'urls'], function(l10n, urls) {
define('views/app/ratings', ['l10n', 'urls', 'user'], function(l10n, urls, user) {

var gettext = l10n.gettext;

return function(builder, args) {
var slug = args[0];

builder.start('ratings/main.html', {
'slug': slug
}).done(function() {
if (!user.logged_in()) {
$('#write-review').text(gettext('Sign in to Review')).on('click', function(e) {
e.preventDefault();
e.stopPropagation();
require('login').login();
});
}
});

builder.z('type', 'leaf');
Expand Down
1 change: 1 addition & 0 deletions hearth/media/js/views/app/ratings/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define('views/app/ratings/add',
});

builder.z('type', 'leaf');
builder.z('reload_on_login', true);
builder.z('parent', urls.reverse('app/ratings', [slug]));
builder.z('title', gettext('Write a Review'));
};
Expand Down
1 change: 1 addition & 0 deletions hearth/media/js/views/app/ratings/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ define('views/app/ratings/edit',
// have even gotten to this page in their current state anyway.
if (!user.logged_in()) {
z.page.trigger('navigate', urls.reverse('app', [slug]));
require('views').reload();
return;
}

Expand Down

1 comment on commit c9afb32

@chuckharmston
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.