More in this section

Forums / Developing with Sitefinity / Sitefinity 3.7 Decline email with comments.

Sitefinity 3.7 Decline email with comments.

17 posts, 0 answered
  1. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    09 Nov 2009
    Link to this post
    Hi Radoslav Georgiev and Ivan Dimitrov,

    As we discussed in the thread as in the below in the link.

    http://www.sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/email-notification-in-sitefinity-3-7.aspx

    We try to implement the point

    4) If the page is “rejected”, an email should be sent to the “content editor” notifying them why it was rejected, with a link to view the page in question.

    So Our client wants some comments to be sent while the page is declined. So we need a " comments text box " while clicking Declined.

    Please suggest as how to implement.

    Thanks,
    Karnan

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    09 Nov 2009
    Link to this post
    Hello karnan sekar,

    The approach will be different than the one discussed in the previous topics. Go to ~/Sitefinity/Admin/ControlTemplates/Pages/PageViewer.ascx and try with the following markup:
    <%@ Control Language="C#" AutoEventWireup="true" %>
    <%@Register TagPrefix="cc1" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms" %>
        <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
     
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.workflow.Controls.Count>0)
                notificationArea.Visible = true;
              this.workflow.Command+=new CommandEventHandler(workflow_Command);
        }
        void workflow_Command(object sender, CommandEventArgs e)
        {
            //throw new NotImplementedException();
            if(e.CommandArgument.Equals(2))
            {
                string declineComment = this.hiddenTextArea.Value;
                if(declineComment!=null){
                    //send email with decline comment
                }
            }
        }
    </script>
    <div id="sf_tlsCnt" class="pageTools clearfix">
        <div class="workflow">
            <cc1:PageWorkflowMenu runat="server" id="workflow" Sufix="or" ></cc1:PageWorkflowMenu>
            <asp:HyperLink runat="server" ID="editPage" CssClass="CmsButLeft editdark"><asp:Literal ID="editLinkText" runat="server" Text="<%$Resources:EditThisPage %>"></asp:Literal></asp:HyperLink>
            <asp:LinkButton runat="server" ID="deleteVersionButton" CssClass="delete" Text="<%$Resources:DeleteThisVersion %>"></asp:LinkButton>
            <asp:Label runat="server" id="InfoText" Visible="false"></asp:Label>
             
        </div>
            <asp:Panel ID="notificationArea" runat="server" visible="false">
                <input type="button" value="Add Decline Comment" id="show" class="CmsButLeft editdark"/>
                <div id="hiddenArea" class="clearfix">
                    <textarea id="hiddenTextArea" cols="80" rows="10" runat="server"></textarea>
                    <br />
                    <input id="hide" type="button" value="Add Comment" class="CmsButLeft editdark"/>
                </div>
            </asp:Panel>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#hiddenArea").hide();
     
                    $("#hide").click(function() {
                        $("#show").show();
                        $("#hiddenArea").hide();
                    });
     
                    $("#show").click(function() {
                        $("#hiddenArea").show();
                        $(this).hide();
                    });
                });
            </script>
             
        <div class="links"><asp:HyperLink runat="server" ID="newWindowLink" Text="<%$Resources:ViewLivePageInANewWindow %>" NavigateUrl="" rel="external"></asp:HyperLink></div>
    </div>
    <iframe runat="server" id="viewport" width="1" height="1" style="display:none" name="viewer" frameborder="0" scrolling="yes" />

    Note this is just a sample. You should extend it to fit your requirements.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    12 Nov 2009
    Link to this post
    Hi  Radoslav Georgiev and Ivan Dimitrov,

    Thanks it is working good. Here is the code, tell us if it is wrong way.


    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageViewer.ascx.cs" Inherits="Sitefinity_Admin_ControlTemplates_Pages_PageViewer" %>



    <%@Register TagPrefix="cc1" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms" %>

    <script src="/javascript/jquery-latest.js" type="text/javascript"></script>


    <div id="sf_tlsCnt" class="pageTools clearfix">
        <div class="workflow">
            <cc1:PageWorkflowMenu runat="server" id="workflow" Sufix="or"></cc1:PageWorkflowMenu>
            <asp:HyperLink runat="server" ID="editPage" CssClass="CmsButLeft editdark"><asp:Literal ID="editLinkText" runat="server" Text="<%$Resources:EditThisPage %>"></asp:Literal></asp:HyperLink>
            <asp:LinkButton runat="server" ID="deleteVersionButton" CssClass="delete" Text="<%$Resources:DeleteThisVersion %>"></asp:LinkButton>
            <asp:Label runat="server" id="InfoText" Visible="false"></asp:Label>
        </div>
        
        
        <asp:Panel ID="notificationArea" runat="server" visible="false">
                <input type="button" value="Add Comment" id="show" class="CmsButLeft editdark"/>
                <div id="hiddenArea" class="clearfix">
                    <textarea id="hiddenTextArea" cols="80" rows="10" runat="server"></textarea>
                    <br />
                    <input id="hide" type="button" value="Add Comment" class="CmsButLeft editdark"/>
                </div>
            </asp:Panel>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#hiddenArea").hide();
     
                    $("#hide").click(function() {
                        $("#show").show();
                        $("#hiddenArea").hide();
                    });
     
                    $("#show").click(function() {
                        $("#hiddenArea").show();
                        $(this).hide();
                    });
                });
            </script>
        
        <div class="links"><asp:HyperLink runat="server" ID="newWindowLink" Text="<%$Resources:ViewLivePageInANewWindow %>" NavigateUrl="" rel="external"></asp:HyperLink></div>
    </div>
    <iframe runat="server" id="viewport" width="1" height="1" style="display:none" name="viewer" frameborder="0" scrolling="yes" />



      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.workflow.Controls.Count > 0)
                notificationArea.Visible = true;

            workflow.Command += new CommandEventHandler(PageWorkflowMenu_Command);
          
        }

        void PageWorkflowMenu_Command(object sender, CommandEventArgs e)
        {
            try
            {


                WorkflowInstance workflow = ((WorkflowMenu)sender).GetWorkflow();

                if (workflow != null)
                {

                    List<EventActivity> commands = new List<EventActivity>();

                    this.LoadCommands(commands, workflow.Activity.Activities);

                    int idx = int.Parse((string)e.CommandArgument);


                    string strRole = string.Empty;


                    Telerik.Cms.CmsManager manager = new Telerik.Cms.CmsManager();

                    Telerik.Cms.ICmsPage page = manager.Provider.GetPageByWorkflow(workflow.ID);

                    System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();

                    CultureInfo myCIintl = new CultureInfo(page.LangID);

                    string strLanguage = "/ar";

                    if (myCIintl.LCID == 9)
                        strLanguage = "/en";

                    if (myCIintl.LCID == 127)
                        strLanguage = "/ar";

                    mailMsg.IsBodyHtml = true;

                    switch (idx)
                    {


                        case 0:
                            mailMsg.Subject = "page pending approval";
                            strRole = ConfigurationManager.AppSettings["Approver"].ToString();
                            string relativeurl = page.DefaultUrl.Url;
                            //mailMsg.Body += String.Format("The '{0}' page has been sent for approval. Comments:" + hiddenTextArea.Value + "  To approve the page, please go to URL: http://{1}{2}?cmspagemode=edit", page.Name, System.Web.HttpContext.Current.Request.Url.Host, relativeurl.Substring(1));
                            mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page has been sent for approval. <br />Comments:" + hiddenTextArea.Value + "  <br /> To approve the page, please go to URL: http://{1}{2}/sitefinity/admin/pages.aspx?select={3}</td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host, strLanguage, page.ID);


                            break;

                        case 1:

                            mailMsg.Subject = "page approved";
                            strRole = ConfigurationManager.AppSettings["Publisher"].ToString();
                            mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page has been approved.<br /> Comments:" + hiddenTextArea.Value + " <br />  To approve the page, please go to URL: http://{1}/Sitefinity/Admin/Pages.aspx </td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host);

                            break;

                        case 2:

                            mailMsg.Subject = "page declined";
                            strRole = ConfigurationManager.AppSettings["ContentEditor"].ToString();
                            mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page has been declined.<br /> Comments:" + hiddenTextArea.Value + " <br /> </td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host);

                            break;


                    }


                    if (!mailMsg.Subject.Equals(string.Empty))
                    {

                        string[] usernames = Telerik.Security.UserManager.Default.GetUsersInRole(strRole);
                        //For every user, send him or her an e-mail
                        foreach (string username in usernames)
                        {
                            System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username);
                            mailMsg.To.Add(user.Email);
                        }

                        // Init SmtpClient and send      
                        System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
                        if (mailMsg.To.Count <= 0)
                            mailMsg.To.Add(mailMsg.From);

                        smtpClient.Send(mailMsg);
                    }




                }
            }
            catch (Exception ex)
            {
                AppLogger.LogError(ex.Message, AppLogger.Severity.Failure);
            }

        }



        private void LoadCommands(List<EventActivity> commands, IList<Activity> activities)
        {

            foreach (Activity act in activities)
            {

                if (act is EventActivity)

                    commands.Add((EventActivity)act);

                this.LoadCommands(commands, act.Activities);

            }

        }


    Thanks,
    karnan
  4. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    12 Jan 2010
    Link to this post
    I was curious about implementing a similar solution in generic content.

    I have a textbox to capture comments,but I once the decline button is clicked the status of the item has already been changed and the item was declined. I'd like to force capturing a "Decline reason" in generic conent when the item has been declined. Would the method be similar to this?

    I was reiewing this item "http://www.sitefinity.com/blogs/ivandimitrov/ivanposts/09-12-25/christmas_bonus_-_workflow_with_comments_in_sitefinity_3_x.aspx", But it isn't quite what I am looking for.

    I am still learning my way around sitefinity. Any help would be appreciated.

    Thanks.

  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2010
    Link to this post
    Hi Mike Boyle,

    The code from the post does exactly what you are looking for ( or at least what you have written)

    I have a textbox to capture comments,but I once the decline button is clicked the status of the item has already been changed and the item was declined.

    The ApprovalStatus is changes and set to Declined by the Workflow. The TextBox from the blog post saves all data that has been entered.

     I'd like to force capturing a "Decline reason" in generic conent when the item has been declined. Would the method be similar to this?


    The post illustrate this - you add the text - why you decline this content item. The implementation is made for ContentBased module.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    12 Jan 2010
    Link to this post
    <%@ Control Language="C#" CodeFile="~/Sitefinity/Admin/ControlTemplates/Generic_Content/ContentPreview.ascx.cs" Inherits="ContentPreview"%> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Workflow.WebControls" Assembly="Telerik.Workflow" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Localization.WebControls" Assembly="Telerik.Localization" %> 
     
    <script src="/javascript/jquery-latest.js" type="text/javascript"></script> 
     
    <div id="sf_tlsCnt" class="pageTools clearfix">  
          
        <asp:Panel ID="notificationArea" runat="server" visible="false">  
                <input type="button" value="Add Comment" id="show" class="CmsButLeft editdark"/>  
                <div id="hiddenArea" class="clearfix">  
                    <textarea id="hiddenTextArea" cols="80" rows="10" runat="server"></textarea> 
                    <br /> 
                </div> 
            </asp:Panel> 
            <script type="text/javascript">  
                $(document).ready(function() {  
                    $("#hiddenArea").hide();  
     
                    $("#hide").click(function() {  
                        $("#show").show();  
                        $("#hiddenArea").hide();  
                    });  
     
                    $("#show").click(function() {  
                        $("#hiddenArea").show();  
                        $(this).hide();  
                    });  
                });  
            </script> 
          
        <div class="links"><asp:HyperLink runat="server" ID="newWindowLink" Text="" NavigateUrl="" rel="external"></asp:HyperLink></div>  
    </div> 
    <iframe runat="server" id="viewport" width="1" height="1" style="display:none" name="viewer" frameborder="0" scrolling="yes" /> 
     
    <%--<script type="text/javascript">  
     
        $(document).ready(function() {  
            $("#" + "<%= postCommentsPlh.ClientID %>").hide();  
        });  
        function ToggleDiv() {  
            $("#" + "<%= postCommentsPlh.ClientID %>").toggle("slow");  
        }    
    </script>  --%> 
     
    <div class="ToolsAll">  
        <asp:Label ID="lockedWarning" runat="server">  
            <class="locked">  
                <strong>{0}</strong>   
                <asp:Literal runat="server" Text="<%$Resources:IsEditingContent %>"></asp:Literal> 
            </p> 
        </asp:Label> 
        <div class="backWrapp">  
            <asp:HyperLink ID="BackButton1" CssClass="actions back" runat="server">  
                <asp:Literal Text="<%$Resources:BackToAllItems %>" runat="server" /> 
            </asp:HyperLink> 
        </div> 
        <telerik:RadTabStrip   
                        id="tabStrip"   
                        Align="Right"   
                        runat="server" 
                        selectedindex="0"   
                        causesvalidation="false" 
                        EnableEmbeddedSkins="false" 
                        Skin="SitefinityPages">  
                            <Tabs> 
                                <telerik:RadTab Text="<%$Resources:View %>" ></telerik:RadTab> 
                                <telerik:RadTab Text="<%$Resources:Edit %>" ></telerik:RadTab> 
                                <telerik:RadTab Text="<%$Resources:History %>" ></telerik:RadTab> 
                            </Tabs> 
                        </telerik:RadTabStrip> 
        <div class="clear"><!-- --></div>  
    </div> 
     
    <%--<href="javascript:void(0)" id="test1" onclick="ToggleDiv();">Leave Workflow comment</a>    
        <div runat="server" id="postCommentsPlh">    
        <asp:TextBox runat="server" ID="WorkflowDeclineComment1" />    
        </div>    
    <asp:Label ID="WorkflowMessageLabel1" runat="server" />    
    --%> 
    <div id="divWorkArea" runat="server" class="workArea">  
        <telerik:MessageControl runat="server" ID="message1">  
            <ItemTemplate> 
                <asp:Label runat="server" ID="messageText"></asp:Label> 
            </ItemTemplate> 
        </telerik:MessageControl> 
        <div class="view">  
            <class="button_area">  
                <telerik:WorkflowMenu ID="workflowMenu" runat="server" /> 
            <asp:HyperLink ID="editCommand1" runat="server" CssClass="CmsButLeft editdark">   
                    <asp:Literal ID="editLiteral" runat="server" Text="<%$Resources:EditThisItem %>"></asp:Literal> 
                </asp:HyperLink>      
            </p> 
            <div class="setW clearfix">  
                <div class="setInW clearfix">                         
                    <div class="viewIn">  
                        <h1 class="viewHead">  
                            <asp:Literal ID="itemName" runat="server" /> 
                        </h1> 
                        <telerik:GenericContent ID="contentPreview" runat="server" /> 
                    </div> 
                    <div class="details">  
                        <h3> 
                            <asp:Literal Text="<%$Resources:Details %>" runat="server" /><br /><br /> 
                        </h3> 
                        <dl> 
                            <asp:Repeater ID="repeaterItemMetaData" runat="server">  
                            <ItemTemplate> 
                                    <dt> 
                                        <asp:Literal ID="lblKey" runat="server" /> 
                                    </dt> 
                                    <dd> 
                                        <asp:Literal ID="lblValue" runat="server" /> 
                                    </dd> 
                            </ItemTemplate> 
                            </asp:Repeater> 
                        </dl> 
                    </div> 
    <%--            <div id="dComments" runat="server" visible=false>  
                    <asp:Label ID="Label5" AssociatedControlID="Comments" runat="server">  
                    <asp:literal ID="Literal18" runat="server" Text="Reason for Decline: "></asp:literal>   
                    <em id="Em2" runat="server"></em></asp:Label> 
                    <asp:TextBox ID="Comments" TextMode="MultiLine" Text="<%$Resources:CommentsInput %>" runat="server"></asp:TextBox> 
                </div>        
    --%>        </div> 
            </div> 
            <div class="bottomW"><div><!-- --></div></div> 
        </div> 
              
        <div class="info">  
            <div class="infoBottom">  
                <asp:PlaceHolder ID="languagePanel" runat="server">  
                    <h3> 
                        <asp:Literal Text="<%$Resources:ChangeLanguage %>" runat="server" /> 
                    </h3> 
                    <div class="langCol set">                 
                        <telerik:LanguageBar CssClass="setIn" ID="languageBar" PostBack="True" runat="server">  
                            <LayoutTemplate> 
                                <telerik:LanguageList ID="languageList" runat="server" CssClass="setIn">  
                                    <ItemTemplate> 
                                        <asp:HyperLink ID="listItem" CssClass="emptyLang" runat="server" /> 
                                    </ItemTemplate> 
                                    <CurrentItemTemplate> 
                                        <asp:Label ID="listItem" CssClass="currentLang"  runat="server" /> 
                                    </CurrentItemTemplate> 
                                    <SelectedItemTemplate> 
                                        <asp:HyperLink ID="listItem" CssClass="filledLang" runat="server" /> 
                                    </SelectedItemTemplate> 
                                </telerik:LanguageList> 
                            </LayoutTemplate> 
                        </telerik:LanguageBar>                        
                    </div>    
                    <div class="bottom"><div><!-- --></div></div> 
                </asp:PlaceHolder> 
            <div id="divViewFaq" runat="server">  
                    <h3> 
                        <asp:Literal Text="<%$Resources:GenericContentFAQ %>" runat="server" /> 
                    </h3> 
                    <asp:Literal Text="<%$Resources:GenericContentFAQText %>" runat="server" /> 
                    <class="hideAllFAQs">  
                        <href="javascript:void(0)" onclick="javascript:Personalization.hideFaqSection('<%= divViewFaq.ClientID %>')">Hide FAQs everywhere</a> 
                    </p> 
                </div> 
            </div> 
        </div>                
        <div class="clear"><!-- --></div>  
     
     
    </div> 
     
     
    //Class file -- in progress  
    using System.Web.UI;  
    using System;  
    using Telerik.Workflow;  
    using System.Web.UI.WebControls;  
    using Telerik.Workflow.WebControls;  
    using System.Collections.Generic;  
    using App_Code;  
     
    public partial class ContentPreview : UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (this.workflowMenu.Controls.Count > 0)  
                notificationArea.Visible = true;  
            this.workflowMenu.Command += new CommandEventHandler(workflowMenu_Command);  
        }  
     
        void workflowMenu_Command(object sender, CommandEventArgs e)  
        {  
            WorkflowInstance workflow = ((WorkflowMenu)sender).GetWorkflow();  
            if (workflow != null)  
            {  
                List<EventActivity> commands = new List<EventActivity>();  
                this.LoadCommands(commands, workflow.Activity.Activities);  
                int idx = int.Parse((string)e.CommandArgument);  
     
                if (e.CommandArgument.Equals("2"))  
                {  
                    string declineComment = this.hiddenTextArea.Value;  
                    if (declineComment != null)  
                    {  
                        //send email with decline comment  
                    }  
                }  
     
                //if (commands.Count > idx)  
                //{  
                //    var commandName = commands[idx].CommandName;  
                //    var contentID = this.contentPreview.ContentID;  
                //    ContentWorkflowNotificationHelper.GetNotificationHelper(ModuleType.Generic).Notify(commandName, contentID);  
                //}  
            }  
        }  
     
        private void LoadCommands(List<EventActivity> commands, IList<Activity> activities)  
        {  
            foreach (Activity act in activities)  
            {  
                if (act is EventActivity)  
                    commands.Add((EventActivity)act);  
                this.LoadCommands(commands, act.Activities);  
            }  
        }   
    }  
     


    Thanks Ivan.

    I'm trying to implement this in the "ContentPreview.ascx" template that we've implemented which I believe would be the correct place for generic content. So far it doesn't seem to be working. I've included the source page html. Maybe I'm missing something.

    This is a work in progress.

    Thanks for your help.



     

     

     

     

  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2010
    Link to this post
    Hi Mike Boyle,

    Please review the blog post again and follow the steps there. The template does not make anything itself, the logic is exposed in the code behind of the template.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    12 Jan 2010
    Link to this post

    Thanks again Ivan.

    I do see that. But I guess my problem is that the comments don't actually seem to be "required". It seems that the text is captured and placed in the email, but if the comment is blank it still goes through the decline process and submits no email. Am I reading this correctly?

    If it is making the comment field required could you tell me which piece is doing that?

    Thanks so much for your help.

  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2010
    Link to this post
    Hello Mike Boyle,

    The textbox is required, but you can easily check if the Text property is string.Empty and not sending an email. You can do this in the following section

    case "Decline":
     if(!String.IsNullOrEmpty(WorkflowDeclineComment1.Text))
       {
           content.SetMetaData("WorkflowDeclineComment1", WorkflowDeclineComment1.Text);
           newsManager.Content.SavedStagedContent(content, ContentStatus.Published);
           break;
       }
       break;


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    12 Jan 2010
    Link to this post
    Hi Ivan.

    I was able to get that to work. We wanted to make sure that if they click "Decline" that it was mandatory for the user to enter a comment before the decline process was kicked off similar to field validation. Is that actually possible?

    Thanks again. It must be late there.... night shift?
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2010
    Link to this post
    Hi Mike Boyle,

    You can use RequiredFieldValidator or client side validation to check whether there is any text in the Textbox control.

    sample client side validation

    function validate() {
             // get the control by id
             if (document.getElementById("<%=WorkflowDeclineComment1.ClientID%>").value == "") {
                 alert("Please enter a comment");
                 // call ToggleDiv - this will cause toggle("slow") effect
                 ToggleDiv();
                 return false;
             }
         }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    12 Jan 2010
    Link to this post
    Is there a way to only do this if "Decline" was clicked? We only want to force someone to enter comments if they are going to decline the item.

    Thanks.
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jan 2010
    Link to this post
    Hello Mike Boyle,

    In void workflowMenu_Command do not use "switch" block. You can use if clause

    if(commands[idx].CommandName == "Decline")


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    13 Jan 2010
    Link to this post
    Thanks for your help. I'll let you know if we have any more questions.
  15. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    13 Jan 2010
    Link to this post
    Hi Ivan.

    I was tempted to take one more stab at this. Really what I want to do is intercept the "Click" event of the decline button so the status will not change if comments are not provided.

    Is there any way we can get access to and/or customize the control that is displayed when approving/declining generic content?

    I am attaching a screenshot of the control I am actually looking to customize.

    Thanks.
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jan 2010
    Link to this post
    Hi Mike Boyle,

    You have to create a custom class that inherits from WorkflowMenu class and implement the new logic.

    1. You have to implement the TextBox in the class that derives from WorkflowMenu
    2. Override CreateChildControls
    3. You have to subscribe for the button.Command event and stop the EventActivity.Execute handler when the textbox is empty.
    4. You have to replace the built in WorkflowMenu control with the custom one in each ContentPreview template.

    sample code:

          protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
          {
              this.tb = new TextBox();
              Controls.Add(tb);
     
              if (dataBinding && dataSource != null)
              {
                  this.visible = 0;
                  IEnumerator e = dataSource.GetEnumerator();
                  if (e.MoveNext())
                  {
                      this.workflowInstanceId = (Guid)e.Current;
                      this.InitWorkflowRuntime();
                  }
              }
     
              for (int i = 0; i < this.count; i++)
              {
                  LinkButton btn = new LinkButton();
                  btn.CommandArgument = i.ToString();
                  btn.Attributes.Add("class", "CmsButLeft dark");
                  btn.Command += new CommandEventHandler(Button_Command);
                  this.Controls.Add(btn);
     
                  HtmlGenericControl strong = new HtmlGenericControl("strong");
                  strong.Attributes.Add("class", "CmsButRight dark");
                  btn.Controls.Add(strong);
     
                  if (dataBinding)
                  {
                      EventActivity ea = this.commands[i];
                      strong.InnerText = ea.Caption;
                      btn.Visible = ea.Parent.Status == ActivityExecutionStatus.Executing;
                      if (btn.Visible) this.visible++;
                  }
              }
              return this.count;
          }
     
          void Button_Command(object sender, CommandEventArgs e)
          {
              this.InitWorkflowRuntime();
              int idx = int.Parse((string)e.CommandArgument);
     
              if (this.commands.Count > idx)
              {
                       // HERE WE ARE CHECKING ONLY DECLINE ACTIVITY
                       // IF THERE IS NO TEXT FOR THE OTHER ACTIVITIES
                       // WE DO NOT DO ANYTHING
                  if (!(idx == 2 && String.IsNullOrEmpty(this.Tb.Text)))
                  {
                      this.commands[idx].Execute(WorkflowRuntime.Instance);
                  }
              }
     
              this.RequiresDataBinding = true;
              if (this.Command != null)
                  this.Command(this, e);
          }
     
     
    public TextBox Tb
          {
              get
              {
                  return this.tb;
              }
          }
     
     private TextBox tb;


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  17. Mike Boyle
    Mike Boyle avatar
    22 posts
    Registered:
    17 Dec 2009
    14 Jan 2010
    Link to this post
    Thanks so much for this. I believe this is what we were looking for.
Register for webinar
17 posts, 0 answered