Test and fine tune 3rd level nested archetypes
This commit is contained in:
@@ -143,13 +143,21 @@ namespace Archetype.PropertyEditors
|
||||
var additionalData = new Dictionary<string, object>();
|
||||
|
||||
// figure out if we need to pass a files collection in the additional data to the property value editor
|
||||
if(uploadedFiles != null && propDef.FileNames != null && propDef.FileNames.Any())
|
||||
if(uploadedFiles != null)
|
||||
{
|
||||
// get the uploaded files that belongs to this property (if any)
|
||||
var propertyFiles = propDef.FileNames.Select(f => uploadedFiles.FirstOrDefault(u => u.FileName == f)).Where(f => f != null).ToList();
|
||||
if(propertyFiles.Any())
|
||||
if(dtd.PropertyEditorAlias == Constants.PropertyEditorAlias)
|
||||
{
|
||||
additionalData["files"] = propertyFiles;
|
||||
// it's a nested Archetype - just pass all uploaded files to the value editor
|
||||
additionalData["files"] = uploadedFiles.ToList();
|
||||
}
|
||||
else if(propDef.FileNames != null && propDef.FileNames.Any())
|
||||
{
|
||||
// pass the uploaded files that belongs to this property (if any) to the value editor
|
||||
var propertyFiles = propDef.FileNames.Select(f => uploadedFiles.FirstOrDefault(u => u.FileName == f)).Where(f => f != null).ToList();
|
||||
if(propertyFiles.Any())
|
||||
{
|
||||
additionalData["files"] = propertyFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,14 +200,10 @@
|
||||
}
|
||||
|
||||
// issue 114: handler for file selection
|
||||
function setFiles(property, alias, files) {
|
||||
function setFiles(files) {
|
||||
// get all currently selected files from file manager
|
||||
var currentFiles = fileManager.getFiles();
|
||||
|
||||
// remove the files set for this property alias
|
||||
// NOTE: we can't use property.alias because the file manager registers the selected files on the assigned Archetype property alias (e.g. "archetype-property-archetype-0-1")
|
||||
fileManager.setFiles(alias, []);
|
||||
|
||||
|
||||
// get the files already selected for this archetype (by alias)
|
||||
var archetypeFiles = [];
|
||||
_.each(currentFiles, function (item) {
|
||||
@@ -216,27 +212,13 @@
|
||||
}
|
||||
});
|
||||
|
||||
// remove the previously selected files for this property (if any)
|
||||
//if (property.fileNames != null) {
|
||||
// console.log("rejecting files", property.alias, property.fileNames);
|
||||
// archetypeFiles = _.reject(archetypeFiles, function (item) {
|
||||
// return property.fileNames.indexOf(item.name) != -1;
|
||||
// });
|
||||
//}
|
||||
|
||||
// add the newly selected files
|
||||
_.each(files, function (file) {
|
||||
archetypeFiles.push(file);
|
||||
});
|
||||
|
||||
// update the selected files for this archetype (by alias))
|
||||
// update the selected files for this archetype (by alias)
|
||||
fileManager.setFiles($scope.model.alias, archetypeFiles);
|
||||
|
||||
// update the property files collection
|
||||
property.fileNames = [];
|
||||
_.each(files, function (item) {
|
||||
property.fileNames.push(item.name);
|
||||
});
|
||||
}
|
||||
|
||||
//watch for changes
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q) {
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q, fileManager) {
|
||||
|
||||
function getFieldsetByAlias(fieldsets, alias)
|
||||
{
|
||||
@@ -166,7 +166,19 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
|
||||
// issue 114: handle file selection on property editors
|
||||
scope.$on("filesSelected", function (event, args) {
|
||||
scope.archetypeRenderModel.setFiles(scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex], scope.model.alias, args.files);
|
||||
// populate the fileNames collection on the property
|
||||
var property = scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex];
|
||||
property.fileNames = [];
|
||||
_.each(args.files, function (item) {
|
||||
property.fileNames.push(item.name);
|
||||
});
|
||||
|
||||
// remove the files set for this property
|
||||
// NOTE: we can't use property.alias because the file manager registers the selected files on the assigned Archetype property alias (e.g. "archetype-property-archetype-property-archetype-property-content-0-2-0-1-0-0")
|
||||
fileManager.setFiles(scope.model.alias, []);
|
||||
|
||||
// now tell the containing Archetype to pick up the selected files
|
||||
scope.archetypeRenderModel.setFiles(args.files);
|
||||
});
|
||||
|
||||
element.html(data).show();
|
||||
|
||||
Reference in New Issue
Block a user