diff --git a/frontends/etiquette_flask/etiquette_flask/common.py b/frontends/etiquette_flask/etiquette_flask/common.py index dcd4c7b..c2fb320 100644 --- a/frontends/etiquette_flask/etiquette_flask/common.py +++ b/frontends/etiquette_flask/etiquette_flask/common.py @@ -80,8 +80,8 @@ def P_album(album_id): return P.get_album(album_id) @P_wrapper -def P_bookmark(bookmarkid): - return P.get_bookmark(bookmarkid) +def P_bookmark(bookmark_id): + return P.get_bookmark(bookmark_id) @P_wrapper def P_photo(photo_id): diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/bookmark_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/bookmark_endpoints.py index 4ec40c7..cff725a 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/bookmark_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/bookmark_endpoints.py @@ -12,20 +12,30 @@ session_manager = common.session_manager # Individual bookmarks ############################################################################# -@site.route('/bookmark/.json') +@site.route('/bookmarks/create_bookmark', methods=['POST']) +@decorators.catch_etiquette_exception +@decorators.required_fields(['url'], forbid_whitespace=True) +def post_bookmark_create(): + url = request.form['url'] + title = request.form.get('title', None) + user = session_manager.get(request).user + bookmark = common.P.new_bookmark(url=url, title=title, author=user) + response = etiquette.jsonify.bookmark(bookmark) + response = jsonify.make_json_response(response) + return response + +@site.route('/bookmark/.json') @session_manager.give_token -def get_bookmark_json(bookmarkid): - bookmark = common.P_bookmark(bookmarkid) +def get_bookmark_json(bookmark_id): + bookmark = common.P_bookmark(bookmark_id, response_type='json') response = etiquette.jsonify.bookmark(bookmark) return jsonify.make_json_response(response) -# Bookmark metadata operations ##################################################################### - -@site.route('/bookmark//edit', methods=['POST']) +@site.route('/bookmark//edit', methods=['POST']) @session_manager.give_token @decorators.catch_etiquette_exception -def post_bookmark_edit(bookmarkid): - bookmark = common.P_bookmark(bookmarkid) +def post_bookmark_edit(bookmark_id): + bookmark = common.P_bookmark(bookmark_id, response_type='json') # Emptystring is okay for titles, but not for URL. title = request.form.get('title', None) url = request.form.get('url', None) or None @@ -35,6 +45,14 @@ def post_bookmark_edit(bookmarkid): response = jsonify.make_json_response(response) return response +@site.route('/bookmark//delete', methods=['POST']) +@decorators.catch_etiquette_exception +def post_bookmark_delete(bookmark_id): + bookmark = common.P_bookmark(bookmark_id, response_type='json') + bookmark.delete() + return jsonify.make_json_response({}) + + # Bookmark listings ################################################################################ @site.route('/bookmarks') @@ -49,24 +67,3 @@ def get_bookmarks_html(): def get_bookmarks_json(): bookmarks = [etiquette.jsonify.bookmark(b) for b in common.P.get_bookmarks()] return jsonify.make_json_response(bookmarks) - -# Bookmark create and delete ####################################################################### - -@site.route('/bookmarks/create_bookmark', methods=['POST']) -@decorators.catch_etiquette_exception -@decorators.required_fields(['url'], forbid_whitespace=True) -def post_bookmarks_create(): - url = request.form['url'] - title = request.form.get('title', None) - user = session_manager.get(request).user - bookmark = common.P.new_bookmark(url=url, title=title, author=user) - response = etiquette.jsonify.bookmark(bookmark) - response = jsonify.make_json_response(response) - return response - -@site.route('/bookmark//delete', methods=['POST']) -@decorators.catch_etiquette_exception -def post_bookmark_delete(bookmark_id): - bookmark = common.P_bookmark(bookmark_id, response_type='json') - bookmark.delete() - return jsonify.make_json_response({}) diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py index 9cdf245..694ce79 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py @@ -31,8 +31,6 @@ def get_tag_id_redirect(tag_id): url = request.url.replace(url_from, url_to) return flask.redirect(url) -# Tag metadata operations ########################################################################## - @site.route('/tag//edit', methods=['POST']) @decorators.catch_etiquette_exception def post_tag_edit(specific_tag): @@ -119,9 +117,6 @@ def get_tags_json(specific_tag_name=None): @session_manager.give_token @decorators.required_fields(['tagname'], forbid_whitespace=True) def post_tag_create(): - ''' - Create a tag. - ''' easybake_string = request.form['tagname'] user = session_manager.get(request).user notes = common.P.easybake(easybake_string, author=user) @@ -133,9 +128,6 @@ def post_tag_create(): @session_manager.give_token @decorators.required_fields(['tagname'], forbid_whitespace=True) def post_tag_delete_synonym(): - ''' - Delete a synonym. - ''' synonym = request.form['tagname'] synonym = synonym.split('+')[-1].split('.')[-1] @@ -154,9 +146,6 @@ def post_tag_delete_synonym(): @session_manager.give_token @decorators.required_fields(['tagname'], forbid_whitespace=True) def post_tag_delete(): - ''' - Delete a tag. - ''' tagname = request.form['tagname'] tagname = tagname.split('+')[0] if '.' in tagname: diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/user_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/user_endpoints.py index c854e6e..17d432e 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/user_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/user_endpoints.py @@ -123,4 +123,3 @@ def post_register(): session = sessions.Session(request, user) session_manager.add(session) return jsonify.make_json_response({}) - diff --git a/frontends/etiquette_flask/static/js/common.js b/frontends/etiquette_flask/static/js/common.js index ac6649f..c35c33e 100644 --- a/frontends/etiquette_flask/static/js/common.js +++ b/frontends/etiquette_flask/static/js/common.js @@ -2,22 +2,6 @@ var common = {}; common.INPUT_TYPES = new Set(["INPUT", "TEXTAREA"]); -common.create_message_bubble = -function create_message_bubble(message_area, message_positivity, message_text, lifespan) -{ - if (lifespan === undefined) - { - lifespan = 8000; - } - var message = document.createElement("div"); - message.className = "message_bubble " + message_positivity; - var span = document.createElement("span"); - span.innerHTML = message_text; - message.appendChild(span); - message_area.appendChild(message); - setTimeout(function(){message_area.removeChild(message);}, lifespan); -} - common._request = function _request(method, url, callback) { @@ -58,15 +42,6 @@ function post(url, data, callback) request.send(data); } -common.delete_all_children = -function delete_all_children(element) -{ - while (element.firstChild) - { - element.removeChild(element.firstChild); - } -} - common.bind_box_to_button = function bind_box_to_button(box, button, ctrl_enter) { @@ -87,6 +62,31 @@ function bind_box_to_button(box, button, ctrl_enter) box.addEventListener("keyup", bound_box_hook); } +common.create_message_bubble = +function create_message_bubble(message_area, message_positivity, message_text, lifespan) +{ + if (lifespan === undefined) + { + lifespan = 8000; + } + var message = document.createElement("div"); + message.className = "message_bubble " + message_positivity; + var span = document.createElement("span"); + span.innerHTML = message_text; + message.appendChild(span); + message_area.appendChild(message); + setTimeout(function(){message_area.removeChild(message);}, lifespan); +} + +common.delete_all_children = +function delete_all_children(element) +{ + while (element.firstChild) + { + element.removeChild(element.firstChild); + } +} + common.entry_with_history_hook = function entry_with_history_hook(event) { @@ -134,19 +134,6 @@ function html_to_element(html) return template.content.firstChild; } -common.normalize_tagname = -function normalize_tagname(tagname) -{ - tagname = tagname.trim(); - tagname = tagname.toLocaleLowerCase(); - tagname = tagname.split("."); - tagname = tagname[tagname.length-1]; - tagname = tagname.split("+")[0]; - tagname = tagname.replace(new RegExp(" ", 'g'), "_"); - tagname = tagname.replace(new RegExp("-", 'g'), "_"); - return tagname; -} - common.init_button_with_confirm = function init_button_with_confirm() { @@ -231,6 +218,25 @@ function init_button_with_confirm() } } +common.normalize_tagname = +function normalize_tagname(tagname) +{ + tagname = tagname.trim(); + tagname = tagname.toLocaleLowerCase(); + tagname = tagname.split("."); + tagname = tagname[tagname.length-1]; + tagname = tagname.split("+")[0]; + tagname = tagname.replace(new RegExp(" ", 'g'), "_"); + tagname = tagname.replace(new RegExp("-", 'g'), "_"); + return tagname; +} + +common.refresh = +function refresh() +{ + window.location.reload(); +} + common.on_pageload = function on_pageload() { diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 2af4446..536658f 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -150,7 +150,7 @@ function _paste_unpaste_photo_clipboard(add_or_remove) { return; } - location.reload(); + common.refresh(); }; common.post(url, data, callback); } @@ -162,6 +162,7 @@ function unpaste_photo_clipboard() { _paste_unpaste_photo_clipboard("remove_photo"); } + var paste_photo_clipboard_button = document.createElement("button"); paste_photo_clipboard_button.classList.add("green_button"); paste_photo_clipboard_button.innerText = "Add to this album"; diff --git a/frontends/etiquette_flask/templates/bookmarks.html b/frontends/etiquette_flask/templates/bookmarks.html index c3b36b0..6c956a7 100644 --- a/frontends/etiquette_flask/templates/bookmarks.html +++ b/frontends/etiquette_flask/templates/bookmarks.html @@ -86,7 +86,7 @@
- +
@@ -94,7 +94,19 @@