Permalink
Browse files

Further tweaks to the JS for showing messages.

  • Loading branch information...
1 parent 701ed80 commit 3410dd1ffe7b082ac6562236bf061cbde9572e8e @akavlie committed Oct 14, 2010
Showing with 21 additions and 9 deletions.
  1. +5 −3 sms/static/sms.js
  2. +2 −2 sms/templates/index.html
  3. +3 −0 sms/templates/new_message.html
  4. +1 −1 sms/templates/sent_message.html
  5. +10 −3 sms/views.py
View
@@ -10,7 +10,7 @@ $(function() {
});
// SMS SUBMISION
// -------------
- $("#sms_form").submit(function() {
+ $('#sms_form').submit(function() {
// Post form data via AJAX
$.post($SCRIPT_ROOT + "/sms", $("#sms_form").serialize(),
function(data) {
@@ -27,6 +27,7 @@ $(function() {
status_checker = setInterval('checkStatus()', 5000);
}
});
+ //$('#sms_form')[0].reset();
return false;
});
@@ -69,10 +70,11 @@ function checkStatus() {
$(this).children('.status').load($SCRIPT_ROOT + '/sms/update/' + sid, function(data) {
// Add class based on current status; remove former status class
if(data != status) {
- $(this).parent().fadeOut();
+ // Hide, change class, then fade in, to call attention to status changes
+ $(this).parent().hide();
$(this).parent().removeClass('queued sending')
.addClass(data)
- .fadeIn();
+ .fadeIn(1000);
}
//.children('.sent_message, .status').effect('highlight', {color: '#ffffff'}, 3000);
});
View
@@ -4,8 +4,6 @@
<script type="text/javascript" src="{{ url_for('static', filename='sms.js') }}"></script>
-<!--<button id="test">Test!</button>-->
-
<div id="sms_box" class="rounded">
<form id="sms_form" action="">
<div id="db_users" class="rounded">
@@ -31,6 +29,8 @@
</form>
</div>
+<button id="test">Test!</button>
+
<div id="sent_message_list">
<h2>Message History</h2>
{% for message in sent_messages %}
@@ -0,0 +1,3 @@
+{% extends 'sent_message.html' %}
+
+{% block class %}new hidden{% endblock %}
@@ -1,4 +1,4 @@
-<div class="sent_message rounded {{ extra_classes|default() }} {{ message.status }}">
+<div class="sent_message rounded {% block class %}{% endblock %} {{ message.status }}">
<div class="status rounded_top">{{ message.status }}</div>
<div class="sent_body">
<div class="phone">{{ message.phone }}</div>
View
@@ -22,11 +22,19 @@ def sms():
phone_numbers = request.form.getlist('user_phone')
+ e = Environment()
template = ''
for p in phone_numbers:
+
+ # Render Jinja2 template from message
+ u = User.query.filter(User.phone == p).one()
+ msg_template = e.from_string(request.form['message'])
+ message = msg_template.render(first_name=u.first_name,
+ last_name=u.last_name, phone=p)
+
# Send to Twilio
- tw_response = twilio_send(p, request.form['message'])
+ tw_response = twilio_send(p, message)
# Convert JSON from Twilio to Python dict
sms_data = json.loads(tw_response)
@@ -36,8 +44,7 @@ def sms():
sms = SentMessage(sms_data['to'], sms_data['body'], sms_data['status'],
sms_data['sid'], datetime.now())
db.session.add(sms)
- template += render_template('sent_message.html', message=sms,
- extra_classes='new hidden')
+ template += render_template('new_message.html', message=sms)
db.session.commit()

0 comments on commit 3410dd1

Please sign in to comment.