Move specific functions out of common.js
This commit is contained in:
parent
69443d7a8c
commit
36acf79bbe
3 changed files with 73 additions and 72 deletions
|
@ -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)
|
if (lifespan === undefined)
|
||||||
{
|
{
|
||||||
|
@ -20,43 +20,6 @@ function add_album_tag(albumid, tagname, callback)
|
||||||
data.append("add_tag", tagname);
|
data.append("add_tag", tagname);
|
||||||
return post(url, data, callback);
|
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)
|
function post(url, data, callback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,6 +166,51 @@ var add_tag_button = document.getElementById('add_tag_button');
|
||||||
var message_area = document.getElementById('message_area');
|
var message_area = document.getElementById('message_area');
|
||||||
add_tag_box.onkeydown = function(){entry_with_history_hook(add_tag_box, add_tag_button)};
|
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()
|
function enable_hoverzoom()
|
||||||
{
|
{
|
||||||
console.log("enable");
|
console.log("enable");
|
||||||
|
@ -254,33 +299,5 @@ function move_hoverzoom(event)
|
||||||
//console.log(x);
|
//console.log(x);
|
||||||
photo_img_holder.style.backgroundPosition=(-x)+"px "+(-y)+"px";
|
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 = "";
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -93,6 +93,32 @@ var button = document.getElementById('add_tag_button');
|
||||||
var message_area = document.getElementById('message_area');
|
var message_area = document.getElementById('message_area');
|
||||||
box.onkeydown = function(){entry_with_history_hook(box, button)};
|
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)
|
function receive_callback(responses)
|
||||||
{
|
{
|
||||||
if (!(responses instanceof Array))
|
if (!(responses instanceof Array))
|
||||||
|
@ -134,13 +160,8 @@ function receive_callback(responses)
|
||||||
{message_text = "Deleted synonym " + response["synonym"];}
|
{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 = "";
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue