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 06, 2017 @ 06:29
    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.

    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");
                                });
                            });
                    }
    

    My value object is structured like this:

    [  
       {  
          "alias":"Thumbnail",
          "width":250,
          "height":250,
          "coordinates":{  
             "x1":0.01589769056327682,
             "y1":0,
             "x2":0.7660883937115032,
             "y2":0.5876390687240729
          },
          "$$hashKey":"0DH"
       },
       {  
          "alias":"Banner",
          "width":500,
          "height":200,
          "coordinates":{  
             "x1":0.32455352988325237,
             "y1":0.4889725556868949,
             "x2":0,
             "y2":0
          },
          "$$hashKey":"0DI"
       },
       {  
          "alias":"Main",
          "width":600,
          "height":500,
          "coordinates":{  
             "x1":0,
             "y1":1.51582450295488e-16,
             "x2":0.3655638082376773,
             "y2":0
          },
          "$$hashKey":"0DJ"
       }
    ]
    

    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