function afterMkdir(data) {
    if (data['success'].length > 0) {
        for (var i = 0, len = data['success'].length; i < len; i++) {
            var dir_name = data['success'][i]['name'];
            var dir_id = data['success'][i]['id'];
            var field = "<label class='control-label' for='desc-" + dir_id + "'>"
                        + "Enter a description for folder \"<strong>" + dir_name + "</strong>\":"
                        + "<a href='/view/dir/" + dir_id + "'>(View folder)</a></label>"
                        + "<input type='text' class='form-control' id='desc-" + dir_id + "'>";
            $('#descriptions .modal-body .form-group').append(field);
        }
        $('#descriptions input').focusout(function() {
            var this_id = $(this).attr('id').substr($(this).attr('id').indexOf("-") + 1)
            $.ajax({
                type: "POST",
                url: "/api/dir/describe/" + this_id,
                data: {
                    description: $('input[id="desc-' + this_id + '"]').val()
                }
            });
        });
        $('#descriptions').modal('show');
    }
}

// Create a new directory
function createDirectory() {
    $.ajax({
        type: "POST",
        url: "/api/mkdir",
        data: {
            dir_name: $('input[name="gallery_dir_name"]').val(),
            parent_id: $('input[name="gallery_dir_id"]').val()
        },
        success: afterMkdir
    });
}

function afterUpload(file, response) {
    console.log("Uploaded file:");
    console.log(file);
    console.log("Response:");
    console.log(response);
    // TODO pop up a thing to create a directory description for each
    // /api/file/describe/<id>
}

// Rebuild the directory tree
function populateDirTree() {
    $.get("/api/get_dir_tree", function(data) {
        $('#fileList').tree({
            data: [data],
            autoOpen: 0
        });
        $('#fileList').bind(
            'tree.click',
            function(event) {
                // The clicked node is 'event.node'
                var node = event.node;
                $('input[name="gallery_dir_id"]').val(node.id);
            }
        );
    });
}

function editFileDescription() {
    $('#edit-description').modal('show');
    $('#edit-description button').click(function() {
        var this_id = $('#edit-description input').attr('id').substr($('#edit-description input').attr('id').indexOf("-") + 1);
        $.ajax({
            type: "POST",
            url: "/api/file/describe/" + this_id,
            data: {
                caption: $('input[id="desc-' + this_id + '"]').val()
            }
        });
    });
}

@@ -2425,16 +2425,213 @@
 ) + 1);%0A
+            console.log($('#edit-description input').attr('id'));%0A            console.log($('#edit-description input').attr('id').substr($('#edit-description input').attr('id').indexOf(%22-%22) + 1));%0A
         
@@ -2796,32 +2796,164 @@
 d + '%22%5D').val()%0A
+            %7D,%0A            success: function() %7B%0A                console.log(%22Successfully posted description for file%22 + this_id);%0A
             %7D%0A  

Add debug for file description changes