Beispiel #1
0
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "lefnodename":
        case "rightnodename":
            var tr = new ObjectTransformation(PredefinedObjectType.NODE, ValidationHelper.GetInteger(parameter, 0));
            tr.EncodeOutput   = false;
            tr.Transformation = "{%Object.GetIcon()%} {%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
            return(tr);

        case "delete":
            var btn = ((CMSGridActionButton)sender);
            btn.PreRender += imgDelete_PreRender;
            break;

        // Hide ordering actions if relationship is not ad hoc and does not support ordering
        case "moveup":
        case "movedown":
        {
            var button = sender as CMSGridActionButton;
            if (button != null)
            {
                // Ordering is not supported for standard relationships. Available only for ad-hoc.
                button.Visible = IsAdHocRelationship;
            }
        }
        break;
        }

        return(parameter);
    }
    /// <summary>
    /// Gets the transformation to display object name
    /// </summary>
    /// <param name="parameter">Row parameter</param>
    /// <param name="left">If true, the object is served from the left object</param>
    protected ObjectTransformation GetDisplayTransformation(object parameter, bool left)
    {
        DataRowView data = (DataRowView)parameter;

        var colName          = (left ? "Left" : "Right");
        var objectTypeColumn = String.Format("Relationship{0}ObjectType", colName);
        var idColumn         = String.Format("Relationship{0}ObjectID", colName);

        string objectType = ValidationHelper.GetString(data[objectTypeColumn], "");
        int    objectId   = ValidationHelper.GetInteger(data[idColumn], 0);

        var tr = new ObjectTransformation(objectType, objectId);

        bool   identity = ((Object.ObjectType == objectType) && (Object.ObjectID == objectId));
        string format   = "{{% Object.GetFullObjectName(true, {0}) %}}";

        if (identity)
        {
            //format += " (this)";
        }

        tr.Transformation       = String.Format(format, (pnlSite.Visible && !identity ? "false" : "true"));
        tr.NoDataTransformation = GetString("General.NotFound");

        return(tr);
    }
Beispiel #3
0
    /// <summary>
    /// External data bound handler.
    /// </summary>
    protected object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView          discountRow  = parameter as DataRowView;
        MultiBuyDiscountInfo discountInfo = null;

        if (discountRow != null)
        {
            discountInfo = new MultiBuyDiscountInfo(discountRow.Row);
        }
        if (discountInfo == null)
        {
            return(String.Empty);
        }

        switch (sourceName.ToLowerCSafe())
        {
        case "status":
            // Ensure correct values for unigrid export
            if (sender == null)
            {
                return(discountInfo.Status.ToLocalizedString("com.discountstatus"));
            }

            return(new DiscountStatusTag(couponCountsDataProvider, discountInfo));

        case "application":
            // Display dash if discount don't use coupons
            if (!discountInfo.MultiBuyDiscountUsesCoupons)
            {
                return("&mdash;");
            }

            var tr = new ObjectTransformation("CouponsCounts", discountInfo.MultiBuyDiscountID)
            {
                DataProvider         = couponCountsDataProvider,
                Transformation       = "{% FormatString(GetResourceString(\"com.couponcode.appliedxofy\"), Convert.ToString(Uses, \"0\"), (UnlimitedCodeCount != 0)? GetResourceString(\"com.couponcode.unlimited\") : Convert.ToString(Limit, \"0\")) %}",
                NoDataTransformation = "{$com.discount.notcreated$}",
                EncodeOutput         = false
            };

            return(tr);

        case "discountpriority":
            // Ensure correct values for unigrid export
            if ((sender == null) || !ECommerceContext.IsUserAuthorizedToModifyDiscount())
            {
                return(discountInfo.MultiBuyDiscountPriority);
            }

            return(new PriorityInlineEdit
            {
                PrioritizableObject = discountInfo,
                Unigrid = Control
            });
        }

        return(parameter);
    }
Beispiel #4
0
    /// <summary>
    /// Unigrid external databound event handler.
    /// </summary>
    protected object UniGridSubscribers_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        string sourceNameUpper = sourceName.ToUpperInvariant();
        bool isContactSubscriber = false;
        var param = parameter as DataRowView;

        if (param != null)
        {
            isContactSubscriber = string.Equals(ValidationHelper.GetString(param["SubscriberType"], string.Empty), PredefinedObjectType.CONTACT, StringComparison.OrdinalIgnoreCase);
        }

        switch (sourceNameUpper)
        {
            case APPROVE:
                bool approved = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["SubscriptionApproved"], true);
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.Visible = !approved;
                break;

            case "STATUS":
                if (isContactSubscriber)
                {
                    var statusTransformation = new ObjectTransformation
                    {
                        ObjectType = "newsletter.subscribernewsletterlist",
                        ObjectID = ValidationHelper.GetInteger(((DataRowView)parameter)["SubscriberID"], 0),
                        DataProvider = mStatusDataProvider,
                        Transformation = "{% GetResourceString(\"emailmarketing.ui.\" + " + RecipientStatusCalculator.SUBSCRIPTION_STATUS + ") %}",
                        EncodeOutput = false
                    };

                    return statusTransformation;
                }

                return null;

            case "ISMARKETABLE":
                if (isContactSubscriber)
                {
                    var isMarketableTransformation = new ObjectTransformation
                    {
                        ObjectType = "newsletter.subscribernewsletterlist",
                        ObjectID = ValidationHelper.GetInteger(((DataRowView)parameter)["SubscriberID"], 0),
                        DataProvider = mStatusDataProvider,
                        Transformation = "<span class=\" {% (" + RecipientStatusCalculator.EMAIL_RECIPIENT_STATUS + " == \"Marketable\") ? \"tag tag-active\" : \"tag tag-incomplete\" %} \"> {% GetResourceString(\"emailmarketing.status.\" + " + RecipientStatusCalculator.EMAIL_RECIPIENT_STATUS + ") %} </span>",
                        EncodeOutput = false
                    };

                    return isMarketableTransformation;
                }

                return null;
        }

        return null;
    }
Beispiel #5
0
    /// <summary>
    /// Get the transformation to interpret task related object data.
    /// </summary>
    /// <param name="row">Grid row</param>
    /// <returns>Transformation that displays object identified by object type and ID.</returns>
    private object RenderRelatedObject(DataRowView row)
    {
        if (row == null)
        {
            return(String.Empty);
        }

        int    objectId    = ValidationHelper.GetInteger(row.Row["SearchTaskRelatedObjectID"], 0);
        string taskTypeRaw = ValidationHelper.GetString(row.Row["SearchTaskType"], "");

        SearchTaskTypeEnum taskType;
        string             objectType = null;


        // try to get search task type. Type doesn't have a default value.
        try
        {
            taskType = ValidationHelper.GetString(taskTypeRaw, "").ToEnum <SearchTaskTypeEnum>();
        }
        catch (Exception ex)
        {
            EventLogProvider.LogEvent(
                EventType.ERROR,
                "Smart search",
                "LISTSEARCHTASKS",
                "Unknown search task type: " + taskTypeRaw + ". Original exception:" + Environment.NewLine + EventLogProvider.GetExceptionLogMessage(ex)
                );

            return(String.Empty);
        }

        // Object type
        objectType = SearchTaskInfoProvider.GetSearchTaskRelatedObjectType(ValidationHelper.GetString(row.Row["SearchTaskObjectType"], ""), taskType);

        // Object cannot be interpreted
        if (String.IsNullOrEmpty(objectType) || (objectId == 0))
        {
            return(String.Empty);
        }

        // create transformation
        ObjectTransformation transformation = new ObjectTransformation(objectType, objectId);

        transformation.Transformation = String.Format("{{% Object.GetFullObjectName(false, true) %}}");

        ObjectTypeInfo typeInfo = ObjectTypeManager.GetTypeInfo(objectType);

        if (typeInfo != null)
        {
            transformation.NoDataTransformation = LocalizationHelper.GetStringFormat("smartsearch.searchtaskrelatedobjectnotexist", typeInfo.GetNiceObjectTypeName(), objectId);
        }

        return(transformation);
    }
    /// <summary>
    /// Renders the particular macro expression
    /// </summary>
    protected void RenderItem(MacroExpr expression)
    {
        var sb = new StringBuilder();

        sb.Append("<tr>");

        // Expression
        string exprTag = expression.RuleText ?? TextHelper.EnsureHTMLLineEndings(HTMLHelper.HTMLEncode(TextHelper.LimitLength(expression.Expression, 500)));

        sb.Append("<td class=\"wrap-normal\"><span class=\"MacroExpression\" title=\"", HTMLHelper.HTMLEncode(expression.Expression), "\">", exprTag, "</span></td>");

        // Syntax valid
        var errorText = UniGridFunctions.ColoredSpanYesNo(!expression.Error);

        if (!String.IsNullOrEmpty(expression.ErrorMessage))
        {
            errorText = String.Format("<span title=\"{0}\">{1}</span>", HTMLHelper.HTMLEncode(expression.ErrorMessage), errorText);
        }

        sb.Append("<td class=\"text-center\">", errorText, "</td>");

        // Signed by
        sb.Append("<td>", HTMLHelper.HTMLEncode(expression.SignedBy), "</td>");

        // Signature valid
        sb.Append("<td class=\"text-center\">", UniGridFunctions.ColoredSpanYesNo(expression.SignatureValid), "</td><td>");

        sb.Append();

        plcRows.Controls.Add(new LiteralControl(sb.ToString()));
        sb.Clear();

        // Object
        var tr = new ObjectTransformation(expression.ObjectType, expression.ObjectID)
        {
            UseEmptyInfoForObjectLimitedByLicense = true,
            Transformation = "{% Object.GetFullObjectName(true, true) %}"
        };

        plcRows.Controls.Add(tr);

        // Column
        //sb.Append(" (", expression.ObjectID, ")");
        sb.Append("</td><td>", expression.Field, "</td></tr>");

        plcRows.Controls.Add(new LiteralControl(sb.ToString()));
        sb.Clear();
    }
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerInvariant())
        {
        case "lefnodename":
        case "rightnodename":
            var tr = new ObjectTransformation(PredefinedObjectType.NODE, ValidationHelper.GetInteger(parameter, 0));
            tr.EncodeOutput   = false;
            tr.Transformation = "{%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
            return(tr);

        case "delete":
            var btn = ((CMSGridActionButton)sender);
            btn.PreRender += imgDelete_PreRender;
            break;
        }

        return(parameter);
    }
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        var objectTransformation = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);

        switch (trigger.TriggerObjectType)
        {
        case ScoreInfo.OBJECT_TYPE:
            objectTransformation.Transformation = string.Format(GetString("ma.trigger.scorereached.listing"), "{% DisplayName %}", trigger.TriggerParameters["ScoreValue"]);
            return(objectTransformation);

        case ActivityInfo.OBJECT_TYPE:
            if (trigger.TriggerTargetObjectID == 0)
            {
                return(GetString("ma.trigger.anyActivityPerformed"));
            }
            objectTransformation.Transformation = string.Format("{0} '{{% DisplayName %}}'", GetString("ma.trigger.performed"));
            return(objectTransformation);
        }
        return(null);
    }
Beispiel #9
0
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerInvariant())
        {
        case "lefnodename":
        case "rightnodename":
            string tooltip    = null;
            string customName = null;
            int    NodeID     = ValidationHelper.GetInteger(parameter, 0);
            var    NodeObj    = new DocumentQuery().WhereEquals("NodeID", NodeID).Columns("NodeID, NodeName, NodeLevel, ClassName").FirstOrDefault();
            // Not root and is in the allowed page types
            if (NodeObj.NodeLevel != 0 && (!string.IsNullOrWhiteSpace(ToolTipFormat) || !string.IsNullOrWhiteSpace(DisplayNameFormat)) && AllowedPageTypes.ToLower().Split(";,|".ToCharArray()).Contains(NodeObj.NodeClassName.ToLower()))
            {
                ValidationHelper.GetInteger(parameter, 0);
                MacroResolver NodeResolver = GetNodeMacroResolver(NodeObj.NodeID, NodeObj.ClassName);
                if (!string.IsNullOrWhiteSpace(ToolTipFormat))
                {
                    tooltip = NodeResolver.ResolveMacros(ToolTipFormat);
                }
                if (!string.IsNullOrWhiteSpace(DisplayNameFormat))
                {
                    customName = NodeResolver.ResolveMacros(DisplayNameFormat);
                }
                return(string.Format("<div title=\"{0}\">{1}</div>", HTMLHelper.EncodeForHtmlAttribute(tooltip), (!string.IsNullOrWhiteSpace(customName) ? customName : NodeObj.NodeName)));
            }
            else
            {
                var tr = new ObjectTransformation(PredefinedObjectType.NODE, NodeID);
                tr.EncodeOutput   = false;
                tr.Transformation = "{%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
                return(tr);
            }

        case "delete":
            var btn = ((CMSGridActionButton)sender);
            btn.PreRender += imgDelete_PreRender;
            break;
        }

        return(parameter);
    }
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        ObjectTransformation tr = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);
        string objectType       = GetString(TypeHelper.GetObjectTypeResourceKey(trigger.TriggerObjectType));

        switch (trigger.TriggerObjectType)
        {
        case PredefinedObjectType.SCORE:
            tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1} {2} '{3}'", objectType, GetString("ma.trigger.exceeded").ToLowerCSafe(), GetString("General.Value").ToLowerCSafe(), trigger.TriggerParameters["ScoreValue"]);
            return(tr);

        case PredefinedObjectType.ACTIVITY:
            if (trigger.TriggerTargetObjectID == 0)
            {
                return(GetString("ma.trigger.anyActivityPerformed"));
            }
            tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1}", objectType, GetString("ma.trigger.performed").ToLowerCSafe());
            return(tr);
        }
        return(null);
    }
Beispiel #11
0
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        ObjectTransformation tr = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);
        string objectType       = ScriptHelper.GetLocalizedString(TypeHelper.GetObjectTypeResourceKey(trigger.TriggerObjectType), false);

        switch (trigger.TriggerObjectType)
        {
        case ScoreInfo.OBJECT_TYPE:
            tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1} {2} '{3}'", objectType, ScriptHelper.GetLocalizedString("ma.trigger.exceeded", false).ToLowerCSafe(), ScriptHelper.GetLocalizedString("General.Value", false).ToLowerCSafe(), trigger.TriggerParameters["ScoreValue"]);
            return(tr);

        case ActivityInfo.OBJECT_TYPE:
            if (trigger.TriggerTargetObjectID == 0)
            {
                return(GetString("ma.trigger.anyActivityPerformed"));
            }
            tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1}", objectType, ScriptHelper.GetLocalizedString("ma.trigger.performed", false).ToLowerCSafe());
            return(tr);
        }
        return(null);
    }
Beispiel #12
0
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        sourceName = sourceName.ToLowerInvariant();
        switch (sourceName)
        {
        case "rollback":
        {
            CMSGridActionButton imgRollback = ((CMSGridActionButton)sender);
            int versionId = ValidationHelper.GetInteger(imgRollback.CommandArgument, 0);
            if (!WorkflowManager.CheckStepPermissions(Node, WorkflowActionEnum.Approve) || !CanModify || (CheckedOutByAnotherUser && !CanCheckIn) || (versionId == Node.DocumentCheckedOutVersionHistoryID))
            {
                imgRollback.Enabled = false;
            }
        }
        break;

        case "allowdestroy":
        {
            CMSGridActionButton imgDestroy = ((CMSGridActionButton)sender);
            int versionId = ValidationHelper.GetInteger(imgDestroy.CommandArgument, 0);
            if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn) || (versionId == Node.DocumentCheckedOutVersionHistoryID))
            {
                imgDestroy.Enabled = false;
            }
        }
        break;

        case "modifiedwhenby":
            DataRowView data         = (DataRowView)parameter;
            DateTime    modifiedwhen = ValidationHelper.GetDateTime(data["ModifiedWhen"], DateTimeHelper.ZERO_TIME);
            int         userId       = ValidationHelper.GetInteger(data["ModifiedByUserID"], 0);

            var tr = new ObjectTransformation("cms.user", userId);
            tr.EncodeOutput   = false;
            tr.Transformation = string.Format("{0} <br /> {{% Object.GetFormattedUserName()|(encode) %}}", UniGridFunctions.UserDateTimeGMT(modifiedwhen));
            return(tr);
        }

        return(parameter);
    }
    /// <summary>
    /// Returns subscriber's e-mail address.
    /// </summary>
    private object GetEmail(DataRowView rowView)
    {
        // Try to get subscriber email
        string email = ValidationHelper.GetString(rowView.Row["SubscriberEmail"], string.Empty);

        if (string.IsNullOrEmpty(email))
        {
            // Try to get user email
            email = ValidationHelper.GetString(rowView.Row["Email"], string.Empty);
        }

        if (string.IsNullOrEmpty(email) && ValidationHelper.GetString(rowView.Row["SubscriberType"], string.Empty).EqualsCSafe(PredefinedObjectType.CONTACT))
        {
            // Add the field transformation control that handles the translation
            var tr = new ObjectTransformation("om.contact", ValidationHelper.GetInteger(rowView.Row["SubscriberRelatedID"], 0));
            tr.Transformation = "ContactEmail";

            return(tr);
        }

        return(email);
    }
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerInvariant())
        {
        case "lefnodename":
        case "rightnodename":
            var tr = new ObjectTransformation(PredefinedObjectType.NODE, ValidationHelper.GetInteger(parameter, 0));
            tr.EncodeOutput   = false;
            tr.Transformation = "{%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
            return(tr);

        case "delete":
            var btn = ((CMSGridActionButton)sender);
            btn.PreRender += imgDelete_PreRender;
            break;

        case "preview":
            var btnPreview = ((CMSGridActionButton)sender);
            btnPreview.CausesValidation = false;
            btnPreview.OnClientClick    = "var win = window.open('/Admin/CMSAdministration.aspx?action=edit&nodeid=" + btnPreview.CommandArgument + "&culture=en-US#95a82f36-9c40-45f0-86f1-39aa44db9a77', '_blank'); win.focus(); return false; return;";
            break;

        // Hide ordering actions if relationship is not ad hoc and does not support ordering
        case "moveup":
        case "movedown":
        {
            var button = sender as CMSGridActionButton;
            if (button != null)
            {
                // Ordering is not supported for standard relationships. Available only for ad-hoc.
                button.Visible = IsAdHocRelationship;
            }
        }
        break;
        }

        return(parameter);
    }
    protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = null;

        if (parameter is DataRowView)
        {
            row = (DataRowView)parameter;
        }
        int subscriberId = 0;

        switch (sourceName)
        {
        case "name":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            string name = null;
            if (subscriberId == 0)
            {
                // Get full name for contact group member (contact)
                name = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberFullName"), string.Empty);

                // Return encoded name
                return(HTMLHelper.HTMLEncode(name));
            }
            else
            {
                // Add the field transformation control that handles the translation
                var tr = new ObjectTransformation("newsletter.subscriber", subscriberId);
                tr.Transformation = "SubscriberFullName";

                return(tr);
            }

        case "email":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            string email = null;
            if (subscriberId == 0)
            {
                // Get email for contact group member (contact)
                email = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberEmail"), string.Empty);
            }
            else
            {
                SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
                if (subscriber != null)
                {
                    if (subscriber.SubscriberType == null)
                    {
                        // Get email for classic subscriber
                        email = subscriber.SubscriberEmail;
                    }
                    else
                    {
                        switch (subscriber.SubscriberType)
                        {
                        case PredefinedObjectType.USER:
                            UserInfo user = UserInfoProvider.GetUserInfo(subscriber.SubscriberRelatedID);
                            if (user != null)
                            {
                                // Get email for user subscriber
                                email = user.Email;
                            }
                            break;

                        case PredefinedObjectType.CONTACT:
                            DataSet ds = ModuleCommands.OnlineMarketingGetContactForNewsletters(subscriber.SubscriberRelatedID, "ContactEmail");
                            if (!DataHelper.DataSourceIsEmpty(ds))
                            {
                                // Get email from contact subscriber
                                email = ValidationHelper.GetString(ds.Tables[0].Rows[0]["ContactEmail"], string.Empty);
                            }
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(email))
            {
                // Return encoded email
                email = HTMLHelper.HTMLEncode(email);
            }

            return(email);

        case "variantname":
            if (!isMainABTestIssue)
            {
                return(null);
            }

            IssueInfo issue       = IssueInfoProvider.GetIssueInfo(ValidationHelper.GetInteger(parameter, 0));
            string    variantName = null;

            if (issue != null)
            {
                if (!issue.IssueIsVariant)
                {
                    // Get varinat name from the winner issue
                    if (winnerIssue == null)
                    {
                        ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
                        if (test != null)
                        {
                            // Get A/B test winner variant
                            winnerIssue = IssueInfoProvider.GetIssueInfo(test.TestWinnerIssueID);
                        }
                    }

                    if (winnerIssue != null)
                    {
                        // Get variant name
                        variantName = winnerIssue.IssueVariantName;
                    }
                }
                else
                {
                    // Get variant name
                    variantName = issue.IssueVariantName;
                }
            }

            return(variantName);

        default:
            return(parameter);
        }
    }
    protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = null;
        if (parameter is DataRowView)
        {
            row = (DataRowView)parameter;
        }
        int subscriberId = 0;

        switch (sourceName)
        {
            case "name":
                subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
                string name = null;
                if (subscriberId == 0)
                {
                    // Get full name for contact group member (contact)
                    name = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberFullName"), string.Empty);

                    // Return encoded name
                    return HTMLHelper.HTMLEncode(name);
                }
                else
                {
                    // Add the field transformation control that handles the translation
                    var tr = new ObjectTransformation("newsletter.subscriber", subscriberId);
                    tr.Transformation = "SubscriberFullName";

                    return tr;
                }

            case "email":
                subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
                string email = null;
                if (subscriberId == 0)
                {
                    // Get email for contact group member (contact)
                    email = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberEmail"), string.Empty);
                }
                else
                {
                    SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
                    if (subscriber != null)
                    {
                        if (subscriber.SubscriberType == null)
                        {
                            // Get email for classic subscriber
                            email = subscriber.SubscriberEmail;
                        }
                        else
                        {
                            switch (subscriber.SubscriberType)
                            {
                                case UserInfo.OBJECT_TYPE:
                                    UserInfo user = UserInfoProvider.GetUserInfo(subscriber.SubscriberRelatedID);
                                    if (user != null)
                                    {
                                        // Get email for user subscriber
                                        email = user.Email;
                                    }
                                    break;
                                case PredefinedObjectType.CONTACT:
                                    DataSet ds = ModuleCommands.OnlineMarketingGetContactForNewsletters(subscriber.SubscriberRelatedID, "ContactEmail");
                                    if (!DataHelper.DataSourceIsEmpty(ds))
                                    {
                                        // Get email from contact subscriber
                                        email = ValidationHelper.GetString(ds.Tables[0].Rows[0]["ContactEmail"], string.Empty);
                                    }
                                    break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(email))
                {
                    // Return encoded email
                    email = HTMLHelper.HTMLEncode(email);
                }

                return email;

            case "variantname":
                if (!isMainABTestIssue)
                {
                    return null;
                }

                IssueInfo issue = IssueInfoProvider.GetIssueInfo(ValidationHelper.GetInteger(parameter, 0));
                string variantName = null;

                if (issue != null)
                {
                    if (!issue.IssueIsVariant)
                    {
                        // Get varinat name from the winner issue
                        if (winnerIssue == null)
                        {
                            ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
                            if (test != null)
                            {
                                // Get A/B test winner variant
                                winnerIssue = IssueInfoProvider.GetIssueInfo(test.TestWinnerIssueID);
                            }
                        }

                        if (winnerIssue != null)
                        {
                            // Get variant name
                            variantName = winnerIssue.IssueVariantName;
                        }
                    }
                    else
                    {
                        // Get variant name
                        variantName = issue.IssueVariantName;
                    }
                }

                return variantName;

            default:
                return parameter;
        }
    }
    /// <summary>
    /// Gets the transformation to display object name
    /// </summary>
    /// <param name="parameter">Row parameter</param>
    /// <param name="left">If true, the object is served from the left object</param>
    protected ObjectTransformation GetDisplayTransformation(object parameter, bool left)
    {
        DataRowView data = (DataRowView)parameter;

        var colName = (left ? "Left" : "Right");
        var objectTypeColumn = String.Format("Relationship{0}ObjectType", colName);
        var idColumn = String.Format("Relationship{0}ObjectID", colName);

        string objectType = ValidationHelper.GetString(data[objectTypeColumn], "");
        int objectId = ValidationHelper.GetInteger(data[idColumn], 0);

        var tr = new ObjectTransformation(objectType, objectId);

        bool identity = ((Object.TypeInfo.ObjectType == objectType) && (Object.ObjectID == objectId));
        string format = "{{% Object.GetFullObjectName(true, {0}) %}}";
        if (identity)
        {
            //format += " (this)";
        }

        tr.Transformation = String.Format(format, (pnlSite.Visible && !identity ? "false" : "true"));
        tr.NoDataTransformation = GetString("General.NotFound");

        return tr;
    }
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
            case "lefnodename":
            case "rightnodename":
                var tr = new ObjectTransformation(PredefinedObjectType.NODE, ValidationHelper.GetInteger(parameter, 0));
                tr.EncodeOutput = false;
                tr.Transformation = "{%Object.GetIcon()%} {%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
                return tr;

            case "delete":
                CMSGridActionButton btn = ((CMSGridActionButton)sender);
                btn.PreRender += imgDelete_PreRender;
                break;
        }

        return parameter;
    }
    object categoryGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        OptionCategoryInfo category;

        // Formatting columns
        switch (sourceName.ToLowerCSafe())
        {
        case "categorydisplayname":
            category = OptionCategoryInfo.Provider.Get(ValidationHelper.GetInteger(parameter, 0));
            return(HTMLHelper.HTMLEncode(category.CategoryFullName));

        case "categorytype":
            return(EnumStringRepresentationExtensions.ToEnum <OptionCategoryTypeEnum>(ValidationHelper.GetString(parameter, "")).ToLocalizedString("com.optioncategorytype"));

        case "optionscounts":
            category = OptionCategoryInfo.Provider.Get(ValidationHelper.GetInteger(parameter, 0));

            if (category.CategoryType != OptionCategoryTypeEnum.Text)
            {
                var tr = new ObjectTransformation("OptionsCounts", category.CategoryID)
                {
                    DataProvider         = countsDataProvider,
                    Transformation       = "{% if(AllowAllOptions) { GetResourceString(\"general.all\") } else { FormatString(GetResourceString(\"com.ProductOptions.availableXOfY\"), SelectedOptions, AllOptions) } %}",
                    NoDataTransformation = "{$com.productoptions.nooptions$}",
                    EncodeOutput         = false
                };

                return(tr);
            }

            return("");

        case "edititem":
            category = new OptionCategoryInfo(((DataRowView)((GridViewRow)parameter).DataItem).Row);

            CMSGridActionButton btn = sender as CMSGridActionButton;

            // Disable edit button if category is global and global categories are NOT allowed
            if (btn != null)
            {
                if (!allowedGlobalCat && category.IsGlobal)
                {
                    btn.Enabled = false;
                }

                var    query       = QueryHelper.BuildQuery("siteId", category.CategorySiteID.ToString(), "productId", ProductID.ToString());
                string redirectUrl = ApplicationUrlHelper.GetElementDialogUrl(ModuleName.ECOMMERCE, "EditProductOptionCategory", category.CategoryID, query);
                btn.OnClientClick = "modalDialog('" + redirectUrl + "','categoryEdit', '1000', '800');";
            }
            break;

        case "selectoptions":
            category = new OptionCategoryInfo(((DataRowView)((GridViewRow)parameter).DataItem).Row);

            CMSGridActionButton btnSelect = sender as CMSGridActionButton;

            if (btnSelect != null)
            {
                // Disable select button if category is type of Text
                if (category.CategoryType == OptionCategoryTypeEnum.Text)
                {
                    btnSelect.Enabled = false;
                }
                else
                {
                    var query = QueryHelper.BuildQuery("productId", ProductID.ToString());
                    // URL of allowed option selector pop-up
                    string urlSelect = ApplicationUrlHelper.GetElementDialogUrl(ModuleName.ECOMMERCE, "ProductOptions.SelectOptions", category.CategoryID, query);

                    // Open allowed options selection dialog
                    btnSelect.OnClientClick = ScriptHelper.GetModalDialogScript(urlSelect, "selectoptions", 1000, 650);
                }
            }
            break;
        }

        return(parameter);
    }
    /// <summary>
    /// Returns subscriber's e-mail address.
    /// </summary>
    private object GetEmail(DataRowView rowView)
    {
        // Try to get subscriber email
        string email = ValidationHelper.GetString(rowView.Row["SubscriberEmail"], string.Empty);
        if (string.IsNullOrEmpty(email))
        {
            // Try to get user email
            email = ValidationHelper.GetString(rowView.Row["Email"], string.Empty);
        }

        if (string.IsNullOrEmpty(email) && ValidationHelper.GetString(rowView.Row["SubscriberType"], string.Empty).EqualsCSafe(PredefinedObjectType.CONTACT))
        {
            // Add the field transformation control that handles the translation
            var tr = new ObjectTransformation("om.contact", ValidationHelper.GetInteger(rowView.Row["SubscriberRelatedID"], 0));
            tr.Transformation = "ContactEmail";

            return tr;
        }

        return email;
    }
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        ObjectTransformation tr = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);
        string objectType = ScriptHelper.GetLocalizedString(TypeHelper.GetObjectTypeResourceKey(trigger.TriggerObjectType), false);
        switch (trigger.TriggerObjectType)
        {
            case ScoreInfo.OBJECT_TYPE:
                tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1} {2} '{3}'", objectType, ScriptHelper.GetLocalizedString("ma.trigger.exceeded", false).ToLowerCSafe(), ScriptHelper.GetLocalizedString("General.Value", false).ToLowerCSafe(), trigger.TriggerParameters["ScoreValue"]);
                return tr;

            case ActivityInfo.OBJECT_TYPE:
                if (trigger.TriggerTargetObjectID == 0)
                {
                    return GetString("ma.trigger.anyActivityPerformed");
                }
                tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1}", objectType, ScriptHelper.GetLocalizedString("ma.trigger.performed", false).ToLowerCSafe());
                return tr;
        }
        return null;
    }
    /// <summary>
    /// Binds the grid columns.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
            case "lefnodename":
            case "rightnodename":
                var tr = new ObjectTransformation(PredefinedObjectType.NODE, ValidationHelper.GetInteger(parameter, 0));
                tr.EncodeOutput = false;
                tr.Transformation = "{%Object.GetIcon()%} {%NodeName|(default)" + GetString("general.root") + "|(encode)%}";
                return tr;

            case "delete":
                var btn = ((CMSGridActionButton)sender);
                btn.PreRender += imgDelete_PreRender;
                break;
            // Hide ordering actions if relationship is not ad hoc and does not support ordering
            case "moveup":
            case "movedown":
                {
                    var button = sender as CMSGridActionButton;
                    if (button != null)
                    {
                        // Ordering is not supported for standard relationships. Available only for ad-hoc.
                        button.Visible = IsAdHocRelationship;
                    }
                }
                break;
        }

        return parameter;
    }
    /// <summary>
    /// Renders the particular macro expression
    /// </summary>
    protected void RenderItem(MacroExpr expression)
    {
        var sb = new StringBuilder();

        sb.Append("<tr>");

        // Expression
        string exprTag = expression.RuleText ?? TextHelper.EnsureHTMLLineEndings(HTMLHelper.HTMLEncode(TextHelper.LimitLength(expression.Expression, 500)));

        sb.Append("<td class=\"wrap-normal\"><span class=\"MacroExpression\" title=\"", HTMLHelper.HTMLEncode(expression.Expression), "\">", exprTag, "</span></td>");

        // Syntax valid
        var errorText = UniGridFunctions.ColoredSpanYesNo(!expression.Error);
        if (!String.IsNullOrEmpty(expression.ErrorMessage))
        {
            errorText = String.Format("<span title=\"{0}\">{1}</span>", HTMLHelper.HTMLEncode(expression.ErrorMessage), errorText);
        }

        sb.Append("<td class=\"text-center\">", errorText, "</td>");

        // Signed by
        sb.Append("<td>", HTMLHelper.HTMLEncode(expression.SignedBy), "</td>");

        // Signature valid
        sb.Append("<td class=\"text-center\">", UniGridFunctions.ColoredSpanYesNo(expression.SignatureValid), "</td><td>");

        sb.Append();

        plcRows.Controls.Add(new LiteralControl(sb.ToString()));
        sb.Clear();

        // Object
        var tr = new ObjectTransformation(expression.ObjectType, expression.ObjectID)
        {
            UseEmptyInfoForObjectLimitedByLicense = true,
            Transformation = "{% Object.GetFullObjectName(true, true) %}"
        };

        plcRows.Controls.Add(tr);

        // Column
        //sb.Append(" (", expression.ObjectID, ")");
        sb.Append("</td><td>", expression.Field, "</td></tr>");

        plcRows.Controls.Add(new LiteralControl(sb.ToString()));
        sb.Clear();
    }
Beispiel #24
0
    protected object ugDiscounts_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView  discountRow  = parameter as DataRowView;
        DiscountInfo discountInfo = null;

        if (discountRow != null)
        {
            discountInfo = new DiscountInfo(discountRow.Row);
        }

        switch (sourceName.ToLowerCSafe())
        {
        // Append to a value field char '%' or site currency in case of flat discount
        case "value":
            if ((DiscountType == DiscountApplicationEnum.Shipping) && (!discountInfo.DiscountIsFlat) && (discountInfo.DiscountValue == 100))
            {
                return(GetString("general.free"));
            }

            return((discountInfo.DiscountIsFlat) ? CurrencyInfoProvider.GetFormattedPrice(discountInfo.DiscountValue, discountInfo.DiscountSiteID) : discountInfo.DiscountValue + "%");

        // Display discount status
        case "status":
            return(discountInfo.DiscountStatus.ToLocalizedString("com.discountstatus"));

        case "discountorder":
            // Ensure correct values for unigrid export
            if (sender == null)
            {
                return(discountInfo.DiscountOrder);
            }
            else
            {
                InlineEditingTextBox txtDiscountOrder = new InlineEditingTextBox();
                txtDiscountOrder.Text = discountInfo.DiscountOrder.ToString();

                txtDiscountOrder.Update += (s, e) =>
                {
                    CheckModifyPermission();

                    // Discount order must be double number
                    double order = ValidationHelper.GetDouble(txtDiscountOrder.Text, -1);

                    // Update price if new value is valid, must be higher or equal 1
                    if (order >= 1)
                    {
                        discountInfo.DiscountOrder = order;
                        discountInfo.MakeComplete(true);
                        discountInfo.Update();

                        ugDiscounts.ReloadData();
                    }
                    else
                    {
                        txtDiscountOrder.ErrorText = GetString("com.discountedit.weightinvalid");
                    }
                };

                return(txtDiscountOrder);
            }

        case "application":

            // Display blank value if discount don't use coupons
            if ((discountInfo == null) || !discountInfo.DiscountUsesCoupons)
            {
                return(String.Empty);
            }

            var tr = new ObjectTransformation("CouponsCounts", discountInfo.DiscountID)
            {
                DataProvider         = couponCountsDataProvider,
                Transformation       = "{% FormatString(GetResourceString(\"com.couponcode.appliedxofy\"), Convert.ToString(Uses, \"0\"), (UnlimitedCodeCount != 0)? GetResourceString(\"com.couponcode.unlimited\") : Convert.ToString(Limit, \"0\")) %}",
                NoDataTransformation = "{$com.discount.notcreated$}",
                EncodeOutput         = false
            };

            return(tr);

        case "orderamount":
            double totalPriceInMainCurrency = ValidationHelper.GetDouble(discountInfo.DiscountItemMinOrderAmount, 0);

            // Display blank value in the discount listing if order amount is not configured
            if (totalPriceInMainCurrency == 0)
            {
                return(string.Empty);
            }
            // Format currency
            string priceInMainCurrencyFormatted = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, SiteContext.CurrentSiteID);

            return(HTMLHelper.HTMLEncode(priceInMainCurrencyFormatted));
        }

        return(parameter);
    }
    protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = (DataRowView)parameter;
        int subscriberId = 0;

        switch (sourceName)
        {
            case "name":
                subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
                string name = null;
                if (subscriberId == 0)
                {
                    // Get full name for contact group member (contact)
                    name = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberFullName"), string.Empty);

                    // Return encoded name
                    return HTMLHelper.HTMLEncode(name);
                }
                else
                {
                    // Add the field transformation control that handles the translation
                    var tr = new ObjectTransformation("newsletter.subscriber", subscriberId);
                    tr.Transformation = "SubscriberFullName";

                    return tr;
                }

            case "email":
                subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
                string email = null;
                if (subscriberId == 0)
                {
                    // Get email for contact group member (contact)
                    email = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberEmail"), string.Empty);
                }
                else
                {
                    SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
                    if (subscriber != null)
                    {
                        if (subscriber.SubscriberType == null)
                        {
                            // Get email for classic subscriber
                            email = subscriber.SubscriberEmail;
                        }
                        else
                        {
                            switch (subscriber.SubscriberType)
                            {
                                case PredefinedObjectType.USER:
                                    UserInfo user = UserInfoProvider.GetUserInfo(subscriber.SubscriberRelatedID);
                                    if (user != null)
                                    {
                                        // Get email for user subscriber
                                        email = user.Email;
                                    }
                                    break;
                                case PredefinedObjectType.CONTACT:
                                    DataSet ds = ModuleCommands.OnlineMarketingGetContactForNewsletters(subscriber.SubscriberRelatedID, "ContactEmail");
                                    if (!DataHelper.DataSourceIsEmpty(ds))
                                    {
                                        // Get email from contact subscriber
                                        email = ValidationHelper.GetString(ds.Tables[0].Rows[0]["ContactEmail"], string.Empty);
                                    }
                                    break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(email))
                {
                    // Return encoded email
                    email = HTMLHelper.HTMLEncode(email);
                }

                return email;

            default:
                return parameter;
        }
    }
    protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = (DataRowView)parameter;
        int         subscriberId;

        switch (sourceName)
        {
        case "name":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            if (subscriberId == 0)
            {
                // Get full name for contact group member (contact)
                string name = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberFullName"), string.Empty);

                // Return encoded name
                return(HTMLHelper.HTMLEncode(name));
            }
            else
            {
                // Add the field transformation control that handles the translation
                var tr = new ObjectTransformation("newsletter.subscriber", subscriberId);
                tr.Transformation = "SubscriberFullName";

                return(tr);
            }

        case "email":
            subscriberId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(row.Row, "SubscriberID"), 0);
            string email = null;
            if (subscriberId == 0)
            {
                // Get email for contact group member (contact)
                email = ValidationHelper.GetString(DataHelper.GetDataRowValue(row.Row, "SubscriberEmail"), string.Empty);
            }
            else
            {
                SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
                if (subscriber != null)
                {
                    if (subscriber.SubscriberType == null)
                    {
                        // Get email for classic subscriber
                        email = subscriber.SubscriberEmail;
                    }
                    else
                    {
                        switch (subscriber.SubscriberType)
                        {
                        case UserInfo.OBJECT_TYPE:
                            UserInfo user = UserInfoProvider.GetUserInfo(subscriber.SubscriberRelatedID);
                            if (user != null)
                            {
                                // Get email for user subscriber
                                email = user.Email;
                            }
                            break;

                        case PredefinedObjectType.CONTACT:
                            DataSet ds = ModuleCommands.OnlineMarketingGetContactForNewsletters(subscriber.SubscriberRelatedID, "ContactEmail");
                            if (!DataHelper.DataSourceIsEmpty(ds))
                            {
                                // Get email from contact subscriber
                                email = ValidationHelper.GetString(ds.Tables[0].Rows[0]["ContactEmail"], string.Empty);
                            }
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(email))
            {
                // Return encoded email
                email = HTMLHelper.HTMLEncode(email);
            }

            return(email);

        default:
            return(parameter);
        }
    }
    protected object ugDiscounts_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView  discountRow  = parameter as DataRowView;
        DiscountInfo discountInfo = null;

        if (discountRow != null)
        {
            discountInfo = new DiscountInfo(discountRow.Row);
        }
        if (discountInfo == null)
        {
            return(String.Empty);
        }

        switch (sourceName.ToLowerCSafe())
        {
        // Append to a value field char '%' or site currency in case of flat discount
        case "value":
            if ((DiscountType == DiscountApplicationEnum.Shipping) && (!discountInfo.DiscountIsFlat) && (discountInfo.DiscountValue == 100))
            {
                return(GetString("general.free"));
            }

            return((discountInfo.DiscountIsFlat) ? CurrencyInfoProvider.GetFormattedPrice(discountInfo.DiscountValue, discountInfo.DiscountSiteID) : discountInfo.DiscountValue + "%");

        // Display discount status
        case "status":
            // Ensure correct values for unigrid export
            if (sender == null)
            {
                return(discountInfo.DiscountStatus.ToLocalizedString("com.discountstatus"));
            }
            return(new DiscountStatusTag(couponCountsDataProvider, discountInfo));

        case "discountorder":
            // Ensure correct values for unigrid export
            if ((sender == null) || !ECommerceContext.IsUserAuthorizedToModifyDiscount())
            {
                return(discountInfo.DiscountOrder);
            }

            return(new PriorityInlineEdit
            {
                PrioritizableObject = discountInfo,
                Unigrid = ugDiscounts
            });

        case "application":

            // Display blank value if discount don't use coupons
            if (!discountInfo.DiscountUsesCoupons)
            {
                return("&mdash;");
            }

            var tr = new ObjectTransformation("CouponsCounts", discountInfo.DiscountID)
            {
                DataProvider         = couponCountsDataProvider,
                Transformation       = "{% FormatString(GetResourceString(\"com.couponcode.appliedxofy\"), Convert.ToString(Uses, \"0\"), (UnlimitedCodeCount != 0)? GetResourceString(\"com.couponcode.unlimited\") : Convert.ToString(Limit, \"0\")) %}",
                NoDataTransformation = "{$com.discount.notcreated$}",
                EncodeOutput         = false
            };

            return(tr);

        case "orderamount":
            double totalPriceInMainCurrency = ValidationHelper.GetDouble(discountInfo.DiscountItemMinOrderAmount, 0);

            // Display blank value in the discount listing if order amount is not configured
            if (totalPriceInMainCurrency == 0)
            {
                return(string.Empty);
            }
            // Format currency
            string priceInMainCurrencyFormatted = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, SiteContext.CurrentSiteID);

            return(HTMLHelper.HTMLEncode(priceInMainCurrencyFormatted));
        }

        return(parameter);
    }
    protected object ugDiscounts_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView discountRow = parameter as DataRowView;
        DiscountInfo discountInfo = null;

        if (discountRow != null)
        {
            discountInfo = new DiscountInfo(discountRow.Row);
        }
        if (discountInfo == null)
        {
            return String.Empty;
        }

        switch (sourceName.ToLowerCSafe())
        {
            // Append to a value field char '%' or site currency in case of flat discount
            case "value":
                if ((DiscountType == DiscountApplicationEnum.Shipping) && (!discountInfo.DiscountIsFlat) && (discountInfo.DiscountValue == 100))
                {
                    return GetString("general.free");
                }

                return ((discountInfo.DiscountIsFlat) ? CurrencyInfoProvider.GetFormattedPrice(discountInfo.DiscountValue, discountInfo.DiscountSiteID) : discountInfo.DiscountValue + "%");

            // Display discount status
            case "status":
                return new DiscountStatusTag(couponCountsDataProvider, discountInfo);

            case "discountorder":
                // Ensure correct values for unigrid export
                if ((sender == null) || !ECommerceContext.IsUserAuthorizedToModifyDiscount())
                {
                    return discountInfo.DiscountOrder;
                }

                return new PriorityInlineEdit
                {
                    PrioritizableObject = discountInfo,
                    Unigrid = ugDiscounts
                };

            case "application":

                // Display blank value if discount don't use coupons
                if (!discountInfo.DiscountUsesCoupons)
                {
                    return "&mdash;";
                }

                var tr = new ObjectTransformation("CouponsCounts", discountInfo.DiscountID)
                {
                    DataProvider = couponCountsDataProvider,
                    Transformation = "{% FormatString(GetResourceString(\"com.couponcode.appliedxofy\"), Convert.ToString(Uses, \"0\"), (UnlimitedCodeCount != 0)? GetResourceString(\"com.couponcode.unlimited\") : Convert.ToString(Limit, \"0\")) %}",
                    NoDataTransformation = "{$com.discount.notcreated$}",
                    EncodeOutput = false
                };

                return tr;

            case "orderamount":
                double totalPriceInMainCurrency = ValidationHelper.GetDouble(discountInfo.DiscountItemMinOrderAmount, 0);

                // Display blank value in the discount listing if order amount is not configured
                if (totalPriceInMainCurrency == 0)
                {
                    return string.Empty;
                }
                // Format currency
                string priceInMainCurrencyFormatted = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, SiteContext.CurrentSiteID);

                return HTMLHelper.HTMLEncode(priceInMainCurrencyFormatted);
        }

        return parameter;
    }
    object categoryGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        OptionCategoryInfo category;

        // Formatting columns
        switch (sourceName.ToLowerCSafe())
        {
            case "categorydisplayname":
                category = OptionCategoryInfoProvider.GetOptionCategoryInfo(ValidationHelper.GetInteger(parameter, 0));
                return HTMLHelper.HTMLEncode(category.CategoryFullName);

            case "categorytype":
                return ValidationHelper.GetString(parameter, "").ToEnum<OptionCategoryTypeEnum>().ToLocalizedString("com.optioncategorytype");

            case "optionscounts":
                category = OptionCategoryInfoProvider.GetOptionCategoryInfo(ValidationHelper.GetInteger(parameter, 0));

                if (category.CategoryType != OptionCategoryTypeEnum.Text)
                {
                    var tr = new ObjectTransformation("OptionsCounts", category.CategoryID)
                    {
                        DataProvider = countsDataProvider,
                        Transformation = "{% if(AllowAllOptions) { GetResourceString(\"general.all\") } else { FormatString(GetResourceString(\"com.ProductOptions.availableXOfY\"), SelectedOptions, AllOptions) } %}",
                        NoDataTransformation = "{$com.productoptions.nooptions$}",
                        EncodeOutput = false
                    };

                    return tr;
                }

                return "";

            case "edititem":
                category = new OptionCategoryInfo(((DataRowView)((GridViewRow)parameter).DataItem).Row);

                CMSGridActionButton btn = sender as CMSGridActionButton;

                // Disable edit button if category is global and global categories are NOT allowed
                if (btn != null)
                {
                    if (!allowedGlobalCat && category.IsGlobal)
                    {
                        btn.Enabled = false;
                    }

                    var query = QueryHelper.BuildQuery("siteId", category.CategorySiteID.ToString(), "productId", ProductID.ToString());
                    string redirectUrl = UIContextHelper.GetElementDialogUrl("CMS.Ecommerce", "EditProductOptionCategory", category.CategoryID, query);
                    btn.OnClientClick = "modalDialog('" + redirectUrl + "','categoryEdit', '1000', '800');";
                }
                break;

            case "selectoptions":
                category = new OptionCategoryInfo(((DataRowView)((GridViewRow)parameter).DataItem).Row);

                CMSGridActionButton btnSelect = sender as CMSGridActionButton;

                if (btnSelect != null)
                {
                    // Disable select button if category is type of Text
                    if (category.CategoryType == OptionCategoryTypeEnum.Text)
                    {
                        btnSelect.Enabled = false;
                    }
                    else
                    {
                        var query = QueryHelper.BuildQuery("productId", ProductID.ToString());
                        // URL of allowed option selector pop-up
                        string urlSelect = UIContextHelper.GetElementDialogUrl("CMS.Ecommerce", "ProductOptions.SelectOptions", category.CategoryID, query);

                        // Open allowed options selection dialog
                        btnSelect.OnClientClick = ScriptHelper.GetModalDialogScript( urlSelect, "selectoptions", 1000, 650);
                    }
                }
                break;
        }

        return parameter;
    }
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        var objectTransformation = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);
        switch (trigger.TriggerObjectType)
        {
            case ScoreInfo.OBJECT_TYPE:
                objectTransformation.Transformation = string.Format(GetString("ma.trigger.scorereached.listing"), "{% DisplayName %}", trigger.TriggerParameters["ScoreValue"]);
                return objectTransformation;

            case ActivityInfo.OBJECT_TYPE:
                if (trigger.TriggerTargetObjectID == 0)
                {
                    return GetString("ma.trigger.anyActivityPerformed");
                }
                objectTransformation.Transformation = string.Format("{0} '{{% DisplayName %}}'", GetString("ma.trigger.performed"));
                return objectTransformation;
        }
        return null;
    }
    /// <summary>
    /// Returns transformation for trigger type.
    /// </summary>
    /// <param name="trigger">Trigger info object</param>
    private object GetTriggerDescription(ObjectWorkflowTriggerInfo trigger)
    {
        ObjectTransformation tr = new ObjectTransformation(trigger.TriggerTargetObjectType, trigger.TriggerTargetObjectID);
        string objectType = GetString(TypeHelper.GetObjectTypeResourceKey(trigger.TriggerObjectType));
        switch (trigger.TriggerObjectType)
        {
            case PredefinedObjectType.SCORE:
                tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1} {2} '{3}'", objectType, GetString("ma.trigger.exceeded").ToLowerCSafe(), GetString("General.Value").ToLowerCSafe(), trigger.TriggerParameters["ScoreValue"]);
                return tr;

            case PredefinedObjectType.ACTIVITY:
                if(trigger.TriggerTargetObjectID == 0)
                {
                    return GetString("ma.trigger.anyActivityPerformed");
                }
                tr.Transformation = string.Format("{0} '{{% DisplayName %}}' {1}", objectType, GetString("ma.trigger.performed").ToLowerCSafe());
                return tr;
        }
        return null;
    }