161: Implemented "mandatory" events.

This commit is contained in:
Sipke Schoorstra
2014-07-01 19:38:06 -07:00
parent 7a8765811b
commit 1dc4837c69
8 changed files with 26 additions and 8 deletions

View File

@@ -39,13 +39,14 @@ namespace Orchard.AuditTrail.Drivers {
Event = eventDescriptor.Event,
Name = eventDescriptor.Name,
Description = eventDescriptor.Description,
IsEnabled = eventSetting != null ? eventSetting.IsEnabled : eventDescriptor.IsEnabledByDefault
IsEnabled = eventDescriptor.IsMandatory || (eventSetting != null ? eventSetting.IsEnabled : eventDescriptor.IsEnabledByDefault),
IsMandatory = eventDescriptor.IsMandatory
}).ToList()
}).ToList()
};
if (updater != null) {
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
if (updater.TryUpdateModel(viewModel, Prefix, new[] { "IsEnabled" }, null)) {
foreach (var eventSettingViewModel in viewModel.Categories.SelectMany(x => x.Events)) {
var eventSetting = eventSettings.FirstOrDefault(x => x.EventName == eventSettingViewModel.Event);
@@ -54,7 +55,7 @@ namespace Orchard.AuditTrail.Drivers {
eventSettings.Add(eventSetting);
}
eventSetting.IsEnabled = eventSettingViewModel.IsEnabled;
eventSetting.IsEnabled = eventSettingViewModel.IsEnabled || eventSettingViewModel.IsMandatory;
}
part.EventSettings = eventSettings;
}

View File

@@ -8,7 +8,7 @@ namespace Orchard.AuditTrail.Providers.AuditTrail {
public override void Describe(DescribeContext context) {
context.For("AuditTrailSettings", T("Audit Trail Settings"))
.Event(this, EventsChanged, T("Events Changed"), T("Audit Trail event settings were changed."), enableByDefault: true);
.Event(this, EventsChanged, T("Events Changed"), T("Audit Trail event settings were changed."), enableByDefault: true, isMandatory: true);
}
}
}

View File

@@ -14,7 +14,7 @@
$("table.check-all").each(function() {
var table = $(this);
var controller = table.find("thead input[type=\"checkbox\"]");
var checkboxes = table.find("tbody input[type=\"checkbox\"]");
var checkboxes = table.find("tbody input[type=\"checkbox\"]:not(:disabled)");
var updateController = function () {
var allChecked = checkboxes.filter(":not(:checked)").length == 0;

View File

@@ -160,6 +160,9 @@ namespace Orchard.AuditTrail.Services {
}
private bool IsEventEnabled(AuditTrailEventDescriptor eventDescriptor) {
if(eventDescriptor.IsMandatory)
return true;
var settingsDictionary = _cacheManager.Get("AuditTrail.EventSettings", context => {
context.Monitor(_signals.When("AuditTrail.EventSettings"));
return _siteService.GetSiteSettings().As<AuditTrailSettingsPart>().EventSettings.ToDictionary(x => x.EventName);

View File

@@ -7,5 +7,10 @@ namespace Orchard.AuditTrail.Services.Models {
public LocalizedString Name { get; set; }
public LocalizedString Description { get; set; }
public bool IsEnabledByDefault { get; set; }
/// <summary>
/// Wether the event can be disabled or not.
/// </summary>
public bool IsMandatory { get; set; }
}
}

View File

@@ -18,7 +18,14 @@ namespace Orchard.AuditTrail.Services.Models {
public string Category { get; private set; }
public LocalizedString Name { get; private set; }
public DescribeFor Event(IAuditTrailEventProvider provider, string eventName, LocalizedString name, LocalizedString description, bool enableByDefault = false) {
public DescribeFor Event(
IAuditTrailEventProvider provider,
string eventName,
LocalizedString name,
LocalizedString description,
bool enableByDefault = false,
bool isMandatory = false) {
_events.Add(new AuditTrailEventDescriptor {
CategoryDescriptor = new AuditTrailCategoryDescriptor {
Category = Category,
@@ -28,7 +35,8 @@ namespace Orchard.AuditTrail.Services.Models {
Event = EventNameHelper.GetFullyQualifiedEventName(provider.GetType(), eventName),
Name = name,
Description = description,
IsEnabledByDefault = enableByDefault
IsEnabledByDefault = enableByDefault,
IsMandatory = isMandatory
});
return this;
}

View File

@@ -7,5 +7,6 @@ namespace Orchard.AuditTrail.ViewModels {
public LocalizedString Name { get; set; }
public LocalizedString Description { get; set; }
public bool IsEnabled { get; set; }
public bool IsMandatory { get; set; }
}
}

View File

@@ -38,7 +38,7 @@
</td>
<td>@evnt.Description</td>
<td>
<input type="checkbox" id="@checkboxId" name="AuditTrailSettingsPart.Categories[@i].Events[@j].IsEnabled" value="@Boolean.TrueString" @if(evnt.IsEnabled){<text>checked="checked"</text>} />
<input type="checkbox" id="@checkboxId" name="AuditTrailSettingsPart.Categories[@i].Events[@j].IsEnabled" value="@Boolean.TrueString" @if(evnt.IsEnabled || evnt.IsMandatory){<text>checked="checked"</text>} @if(evnt.IsMandatory){<text>disabled="disabled"</text>}/>
</td>
</tr>
j++;