PageSelector & PagesService

Posted by Community Admin on 04-Aug-2018 06:50

PageSelector & PagesService

All Replies

Posted by Community Admin on 16-Nov-2012 00:00

Hello,

I am using Sitefinity 5.1 and have problems with a widget. Besides an image and some text tThe widget provides a page selector.
The website is multilingual. Now it seems that the page selector always shows the page tree of the default language (set unter 'Administration - Languages -> choose default language'). If the default language is english, the english page tree will be displayed. If it is german, the german page tree will be displayed. This is independent from the choosen language in which you edit a page.
Thus editing the widget on an english page will show the german tree if the default  language is set to german.
From the ajax request I saw that the service (PagesService.svc) returns only two values for each tree node. One has an empty key which is like a default value I guess and one key is the default (as set under "Administration") culture (e.g. "en" or "de-DE").

In the javascript part of the Designer of the widget I initialize the page selector with the page culture:

var my_href = window.location.href;
var propertyValueCulturePosition = my_href.search(/propertyValueCulture/i);
var pageCulture = my_href.slice(propertyValueCulturePosition + 21, propertyValueCulturePosition + 23);
this.get_PageSelector().set_uiCulture(pageCulture);
this.get_PageSelector().set_culture(pageCulture);

So I can set the culture of this element to "en" for example. But if the default culture is "de-DE" the the service only returns the german names of the nodes. Thus I guess the page selector falls back to the default values which is the same like the values for "de-DE".

After all I guess I have to enable multilanguage support for the url service. Or send a parameter for the desired language (of the pages (tree nodes)) with every request.
I set the service URL and the UICulture for the Elements in the ascx.cs file of the Designer:

protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)

   ...
   this.PageSelector.WebServiceUrl = "~/Sitefinity/Services/Pages/PagesService.svc/";
   this.PageSelector.RootNodeID = Telerik.Sitefinity.Abstractions.SiteInitializer.FrontendRootNodeId;
   this.PageSelector.DisplayMode = FieldDisplayMode.Write;
   ...
   
  string culture = this.Page.Request.Params["propertyValueCulture"];
   if (culture == null) culture = CultureInfo.CurrentUICulture.ToString();
   this.HtmlContent.UICulture = culture;
   ...      


Is there a way to add a parameter there to the web service URL? Where I can configure the web service that it either returns always all existing languages of the pages or that it returns a specified language?

Regards
Markus

Posted by Community Admin on 16-Nov-2012 00:00

Hey Markus,

I'm not sure how you build up your page selector, without seeing any code.

You could try to use this code in your designer.cs

if (this.PropertyEditor != null)
   var uiCulture = this.PropertyEditor.PropertyValuesCulture;
   this.PageSelectorPageId.UICulture = uiCulture;

It should be inserted on the InitializeControls() method.

Regards,
Daniel

Posted by Community Admin on 19-Nov-2012 00:00

Helo Daniel,

thank you for your reply. I tried to insert your code but this.PageSelectorPageId can't be resolved. How can I get an instance of this object?
Here is the complete code of the Designer:

using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using FPWidgets.Base.Widgets;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.Web.UI.Fields;
using Telerik.Sitefinity.Web.UI.Fields.Enums;
using Telerik.Web.UI;
using SitefinityFields = Telerik.Sitefinity.Web.UI.Fields;
using System;
using Telerik.Sitefinity.Pages.Model;
using FPWidgets.Common;
using System.Globalization;

namespace FPWidgets.CommonWidgets.Designers

public partial class ToggleContentLinkDesigner : ControlDesignerBase
protected Literal litTitle get return base.Container.GetControl<Literal>("litTitle", true);
protected Literal litLinkTitle get return base.Container.GetControl<Literal>("litLinkTitle", true);
protected SitefinityFields.ChoiceField ShowMode get return Container.GetControl<SitefinityFields.ChoiceField>("ShowMode", true);
protected HtmlField HtmlContent get return base.Container.GetControl<HtmlField>("HtmlContent", true);

protected Literal litExternalInternal get return base.Container.GetControl<Literal>("litExternalInternal", true);
protected PlaceHolder plhLinkType get return base.Container.GetControl<PlaceHolder>("plhLinkType", true);
protected PageField PageSelector get return base.Container.GetControl<PageField>("PageSelector", true);
protected Literal litExternal get return base.Container.GetControl<Literal>("litExternal", true);
protected TextBox txtExternalUrl get return base.Container.GetControl<TextBox>("txtExternalUrl", true);


protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)

this.DesignerMode = ControlDesignerModes.Advanced;
// this.PropertyEditor.HideAdvancedMode = true;
this.PropertyEditor.Width = new Unit(600, UnitType.Pixel); this.litTitle.Text = Helpers.GetResourceString("General.Title.Text");

var showMode = (from p in this.PropertyEditor.ControlData.Properties where p.Name == "ShowMode" select p).FirstOrDefault();
string show = showMode != null ? showMode.Value : ShowModes.show;

this.ShowMode.Title = Helpers.GetResourceString("ToggleContentDesigner.ShowMode.Text"); 
this.ShowMode.RenderChoicesAs = RenderChoicesAs.RadioButtons;
this.ShowMode.Choices.Add(new ChoiceItem() Text = Helpers.GetResourceString("ToggleContentDesigner.ShowModeInActive.Text"), Enabled = true, Selected = show == ShowModes.hide, Value = ShowModes.hide );
this.ShowMode.Choices.Add(new ChoiceItem() Text = Helpers.GetResourceString("ToggleContentDesigner.ShowModeActive.Text"), Enabled = true, Selected = show == ShowModes.show, Value = ShowModes.show );
this.ShowMode.DisplayMode = FieldDisplayMode.Write;
this.ShowMode.Value = show;

// Sets the properties of our HtmlField control
this.HtmlContent.Title = Helpers.GetResourceString("General.Teaser.HtmlContent.Text");
this.HtmlContent.DisplayMode = FieldDisplayMode.Write;
this.HtmlContent.FixCursorIssue = true;
this.HtmlContent.EditorContentFilters = EditorFilters.DefaultFilters;

//Retrieve the current culture information
string cult = this.Page.Request.Params["propertyValueCulture"];

if (cult == null)
cult = CultureInfo.CurrentUICulture.ToString();
// this.HtmlContent.UICulture = this.Page.UICulture;
this.HtmlContent.UICulture = cult;


            if (this.PropertyEditor != null)
           
                var uiCulture = this.PropertyEditor.PropertyValuesCulture;
                this.PageSelectorPageId.UICulture = uiCulture;

                //this.PageSelectorControl.UICulture = uiCulture;
                Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Write("uiCulture=" + uiCulture);
           

this.HtmlContent.EditorStripFormattingOptions = EditorStripFormattingOptions.MSWord
& EditorStripFormattingOptions.Css
& EditorStripFormattingOptions.Font
& EditorStripFormattingOptions.Span
& EditorStripFormattingOptions.ConvertWordLists;

this.litExternalInternal.Text = Helpers.GetResourceString("General.Designer.Link.Text");
var targetPageId = (from p in this.PropertyEditor.ControlData.Properties where p.Name == "TargetPageId" select p).FirstOrDefault();
var targetUrl = (from p in this.PropertyEditor.ControlData.Properties where p.Name == "TargetUrl" select p).FirstOrDefault();
if (targetUrl != null)
this.txtExternalUrl.Text = targetUrl.Value;

string linkType = "";

linkType = (targetUrl != null && !String.IsNullOrEmpty(targetUrl.Value)) ? "external" : linkType;
linkType = targetPageId != null ? "internal" : linkType;

this.plhLinkType.Controls.Add(new RadioButton() ID = "rbNoLink", Text = Helpers.GetResourceString("General.Designer.NoLink.Text"), GroupName = "LinkType", Checked = (linkType == "") );
this.plhLinkType.Controls.Add(new RadioButton() ID = "rbInternal", Text = Helpers.GetResourceString("General.Designer.InternalLink.Text"), GroupName = "LinkType", Checked = (linkType == "internal") );
this.plhLinkType.Controls.Add(new RadioButton() ID = "rbExternal", Text = Helpers.GetResourceString("General.Designer.ExternalLink.Text"), GroupName = "LinkType", Checked = (linkType == "external") );

this.PageSelector.WebServiceUrl = "~/Sitefinity/Services/Pages/PagesService.svc/";
            //this.PageSelector.RootNodeID = this.CurrentFrontendRootNodeId;
this.PageSelector.RootNodeID = Telerik.Sitefinity.Abstractions.SiteInitializer.FrontendRootNodeId;
this.PageSelector.DisplayMode = FieldDisplayMode.Write;


this.litExternal.Text = Helpers.GetResourceString("General.Designer.ExternalLink.Text");
this.litLinkTitle.Text = Helpers.GetResourceString("General.LinkTitle.Text");


protected override string LayoutTemplateName

get return "FPWidgets.CommonWidgets.Designers.ToggleContentLinkDesigner.ascx";


public override IEnumerable<ScriptReference> GetScriptReferences()

var res = new List<ScriptReference>(base.GetScriptReferences());
var assemblyName = this.GetType().Assembly.GetName().ToString();
res.Add(new ScriptReference("FPWidgets.Scripts.ToggleContentLinkDesigner.js", assemblyName));
return res.ToArray();


public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()

var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
var desc = (ScriptControlDescriptor)scriptDescriptors.Last();

desc.AddComponentProperty("ShowMode", this.ShowMode.ClientID);
desc.AddComponentProperty("HtmlContent", this.HtmlContent.ClientID);
desc.AddComponentProperty("PageSelector", this.PageSelector.ClientID);

desc.AddElementProperty("noLink", this.plhLinkType.FindControl("rbNoLink").ClientID);
desc.AddElementProperty("internalLink", this.plhLinkType.FindControl("rbInternal").ClientID);
desc.AddElementProperty("externalLink", this.plhLinkType.FindControl("rbExternal").ClientID);
desc.AddElementProperty("txtExternalUrl", this.txtExternalUrl.ClientID);

return new[] desc ;


Many thanks in advance Markus


Posted by Community Admin on 19-Nov-2012 00:00

I have also experienced this problem but with the built in HtmlField control provided by Sitefinity.  When I created a support ticket asking for this information.

My Ticket:
I have a designer for a custom control. The designer is using an HTMLField. However, when using the HTMLField and I try to add a link using the Sitefinity Pages, all of the pages are grey out making them unselectable. I found that if I removed all of my extra languages and just my default English language, the pages were selectable with no issues. Is this a bug or do I need to add a setting to my HTML field so the pages are selectable. I've attached the code that I am using.

Sitefinity Response:
Hi,Thank you for using our services.

Actually, this is a bug on our side, which we will make sure to fix as quickly as possible. Please excuse us for the inconvenience.  There is not a workaround for this issue. I am checking with the developers as to when this may be resolved.

I apologize for the inconvenience this causes you.


Whether or not there is a solution is up in the air.  I've been able to work around other issues even though they said it couldn't be done.  I just didn't have time to research at the time.

This thread is closed