mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixed modelstate persistence on import screen in case of validation errors.
This commit is contained in:
@@ -86,6 +86,17 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
||||
}
|
||||
}
|
||||
|
||||
var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));
|
||||
|
||||
// Update the view model with non-submitted values.
|
||||
viewModel.SuperUserName = _orchardServices.WorkContext.CurrentSite.SuperUser;
|
||||
foreach (var stepViewModel in viewModel.RecipeExecutionSteps) {
|
||||
var step = _recipeExecutionSteps.Single(x => x.Name == stepViewModel.Name);
|
||||
stepViewModel.DisplayName = step.DisplayName;
|
||||
stepViewModel.Description = step.Description;
|
||||
stepViewModel.Editor = step.UpdateEditor(shapeFactory, stepUpdater);
|
||||
}
|
||||
|
||||
if (!isInValid) {
|
||||
// Read recipe file.
|
||||
RecipeDocument = XDocument.Parse(new StreamReader(file.InputStream).ReadToEnd());
|
||||
@@ -100,13 +111,12 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
||||
where provider != null
|
||||
select provider;
|
||||
var executionSteps = executionStepsQuery.ToArray();
|
||||
var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));
|
||||
foreach (var executionStep in executionSteps) {
|
||||
var context = new UpdateRecipeExecutionStepContext {
|
||||
RecipeDocument = RecipeDocument,
|
||||
Step = orchardElement.Element(executionStep.Name)
|
||||
};
|
||||
executionStep.UpdateEditor(shapeFactory, stepUpdater, context);
|
||||
executionStep.UpdateStep(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
<input type="file" id="RecipeFile" size="64" name="RecipeFile" value="@T("Browse...")"/>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div>
|
||||
<legend>
|
||||
@Html.CheckBoxFor(m => m.ResetSite)
|
||||
@Html.LabelFor(m => m.ResetSite, T("Reset Site").ToString(), new {@class = "forcheckbox"})
|
||||
</legend>
|
||||
@Html.Hint(T("Check this option to reset your site before executing the uploaded recipe."))
|
||||
</div>
|
||||
<div data-controllerid="@Html.FieldIdFor(m => m.ResetSite)">
|
||||
<div class="message message-Warning">@T("This will delete your database tables. Please consider creating a backup first.")</div>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.SuperUserPassword, T("Super User Password"))
|
||||
@Html.PasswordFor(m => m.SuperUserPassword, new {@class = "text medium"})
|
||||
@@ -27,19 +28,19 @@
|
||||
@Html.PasswordFor(m => m.SuperUserPasswordConfirmation, new {@class = "text medium"})
|
||||
@Html.Hint(T("Repeat the password to make sure you didn't mistype anything."))
|
||||
</div>
|
||||
<div class="message message-Warning">@T("This will delete your database tables. Please consider creating a backup first.")</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
@{
|
||||
var stepIndex = 0;
|
||||
foreach (var step in Model.RecipeExecutionSteps) {
|
||||
var stepName = Html.NameFor(m => m.RecipeExecutionSteps[stepIndex].IsSelected).ToString();
|
||||
var stepId = stepName.HtmlClassify();
|
||||
|
||||
var stepId = Html.FieldIdFor(m => m.RecipeExecutionSteps[stepIndex].IsSelected);
|
||||
if (stepIndex <= Model.RecipeExecutionSteps.Count) {
|
||||
<hr />
|
||||
}
|
||||
<fieldset class="recipe-builder-step recipe-builder-step-@step.Name.HtmlClassify()">
|
||||
<legend>
|
||||
<input type="hidden" name="@Html.NameFor(m => m.RecipeExecutionSteps[stepIndex].Name)" value="@Model.RecipeExecutionSteps[stepIndex].Name" />
|
||||
<input type="checkbox" id="@stepId" name="@stepName" value="true" />
|
||||
<input type="hidden" name="@Html.FieldNameFor(m => m.RecipeExecutionSteps[stepIndex].Name)" value="@Model.RecipeExecutionSteps[stepIndex].Name" />
|
||||
@Html.CheckBoxFor(m => m.RecipeExecutionSteps[stepIndex].IsSelected)
|
||||
<label for="@stepId" class="forcheckbox">@step.DisplayName</label>
|
||||
</legend>
|
||||
@Html.Hint(step.Description)
|
||||
@@ -48,8 +49,5 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
stepIndex++;
|
||||
if (stepIndex < Model.RecipeExecutionSteps.Count) {
|
||||
<hr />
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,22 +33,28 @@ namespace Orchard.Recipes.Providers.Executors {
|
||||
get { return T("Provides additional coniguration for the Content recipe step."); }
|
||||
}
|
||||
|
||||
public int? BatchSize { get; set; }
|
||||
|
||||
public override dynamic BuildEditor(dynamic shapeFactory) {
|
||||
return UpdateEditor(shapeFactory, null, null);
|
||||
return UpdateEditor(shapeFactory, null);
|
||||
}
|
||||
|
||||
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater, UpdateRecipeExecutionStepContext context) {
|
||||
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
|
||||
var viewModel = new ContentExecutionStepViewModel();
|
||||
|
||||
if (updater != null) {
|
||||
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||
SetBatchSizeForDataStep(context.Step, viewModel.BatchSize);
|
||||
BatchSize = viewModel.BatchSize;
|
||||
}
|
||||
}
|
||||
|
||||
return shapeFactory.EditorTemplate(TemplateName: "ExecutionSteps/Content", Model: viewModel, Prefix: Prefix);
|
||||
}
|
||||
|
||||
public override void UpdateStep(UpdateRecipeExecutionStepContext context) {
|
||||
SetBatchSizeForDataStep(context.Step, BatchSize);
|
||||
}
|
||||
|
||||
// <Data />
|
||||
// Import Data.
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Orchard.Recipes.Services {
|
||||
LocalizedString DisplayName { get; }
|
||||
LocalizedString Description { get; }
|
||||
dynamic BuildEditor(dynamic shapeFactory);
|
||||
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater, UpdateRecipeExecutionStepContext context);
|
||||
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);
|
||||
void UpdateStep(UpdateRecipeExecutionStepContext context);
|
||||
void Execute(RecipeExecutionContext context);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,13 @@ namespace Orchard.Recipes.Services {
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater, UpdateRecipeExecutionStepContext context) {
|
||||
public virtual dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void UpdateStep(UpdateRecipeExecutionStepContext context) {
|
||||
}
|
||||
|
||||
public abstract void Execute(RecipeExecutionContext context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user