Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Highlighting added for users checked off. Support added for multiple …

…simultaneous phone submissions (needs testing).
  • Loading branch information...
commit 251ccc08ca13c6351b06d3b50d17ef4c2c0445f1 1 parent 78254b0
@akavlie authored
View
37 sms/static/sms.js
@@ -30,16 +30,32 @@ $(function() {
return false;
});
-/* $('#new_user').submit(function() {
- $.post($SCRIPT_ROOT + '/user', $('#user_form').serialize()
- function(data) {
- });
- return false;
- });
- */
- // Plugin for placeholder text
$('input:text').placeholder();
+ // Highlight row for user when checked
+ $('#db_users input').click(function() {
+ if($(this).attr('checked')) {
+ $(this).closest('tr').addClass('highlight');
+ } else {
+ $(this).closest('tr').removeClass('highlight');
+ }
+ });
+
+ // Rows should remain highlighted after page refresh
+ $('#db_users input:checked').closest('tr').addClass('highlight');
+
+
+
+ // Not concerned with new user addition right now.
+ /* $('#new_user').submit(function() {
+ $.post($SCRIPT_ROOT + '/user', $('#user_form').serialize()
+ function(data) {
+ });
+ return false;
+ });
+ */
+ // Plugin for placeholder text
+
});
function checkStatus() {
@@ -52,9 +68,8 @@ 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()
- .removeClass('queued sending')
+ $(this).parent().fadeOut();
+ $(this).parent().removeClass('queued sending')
.addClass(data)
.fadeIn();
}
View
21 sms/static/style.css
@@ -23,6 +23,7 @@ input.placeholder {
.clear {clear: both;}
.hidden {display: none;}
+.highlight {background-color: #FFFF99;}
/* ROUNDED CORNERS */
@@ -55,12 +56,20 @@ input.placeholder {
padding: 10px;
}
+/* #CAE1FF steel blue - for recipients? */
+
#recipients {
+ background-color: #CAE1FF;
+ padding: 10px;
+}
+
+#db_users {
background-color: white;
border: 1px solid black;
+ border-collapse: collapse;
}
- #recipients td {
- padding: 2px 50px 2px 0px;
+ #db_users td {
+ padding: 5px 70px 5px 0px;
}
@@ -105,12 +114,14 @@ input.placeholder {
/* STATUSES */
.queued, .sending {
- border: 2px solid #757575;
- background-color: #CCCCCC;
+ background-color: #CCCCCC; /* light gray */
}
+ .queued .status, .sending .status {
+ background-color: #757575; /* gray */
+ }
.failed {
- background-color: #e7c5c5;
+ background-color: #e7c5c5; /* pink */
}
.failed .status {
background-color: #CC0000; /* red */
View
28 sms/templates/index.html
@@ -7,19 +7,21 @@
<button id="test">Test!</button>
<div id="sms_box" class="rounded">
- <h3>Select Recipients</h3>
- <table id="recipients">
- {% for user in users %}
- <tr>
- <td><input type="checkbox" value="{{ user.id }}"></td>
- <td>{{ user.first_name }} {{ user.last_name }}</td>
- <td>{{ user.phone }}</td>
- </tr>
- {% endfor %}
- </table>
- <form id="sms_form" action="">
- <p>Other</p>
- <p><input type="text" name="phone_number" size="10" placeholder="Phone"></p>
+ <div id="recipients" class="rounded">
+ <h3>Select Recipients</h3>
+ <form id="sms_form" action="">
+ <table id="db_users">
+ {% for user in users %}
+ <tr>
+ <td><input type="checkbox" name="user_phone" value="{{ user.phone }}"></td>
+ <td>{{ user.first_name }} {{ user.last_name }}</td>
+ <td>{{ user.phone }}</td>
+ </tr>
+ {% endfor %}
+ </table>
+ <h3>Other</h3>
+ <p><input type="text" name="phone_number" size="10" placeholder="Phone"></p>
+ </div>
<p><input type="text" name="message" size="40" placeholder="Message">
<input type="submit" value="Send"></p>
</form>
View
33 sms/views.py
@@ -18,21 +18,30 @@ def index():
def sms():
"""Send an SMS to Twilio and save response to DB. """
- # Send to Twilio
- tw_response = twilio_send(request.form['phone_number'], request.form['message'])
+ phone_numbers = request.form.getlist('user_phone')
+ # Defaults to 'Phone' with placeholder
+ if request.form['phone_number'] != 'Phone':
+ phone_numbers.append(request.form['phone_number'])
+
+ template = ''
+
+ for p in phone_numbers:
+ # Send to Twilio
+ tw_response = twilio_send(p, request.form['message'])
+
+ # Convert JSON from Twilio to Python dict
+ sms_data = json.loads(tw_response)
+ #sms_data = {'to': 1234567899, 'body': 'Fake SMS', 'status': 'fake'}
+
+ # Commit to database
+ 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', sms=sms_data)
- # Convert JSON from Twilio to Python dict
- sms_data = json.loads(tw_response)
- #sms_data = {'to': 1234567899, 'body': 'Fake SMS', 'status': 'fake'}
-
- # Commit to database
- sms = SentMessage(sms_data['to'], sms_data['body'], sms_data['status'],
- sms_data['sid'], datetime.now())
- db.session.add(sms)
db.session.commit()
- # flash('SMS sent to %s' % request.form['phone_number'])
- return render_template('sent_message.html', sms=sms_data)
+ return template
@app.route('/sms/update/<sid>')
def sms_update(sid):
Please sign in to comment.
Something went wrong with that request. Please try again.