Update clipboard.html's button function naming scheme like others.

I have finally found a pattern I like which is
function, function_callback, and function_form
for the backend, callback, and button handler respectively.
This commit is contained in:
voussoir 2018-08-14 23:24:12 -07:00
parent bea9f905bd
commit 1fcacb81fc

View file

@ -99,27 +99,27 @@ body
<div id="right"> <div id="right">
<div id="add_tag_area"> <div id="add_tag_area">
<input type="text" id="add_tag_textbox" list="tag_autocomplete_datalist"> <input type="text" id="add_tag_textbox" list="tag_autocomplete_datalist">
<button class="add_tag_button green_button" id="add_tag_button" onclick="submit_add_tag(add_remove_callback);">Add tag</button> <button class="add_tag_button green_button" id="add_tag_button" onclick="add_tag_form();">Add tag</button>
</div> </div>
<div id="remove_tag_area"> <div id="remove_tag_area">
<input type="text" id="remove_tag_textbox" list="tag_autocomplete_datalist"> <input type="text" id="remove_tag_textbox" list="tag_autocomplete_datalist">
<button class="red_button" id="remove_tag_button" onclick="submit_remove_tag(add_remove_callback);">Remove tag</button> <button class="red_button" id="remove_tag_button" onclick="remove_tag_form();">Remove tag</button>
</div> </div>
<div id="refresh_metadata_area"> <div id="refresh_metadata_area">
<button class="green_button" id="refresh_metadata_button" onclick="submit_refresh_metadata(refresh_metadata_callback);">Refresh metadata</button> <button class="green_button" id="refresh_metadata_button" onclick="refresh_metadata_form();">Refresh metadata</button>
</div> </div>
<div id="searchhidden_area"> <div id="searchhidden_area">
<span> <span>
<button class="yellow_button" id="set_searchhidden_button" onclick="submit_set_searchhidden(searchhidden_callback)">Searchhide</button> <button class="yellow_button" id="set_searchhidden_button" onclick="set_searchhidden_form()">Searchhide</button>
<button class="yellow_button" id="unset_searchhidden_button" onclick="submit_unset_searchhidden(searchhidden_callback)">Unhide</button> <button class="yellow_button" id="unset_searchhidden_button" onclick="unset_searchhidden_form()">Unhide</button>
</span> </span>
</div> </div>
<div id="download_zip_area"> <div id="download_zip_area">
<button class="yellow_button" id="download_zip_button" onclick="submit_download_zip(download_zip_callback)">Download .zip</button> <button class="yellow_button" id="download_zip_button" onclick="download_zip_form()">Download .zip</button>
</div> </div>
<div id="message_area"> <div id="message_area">
@ -203,7 +203,7 @@ function request_more_divs()
common.post(url, data, callback); common.post(url, data, callback);
} }
function myhook() function my_clipboard_load_save_hook()
{ {
recalculate_needed(); recalculate_needed();
request_more_divs(); request_more_divs();
@ -211,31 +211,12 @@ function myhook()
} }
tag_autocomplete.init_datalist(); tag_autocomplete.init_datalist();
photo_clipboard.on_load_hooks.push(myhook); photo_clipboard.on_load_hooks.push(my_clipboard_load_save_hook);
photo_clipboard.on_save_hooks.push(myhook); photo_clipboard.on_save_hooks.push(my_clipboard_load_save_hook);
////////////////////////////////////////////////////////////////////////////////////////////////////
function submit_add_tag(callback) function add_remove_tag(action, tagname)
{
var box = document.getElementById("add_tag_textbox");
var tagname = box.value.trim();
if (! tagname)
{return}
box.value = "";
return submit_add_remove_tag("add", tagname, callback);
}
function submit_remove_tag(callback)
{
var box = document.getElementById("remove_tag_textbox");
var tagname = box.value.trim();
if (! tagname)
{return}
box.value = "";
return submit_add_remove_tag("remove", tagname, callback);
}
function submit_add_remove_tag(action, tagname, callback)
{ {
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
@ -244,9 +225,9 @@ function submit_add_remove_tag(action, tagname, callback)
var data = new FormData(); var data = new FormData();
data.append("photo_ids", photo_ids); data.append("photo_ids", photo_ids);
data.append("tagname", tagname); data.append("tagname", tagname);
common.post(url, data, callback); common.post(url, data, add_remove_tag_callback);
} }
function add_remove_callback(response) function add_remove_tag_callback(response)
{ {
response = response["data"]; response = response["data"];
var tagname = response["tagname"]; var tagname = response["tagname"];
@ -271,17 +252,25 @@ function add_remove_callback(response)
} }
common.create_message_bubble(message_area, message_positivity, message_text, 8000); common.create_message_bubble(message_area, message_positivity, message_text, 8000);
} }
function add_tag_form()
function submit_download_zip(callback)
{ {
if (photo_clipboard.clipboard.size == 0) var box = document.getElementById("add_tag_textbox");
{return;} var tagname = box.value.trim();
if (! tagname)
{return}
var url = "/batch/photos/download_zip"; box.value = "";
var photo_ids = Array.from(photo_clipboard.clipboard).join(","); return add_remove_tag("add", tagname);
var data = new FormData(); }
data.append("photo_ids", photo_ids); function remove_tag_form()
common.post(url, data, callback); {
var box = document.getElementById("remove_tag_textbox");
var tagname = box.value.trim();
if (! tagname)
{return}
box.value = "";
return add_remove_tag("remove", tagname);
} }
function download_zip_callback(response) function download_zip_callback(response)
@ -290,23 +279,19 @@ function download_zip_callback(response)
var url = `/batch/photos/download_zip/${zip_token}.zip`; var url = `/batch/photos/download_zip/${zip_token}.zip`;
window.location.href = url; window.location.href = url;
} }
function download_zip_form()
var refresh_in_progress = false;
function submit_refresh_metadata(callback)
{ {
if (refresh_in_progress)
{return;}
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
var url = "/batch/photos/refresh_metadata"; var url = "/batch/photos/download_zip";
var photo_ids = Array.from(photo_clipboard.clipboard).join(","); var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
var data = new FormData(); var data = new FormData();
data.append("photo_ids", photo_ids); data.append("photo_ids", photo_ids);
refresh_in_progress = true; common.post(url, data, download_zip_callback);
common.post(url, data, callback);
} }
var refresh_in_progress = false;
function refresh_metadata_callback(response) function refresh_metadata_callback(response)
{ {
response = response["data"]; response = response["data"];
@ -323,8 +308,23 @@ function refresh_metadata_callback(response)
common.refresh(); common.refresh();
} }
} }
function refresh_metadata_form()
{
if (refresh_in_progress)
{return;}
function searchhidden_callback(response) if (photo_clipboard.clipboard.size == 0)
{return;}
var url = "/batch/photos/refresh_metadata";
var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
var data = new FormData();
data.append("photo_ids", photo_ids);
refresh_in_progress = true;
common.post(url, data, refresh_metadata_callback);
}
function set_unset_searchhidden_callback(response)
{ {
response = response["data"]; response = response["data"];
var message_area = document.getElementById("message_area"); var message_area = document.getElementById("message_area");
@ -342,7 +342,7 @@ function searchhidden_callback(response)
} }
common.create_message_bubble(message_area, message_positivity, message_text, 8000); common.create_message_bubble(message_area, message_positivity, message_text, 8000);
} }
function submit_set_searchhidden(callback) function set_searchhidden_form()
{ {
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
@ -352,9 +352,9 @@ function submit_set_searchhidden(callback)
var photo_ids = Array.from(photo_clipboard.clipboard).join(","); var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
data.append("photo_ids", photo_ids); data.append("photo_ids", photo_ids);
common.post(url, data, callback); common.post(url, data, set_unset_searchhidden_callback);
} }
function submit_unset_searchhidden(callback) function unset_searchhidden_form()
{ {
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{return;} {return;}
@ -364,7 +364,7 @@ function submit_unset_searchhidden(callback)
var photo_ids = Array.from(photo_clipboard.clipboard).join(","); var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
data.append("photo_ids", photo_ids); data.append("photo_ids", photo_ids);
common.post(url, data, callback); common.post(url, data, set_unset_searchhidden_callback);
} }
</script> </script>
</html> </html>