Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Oct 08, 2015 @ 13:18
    Saied
    0

    Make multi media picker directive handle multiple images?

    I was following the post by Tim here: http://www.nibble.be/?p=440

    I got the code working to handle one image in the media picker, but I want the user to be able to pick multiple images. On save, I then basically want to save the image id's in an external table. I set the multi flag to true, but the directive is setup for single image only. How can I modify it to handle multiple images? Here is the directive:

    angular.module("umbraco.directives")
    .directive('umbMediaPicker', function (dialogService, entityResource) {
        return {
            restrict: 'E',
            replace: true,
            templateUrl: '/App_Plugins/Products/umb-media-picker.html',
            require: "ngModel",
            link: function (scope, element, attr, ctrl) {
    
                ctrl.$render = function () {
                    var val = parseInt(ctrl.$viewValue);
                    if (!isNaN(val) && angular.isNumber(val) && val > 0) {
    
                        entityResource.getById(val, "Media").then(function (item) {
                            scope.node = item;
                        });
                    }
                };
    
                scope.openMediaPicker = function () {
                    dialogService.mediaPicker({
                        multiPicker: true,
                        callback: populatePicture
                    });
                }
    
                scope.removePicture = function () {
                    scope.node = undefined;
                    updateModel(0);
                }
    
                function populatePicture(item) {
    
                    scope.node = item;
                    updateModel(item.id);
                }
    
                function updateModel(id) {
                    ctrl.$setViewValue(id);
    
                }
            }
        };
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft