function loadImagesList(data, collectionId) {
  var html = templates.workEditImages(data);
  $('#images').replaceWith(html);
  initialiseImagesList(data, collectionId);
}

function refreshImagesList(data, collectionId) {
  var html = templates.workEditImages(data);
  $('#image-list').replaceWith($(html).find('#image-list'));
  initialiseImagesList(data, collectionId);
}

function initialiseImagesList(data, collectionId) {

  $(data.images).each(function (index, image) {
    var basePath = data.uri;
    var noExtension = image.uri.match(/^(.+?)(\.[^.]*$|$)/);
    var imageJson = noExtension[1] + '.json';

    $("#image-edit_" + index).click(function () {
      getPageResource(collectionId, imageJson,
        onSuccess = function (imageData) {
          loadImageBuilder(data, function () {
            Florence.Editor.isDirty = false;
            //refreshPreview();
            refreshImagesList(data, collectionId);
          }, imageData);
        })
    });

    $("#image-delete_" + index).click(function () {
      var result = confirm("Are you sure you want to delete this image?");
      if (result === true) {
        $("#image_" + index).remove();
        // delete any files associated with the image.

        getPageResource(collectionId, imageJson,
          onSuccess = function (imageData) {
            _.each(imageData.files, function(file) {
              var fileUri = basePath + '/' + file.filename;
              console.log('deleting ' + fileUri);
              deleteContent(collectionId, fileUri,
                onSuccess = function () {
                },
                onError = function (error) {
                  handleApiError(error);
                });
            });
          });

        // delete the image json file
        deleteContent(collectionId, imageJson,
          onSuccess = function () {
            // remove the image from the page json when its deleted
            data.images = _(data.images).filter(function (item) {
              return item.filename !== image.filename;
            });

            // save the updated page json
            postContent(collectionId, basePath, JSON.stringify(data),
              success = function () {
                Florence.Editor.isDirty = false;
                refreshImagesList(data, collectionId);
              },
              error = function (response) {
                handleApiError(response);
              }
            );
          }
        );
      }
    });
  });
}

@@ -1302,32 +1302,68 @@
 n (imageData) %7B%0A
+            if(imageData.files) %7B%0A  
             _.ea
@@ -1390,16 +1390,17 @@
 function
+ 
 (file) %7B
@@ -1396,24 +1396,26 @@
 on (file) %7B%0A
+  
             
@@ -1454,32 +1454,34 @@
  file.filename;%0A
+  
               co
@@ -1520,32 +1520,34 @@
 ;%0A              
+  
 deleteContent(co
@@ -1567,16 +1567,337 @@
 ileUri,%0A
+                  onSuccess = function () %7B%0A                  %7D,%0A                  onError = function (error) %7B%0A                    handleApiError(error);%0A                  %7D);%0A              %7D);%0A            %7D else %7B%0A              console.log('deleting ' + image.uri);%0A              deleteContent(collectionId, image.uri,%0A
         
@@ -2047,32 +2047,32 @@
             %7D);%0A
+
             %7D);%0A
@@ -2060,34 +2060,32 @@
 );%0A            %7D
-);
 %0A          %7D);%0A%0A

Delete image file when deleting whole image.