Skip to content

Commit

Permalink
Editable filter names.
Browse files Browse the repository at this point in the history
Fixes #12 and #49.
  • Loading branch information
ralphbean committed Mar 20, 2015
1 parent 8a7205a commit 55d3ae9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
14 changes: 8 additions & 6 deletions fmn/web/app.py
Expand Up @@ -640,6 +640,7 @@ def handle_filter():
openid = form.openid.data
context = form.context.data
filter_name = form.filter_name.data
filter_id = form.filter_id.data
method = (form.method.data or flask.request.method).upper()

if flask.g.auth.openid != openid and not admin(flask.g.auth.openid):
Expand All @@ -665,13 +666,14 @@ def handle_filter():

try:
if method == 'POST':
# Ensure that a filter with this name doesn't already exist.
if pref.has_filter_name(SESSION, filter_name):
raise APIError(404, dict(
reason="%r already exists" % filter_name))
if pref.has_filter(SESSION, filter_id):
filter = pref.get_filter(SESSION, filter_id)
filter.name = filter_name
SESSION.commit()
else:
filter = fmn.lib.models.Filter.create(SESSION, filter_name)
pref.add_filter(SESSION, filter)

filter = fmn.lib.models.Filter.create(SESSION, filter_name)
pref.add_filter(SESSION, filter)
next_url = flask.url_for(
'filter',
openid=openid,
Expand Down
1 change: 1 addition & 0 deletions fmn/web/forms.py
Expand Up @@ -2,6 +2,7 @@


class FilterForm(Form):
filter_id = IntegerField('filter_id')
openid = TextField('openid', [validators.Required()])
context = TextField('context', [validators.Required()])
filter_name = TextField('filter_name', [validators.Required()])
Expand Down
18 changes: 16 additions & 2 deletions fmn/web/templates/filter.html
Expand Up @@ -2,8 +2,21 @@

{% block body %}
<div class="page-header">
<h1>Rules for {{g.auth.email}}'s <em>{{filter.name}}</em> filter
<small>for the {{current}} messaging context</small></h1>
<h1 id="name-read"> {{filter.name}}
<a href="#" id="edit" class="btn btn-xs btn-default">Edit</a></h1>
<h2 id="name-write" class="hidden">
<form class="form-inline" role="form"
action="{{url_for('handle_filter')}}" method="post">
<input name="openid" id="openid" value="{{openid}}" type="hidden">
<input name="context" id="context" value="{{current}}" type="hidden">
<input name="filter_id" id="filter_id" value="{{filter.id}}" type="hidden">
<input name="filter_name" id="filter_name" value="{{filter.name}}">
<button type="submit" class="btn btn-xs btn-primary" name="method" value="post">
<span class="glyphicon glyphicon-ok-circle"></span>Save</button>
<a href="#" id="cancel" class="btn btn-xs btn-default">Cancel</a>
</form>
</h2>
<h3>sent to {{current}}</h3>
</div>

<div class="row-fluid">
Expand All @@ -13,6 +26,7 @@ <h1>Rules for {{g.auth.email}}'s <em>{{filter.name}}</em> filter
<input name="openid" id="openid" value="{{openid}}" type="hidden">
<input name="context" id="context" value="{{current}}" type="hidden">
<input name="filter_name" id="filter_name" value="{{filter.name}}" type="hidden">
<input name="filter_id" id="filter_id" value="{{filter.id}}" type="hidden">
<div class="btn-group pull-right">
<span>
<a class="btn btn-info" href="{{url_for('context_json', openid=openid, context=current)}}">
Expand Down
13 changes: 13 additions & 0 deletions fmn/web/templates/master.html
Expand Up @@ -138,5 +138,18 @@
<script src="{{ url_for('static', filename='bootstrap/js/bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/site.js')}}"></script>
<script>$('[data-toggle="tooltip"]').tooltip();</script>
<script>
$(document).ready(function() {
$("#edit").click(function(ev) {
$("#name-read").addClass('hidden');
$("#name-write").removeClass('hidden');
});
$("#cancel").click(function(ev) {
$("#name-write").addClass('hidden');
$("#name-read").removeClass('hidden');
});
});
</script>

</body>
</html>

0 comments on commit 55d3ae9

Please sign in to comment.