Fixes: U4-3501 Error when selecting multiple items with the media picker in v7 - ensures the standard media picker cannot multi-select, hides the add button when multi select is disabled and there's a value.

This commit is contained in:
Shannon
2013-11-14 20:32:11 +11:00
parent 367bbd7eff
commit 9eb9b8df92
3 changed files with 34 additions and 2 deletions

View File

@@ -3,6 +3,8 @@
angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerController",
function($rootScope, $scope, dialogService, mediaResource, imageHelper, $log) {
//check the pre-values for multi-picker
var multiPicker = $scope.model.config.multiPicker !== undefined ? $scope.model.config.multiPicker : true;
function setupViewModel() {
$scope.images = [];
@@ -33,9 +35,14 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
$scope.add = function() {
dialogService.mediaPicker({
multiPicker: true,
multiPicker: multiPicker,
callback: function(data) {
//it's only a single selector, so make it into an array
if (!multiPicker) {
data = [data];
}
_.each(data, function(media, i) {
var img = {};
img.id = media.id;
@@ -67,6 +74,15 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
$scope.model.value = $scope.ids.join();
};
$scope.showAdd = function () {
if (!multiPicker) {
if ($scope.model.value && $scope.model.value !== "") {
return false;
}
}
return true;
};
//here we declare a special method which will be called whenever the value has changed from the server
//this is instead of doing a watch on the model.value = faster
$scope.model.onValueChanged = function (newVal, oldVal) {

View File

@@ -8,7 +8,7 @@
</li>
</ul>
<ul class="thumbnails umb-thumbnails">
<ul class="thumbnails umb-thumbnails" ng-if="showAdd()">
<li class="umb-thumbnail thumbnail">
<a href="#" class="add-link" ng-click="add()" prevent-default>
<i class="icon icon-add large"></i>

View File

@@ -12,12 +12,28 @@ namespace Umbraco.Web.PropertyEditors
[PropertyEditor(Constants.PropertyEditors.MediaPickerAlias, "Media Picker", "INT", "mediapicker")]
public class MediaPickerPropertyEditor : PropertyEditor
{
public MediaPickerPropertyEditor()
{
_defaultPreValues = new Dictionary<string, object>
{
{"multiPicker", false}
};
}
private IDictionary<string, object> _defaultPreValues;
protected override PropertyValueEditor CreateValueEditor()
{
//TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists!
return base.CreateValueEditor();
}
public override IDictionary<string, object> DefaultPreValues
{
get { return _defaultPreValues; }
set { _defaultPreValues = value; }
}
}
}