Add namespacing to albums.js.

This commit is contained in:
voussoir 2018-07-22 20:08:12 -07:00
parent 1bff642ca7
commit c840845c7d
3 changed files with 37 additions and 31 deletions

View file

@ -1,37 +1,31 @@
var create_child_prompt_button; var albums = {};
var create_child_title_entry;
var create_child_submit_button;
var create_child_cancel_button;
function on_pageload()
{
create_child_prompt_button = document.getElementById("create_child_prompt_button");
create_child_title_entry = document.getElementById("create_child_title_entry");
create_child_submit_button = document.getElementById("create_child_submit_button");
create_child_cancel_button = document.getElementById("create_child_cancel_button");
common.bind_box_to_button(create_child_title_entry, create_child_submit_button);
}
document.addEventListener("DOMContentLoaded", on_pageload);
albums.create_child_prompt_button = null;
albums.create_child_title_entry = null;
albums.create_child_submit_button = null;
albums.create_child_cancel_button = null;
albums.open_creator_prompt =
function open_creator_prompt(event) function open_creator_prompt(event)
{ {
create_child_prompt_button.classList.add("hidden"); albums.create_child_prompt_button.classList.add("hidden");
create_child_title_entry.classList.remove("hidden"); albums.create_child_title_entry.classList.remove("hidden");
create_child_title_entry.focus(); albums.create_child_title_entry.focus();
create_child_submit_button.classList.remove("hidden"); albums.create_child_submit_button.classList.remove("hidden");
create_child_cancel_button.classList.remove("hidden"); albums.create_child_cancel_button.classList.remove("hidden");
} }
albums.cancel_create_child =
function cancel_create_child(event) function cancel_create_child(event)
{ {
create_child_prompt_button.classList.remove("hidden"); albums.create_child_prompt_button.classList.remove("hidden");
create_child_title_entry.value = ""; albums.create_child_title_entry.value = "";
create_child_title_entry.classList.add("hidden"); albums.create_child_title_entry.classList.add("hidden");
create_child_submit_button.classList.add("hidden"); albums.create_child_submit_button.classList.add("hidden");
create_child_cancel_button.classList.add("hidden"); albums.create_child_cancel_button.classList.add("hidden");
} }
albums.create_album_and_follow =
function create_album_and_follow(title, parent) function create_album_and_follow(title, parent)
{ {
var url = "/albums/create_album"; var url = "/albums/create_album";
@ -58,6 +52,7 @@ function create_album_and_follow(title, parent)
common.post(url, data, receive_callback); common.post(url, data, receive_callback);
} }
albums.submit_create_child =
function submit_create_child(event) function submit_create_child(event)
{ {
var title = document.getElementById("create_child_title_entry").value; var title = document.getElementById("create_child_title_entry").value;
@ -66,5 +61,16 @@ function submit_create_child(event)
title = undefined; title = undefined;
} }
var parent_id = ALBUM_ID; var parent_id = ALBUM_ID;
create_album_and_follow(title, parent_id); albums.create_album_and_follow(title, parent_id);
} }
albums.on_pageload =
function on_pageload()
{
albums.create_child_prompt_button = document.getElementById("create_child_prompt_button");
albums.create_child_title_entry = document.getElementById("create_child_title_entry");
albums.create_child_submit_button = document.getElementById("create_child_submit_button");
albums.create_child_cancel_button = document.getElementById("create_child_cancel_button");
common.bind_box_to_button(albums.create_child_title_entry, albums.create_child_submit_button);
}
document.addEventListener("DOMContentLoaded", albums.on_pageload);

View file

@ -80,10 +80,10 @@ p
<li><a href="/album/{{sub_album.id}}{{viewparam}}">{{sub_album.display_name}}</a></li> <li><a href="/album/{{sub_album.id}}{{viewparam}}">{{sub_album.display_name}}</a></li>
{% endfor %} {% endfor %}
<li> <li>
<button id="create_child_prompt_button" class="green_button" onclick="open_creator_prompt(event);">Create child</button> <button id="create_child_prompt_button" class="green_button" onclick="albums.open_creator_prompt(event);">Create child</button>
<input type="text" id="create_child_title_entry" class="hidden" placeholder="Album title"> <input type="text" id="create_child_title_entry" class="hidden" placeholder="Album title">
<button id="create_child_submit_button" class="green_button hidden" onclick="submit_create_child(event);">Create</button> <button id="create_child_submit_button" class="green_button hidden" onclick="albums.submit_create_child(event);">Create</button>
<button id="create_child_cancel_button" class="red_button hidden" onclick="cancel_create_child(event);">Cancel</button> <button id="create_child_cancel_button" class="red_button hidden" onclick="albums.cancel_create_child(event);">Cancel</button>
</li> </li>
</ul> </ul>
</ul> </ul>

View file

@ -27,10 +27,10 @@
<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> <li>
<button id="create_child_prompt_button" class="green_button" onclick="open_creator_prompt(event);">Create album</button> <button id="create_child_prompt_button" class="green_button" onclick="albums.open_creator_prompt(event);">Create album</button>
<input type="text" id="create_child_title_entry" class="hidden" placeholder="Album title"> <input type="text" id="create_child_title_entry" class="hidden" placeholder="Album title">
<button id="create_child_submit_button" class="green_button hidden" onclick="submit_create_child(event);">Create</button> <button id="create_child_submit_button" class="green_button hidden" onclick="albums.submit_create_child(event);">Create</button>
<button id="create_child_cancel_button" class="red_button hidden" onclick="cancel_create_child(event);">Cancel</button> <button id="create_child_cancel_button" class="red_button hidden" onclick="albums.cancel_create_child(event);">Cancel</button>
</li> </li>
</ul> </ul>
</div> </div>