Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (45 sloc) 1.94 KB
{% extends 'admin/model/list.html' %}
{% block realtime %}
<script src="{{url_for('static', filename='js/socket.io-1.4.5.js')}}"></script>
<script>
var list_columns = {{ list_columns|safe }};
var socket = io.connect('/', {
'reconnection': true,
'reconnectionDelay': 500,
'randomizationFactor': 0.5,
'reconnectionAttempts': 'Infinity'
});
document.onbeforeunload = function () {
console.log('Disconnecting from SocketIO ...');
socket.disconnect();
};
socket.on('connect', function () {
socket.emit('record_ids', {{ get_record_ids(data, get_pk_value)|safe }})
});
socket.on('insert', function (data) {
var new_row = document.createElement('tr');
new_row.setAttribute("id", 'row-' + data['id']);
var checkbox_cell = document.createElement('td');
new_row.appendChild(checkbox_cell);
var actions_cell = document.createElement('td');
new_row.appendChild(actions_cell);
for (let column of list_columns) {
column = column.toLowerCase();
var column_cell = document.createElement('td');
column_cell.setAttribute('id', column + '-' + data['id']);
column_cell.setAttribute('class', 'col-' + column);
column_cell.textContent = data[column];
new_row.appendChild(column_cell);
}
document.getElementById('flask-admin-table').lastChild.appendChild(new_row);
});
socket.on('update', function (data) {
for (let column of list_columns) {
column = column.toLowerCase();
console.log(column);
var existing_cell = document.getElementById(column + '-' + data['id']);
existing_cell.textContent = data[column]
}
});
</script>
{% endblock %}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.