Clean up the usage of ModelTemplate class a bit

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042780
This commit is contained in:
loudej
2009-12-01 00:18:59 +00:00
parent a39498fcc2
commit cd39efe610
7 changed files with 22 additions and 24 deletions

View File

@@ -29,7 +29,7 @@ namespace Orchard.Comments.Models {
if (context.ContentItem.Has<HasComments>() == false) {
return;
}
context.Displays.Add(new ModelTemplate { Model = context.ContentItem.Get<HasComments>(), Prefix = String.Empty });
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasComments>()));
}
protected override void Loading(LoadContentContext context) {

View File

@@ -4,10 +4,10 @@ using Orchard.UI.Models;
namespace Orchard.DevTools.Models {
public class DebugLinkProvider : ContentProvider {
protected override void GetDisplays(GetDisplaysContext context) {
context.Displays.Add(new ModelTemplate { Model = new ShowDebugLink { ContentItem = context.ContentItem } });
context.Displays.Add(new ModelTemplate(new ShowDebugLink { ContentItem = context.ContentItem }));
}
protected override void GetEditors(GetEditorsContext context) {
context.Editors.Add(new ModelTemplate { Model = new ShowDebugLink { ContentItem = context.ContentItem } });
context.Editors.Add(new ModelTemplate(new ShowDebugLink { ContentItem = context.ContentItem }));
}
}
}

View File

@@ -28,7 +28,7 @@ namespace Orchard.Media.Models {
if (model == null)
return;
context.Editors.Add(ModelTemplate.For(model.Record, "MediaSettings"));
context.Editors.Add(new ModelTemplate(model.Record, "MediaSettings"));
}
protected override void UpdateEditors(UpdateContentContext context) {
@@ -37,7 +37,7 @@ namespace Orchard.Media.Models {
return;
context.Updater.TryUpdateModel(model.Record, "MediaSettings", null, null);
context.Editors.Add(ModelTemplate.For(model.Record, "MediaSettings"));
context.Editors.Add(new ModelTemplate(model.Record, "MediaSettings"));
}
}
}

View File

@@ -46,7 +46,7 @@ namespace Orchard.Roles.Models {
Roles = roles.ToList(),
};
context.Editors.Add(ModelTemplate.For(viewModel, "UserRoles"));
context.Editors.Add(new ModelTemplate(viewModel, "UserRoles"));
}
}
@@ -71,7 +71,7 @@ namespace Orchard.Roles.Models {
}
}
context.Editors.Add(ModelTemplate.For(viewModel, "UserRoles"));
context.Editors.Add(new ModelTemplate(viewModel, "UserRoles"));
}
}
}

View File

@@ -31,7 +31,7 @@ namespace Orchard.Tags.Models {
if (context.ContentItem.Has<HasTags>() == false) {
return;
}
context.Displays.Add(new ModelTemplate { Model = context.ContentItem.Get<HasTags>(), Prefix = String.Empty });
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()));
}
protected override void Loading(LoadContentContext context) {

View File

@@ -10,12 +10,12 @@ namespace Orchard.Models.Driver {
}
protected override void GetEditors(GetEditorsContext context, ContentPart<TRecord> part) {
context.Editors.Add(ModelTemplate.For(part.Record, _prefix));
context.Editors.Add(new ModelTemplate(part.Record, _prefix));
}
protected override void UpdateEditors(UpdateContentContext context, ContentPart<TRecord> part) {
context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
context.Editors.Add(ModelTemplate.For(part.Record, _prefix));
context.Editors.Add(new ModelTemplate(part.Record, _prefix));
}
}
}

View File

@@ -1,22 +1,20 @@
namespace Orchard.UI.Models {
public class ModelTemplate {
public ModelTemplate()
: this(null) {
}
public ModelTemplate(object model)
: this(model, string.Empty) {
}
public ModelTemplate(object model, string prefix) {
Model = model;
Prefix = prefix;
}
public object Model { get; set; }
public string Prefix { get; set; }
public string TemplateName { get; set; }
public static ModelTemplate For<TModel>(TModel model, string prefix) {
return new ModelTemplate {
Model = model,
Prefix = prefix,
};
}
public static ModelTemplate For<TModel>(TModel model, string prefix, string editorTemplateName) {
return new ModelTemplate {
Model = model,
Prefix = prefix,
TemplateName = editorTemplateName,
};
}
}
}