obsoletes imageHelper in favor of the new mediaHelper, updates the link picker to fix: U4-3882 Can't Link to Non-Image Media in 7.0.1
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.services.imageHelper
|
||||
* @description A helper object used for parsing image paths
|
||||
* @name umbraco.services.mediaHelper
|
||||
* @description A helper object used for dealing with media items
|
||||
**/
|
||||
function imageHelper(umbRequestHelper) {
|
||||
function mediaHelper(umbRequestHelper) {
|
||||
return {
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @name umbraco.services.mediaHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns the actual image path associated with the image property if there is one
|
||||
* Returns the file path associated with the media property if there is one
|
||||
*
|
||||
* @param {object} options Options object
|
||||
* @param {object} options.imageModel The media object to retrieve the image path from
|
||||
* @param {object} options.mediaModel The media object to retrieve the image path from
|
||||
* @param {object} options.imageOnly Optional, if true then will only return a path if the media item is an image
|
||||
*/
|
||||
getImagePropertyValue: function (options) {
|
||||
if (!options && !options.imageModel) {
|
||||
throw "The options objet does not contain the required parameters: imageModel";
|
||||
getMediaPropertyValue: function (options) {
|
||||
if (!options && !options.mediaModel) {
|
||||
throw "The options objet does not contain the required parameters: mediaModel";
|
||||
}
|
||||
|
||||
|
||||
//combine all props, TODO: we really need a better way then this
|
||||
var props = [];
|
||||
if (options.imageModel.properties) {
|
||||
props = options.imageModel.properties;
|
||||
if (options.mediaModel.properties) {
|
||||
props = options.mediaModel.properties;
|
||||
} else {
|
||||
$(options.imageModel.tabs).each(function (i, tab) {
|
||||
$(options.mediaModel.tabs).each(function (i, tab) {
|
||||
props = props.concat(tab.properties);
|
||||
});
|
||||
}
|
||||
@@ -52,27 +52,54 @@ function imageHelper(umbRequestHelper) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var imageVal;
|
||||
var mediaVal;
|
||||
|
||||
//our default images might store one or many images (as csv)
|
||||
var split = imageProp.value.split(',');
|
||||
var self = this;
|
||||
imageVal = _.map(split, function (item) {
|
||||
mediaVal = _.map(split, function (item) {
|
||||
return { file: item, isImage: self.detectIfImageByExtension(item) };
|
||||
});
|
||||
|
||||
//for now we'll just return the first image in the collection.
|
||||
//TODO: we should enable returning many to be displayed in the picker if the uploader supports many.
|
||||
if (imageVal.length && imageVal.length > 0 && imageVal[0].isImage) {
|
||||
return imageVal[0].file;
|
||||
if (mediaVal.length && mediaVal.length > 0) {
|
||||
if (!options.imageOnly || (options.imageOnly === true && mediaVal[0].isImage)) {
|
||||
return mediaVal[0].file;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnail
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @name umbraco.services.mediaHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Returns the actual image path associated with the image property if there is one
|
||||
*
|
||||
* @param {object} options Options object
|
||||
* @param {object} options.imageModel The media object to retrieve the image path from
|
||||
*/
|
||||
getImagePropertyValue: function (options) {
|
||||
if (!options && (!options.imageModel || !options.mediaModel)) {
|
||||
throw "The options objet does not contain the required parameters: imageModel";
|
||||
}
|
||||
|
||||
//required to support backwards compatibility.
|
||||
options.mediaModel = options.imageModel ? options.imageModel : options.mediaModel;
|
||||
|
||||
options.imageOnly = true;
|
||||
|
||||
return this.getMediaPropertyValue(options);
|
||||
},
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#getThumbnail
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
@@ -96,8 +123,8 @@ function imageHelper(umbRequestHelper) {
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#scaleToMaxSize
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @name umbraco.services.mediaHelper#scaleToMaxSize
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
@@ -139,8 +166,8 @@ function imageHelper(umbRequestHelper) {
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnailFromPath
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @name umbraco.services.mediaHelper#getThumbnailFromPath
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
@@ -149,7 +176,7 @@ function imageHelper(umbRequestHelper) {
|
||||
* @param {string} imagePath Image path, ex: /media/1234/my-image.jpg
|
||||
*/
|
||||
getThumbnailFromPath: function (imagePath) {
|
||||
|
||||
|
||||
//get the proxy url for big thumbnails (this ensures one is always generated)
|
||||
var thumbnailUrl = umbRequestHelper.getApiUrl(
|
||||
"imagesApiBaseUrl",
|
||||
@@ -164,8 +191,8 @@ function imageHelper(umbRequestHelper) {
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#detectIfImageByExtension
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @name umbraco.services.mediaHelper#detectIfImageByExtension
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
@@ -180,4 +207,73 @@ function imageHelper(umbRequestHelper) {
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.services').factory('mediaHelper', mediaHelper);
|
||||
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.services.imageHelper
|
||||
* @deprecated
|
||||
**/
|
||||
function imageHelper(umbRequestHelper, mediaHelper) {
|
||||
return {
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getImagePropertyValue
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getImagePropertyValue: function (options) {
|
||||
return mediaHelper.getImagePropertyValue(options);
|
||||
},
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnail
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getThumbnail: function (options) {
|
||||
return mediaHelper.getThumbnail(options);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#scaleToMaxSize
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
scaleToMaxSize: function (maxSize, width, height) {
|
||||
return mediaHelper.getThumbnail(maxSize, width, height);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#getThumbnailFromPath
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
getThumbnailFromPath: function (imagePath) {
|
||||
return mediaHelper.getThumbnailFromPath(imagePath);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.imageHelper#detectIfImageByExtension
|
||||
* @methodOf umbraco.services.imageHelper
|
||||
* @function
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
detectIfImageByExtension: function (imagePath) {
|
||||
return mediaHelper.detectIfImageByExtension(imagePath);
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.services').factory('imageHelper', imageHelper);
|
||||
@@ -1,6 +1,6 @@
|
||||
//used for the media picker dialog
|
||||
angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController",
|
||||
function ($scope, eventsService, dialogService, entityResource, contentResource, imageHelper, $log) {
|
||||
function ($scope, eventsService, dialogService, entityResource, contentResource, mediaHelper, $log) {
|
||||
var dialogOptions = $scope.$parent.dialogOptions;
|
||||
|
||||
$scope.dialogTreeEventHandler = $({});
|
||||
@@ -30,7 +30,7 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController",
|
||||
dialogService.mediaPicker({callback: function(media){
|
||||
$scope.target.id = undefined;
|
||||
$scope.target.name = media.name;
|
||||
$scope.target.url = imageHelper.getImagePropertyValue({imageModel: media});
|
||||
$scope.target.url = mediaHelper.getMediaPropertyValue({mediaModel: media});
|
||||
}});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user