Move several /batch functions into api.js.

This commit is contained in:
voussoir 2020-08-30 19:18:06 -07:00
parent e774b5f101
commit 6b037e1120
2 changed files with 90 additions and 41 deletions

View file

@ -165,6 +165,53 @@ function add_tag(photo_id, tagname, callback)
common.post(url, data, callback);
}
api.photos.batch_add_tag =
function batch_add_tag(photo_ids, tagname, callback)
{
var url = "/batch/photos/add_tag";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
data.append("tagname", tagname);
common.post(url, data, add_remove_tag_callback);
}
api.photos.batch_refresh_metadata =
function batch_refresh_metadata(photo_ids, callback)
{
var url = "/batch/photos/refresh_metadata";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
common.post(url, data, callback);
}
api.photos.batch_remove_tag =
function batch_remove_tag(photo_ids, tagname, callback)
{
var url = "/batch/photos/remove_tag";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
data.append("tagname", tagname);
common.post(url, data, add_remove_tag_callback);
}
api.photos.batch_set_searchhidden =
function batch_set_searchhidden(photo_ids, callback)
{
var url = "/batch/photos/set_searchhidden";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
common.post(url, data, callback);
}
api.photos.batch_unset_searchhidden =
function batch_unset_searchhidden(photo_ids, callback)
{
var url = "/batch/photos/unset_searchhidden";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
common.post(url, data, callback);
}
api.photos.delete =
function _delete(photo_id, delete_file, callback)
{
@ -186,6 +233,29 @@ function generate_thumbnail(photo_id, special, callback)
common.post(url, data, callback);
}
api.photos.get_download_zip_token =
function get_download_zip_token(photo_ids, callback)
{
var url = "/batch/photos/download_zip";
var data = new FormData();
data.append("photo_ids", photo_ids.join(","));
common.post(url, data, callback);
}
api.photos.download_zip =
function download_zip(zip_token)
{
var url = `/batch/photos/download_zip/${zip_token}.zip`;
window.location.href = url;
}
api.photos.callback_download_zip =
function callback_download_zip(response)
{
var zip_token = response.data.zip_token;
api.photos.download_zip(zip_token);
}
api.photos.refresh_metadata =
function refresh_metadata(photo_id, callback)
{

View file

@ -223,17 +223,6 @@ photo_clipboard.on_save_hooks.push(my_clipboard_load_save_hook);
////////////////////////////////////////////////////////////////////////////////////////////////////
function add_remove_tag(action, tagname)
{
if (photo_clipboard.clipboard.size == 0)
{return;}
var url = "/batch/photos/" + action + "_tag";
var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
var data = new FormData();
data.append("photo_ids", photo_ids);
data.append("tagname", tagname);
common.post(url, data, add_remove_tag_callback);
}
function add_remove_tag_callback(response)
{
var tagname = response.data.tagname;
@ -258,45 +247,46 @@ function add_remove_tag_callback(response)
}
common.create_message_bubble(message_area, message_positivity, message_text, 8000);
}
function add_tag_form()
{
if (photo_clipboard.clipboard.size == 0)
{return;}
var box = document.getElementById("add_tag_textbox");
var tagname = box.value.trim();
if (! tagname)
{return}
box.value = "";
return add_remove_tag("add", tagname);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_add_tag(photo_ids, tagname, add_remove_tag_callback);
}
function remove_tag_form()
{
if (photo_clipboard.clipboard.size == 0)
{return;}
var box = document.getElementById("remove_tag_textbox");
var tagname = box.value.trim();
if (! tagname)
{return}
box.value = "";
return add_remove_tag("remove", tagname);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_remove_tag(photo_ids, tagname, add_remove_tag_callback);
}
////////////////////////////////////////////////////////////////////////////////
function download_zip_callback(response)
{
var zip_token = response.data.zip_token;
var url = `/batch/photos/download_zip/${zip_token}.zip`;
window.location.href = url;
}
function download_zip_form()
{
if (photo_clipboard.clipboard.size == 0)
{return;}
var url = "/batch/photos/download_zip";
var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
var data = new FormData();
data.append("photo_ids", photo_ids);
common.post(url, data, download_zip_callback);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.get_download_zip_token(photo_ids, api.photos.callback_download_zip);
}
////////////////////////////////////////////////////////////////////////////////
@ -327,11 +317,8 @@ function refresh_metadata_form()
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);
common.post(url, data, refresh_metadata_callback);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_refresh_metadata(photo_ids, refresh_metadata_callback);
}
////////////////////////////////////////////////////////////////////////////////
@ -358,24 +345,16 @@ function set_searchhidden_form()
if (photo_clipboard.clipboard.size == 0)
{return;}
var url = "/batch/photos/set_searchhidden";
var data = new FormData();
var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
data.append("photo_ids", photo_ids);
common.post(url, data, set_unset_searchhidden_callback);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_set_searchhidden(photo_ids, set_unset_searchhidden_callback);
}
function unset_searchhidden_form()
{
if (photo_clipboard.clipboard.size == 0)
{return;}
var url = "/batch/photos/unset_searchhidden";
var data = new FormData();
var photo_ids = Array.from(photo_clipboard.clipboard).join(",");
data.append("photo_ids", photo_ids);
common.post(url, data, set_unset_searchhidden_callback);
var photo_ids = Array.from(photo_clipboard.clipboard);
api.photos.batch_unset_searchhidden(photo_ids, set_unset_searchhidden_callback);
}
</script>
</html>