chaloBEST/chaloBEST/templates/fuzzystops.html
2012-08-10 02:53:04 +05:30

137 lines
4.1 KiB
HTML

{% comment %}
<h2> Likely Mismatched From stops: </h2>
{% for f in fuzzy_froms %}
<a href="/admin/mumbai/uniqueroute/{{ f.id }}">{{ f.route.alias}}</a> - {{ f.from_stop.name }} - {{ f.from_stop_txt }} <br />
{% endfor %}
<h2> Likely mismatched to stops: </h2>
{% for t in fuzzy_tos %}
<a href="/admin/mumbai/uniqueroute/{{ t.id }}">{{ t.route.alias}}</a> - {{ t.to_stop.name }} - {{ t.to_stop_txt }} <br />
{% endfor %}
{% endcomment %}
<!doctype html>
<html>
<head>
<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<style>
.notfirstStop { background-color: #ffdddd }
.notlastStop { background-color: #ffdddd }
</style>
<script type="text/javascript">
$(function() {
$('.submitFuzzyEdit').click(function() {
var that = this;
saveUNR(that, false);
});
$('.markChecked').click(function() {
var that = this;
saveUNR(that, true);
});
$('.fromStopSelect').change(function() {
var firstOpt = $(this).children().first();
firstOpt.attr("selected") ? $(this).removeClass("notfirstStop") : $(this).addClass("notfirstStop");
$(this).parents('tr').find('.submitFuzzyEdit').click();
});
$('.toStopSelect').change(function() {
var lastOpt = $(this).children().last();
lastOpt.attr("selected") ? $(this).removeClass("notlastStop") : $(this).addClass("notlastStop");
$(this).parents('tr').find('.submitFuzzyEdit').click();
});
});
function saveUNR(elem, markChecked) {
var $that = $(elem);
var oldTxt = $that.text();
$that.text("Saving...");
var $tr = $that.parents('tr');
var params = {
'id': $tr.attr("data-id"),
'from_stop': $tr.find('.fromStopSelect').val(),
'to_stop': $tr.find('.toStopSelect').val(),
'mark_checked': markChecked
};
var xhr = $.post("/fuzzystops_edit/", params, function(response) {
if (response != 'ok') {
alert("error saving data");
return;
}
if (markChecked) {
$tr.slideUp();
} else {
$that.text(oldTxt);
}
});
xhr.fail(function() {
alert("error saving data");
});
}
</script>
</head>
<body>
<table id="unrTable">
<thead>
<tr>
<th>Bus No</th>
<th>From Txt</th>
<th>From Stop</th>
<th>To Txt</th>
<th>To Stop</th>
<th></th>
</tr>
</thead>
<tbody>
{% for u in unrs %}
<tr data-id="{{ u.unr.id }}">
<td>{{ u.unr.route.alias }}</td>
<td>{{ u.unr.from_stop_txt }}</td>
<td>
<select class="fromStopSelect {% if not u.stop_is_first %} notfirstStop {% endif %}" >
{% for stop in u.unr.get_stop_choices %}
<option value="{{ stop.id }}" {% ifequal u.unr.from_stop stop %} selected="selected" {% endifequal %}>
{{ stop.display_name }}
</option>
{% endfor %}
</select>
</td>
<td>{{ u.unr.to_stop_txt }}</td>
<td>
<select class="toStopSelect {% if not u.stop_is_last %} notlastStop {% endif %}" >
{% for stop in u.unr.get_stop_choices %}
<option value="{{ stop.id }}" {% ifequal u.unr.to_stop stop %} selected="selected" {% endifequal %}>
{{ stop.display_name }}
</option>
{% endfor %}
</select>
</td>
<td>
<!-- Change all: <input type="checkbox" class="changeAll" /> &nbsp; -->
<button class="submitFuzzyEdit" style="display:none;">Save</button> &nbsp;
<button class="markChecked">Checked</button> &nbsp;
</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>