<%doc>
USAGE DOCUMENTATION :: PLEASE LEAVE THIS AT THE TOP OF THIS FILE

For Mako templating syntax documentation please visit: http://docs.makotemplates.org/en/latest/

Filename:           edit_library.html
Version:            0.1
Variable names:     data [list]

data :: Usable parameters

== Global keys ==
section_id          Returns the library id of the library.
section_name        Returns the name of the library.
section_type        Returns the type of the library.
library_thumb       Returns the thumbnail for the library.
custom_thumb        Returns the custom thumbnail for the library.
library_art         Returns the artwork for the library.
count               Returns the item count for the library.
parent_count        Returns the parent item count for the library.
child_count         Returns the child item count for the library.
do_notify           Returns bool value for whether to send notifications for the library.
keep_history        Returns bool value for whether to keep history for the library.
deleted_section     Returns bool value for whether the library is marked as deleted.

DOCUMENTATION :: END
</%doc>

<%!
    from plexpy import helpers
%>

% if data != None:
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
            <h4 class="modal-title">Edit library <strong>${data['section_name']}</strong></h4>
        </div>
        <div class="modal-body" id="modal-text">
            <fieldset>
                <div class="form-group">
                    <label for="profile_url">Library Thumbnail URL</label>
                    <div class="row">
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="custom_thumb_url" name="custom_thumb_url" value="${data['library_thumb']}">
                        </div>
                    </div>
                    <p class="help-block">Change the library's thumbnail in Tautulli. To reset to default, leave this field empty and save.</p>
                </div>
                <div class="form-group">
                    <label for="profile_url">Library Background Art URL</label>
                    <div class="row">
                        <div class="col-md-8">
                            <input type="text" class="form-control" id="custom_art_url" name="custom_art_url" value="${data['library_art']}">
                        </div>
                    </div>
                    <p class="help-block">Change the library's background art in Tautulli. To reset to default, leave this field empty and save.</p>
                </div>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" id="keep_history" name="keep_history" value="1" ${helpers.checked(data['keep_history'])}> Keep history
                    </label>
                    <p class="help-block">Uncheck this if you do not want to keep any history on this library's activity.</p>
                </div>
                % if data['section_id']:
                <div class="form-group">
                    <button class="btn btn-danger" id="delete-all-history">Purge</button>
                    <p class="help-block">DANGER ZONE! Click the purge button to remove all history logged for this library. This is permanent!</p>
                </div>
                % endif
                % if data['deleted_section']:
                <div class="form-group">
                    <button class="btn btn-bright" id="undelete-library">Undelete</button>
                    <p class="help-block">Click to re-add the library to the Tautulli libraries list.</p>
                </div>
                % endif
            </fieldset>
        </div>
        <div class="modal-footer">
            <div>
                <span id="edit-library-status-message"></span>
                <input type="button" id="save_library" class="btn btn-bright" value="Save">
            </div>
        </div>
    </div>
</div>
<script>
    // Save library options
    $("#save_library").on('click', function () {
        var custom_thumb = $("#custom_thumb_url").val();
        var custom_art = $("#custom_art_url").val();
        var keep_history = 0;
        if ($("#keep_history").is(":checked")) {
            keep_history = 1;
        }

        $.ajax({
            url: 'edit_library',
            data: {
                section_id: '${data["section_id"]}',
                custom_thumb: custom_thumb,
                custom_art: custom_art,
                keep_history: keep_history
            },
            cache: false,
            async: true,
            success: function (data) {
                location.reload();
            }
        });
    });

    $('#delete-all-history').click(function () {
        var msg = 'Are you REALLY sure you want to purge all history for the <strong>${data["section_name"]}</strong> library?<br>' + 
            'This is permanent and cannot be undone!';
        var url = 'delete_all_library_history';
        confirmAjaxCall(url, msg, { server_id: '${server_id}', section_id: '${data["section_id"]}' }, null, function () { location.reload(); });
    });

    $('#undelete-library').click(function () {
        var msg = 'Are you sure you want to undelete this library?';
        var url = 'undelete_library';
        confirmAjaxCall(url, msg, { section_id: '${data["section_id"]}' }, null, function () { location.reload(); });
    });
</script>
% endif