Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ThomasBrunbjerg 90 posts 182 karma points
    Oct 09, 2017 @ 07:39
    ThomasBrunbjerg
    0

    Saving changes made to media item with image cropper

    I've implemented a custom controller for an image cropper that opens an overlay on a media item in the content section. Right now I can have the overlay display and fiddle around with the crops jut fine, but when I select "Save Crops", the changes are not persisted. If I use the image cropper in the media section, the change is being made correctly.

    I looked through the belle docs for the save function of the media resource, but it doesn't seem to work for me.

    The docs says to first get the id, and then save in the callback:

    mediaResource.getById(1234)
       .then(function(media) {
             media.name = "I want a new name!";
             mediaResource.save(media, false)
               .then(function(media){
                   alert("Retrieved, updated and saved again");
               });
       });
    

    In my overlay object I have this submit function:

    submit: function (model) { //when user clicks save crops button
                        $scope.overlay.saving = true;
                        mediaResource.getById($scope.images[0].udi)
                            .then(function (media) {
                                media.umbracoFile = $scope.overlay.value;
                                mediaResource.save(media, false, []).then(function (media) { //save changes to media item, or craete if new
    
                                    console.log("On saving start end:", $scope);
                                    $scope.overlay.saving = false;
                                    $scope.overlay.show = false;
                                    notificationsService.remove(0);
                                    notificationsService.success("The crops for '" + media.name + "' have been saved");
                                });
                            });
                    }
    

    I get no error response when I hit "Save Crops", which calls the submit function, but the changes are not being saved. I'm unsure which actions I need to perform on the media object to correctly save my changes.

Please Sign in or register to post replies

Write your reply to:

Draft