Skip to content

Commit

Permalink
Iron out wrinkles in async update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehashman committed Aug 17, 2014
1 parent b0269c5 commit ab2ed80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mysite/bugsets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def api_index(request):
return HttpResponse(json.dumps({
'obj_id': data['obj_id'],
'field_name': data['field_name'],
'new_html': getattr(b, data['field_name']),
'new_html': b.get_status_display() if data['field_name'] == 'status' else getattr(b, data['field_name']),
}))

except ObjectDoesNotExist:
Expand Down
20 changes: 14 additions & 6 deletions mysite/static/js/bugsets/bugsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,29 @@ function getNewValue(obj_id, field_name) {
}

function updateHTML(response) {
// stash the tag away
// Don't update fields with empty values
if (response.new_html == '') {
return;
}

node = $('inplaceeditform[obj_id=' + response.obj_id + '][field_name=' +
response.field_name + ']').parent()
ipe_tag = node.find('inplaceeditform').detach()
node.html(response.new_html)
node.append(ipe_tag)

// Two nodes match when field_name='status', so we need a 'foreach' here
$(node).each(function () {
ipe_tag = $(this).find('inplaceeditform').detach()
$(this).html(response.new_html)
$(this).append(ipe_tag)
})
}

function runOnInterval() {
setTimeout(runOnInterval, 5000); // 15s = 15000ms
updateFields();
setTimeout(runOnInterval, 15000); // 15s = 15000ms
}

// Delicious recursive call
runOnInterval();
$(runOnInterval());


/* vim: set ai ts=4 sts=4 et sw=4: */

0 comments on commit ab2ed80

Please sign in to comment.