Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. @using EPiServer.Editor
  2. @using EPiServer.Forms
  3. @using EPiServer.Forms.Configuration
  4. @using EPiServer.Forms.Core
  5. @using EPiServer.Forms.Helpers.Internal
  6. @using EPiServer.Forms.EditView.Internal
  7. @using EPiServer.Forms.Implementation.Elements
  8. @using EPiServer.ServiceLocation
  9. @using EPiServer.Web.Mvc.Html
  10.  
  11. @model FormContainerBlock
  12.  
  13. @{
  14. var formConfig = ServiceLocator.Current.GetInstance<IEPiServerFormsImplementationConfig>();
  15. }
  16.  
  17. @if (PageEditing.PageIsInEditMode)
  18. {
  19. <link rel="stylesheet" type="text/css" data-epiforms-resource="EPiServerForms.css" href="@ModuleHelper.ToClientResource(typeof(FormsModule), "clientresources/viewmode/episerverforms.css")" />
  20.  
  21. if (Model.Form != null)
  22. {
  23. <div class="EPiServerForms">
  24. @Html.PropertyFor(m => m.Title, new { CustomTag = "h2", CssClass = CssClasses.Text.Headings.H2 })
  25. @Html.PropertyFor(m => m.Description, new { CustomTag = "p", CssClass = CssClasses.Text.Scope })
  26. @Html.PropertyFor(m => m.ElementsArea)
  27. </div>
  28. }
  29. else
  30. {
  31. // In case FormContainerBlock is used as a property, we cannot build Form model so we show a warning message to notify user
  32. <div class="EPiServerForms">
  33. <span class="Form__Warning">@Html.Translate("/episerver/forms/editview/cannotbuildformmodel")</span>
  34. </div>
  35. }
  36. }
  37. else if (Model.Form != null)
  38. {
  39. // Using form tag (instead of div) for the sake of html elements' built-in features e.g. reset, file upload
  40. // Using enctype="multipart/form-data" for post data and uploading files
  41.  
  42. <form method="post"
  43. id="@Model.Form.FormGuid"
  44. class="EPiServerForms @(ViewBag.ValidationFail ? "ValidationFail" : "ValidationSuccess")"
  45. enctype="multipart/form-data"
  46. data-epiforms-type="form"
  47. data-epiforms-metadata="@Model.MetadataAttribute">
  48.  
  49. @* Meta data, authoring data of this form is transfer to clientside here. We need to take form with language coresponse with current page's language *@
  50.  
  51. <script src="@(formConfig.CoreController)/GetFormInitScript?formGuid=@(Model.Form.FormGuid)&formLanguage=@(FormsExtensions.GetCurrentPageLanguage())"></script>
  52.  
  53. @* Meta data, send along as a SYSTEM information about this form, so this can work without JS *@
  54. <input type="hidden" class="Form__Element Form__SystemElement FormHidden FormHideInSummarized" name="__FormGuid" value="@Model.Form.FormGuid" />
  55. <input type="hidden" class="Form__Element Form__SystemElement FormHidden FormHideInSummarized" name="__FormHostedPage" value="@FormsExtensions.GetCurrentPageLink().ToString()" />
  56. <input type="hidden" class="Form__Element Form__SystemElement FormHidden FormHideInSummarized" name="__FormLanguage" value="@FormsExtensions.GetCurrentPageLanguage()" />
  57. <input type="hidden" class="Form__Element Form__SystemElement FormHidden FormHideInSummarized" name="__FormCurrentStepIndex" value="@(ViewBag.CurrentStepIndex ?? string.Empty)" />
  58. <input type="hidden" class="Form__Element Form__SystemElement FormHidden FormHideInSummarized" name="__FormSubmissionId" value="@(ViewBag.FormSubmissionId)" />
  59.  
  60. @Html.PropertyFor(m => m.Title, new { CustomTag = "h2", CssClass = CssClasses.Text.Headings.H2 })
  61. @Html.PropertyFor(m => m.Description, new { CustomTag = "p", CssClass = CssClasses.Text.Scope })
  62.  
  63. @{
  64. var statusDisplay = "hide";
  65. var message = ViewBag.Message;
  66.  
  67. if (ViewBag.FormFinalized || ViewBag.IsProgressiveSubmit)
  68. {
  69. statusDisplay = "Form__Success__Message";
  70. }
  71. else if (ViewBag.Submittable == false && string.IsNullOrEmpty(message) == false)
  72. {
  73. statusDisplay = "Form__Warning__Message";
  74. }
  75. }
  76.  
  77. @if (ViewBag.IsReadOnlyMode)
  78. {
  79. <div class="Form__Status Form__Readonly__Message">
  80. @Html.Translate("/episerver/forms/viewmode/readonlymode")
  81. </div>
  82. }
  83.  
  84. <div class="Form__Status Form__Status__Message @statusDisplay">
  85. @if (ViewBag.FormFinalized)
  86. {
  87. @Html.Raw(message)
  88. }
  89. else
  90. {
  91. @message
  92. }
  93. </div>
  94.  
  95. <div class="Form__MainBody">
  96. @{
  97. var stepIndex = 0;
  98. var numberOfSteps = Model.Form.Steps.Count();
  99. var currentStepIndex = ViewBag.CurrentStepIndex == null ? -1 : (int)ViewBag.CurrentStepIndex;
  100. var displayStepNavigation = numberOfSteps > 1 && currentStepIndex > -1 && currentStepIndex < numberOfSteps && !ViewBag.FormFinalized;
  101.  
  102. var stepDisplaying = string.Empty;
  103. }
  104.  
  105. @foreach (var step in Model.Form.Steps)
  106. {
  107. stepDisplaying = (currentStepIndex == stepIndex && !ViewBag.FormFinalized && (bool)ViewBag.IsStepValidToDisplay) ? null : "hide";
  108.  
  109. <div class="FormStep @stepDisplaying" id="@step.ElementName" data-epiforms-element-name="@step.ElementName" data-epiforms-stepindex="@stepIndex">
  110. @{
  111. var stepBlock = (step.SourceContent as ElementBlockBase);
  112.  
  113. if (stepBlock != null)
  114. {
  115. Html.RenderContentData(step.SourceContent, false);
  116. }
  117.  
  118. // Each FormStep groups the elements below it til the next FormStep
  119. Html.RenderFormElements(stepIndex, step.Elements);
  120.  
  121. stepIndex++;
  122. }
  123. </div>
  124. }
  125.  
  126. @if (displayStepNavigation)
  127. {
  128. // show Next/Previous buttons when having Steps > 1 and navigationBar when currentStepIndex is valid
  129. var prevButtonDisableState = (currentStepIndex == 0) || !ViewBag.Submittable ? "disabled" : null;
  130. var nextButtonDisableState = (currentStepIndex == numberOfSteps - 1) || !ViewBag.Submittable ? "disabled" : null;
  131.  
  132. if (Model.ShowNavigationBar)
  133. {
  134. <div class="Form__NavigationBar">
  135. <button @prevButtonDisableState type="submit" name="submit" value="@SubmitButtonType.PreviousStep.ToString()" class="Form__NavigationBar__Action FormExcludeDataRebind btnPrev">
  136. @Html.Translate("/episerver/forms/viewmode/stepnavigation/previous")
  137. </button>
  138.  
  139. @{
  140. // calculate the progress style on-server-side
  141. var currentDisplayStepIndex = currentStepIndex + 1;
  142. var progressWidth = (100 * currentDisplayStepIndex / numberOfSteps) + "%";
  143. }
  144.  
  145. <div class="Form__NavigationBar__ProgressBar">
  146. <div class="Form__NavigationBar__ProgressBar--Progress" style="width: @progressWidth"></div>
  147. <div class="Form__NavigationBar__ProgressBar--Text">
  148. <span class="Form__NavigationBar__ProgressBar__ProgressLabel">@Html.Translate("/episerver/forms/viewmode/stepnavigation/page")</span>
  149. <span class="Form__NavigationBar__ProgressBar__CurrentStep">@currentDisplayStepIndex</span>/<span class="Form__NavigationBar__ProgressBar__StepsCount">@numberOfSteps</span>
  150. </div>
  151. </div>
  152.  
  153. <button @nextButtonDisableState type="submit" name="submit" value="@SubmitButtonType.NextStep.ToString()" class="Form__NavigationBar__Action FormExcludeDataRebind btnNext">
  154. @Html.Translate("/episerver/forms/viewmode/stepnavigation/next")
  155. </button>
  156. </div>
  157. }
  158. }
  159. </div>
  160. </form>
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement