From 36acf79bbe81a75debddcc304b67c26615181e2e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 20 Dec 2016 21:53:59 -0800 Subject: [PATCH] Move specific functions out of common.js --- static/common.js | 39 +---------------------- templates/photo.html | 73 +++++++++++++++++++++++++++----------------- templates/tags.html | 33 ++++++++++++++++---- 3 files changed, 73 insertions(+), 72 deletions(-) diff --git a/static/common.js b/static/common.js index 436bcfa..0c63338 100644 --- a/static/common.js +++ b/static/common.js @@ -1,4 +1,4 @@ -function create_message_bubble(message_positivity, message_text, lifespan) +function create_message_bubble(message_area, message_positivity, message_text, lifespan) { if (lifespan === undefined) { @@ -20,43 +20,6 @@ function add_album_tag(albumid, tagname, callback) data.append("add_tag", tagname); return post(url, data, callback); } -function add_photo_tag(photoid, tagname, callback) -{ - if (tagname === ""){return} - var url = "/photo/" + photoid; - data = new FormData(); - data.append("add_tag", tagname); - return post(url, data, callback); -} -function remove_photo_tag(photoid, tagname, callback) -{ - if (tagname === ""){return} - var url = "/photo/" + photoid; - data = new FormData(); - data.append("remove_tag", tagname); - return post(url, data, callback); -} - -function edit_tags(action, name, callback) -{ - if (name === ""){return} - var url = "/tags"; - data = new FormData(); - data.append(action, name); - return post(url, data, callback); -} -function delete_tag_synonym(name, callback) -{ - return edit_tags("delete_tag_synonym", name, callback); -} -function delete_tag(name, callback) -{ - return edit_tags("delete_tag", name, callback); -} -function create_tag(name, callback) -{ - return edit_tags("create_tag", name, callback); -} function post(url, data, callback) { diff --git a/templates/photo.html b/templates/photo.html index 64e6ac6..34a80f6 100644 --- a/templates/photo.html +++ b/templates/photo.html @@ -166,6 +166,51 @@ var add_tag_button = document.getElementById('add_tag_button'); var message_area = document.getElementById('message_area'); add_tag_box.onkeydown = function(){entry_with_history_hook(add_tag_box, add_tag_button)}; +function add_photo_tag(photoid, tagname, callback) +{ + if (tagname === ""){return} + var url = "/photo/" + photoid; + data = new FormData(); + data.append("add_tag", tagname); + return post(url, data, callback); +} +function remove_photo_tag(photoid, tagname, callback) +{ + if (tagname === ""){return} + var url = "/photo/" + photoid; + data = new FormData(); + data.append("remove_tag", tagname); + return post(url, data, callback); +} +function submit_tag(callback) +{ + add_photo_tag('{{photo.id}}', add_tag_box.value, callback); + add_tag_box.value = ""; +} +function receive_callback(response) +{ + var tagname = response["tagname"]; + if ("error" in response) + { + message_positivity = "callback_message_negative"; + message_text = '"' + tagname + '" ' + response["error"]; + } + else if ("action" in response) + { + var action = response["action"]; + message_positivity = "callback_message_positive"; + if (action == "add_tag") + { + message_text = "Added tag " + tagname; + } + else if (action == "remove_tag") + { + message_text = "Removed tag " + tagname; + } + } + create_message_bubble(message_area, message_positivity, message_text, 8000); +} + function enable_hoverzoom() { console.log("enable"); @@ -254,33 +299,5 @@ function move_hoverzoom(event) //console.log(x); photo_img_holder.style.backgroundPosition=(-x)+"px "+(-y)+"px"; } -function receive_callback(response) -{ - var tagname = response["tagname"]; - if ("error" in response) - { - message_positivity = "callback_message_negative"; - message_text = '"' + tagname + '" ' + response["error"]; - } - else if ("action" in response) - { - var action = response["action"]; - message_positivity = "callback_message_positive"; - if (action == "add_tag") - { - message_text = "Added tag " + tagname; - } - else if (action == "remove_tag") - { - message_text = "Removed tag " + tagname; - } - } - create_message_bubble(message_positivity, message_text, 8000); -} -function submit_tag(callback) -{ - add_photo_tag('{{photo.id}}', add_tag_box.value, callback); - add_tag_box.value = ""; -} diff --git a/templates/tags.html b/templates/tags.html index 2ae7b32..f029a40 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -93,6 +93,32 @@ var button = document.getElementById('add_tag_button'); var message_area = document.getElementById('message_area'); box.onkeydown = function(){entry_with_history_hook(box, button)}; +function submit_tag(callback) +{ + create_tag(box.value, callback); + box.value = ""; +} +function edit_tags(action, tagname, callback) +{ + if (tagname === ""){return} + var url = "/tags"; + data = new FormData(); + data.append(action, tagname); + return post(url, data, callback); +} +function delete_tag_synonym(tagname, callback) +{ + return edit_tags("delete_tag_synonym", tagname, callback); +} +function delete_tag(tagname, callback) +{ + return edit_tags("delete_tag", tagname, callback); +} +function create_tag(tagname, callback) +{ + return edit_tags("create_tag", tagname, callback); +} + function receive_callback(responses) { if (!(responses instanceof Array)) @@ -134,13 +160,8 @@ function receive_callback(responses) {message_text = "Deleted synonym " + response["synonym"];} } - create_message_bubble(message_positivity, message_text, 8000); + create_message_bubble(message_area, message_positivity, message_text, 8000); } } -function submit_tag(callback) -{ - create_tag(box.value, callback); - box.value = ""; -}