2010-07-12 03:03:18 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using JetBrains.Annotations;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
|
|
|
|
using Orchard.Core.Common;
|
|
|
|
|
using Orchard.Core.Localization.Models;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
using Orchard.Core.Localization.Services;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
using Orchard.Core.Localization.ViewModels;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
using Orchard.Localization.Services;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Localization.Drivers {
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class LocalizationDriver : ContentPartDriver<Localized> {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
private readonly ICultureManager _cultureManager;
|
|
|
|
|
private readonly ILocalizationService _localizationService;
|
|
|
|
|
|
|
|
|
|
public LocalizationDriver(IOrchardServices services, ICultureManager cultureManager, ILocalizationService localizationService) {
|
|
|
|
|
_cultureManager = cultureManager;
|
|
|
|
|
_localizationService = localizationService;
|
2010-07-09 14:14:17 -07:00
|
|
|
|
Services = services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Display(Localized part, string displayType) {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
var model = new ContentLocalizationsViewModel(part) {
|
2010-07-12 23:35:43 -07:00
|
|
|
|
CanLocalize = Services.Authorizer.Authorize(Permissions.ChangeOwner) && _cultureManager.ListCultures()
|
2010-07-12 03:03:18 -07:00
|
|
|
|
.Where(s => s != _cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)) && s != _localizationService.GetContentCulture(part.ContentItem))
|
|
|
|
|
.Count() > 0,
|
|
|
|
|
Localizations = _localizationService.GetLocalizations(part.ContentItem)
|
|
|
|
|
};
|
2010-07-09 14:14:17 -07:00
|
|
|
|
return ContentPartTemplate(model, "Parts/Localization.ContentTranslations").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("primary", "5");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(Localized part) {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
return ContentPartTemplate(new SelectLocalizationsViewModel(part), "Parts/Localization.ContentTranslations").Location("secondary", "5");
|
2010-07-09 14:14:17 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|