From c462a41d50f748741220adf5b125d26849c9fd4f Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 9 Mar 2020 15:02:41 -0500 Subject: Added the option to change collection names Remooved a couple imports that weren't used --- wqflask/wqflask/collect.py | 14 +++++++++++- wqflask/wqflask/templates/collections/list.html | 1 - wqflask/wqflask/templates/collections/view.html | 30 +++++++++++++++++++++---- wqflask/wqflask/user_session.py | 7 ++++-- 4 files changed, 44 insertions(+), 8 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index e5c24873..2a94e63d 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -225,4 +225,16 @@ def view_collection(): else: return render_template("collections/view.html", **collection_info - ) \ No newline at end of file + ) + +@app.route("/collections/change_name", methods=('POST',)) +def change_collection_name(): + params = request.form + + collection_id = params['collection_id'] + new_name = params['new_name'] + + g.user_session.change_collection_name(collection_id, new_name) + + return new_name + diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index eb3fc061..a2f1a1f7 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -2,7 +2,6 @@ {% block title %}Your Collections{% endblock %} {% block css %} - {% endblock %} diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index fd0025d9..e5188ed8 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -9,8 +9,11 @@
-

-

{{ uc.name }}

+

+ {{ uc.name }} + + +

This collection has {{ '{}'.format(numify(trait_obs|count, "record", "records")) }}

@@ -158,7 +161,6 @@ {% endblock %} {% block js %} - @@ -224,8 +226,28 @@ url = $(this).data("url") return submit_special(url) }); + + $("#change_collection_name").on("click", function() { + if ($('input[name=new_collection_name]').css('display') == 'none') { + $('input[name=new_collection_name]').css('display', 'inline'); + $('#collection_name').css('display', 'none'); + } else { + new_name = $('input[name=new_collection_name]').val() + $.ajax({ + type: "POST", + url: "/collections/change_name", + data: { + collection_id: $('input[name=uc_id]').val(), + new_name: new_name + } + }); + $('input[name=new_collection_name]').css('display', 'none'); + $('input[name=collection_name]').val(new_name); + $('#collection_name').text(new_name) + $('#collection_name').css('display', 'inline'); + } + }); }); - diff --git a/wqflask/wqflask/user_session.py b/wqflask/wqflask/user_session.py index e19ec9df..49ad4f0a 100644 --- a/wqflask/wqflask/user_session.py +++ b/wqflask/wqflask/user_session.py @@ -169,11 +169,14 @@ class UserSession(object): return collection_dict['id'] def change_collection_name(self, collection_id, new_name): + updated_collections = [] for collection in self.user_collections: + updated_collection = collection if collection['id'] == collection_id: - collection['name'] = new_name - break + updated_collection['name'] = new_name + updated_collections.append(collection) + self.update_collections(updated_collections) return new_name def delete_collection(self, collection_id): -- cgit v1.2.3