Forum Discussion

iftomkins's avatar
10 years ago

Click to load a component

I'm trying to load a component programatically on the Idea Page.

 

The scenario is that I want to have the page load by default without the component "comment-editor". This is preferable to hiding/showing the editor, since I don't want any chance a comment can be added if the person is not authorized. To check if the person is authorized, on pageload, I will check the value of a profile field, in order to see if they have accepted our Terms and Conditions, which is a requirement to post a comment on an idea. If the user HAS already accepted our Terms and Conditions, they're authorized to post a comment, I would like to load the "comment-editor" component dynamically.

 

I found a reference for loading components dynamically here: 

http://community.lithium.com/t5/Developers-Discussion/Click-to-load-a-component/m-p/168251/highlight/true#M6741

 

I've tried including these scripts in a page to see if it will load. The first one loads a Spinner, but nothing more. The second loads nothing:

 

<@liaAddScript>

LITHIUM.Components.renderInPlace("comment-editor");

</@liaAddScript>

 

<@liaAddScript>

LITHIUM.Components.render("comment-editor");

</@liaAddScript>

 

 

What do you think for loading this comment box dynamically? DougS ?

 

10 Replies

  • iftomkins - Did you check in the firebug if you're getting any errors in console? I am getting 404's using both renderInPlace and render.

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    VarunGrazitti - Yes, I'm getting those same 404 errors in the console. I've attached a screenshot. 

     

    Do you have any hunches about what the issue might be? Perhaps it's a deprecated function, or one that needs to be turned on by Lithium support, like Page Initialization? DougS ?Screenshot 2015-04-06 12.13.38.png

     

     

  • DougS's avatar
    DougS
    Khoros Oracle
    10 years ago

    It doesn't look like we support rendering the "comment-editor" component (or "page level" components like it) via these javascript functions.  If this is something you would like to enforce community-wide, you can adjust this setting in the admin:

     

    Screen Shot 2015-04-06 at 1.56.15 PM.png

    If you check the "Users must confirm email before posting and sending private messages" checkbox and save, users will see this when they go to the idea page:

    Screen Shot 2015-04-06 at 1.57.12 PM.png

     

    That checkbox can only be set at the community level -- it makes it so users must verify their email before doing any kind of posting or private messaging anywhere in the community.  We don't currently have a narrorer scope than that.

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    Hi DougS , thanks for your reply. Like the screenshot you posted, we want to prevent users from posting a comment by unless they take an action. However, the action we want them to take is not verifying their email address. We want them to check a box to "Accept Terms and Conditions". 

     

    Is your suggestion that we hijack the verify email address feature for our own purposes? Or do you have another suggestion for how to prevent users from seeing the Comment box, unless we can see via a custom profile field value (already implemented, working) that they have accepted the terms/conditions?

  • DougS's avatar
    DougS
    Khoros Oracle
    10 years ago

    Sorry -- I saw you posted Terms and Conditions but I mixed that up with email verification.

     

    I think the only clean way to do this as a server-side customization would be to work with professional services -- they have the ability to add some java code that runs when forms are submitted that can prevent the comment from being posted if the terms and conditions have not been accepted.

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    Thanks, DougS . We're ok with a workaround. We already have everything working perfectly when it comes to creating a New Idea--we just redirect away form the PostPage if they have not accepted the terms. With the Idea Page it's harder because we need to display the same page whether or not they have accepted the terms, just without the comment box. The Idea page is the last part we need to fix. We're 1/2 way there!

     

    IDEA: What about creating a custom page, using the Idea Page as a quilt, except deleting the comment-editor from that custom page? Then we can redirect any users on Page Initialization who have not accepted the terms to the custom idea page, where they can read all the ideas listed, but just can't post. Is this possible?

     

    Thanks,

    Alan

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    Or... is there any possible way to use freemarker to prevent the comment-editor component from loading? We'll know on Page Init if the user has accepted the terms or not. Can we then use that information to prevent them from submitting a comment on the Idea Page?

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    Thanks, DougS ! That's just what I was looking for. I'll try it shortly and post back.

  • iftomkins's avatar
    iftomkins
    Maven
    10 years ago

    Works perfectly. Thanks again DougS . Here's the code from my Page Initialization tab:

     

    <#-- Idea Page: User must have accepted terms to see the comment-editor component -->
    <#if page.name?lower_case == "ideapage">
        <#-- Check if user has accepted the terms -->
        <#assign terms_accepted = restadmin("/users/id/${user.id}/profiles/name/ideas_terms_accepted").value>
        <#if terms_accepted != 'true'>
            <#-- Replace with custom quilt that does not contain comment-editor component -->
            ${http.response.replaceQuilt("IdeaPage", "Idea_Page_No_Comment")}
        </#if>
    </#if>

     

    "Idea_Page_No_Comment" is a custom page, using the same quilt as the standard IdeaPage, except I removed the comment-editor component.