Add 'Create Album' endpoint and interface.

This commit is contained in:
voussoir 2017-05-13 16:13:26 -07:00
parent 956c55ac9a
commit 1ad83937b4
4 changed files with 36 additions and 10 deletions

View file

@ -684,7 +684,6 @@ def post_album_add_tag(albumid):
response['tagname'] = tag.name response['tagname'] = tag.name
return jsonify.make_json_response(response) return jsonify.make_json_response(response)
@site.route('/album/<albumid>/edit', methods=['POST']) @site.route('/album/<albumid>/edit', methods=['POST'])
@session_manager.give_token @session_manager.give_token
def post_album_edit(albumid): def post_album_edit(albumid):
@ -696,7 +695,22 @@ def post_album_edit(albumid):
title = request.form.get('title', None) title = request.form.get('title', None)
description = request.form.get('description', None) description = request.form.get('description', None)
album.edit(title=title, description=description) album.edit(title=title, description=description)
response = {'title': album.title, 'description': album.description} response = etiquette.jsonify.album(album, minimal=True)
return jsonify.make_json_response(response)
@site.route('/albums/create_album', methods=['POST'])
def post_albums_create():
print(dict(request.form))
title = request.form.get('title', None)
description = request.form.get('description', None)
parent = request.form.get('parent', None)
if parent is not None:
parent = P_album(parent)
album = P.new_album(title=title, description=description)
if parent is not None:
parent.add(album)
response = etiquette.jsonify.album(album, minimal=False)
return jsonify.make_json_response(response) return jsonify.make_json_response(response)

View file

@ -49,8 +49,23 @@ function bind_box_to_button(box, button, ctrl_enter)
button.click(); button.click();
} }
}; };
} }
function create_album_and_follow(parent)
{
var url = "/albums/create_album";
var data = new FormData();
if (parent !== undefined)
{
data.append("parent", parent);
}
function receive_callback(response)
{
window.location.href = "/album/" + response["id"];
}
post(url, data, receive_callback);
}
function entry_with_history_hook(box, button) function entry_with_history_hook(box, button)
{ {
//console.log(event.keyCode); //console.log(event.keyCode);

View file

@ -74,20 +74,15 @@ p
{% endif %} {% endif %}
{% set sub_albums = album.children() %} {% set sub_albums = album.children() %}
{% if sub_albums %}
<h3>Sub-albums</h3> <h3>Sub-albums</h3>
<ul> <ul>
{% for sub_album in sub_albums|sort(attribute='title') %} {% for sub_album in sub_albums|sort(attribute='title') %}
<li><a href="/album/{{sub_album.id}}{{viewparam}}">{{sub_album.display_name}}</a> <li><a href="/album/{{sub_album.id}}{{viewparam}}">{{sub_album.display_name}}</a></li>
</li>
{% endfor %} {% endfor %}
<li><button class="green_button" onclick="var parent='{{album.id}}'; create_album_and_follow(parent);">Create child</button></li>
</ul> </ul>
{% endif %}
{% set photos = album.photos() %} {% set photos = album.photos() %}
{% if photos or sub_albums %}
{% endif %}
{% if photos %} {% if photos %}
<h3>Photos</h3> <h3>Photos</h3>
{% if view != "list" %} {% if view != "list" %}

View file

@ -5,6 +5,7 @@
<title>Albums</title> <title>Albums</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="/static/common.css"> <link rel="stylesheet" href="/static/common.css">
<script src="/static/common.js"></script>
<style> <style>
#content_body #content_body
@ -23,6 +24,7 @@
{% for album in albums %} {% for album in albums %}
<li><a href="/album/{{album.id}}">{{album.display_name}}</a></li> <li><a href="/album/{{album.id}}">{{album.display_name}}</a></li>
{% endfor %} {% endfor %}
<li><button class="green_button" onclick="create_album_and_follow();">Create album</button></li>
</ul> </ul>
</div> </div>
</body> </body>