Skip to content

Commit

Permalink
some cleanup related to #90
Browse files Browse the repository at this point in the history
  • Loading branch information
hbillings committed Oct 21, 2015
1 parent 6a28f4c commit a801891
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions static/css/cityhallmonitor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions static/js/cityhallmonitor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
$ = jQuery;

var handle_subscribe = function(event, url) {
var showMsg = function(msg, type, detail){
$('#post-subscribe-msg').text(msg + (detail ? detail : ''));
if ($('#post-subscribe-msg').hasClass('error') && type != 'error') {
$('#post-subscribe-msg').removeClass('error');
} else if (type == 'error'){
$('#post-subscribe-msg').addClass('error');
}
$('#post-subscribe-msg').show();
}
var email = $('#search-subscribe-email').val().trim();
if(!email) {
$('#post-subscribe-msg').fadeIn('slow')
Expand All @@ -21,15 +30,13 @@ var handle_subscribe = function(event, url) {
dataType: 'json',
timeout: 20000,
error: function(xhr, status, err) {
alert('Error making subscription: '+err);
showMsg('Error making subscription: ', 'error', err);
},
success: function(data) {
if(data.error) {
$('#post-subscribe-msg').fadeIn('slow')
.text('Error making subscription: '+ data.error);
showMsg('Error making subscription: ', 'error', data.error);
} else {
$('#post-subscribe-msg').fadeIn('slow')
.text('We sent you an email. Click the link in it to confirm your subscription.');
showMsg('We sent you an email. Click the link in it to confirm your subscription.', 'success');
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion static/sass/cityhallmonitor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ body {
margin: 40px auto;
}

#post-subscribe-msg {
.status-msg {
text-align: left;
padding: 0 0 0 10px;
font-family: $font-family-sans-serif;
Expand All @@ -130,6 +130,7 @@ body {
}
}


/* notifications.html */
#notifications-list {
table.columns {
Expand Down
2 changes: 1 addition & 1 deletion templates/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2>Manage subscriptions</h2>
var self = this;
// Server-side code expects an array
var sid = [$(this).attr("data-sid")];
// TODO: add visible state indication for loading and deleted searches
// TODO: add visible state indication for loading
$.ajax({
url: '{% url "unsubscribe" %}',
type: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h5>We found <span class="num-of-results"><%= total %> results</span> matching <
<input type="submit" value="Subscribe" id="search-subscribe" class="button postfix small"/>
</div>
<div class="small-4 columns">
<p id="post-subscribe-msg"></p>
<p id="post-subscribe-msg" class="status-msg"></p>
</div>
</div>
</form>
Expand Down
53 changes: 24 additions & 29 deletions templates/subscriptions.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
{% extends "base.html" %}

{% block content %}

<div id="manage-alert" data-alert class="alert-box alert small-8 small-offset-2 columns" style="display: none;">
<span></span>
<a href="#" class="close">&times;</a>
</div>

<div id="manage-alert-success" data-alert class="alert-box info small-8 small-offset-2 columns" style="display: none;">
<span>Your email has been sent!</span>
<a href="#" class="close">&times;</a>
</div>

<div class="row">
<div class="small-8 small-offset-2 columns">
<h2>Manage subscriptions</h2>
<p>Enter your email address below, and we'll send you a link to manage your subscriptions.</p>
<form>
<div class="row collapse">
<div class="small-10 columns">
<div class="small-6 columns">
<input type="text" id="manage-subs" placeholder="Email address you subscribed with">
</div>
<div class="small-2 columns end">
<div class="small-2 columns">
<input type="submit" value="Submit" id="manage-submit" class="button tiny postfix">
</div>
<div class="small-4 columns">
<p id="manage-alert" class="status-msg"><span></span></p>
</div>
</div>
</form>
</div>
Expand All @@ -33,25 +25,28 @@ <h2>Manage subscriptions</h2>

{% block extra_scripts %}

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<script type="text/javascript" src="//cdn.knightlab.com/libs/purpleline/latest/js/foundation.alert.js"></script>
<script type="text/javascript">

function manage_alert(error, detail) {
$('#manage-alert > span').html(error + (detail ? ' ['+detail+']' : ''));
function manage_alert(msg, detail, type) {
$('#manage-alert > span').html(msg + (detail ? detail : ''));
if ($('#manage-alert').hasClass('error') && type != 'error') {
$('#manage-alert').removeClass('error');
} else if (type == 'error'){
$('#manage-alert').addClass('error');
}
$('#manage-alert').show();
}

$(function() {
$(document).foundation();

$('#manage-submit').click(function(event) {
$('#manage-alert, #manage-alert-success').hide();
var email = $('#manage-subs').val().trim();
$('#manage-submit').click(function(event) {
$('#manage-alert').hide();

var email = $('#manage-subs').val().trim();
if(email) {
$('#manage-submit').prop('disabled', true);

$.ajax({
url: '{% url "send_notifications_link" %}',
type: 'GET',
Expand All @@ -62,20 +57,20 @@ <h2>Manage subscriptions</h2>
dataType: 'json',
timeout: 20000,
error: function(xhr, status, err) {
manage_alert('Error sending link', err);
manage_alert('Error sending link', err, "error");
},
success: function(data) {
if(data.error) {
manage_alert('Error sending link', data.error);
} else {
$('#manage-alert-success').show();
manage_alert('Error sending link: ', data.error, "error");
} else {
manage_alert('A link has been sent to ', email, "success");
}
},
complete: function() {
$('#manage-submit').prop('disabled', false);
$('#manage-submit').prop('disabled', false);
}
});
}
});
}
});
});

Expand Down

0 comments on commit a801891

Please sign in to comment.