November Happy Hour will be moved to Thursday December 5th.

Episerver CMS Editor Properties visibility in editor

Vote:
 

Hi,

I am not sure if this is already discussed in the forum or not. I am very new to the episerver platform. Sorry if I am repeating. But I am facing a challenge when defining properties in episerver. When defining the blocks I want a property to be available in the clinet side when the block is edited but the editor won't be able to see it.

So, to simplify, let's say I have a property name B which should be populated via dojo widget in client side when some value is changed in for property A by the editor but the editor should not be able to see that B property from the editor view. It should be hidden but accessible so that I can update the value via dojo widget.

Is it possible? Appreciate a quick help.

I am using Episerver 9

Thanks
Chandan

#174950
Feb 08, 2017 13:38
Vote:
 

For the view, you can use PageEditing.PageIsInEditMode function to check if the page is opened in edit mode.

To hide the properties in All Properties view, you can move them to a custom tab which is only visible to site administrators.

#174953
Feb 08, 2017 13:51
Vote:
 

If I understand your problem correctly, you want to have a property which isn't visible to the editor but is set based on the value a user enters in a different property. In this instance, I'd suggest that, rather than handling this client side in dojo, you should handle this server side.

First of all, to hide your property from the editor, add the following attribute:
[ScaffoldColumn(false)]

This attribute keeps the property as part of the model but instructs the CMS not to include it in the editing interface.

Next you'll need to add the logic to set property B based on property A. The simplest option for this is to add some logic into the getter for property B which references property A. An example of this is the way MetaTitle is handled in Alloy:

        public virtual string MetaTitle
        {
            get
            {
                var metaTitle = this.GetPropertyValue(p => p.MetaTitle);

                // Use explicitly set meta title, otherwise fall back to page name
                return !string.IsNullOrWhiteSpace(metaTitle)
                       ? metaTitle
                       : PageName;
            }
            set { this.SetPropertyValue(p => p.MetaTitle, value); }
        }

If you require more logic than you'd be comfortable adding to your model, or your property value is time sensitive, you can create an initialization module to hook in to the DataFactory.Instance.SavingContent event which is called each time a piece of content is saved. Within this event you can access the content being saved from the Content property of the ContentEventArgs passed in to your event handler. As this event will fire any time any content is saved, you'l need to check the content type of the content being saved to ensure it's the content type you're interested in. You should then be able to set the value of property B and it will be saved alongside property A without ever having appeared in the editor.

#174994
Feb 09, 2017 10:57
Vote:
 

Thanks Paul! You understood my question correctly but the suggested way may not work for me. Let me give you a more detailed scenerio.

Let's say I have a datetime property. And you know the datetime property by default shows local time zone equivalent date and time to the editor as dojo does this behind the scene. But when the same is getting saved in database which is in Universal Coordinated Timezone, it is getting saved in UTC. So, in view when I am showing the same datetime it is actually UTC. I want to know the timezone of the editor who saved the date so that I can do the conversion before showing that in view. Keep in mind the Editor is in different time zone than the web server and database server. How Can I do this Timezone calculation from server side without sending the value from client side? Does property getter will give me the local time zone value? I found that is not the case when debugged.

So I was planning to have a hidden field in the editor so that I can set it with the Local Time Zone of the editor and save it to the DB so that I can convert that when I show that in view. Please suggest if this can be handled in much better, simpler way. I may be missing some coolest parts of episerver. :)

#174997
Feb 09, 2017 11:18
Vote:
 

Hmmmm. I can see this being a bit problematic. The root of the problem is that you want end users to see the date exactly as entered by the editor, regardless of the timezone of either.

Does this website serve a single timezone and are the editors in that timezone? If so, you could make assumptions about the timezone used.

#175018
Feb 09, 2017 15:08
Vote:
 

Hi Paul,

No. The website is in a timezone but the editors are not. Editors could be from different area. So, assuming the editors loation would not give correct result.

Any ideas?

Thanks
Chandan

#175020
Feb 09, 2017 15:35
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.