Skip to content

Instantly share code, notes, and snippets.

@jammykam
Last active January 22, 2016 02:39
Show Gist options
  • Save jammykam/92377635a06ac86d627a to your computer and use it in GitHub Desktop.
Save jammykam/92377635a06ac86d627a to your computer and use it in GitHub Desktop.
Updated form selector to allow selection of existing forms
using System;
using System.Text;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Globalization;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Web.UI.Sheer;
namespace Sitecore.Custom.WFFM.UI
{
public class InsertFormWizard : Sitecore.Forms.Shell.UI.InsertFormWizard
{
protected Radiobutton ChooseExistingForm;
protected override void Localize()
{
base.Localize();
this.ChooseExistingForm.Header = "Select an existing form";
}
protected override bool ActivePageChanging(string page, ref string newpage)
{
if (newpage == "SelectPlaceholder" && page == "SelectForm" && this.ChooseExistingForm.Checked)
newpage = string.IsNullOrEmpty(base.Placeholder) ? "SelectPlaceholder" : "ConfirmationPage";
if (this.ChooseExistingForm.Checked && newpage == "AnalyticsPage")
newpage = "ConfirmationPage";
bool flag = base.ActivePageChanging(page, ref newpage);
if (newpage == "ConfirmationPage" && this.ChooseExistingForm.Checked)
{
base.ChoicesLiteral.Text = RenderFormSelection();
}
return flag;
}
private string RenderFormSelection()
{
Item source = ExistingFormSelection();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("<fieldset class='scfGroupSection' >");
stringBuilder.Append("<legend>FORM</legend>");
stringBuilder.Append("<p>Using existing form: " + source.Paths.FullPath + "</p>");
return stringBuilder.ToString();
}
protected override void ActivePageChanged(string page, string oldPage)
{
base.ActivePageChanged(page, oldPage);
if (page == "ConfirmationPage" && this.ChooseExistingForm.Checked)
{
this.NextButton.Header = "Confirm";
}
}
protected override void OnNext(object sender, EventArgs formEventArgs)
{
if (this.NextButton.Header == "Confirm" && this.ChooseExistingForm.Checked)
{
this.SaveExistingFormSelection();
SheerResponse.SetModified(false);
this.Next();
return;
}
base.OnNext(sender, formEventArgs);
}
private void SaveExistingFormSelection()
{
Item source = ExistingFormSelection();
this.ServerProperties[this.newFormUri] = source.Uri.ToString();
Registry.SetString("/Current_User/Dialogs//sitecore/shell/default.aspx?xmlcontrol=Forms.FormDesigner", "1250,500");
SheerResponse.SetDialogValue(source.ID.ToString());
}
private Item ExistingFormSelection()
{
string queryString = Sitecore.Web.WebUtil.GetQueryString("la");
Language result = Context.ContentLanguage;
if (!string.IsNullOrEmpty(queryString))
Language.TryParse(Sitecore.Web.WebUtil.GetQueryString("la"), out result);
Item source = this.FormsRoot.Database.GetItem(this.multiTree.Selected, result);
return source;
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense">
<Forms.InsertFormWizard>
<Stylesheet runat="server" Src="MultiTreeView.css" DeviceDependant="true"/>
<Stylesheet runat="server" Src="Content Manager.css" DeviceDependant="true"/>
<Stylesheet runat="server" Src="default.css" DeviceDependant="true"/>
<Stylesheet runat="server" Src="/webedit.css" DeviceDependant="true"/>
<Stylesheet Key="SelectFields">
.scPalettePlaceholderSelected,
.scPalettePlaceholder
{
width:100%;
}
</Stylesheet>
<Script runat="server" Src="/sitecore/shell/controls/lib/jquery/jquery.js"/>
<Script type="text/javascript" runat="server">
var $j = jQuery.noConflict();
</Script>
<Script runat="server" Src="/sitecore/shell/Applications/Modules/Web Forms for Marketers/script/jquery.numeric.pack.js"/>
<Script runat="server" Src="/sitecore/shell/controls/SitecoreObjects.js"/>
<Script runat="server" Src="/sitecore/shell/controls/SitecoreVSplitter.js"/>
<Script runat="server" Src="/sitecore/shell/controls/SitecoreWindow.js"/>
<Script runat="server" Src="/sitecore/shell/controls/SitecoreKeyboard.js"/>
<WizardForm Application="Modules/Web Forms for Marketers/Insert Form Wizard"
CodeBeside="Sitecore.Custom.WFFM.UI.InsertFormWizard, Sitecore.Custom">
<Script runat="server" Src="/sitecore/shell/Applications/Modules/Web Forms for Marketers/script/Utils.js"/>
<Script runat="server" Src="/sitecore/shell/Applications/Modules/Web Forms for Marketers/script/Sitecore.PlaceholderManager.js"/>
<WizardFormPage ID="CreateForm" Icon="Applications/32x32/form_green_add.png" >
<Groupbox Width="100%" Height="100%" Cellpadding="2" Style="table-layout:fixed;border:0px;width: auto !important;" Margin="10px 10px 10px 10px" >
<Border ColCount="2" Width="100%" Cellpadding="0" Margin="10px 10px 10px 10px">
<Literal ID="FormNameLiteral" Margin="5px 5px 5px 5px"/>
<Edit ID="EbFormName" Width="80%" Margin="0px 0px 0px 0px"/>
</Border>
<Border Margin="10px">
<Radiobutton ID="CreateBlankForm" Name="ChooseOperation" Value="no"/>
</Border>
<Border Margin="10px">
<Radiobutton ID="ChooseForm" Name="ChooseOperation" Value="yes" />
</Border>
<Border Margin="10px">
<Radiobutton ID="ChooseExistingForm" Name="ChooseOperation" Value="existing" />
</Border>
</Groupbox>
<script type="text/javascript" runat="server">
$j('input[name="ChooseOperation"]').change(function() {
if (this.value == "existing") {
$j("#EbFormName").attr("disabled", "disabled");
} else {
$j("#EbFormName").removeAttr("disabled");
}
});
</script>
</WizardFormPage>
<WizardFormPage ID="SelectForm" Icon="Applications/32x32/form_green_add.png" >
<GridPanel Width="100%" Cellpadding="0" Style="table-layout:fixed" Padding="10px">
<Scrollbox ID="ExistingForms" Width="96%" Position="absolute" Valign="top" Padding="10px 1px 10px 10px" style="overflow:auto;height:455px"/>
</GridPanel>
</WizardFormPage>
<WizardFormPage ID="SelectPlaceholder" Icon="Applications/32x32/form_green_add.png">
<Forms.PlaceholderList ID="Placeholders" />
</WizardFormPage>
<WizardFormPage ID="AnalyticsPage" Icon="Business/32x32/chart.png">
<Border Padding="10px">
<GridPanel Cellpadding="0" Style="table-layout:fixed" >
<Groupbox ID="AnalyticsOptions" Width="100%" Height="100%" Cellpadding="0" Style="table-layout:fixed;border-left:0px;border-right:0px;border-bottom:0px" Margin="0px 10px 0px 10px" >
<Border Padding="0px 0px 0px 20px" Margin="10px 0px 0px 0px">
<Radiobutton ID="CreateGoal" Name="GoalOperation" Value="yes" Click="form:creategoal"/>
<Border Padding="3px 0px 5px 2px">
<GridPanel Columns="2" Cellpadding="0" Padding="0px 0px 0px 20px" Margin="0px">
<Literal ID="GoalNameLiteral" GridPanel.Height="15px" />
<Literal ID="PointsLiteral" GridPanel.Height="15px" GridPanel.Width="35%" Margin="0px 0px 0px 10px"/>
<Edit ID="GoalName" Width="100%"/>
<Edit ID="Points" Class="Range" Margin="0px 0px 0px 10px" Value="0" Width="70%"/>
</GridPanel>
<script type="text/javascript" runat="server">
$j(".Range").numeric();
</script>
</Border>
</Border>
<Border GridPanel.vAlign="top" Height="100%" Padding="0px 0px 0px 20px" Margin="0px 0px 10px 0px">
<Radiobutton ID="SelectGoal" Name="GoalOperation" Value="no" Click="form:creategoal"/>
<DataContext ID="GoalsDataContext" DataViewName="Master" ShowRoot="false" Root="{0CB97A9F-CAFB-42A0-8BE1-89AB9AE32BD9}" Filter="Contains('{059CFBDF-49FC-4F14-A4E5-B63E1E1AFB1E},{475E9026-333F-432D-A4DC-52E03B75CB6B}, {A87A00B1-E6DB-45AB-8B54-636FEC3B5523}, {DB6E13B8-786C-4DD6-ACF2-3E5E6A959905}', @@templateid)" DefaultItem="{0CB97A9F-CAFB-42A0-8BE1-89AB9AE32BD9}"/>
<TreePickerEx ID="Goals" DataContext="GoalsDataContext" SelectOnly="true" AllowNone="false" Width="90%"/>
<script type="text/javascript" language="javascript">
$$('#Goals')[0].setAttribute("disabled", "1");
$$('.scComboboxDropDown')[0].disabled = true;
</script>
</Border>
<Border Padding="0px 10px 0px 10px" Margin="0px 0px 0px 10px" Style="color:#999999">
<Literal ID="SelectGoalLiteral"/>
</Border>
</Groupbox>
<Groupbox ID="DropoutOptions" Width="100%" Height="100%" Cellpadding="0" Style="table-layout:fixed;border-left:0px;border-right:0px;border-bottom:0px" Margin="10px" >
<Checkbox Margin="0px 3px 0px 20px" ID="EnableFormDropoutTracking" Click="form:trackingenable" style="margin-top:10px"/>
<Border Padding="10px 3px 0px 20px" Style="color:#999999">
<Literal ID="EnableFormDropoutTrackingLiteral" />
<br/>
<Literal ID="EnableDropoutSavedToLiteral"/>
</Border>
</Groupbox>
</GridPanel>
</Border>
</WizardFormPage>
<WizardFormPage ID="ConfirmationPage" Icon="Applications/32x32/form_green_add.png" >
<Scrollbox Border="none" Background="transparent" Height="100%" Padding="10px" style="overflow-x:hidden">
<Border ID="ChoicesPanel" Height="90%" Margin="0px 0px 16px 0px" >
<Border class="scWfmConfirmText" Padding="0px 10px 10px 10px" ID="ChoicesPane" >
<Literal ID="ChoicesLiteral"/>
</Border>
</Border>
</Scrollbox>
</WizardFormPage>
</WizardForm>
</Forms.InsertFormWizard>
</control>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment