Creating the pipe control designer
Creating the custom control
To create the class for the view, perform the following.
- From the context menu of folder Web » UI, click Add » Class...
- In the Name input field, enter XmlPipeImportDesignerView.
- Open the file in Visual Studio and add the following namespaces:
using System.Web.UI;
using PublishingModuleExtensions.PublishingSystem;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Publishing.Web.Services.Data;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
- Change the class definition to:
public class XmlPipeImportDesignerView : ControlDesignerBase
{
}
- Add the following constructor:
public XmlPipeImportDesignerView()
{
}
- Add the following field:
private string providerName;
- Save the file.
Creating the template
To create the template of the designer view, perform the following:
- In the context menu of folder Web » UI, click Add » Class...
- In the Name input field, enter XmlPipeImportDesignerView.ascx and click Add.
- Open the newly created file and clear its content.
- Define the markup by pasting the following code:
<%@ Control Language="C#" %>
<div class="sfContentViews">
<div class="sfFormCtrl">
<a href="javascript:void(0);" id="openMappingSettings" runat="server" class="sfLinkBtn sfChange">
<asp:Label runat="server" ID="lMappingSettings" Text="<%$Resources:PublishingMessages, MappingSettings %>" CssClass="sfLinkBtnIn" />
</a>
</div>
</div>
- Save the file.
Implementing the ControlDesignerBase class
To implement the ControlDesignerBase class in XmlPipeImportDesignerView.cs, perform the following:
- Reference the embedded template by pasting the following code into XmlPipeImportDesignerView.cs:
public static readonly string layoutTemplatePath = ControlUtilities.ToVppPath("PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.ascx");
public static readonly string PublishingVirtualPath = "~/SFPublishing/";
public override string LayoutTemplatePath
{
get
{
return String.Concat(PublishingVirtualPath, "PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.ascx");
}
set
{
base.LayoutTemplatePath = value;
}
}
protected override string LayoutTemplateName
{
get
{
return null;
}
}
- Override the InitializeControls method by pasting the following code:
protected override void InitializeControls(GenericContainer container)
{
}
- Provide a property for the open mapping settings dialog by pasting the following code:
protected virtual Control OpenMappingSettingsDialog
{
get { return this.Container.GetControl<Control>("openMappingSettings", true); }
}
- Save the file.
Implementing the client component
You must store the client class in a javascript file in the project, where the view resides.
To create the file, perform the following:
- In the context menu of folder Web » UI, click Add » New Item...
- In the left pane, select Visual C# Items » Web.
- Click JScript File and in the Name input field, enter XmlPipeImportDesignerView.
- Open the newly created file.
- Add the following code to it:
Type._registerScript("XmlPipeImportDesignerView.js", ["IDesignerViewControl.js"]);
Type.registerNamespace("PublishingModuleExtensions.Web.UI");
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView = function (element) {
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.initializeBase(this, [element]);
this._openMappingSettingsButton = null;
this._settingsData = {};
}
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.prototype = {
initialize: function () {
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.callBaseMethod(this, 'initialize');
},
dispose: function () {
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.callBaseMethod(this, 'dispose');
},
refreshUI: function () {
},
applyChanges: function () {
},
validate: function () {
var isValid = true;
return isValid;
},
get_openMappingSettingsButton: function () {
return this._openMappingSettingsButton;
},
set_openMappingSettingsButton: function (val) {
this._openMappingSettingsButton = val;
},
set_controlData: function (value) {
this._settingsData = value;
this.refreshUI();
},
get_controlData: function (value) {
return this._settingsData;
}
}
PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.registerClass('PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView',
Sys.UI.Control, Telerik.Sitefinity.Web.UI.ControlDesign.IDesignerViewControl);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
- Save the file.
Referencing the client script
You must reference the client component from the view class. You do this in the override for the GetScriptReferences method. In it you must create a script reference for your client component. When creating the reference, you must specify the name of the embedded resource that contains the client component and the assembly it resides in. The name of the resource follows the same naming conventions as the name of the template.
public override IEnumerable<ScriptReference> GetScriptReferences()
{
var res = PageManager.GetScriptReferences(ScriptRef.JQuery);
var assemblyName = this.GetType().Assembly.GetName().ToString();
var telerikAssemblyName = typeof(Telerik.Sitefinity.Web.UI.Fields.TextField).Assembly.GetName().FullName;
res.Add(new ScriptReference("Telerik.Sitefinity.Web.UI.ControlDesign.Scripts.IDesignerViewControl.js", telerikAssemblyName));
res.Add(new ScriptReference("PublishingModuleExtensions.Web.UI.XmlPipeImportDesignerView.js", assemblyName));
return res;
}
You must specify a script descriptor for the view. You do this in the GetScriptDescriptors override.
public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
{
ScriptControlDescriptor desc = new ScriptControlDescriptor(this.GetType().FullName, this.ClientID);
desc.AddElementProperty("openMappingSettingsButton", this.OpenMappingSettingsDialog.ClientID);
var settings = new Dictionary<string, object>();
var defaults = PublishingSystemFactory.GetPipe(XmlInboundPipe.PipeName).GetDefaultSettings();
settings.Add("settings", defaults);
settings.Add("pipe", new WcfPipeSettings(XmlInboundPipe.PipeName, this.providerName));
desc.AddProperty("_settingsData", settings);
return new[] { desc };
}