Email Link - Delete Check in Style

The CM Rambler showed how to improve the Email Link Admin console, this post shows how you might add a facility to delete a user's Check in Style from within the admin console.  My main motivation for this is that there is a version of Content Manager out there which makes it difficult for a user to delete a user's check in style from the client, which is a problem when, for example, a user leaves the organisation.

 

The code

As per the video above

An empty TH

<th></th>

A table cell containing a button

<td><button class="btn btn-small" data-place-uri="@record.Uri">Delete</button></td> 

The script

$("button[data-place-uri!=''][data-place-uri]").on("click", function (event) {
    var placeUri = $(this).attr('data-place-uri');

    $.ajax({
        url: "CheckinPlace?q=Uri:" + placeUri + "&resultsOnly=true",
        data: {
            properties: "CheckinPlaceCheckinAs"
        },
        dataType: 'json'
    })
    .done(function (data) {

        for (var n = 0; n < data.Results.length; n++) {
            var place = data.Results[n];

            if (place.CheckinPlaceCheckinAs) {
                $.ajax({
                    url: "CheckinStyle/" + place.CheckinPlaceCheckinAs.Uri + "/Delete",
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json'
                })
                .done(function (response, statusText) {
                    if (statusText === "success") {
                        window.location.reload();
                    }
                })
            }
        }

    });

});