#20542 Sending initial folder structure with page rather than as an async call on load.

This commit is contained in:
Benjamin Grabkowitz
2014-03-09 12:34:43 -04:00
committed by Sebastien Ros
parent 5d2a31ffc0
commit b27e1d5c00
5 changed files with 25 additions and 42 deletions

View File

@@ -49,6 +49,7 @@ namespace Orchard.MediaLibrary.Controllers {
var viewModel = new MediaManagerIndexViewModel {
DialogMode = dialog,
FolderPath = folderPath,
ChildFoldersViewModel = new MediaManagerChildFoldersViewModel{Children = _mediaLibraryService.GetMediaFolders(folderPath)},
MediaTypes = _mediaLibraryService.GetMediaTypes(),
CustomActionsShapes = explorerShape.Actions,
CustomNavigationShapes = explorerShape.Navigation,
@@ -103,12 +104,12 @@ namespace Orchard.MediaLibrary.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Cannot get child folder listing")))
return new HttpUnauthorizedResult();
var childFolders = _mediaLibraryService.GetMediaFolders(folderPath);
var viewModel = new MediaManagerChildFoldersViewModel {
Children = childFolders
Children = _mediaLibraryService.GetMediaFolders(folderPath)
};
Response.ContentType = "text/json";
return View(viewModel);
}

View File

@@ -82,26 +82,6 @@ $(function () {
self.mediaType = ko.observableArray([]);
self.mediaFolders = ko.observableArray([]);
(function () {
var getChildFolderListUrl = function (f) {
return settings.childFolderListingActionUrl + '?folderPath=' + encodeURIComponent(f);
};
var url = getChildFolderListUrl(settings.folderPath);
$.ajax({
type: "GET",
url: url,
cache: false
}).done(function (data) {
var childFolders = data.childFolders;
for (var x = 0; x < childFolders.length; x++) {
self.mediaFolders.push(new mediaFolderViewModel(childFolders[x]));
}
}).fail(function (data) {
console.error(data);
});
})();
self.getMediaItems = function (count, append) {
var folderPath = self.displayed() || '';
@@ -325,11 +305,13 @@ $(function () {
self.isExpanded(true);
}
};
}
$.map(settings.childFolders, function (childFolder, index) {
viewModel.mediaFolders.push(new mediaFolderViewModel(childFolder));
});
enhanceViewModel(viewModel);
ko.applyBindings(viewModel);

View File

@@ -1,13 +1,14 @@
using System.Collections.Generic;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.ViewModels {
public class MediaManagerIndexViewModel {
public string FolderPath { get; set; }
public bool DialogMode { get; set; }
public IEnumerable<ContentTypeDefinition> MediaTypes { get; set; }
public dynamic CustomActionsShapes { get; set; }
public dynamic CustomNavigationShapes { get; set; }
}
using System.Collections.Generic;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.ViewModels {
public class MediaManagerIndexViewModel {
public MediaManagerChildFoldersViewModel ChildFoldersViewModel { get; set; }
public string FolderPath { get; set; }
public bool DialogMode { get; set; }
public IEnumerable<ContentTypeDefinition> MediaTypes { get; set; }
public dynamic CustomActionsShapes { get; set; }
public dynamic CustomNavigationShapes { get; set; }
}
}

View File

@@ -1,7 +1,5 @@
@using Orchard.Utility.Extensions
@model Orchard.MediaLibrary.ViewModels.MediaManagerChildFoldersViewModel
@model Orchard.MediaLibrary.ViewModels.MediaManagerChildFoldersViewModel
@{
Response.ContentType = "text/json";
@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(
new {
childFolders = Model.Children.Select(x => new {

View File

@@ -98,8 +98,9 @@ var mediaLibrarySettings = {
folderPath: '@HttpUtility.JavaScriptStringEncode(viewModel.FolderPath)',
deleteConfirmationMessage: '@HttpUtility.JavaScriptStringEncode(T("Are you sure you want to delete these media items ?").Text)',
errorMessage: '@HttpUtility.JavaScriptStringEncode(T("An unexpected error occured, please refresh the page and try again.").Text)',
antiForgeryToken: '@Html.AntiForgeryTokenValueOrchard()'
};
antiForgeryToken: '@Html.AntiForgeryTokenValueOrchard()',
childFolders: (@Display.Partial(TemplateName: "ChildFolders", Model: viewModel.ChildFoldersViewModel))['childFolders']
};
//]]>
</script>
<script type="text/html" id="media-folder-template">