update media items in media picker if they are changed in the infinite media editor
This commit is contained in:
@@ -311,28 +311,9 @@ angular.module("umbraco")
|
||||
entityResource.getPagedDescendants($scope.startNodeId, "Media", $scope.searchOptions)
|
||||
.then(function(data) {
|
||||
// update image data to work with image grid
|
||||
angular.forEach(data.items,
|
||||
function(mediaItem) {
|
||||
// set thumbnail and src
|
||||
mediaItem.thumbnail = mediaHelper.resolveFileFromEntity(mediaItem, true);
|
||||
mediaItem.image = mediaHelper.resolveFileFromEntity(mediaItem, false);
|
||||
// set properties to match a media object
|
||||
if (mediaItem.metaData &&
|
||||
mediaItem.metaData.umbracoWidth &&
|
||||
mediaItem.metaData.umbracoHeight) {
|
||||
|
||||
mediaItem.properties = [
|
||||
{
|
||||
alias: "umbracoWidth",
|
||||
value: mediaItem.metaData.umbracoWidth.Value
|
||||
},
|
||||
{
|
||||
alias: "umbracoHeight",
|
||||
value: mediaItem.metaData.umbracoHeight.Value
|
||||
}
|
||||
];
|
||||
}
|
||||
});
|
||||
angular.forEach(data.items, function(mediaItem) {
|
||||
setMediaMetaData(mediaItem);
|
||||
});
|
||||
// update images
|
||||
$scope.images = data.items ? data.items : [];
|
||||
// update pagination
|
||||
@@ -348,6 +329,28 @@ angular.module("umbraco")
|
||||
});
|
||||
}
|
||||
|
||||
function setMediaMetaData(mediaItem) {
|
||||
// set thumbnail and src
|
||||
mediaItem.thumbnail = mediaHelper.resolveFileFromEntity(mediaItem, true);
|
||||
mediaItem.image = mediaHelper.resolveFileFromEntity(mediaItem, false);
|
||||
// set properties to match a media object
|
||||
if (mediaItem.metaData &&
|
||||
mediaItem.metaData.umbracoWidth &&
|
||||
mediaItem.metaData.umbracoHeight) {
|
||||
|
||||
mediaItem.properties = [
|
||||
{
|
||||
alias: "umbracoWidth",
|
||||
value: mediaItem.metaData.umbracoWidth.Value
|
||||
},
|
||||
{
|
||||
alias: "umbracoHeight",
|
||||
value: mediaItem.metaData.umbracoHeight.Value
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
function getChildren(id) {
|
||||
$scope.loading = true;
|
||||
return mediaResource.getChildren(id)
|
||||
@@ -384,19 +387,26 @@ angular.module("umbraco")
|
||||
}
|
||||
|
||||
$scope.editMediaItem = function(item) {
|
||||
|
||||
var mediaEditor = {
|
||||
"node": item,
|
||||
submit: function(model) {
|
||||
editorService.close(model.id);
|
||||
editorService.close()
|
||||
// update the media picker item in the picker so it matched the saved media item
|
||||
// the media picker is using media entities so we get the
|
||||
// entity so we easily can format it for use in the media grid
|
||||
if(model && model.mediaNode) {
|
||||
entityResource.getById(model.mediaNode.id, "media")
|
||||
.then(function (mediaEntity) {
|
||||
angular.extend(item, mediaEntity);
|
||||
setMediaMetaData(item);
|
||||
});
|
||||
}
|
||||
},
|
||||
close: function(model) {
|
||||
editorService.close(model.id);
|
||||
editorService.close();
|
||||
}
|
||||
};
|
||||
|
||||
editorService.mediaEditor(mediaEditor);
|
||||
|
||||
};
|
||||
|
||||
$scope.submit = function() {
|
||||
|
||||
@@ -95,21 +95,32 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
};
|
||||
|
||||
$scope.editItem = function(item) {
|
||||
|
||||
var mediaEditor = {
|
||||
"node": item,
|
||||
submit: function(model) {
|
||||
console.log("submitted", model);
|
||||
editorService.close(model.id);
|
||||
editorService.close();
|
||||
// update the selected media item to match the saved media item
|
||||
// the media picker is using media entities so we get the
|
||||
// entity so we easily can format it for use in the media grid
|
||||
if(model && model.mediaNode) {
|
||||
entityResource.getById(model.mediaNode.id, "media")
|
||||
.then(function (mediaEntity) {
|
||||
// if an image is selecting more than once
|
||||
// we need to update all the media items
|
||||
angular.forEach($scope.images, function(image){
|
||||
if(image.id === model.mediaNode.id) {
|
||||
angular.extend(image, mediaEntity);
|
||||
image.thumbnail = mediaHelper.resolveFileFromEntity(image, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
close: function(model) {
|
||||
console.log("closed", model);
|
||||
editorService.close(model.id);
|
||||
editorService.close();
|
||||
}
|
||||
};
|
||||
|
||||
editorService.mediaEditor(mediaEditor);
|
||||
|
||||
};
|
||||
|
||||
$scope.add = function() {
|
||||
@@ -135,15 +146,18 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
else {
|
||||
$scope.ids.push(media.id);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$scope.sync();
|
||||
|
||||
setupViewModel();
|
||||
|
||||
editorService.close(model.id);
|
||||
editorService.close();
|
||||
|
||||
},
|
||||
close: function(model) {
|
||||
editorService.close(model.id);
|
||||
editorService.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user