/// <summary>
    /// External history binding.
    /// </summary>
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView drv = null;

        switch (sourceName.ToLowerCSafe())
        {
        case "action":
            drv = (DataRowView)parameter;
            bool wasrejected = ValidationHelper.GetBoolean(drv["HistoryWasRejected"], false);

            // Get type of the steps
            WorkflowStepTypeEnum       stepType       = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "HistoryStepType"), 0);
            WorkflowStepTypeEnum       targetStepType = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "HistoryTargetStepType"), 0);
            WorkflowTransitionTypeEnum transitionType = (WorkflowTransitionTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "HistoryTransitionType"), 0);

            if (!wasrejected)
            {
                bool   isAutomatic  = (transitionType == WorkflowTransitionTypeEnum.Automatic);
                string actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") + " ({0})" : "{0}";
                // Return correct step title
                switch (targetStepType)
                {
                case WorkflowStepTypeEnum.Finished:
                    actionString = string.Format(actionString, GetString("ma.finished"));
                    break;

                default:
                    if (stepType == WorkflowStepTypeEnum.Start)
                    {
                        actionString = string.Format(actionString, GetString("ma.started"));
                    }
                    else
                    {
                        actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") : GetString("ma.movedtonextstep");
                    }
                    break;
                }

                return(actionString);
            }
            else
            {
                return(GetString("ma.movedtopreviousstep"));
            }

        case "stepname":
            drv = (DataRowView)parameter;
            string step       = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "HistoryStepDisplayName"), String.Empty);
            string targetStep = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "HistoryTargetStepDisplayName"), String.Empty);
            if (!string.IsNullOrEmpty(targetStep))
            {
                step += " -> " + targetStep;
            }
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(step)));
        }
        return(parameter);
    }
Exemplo n.º 2
0
    /// <summary>
    /// External history binding.
    /// </summary>
    protected object gridHistory_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView drv;

        switch (sourceName.ToLowerInvariant())
        {
        case "action":
            drv = (DataRowView)parameter;
            bool wasRejected = ValidationHelper.GetBoolean(drv["WasRejected"], false);

            // Get type of the steps
            WorkflowStepTypeEnum       stepType       = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "StepType"), 0);
            WorkflowStepTypeEnum       targetStepType = (WorkflowStepTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "TargetStepType"), (int)stepType);
            WorkflowTransitionTypeEnum transitionType = (WorkflowTransitionTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "HistoryTransitionType"), 0);

            // Get name of steps
            string stepName       = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "StepName"), String.Empty);
            string targetStepName = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "TargetStepName"), stepName);
            if (!wasRejected)
            {
                // If step type defined, use it for identification
                if (targetStepType != WorkflowStepTypeEnum.Undefined)
                {
                    bool   isAutomatic  = (transitionType == WorkflowTransitionTypeEnum.Automatic);
                    string actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") + " ({0})" : "{0}";
                    // Return correct step title
                    switch (targetStepType)
                    {
                    case WorkflowStepTypeEnum.DocumentArchived:
                        actionString = string.Format(actionString, GetString("WorfklowProperties.Archived"));
                        break;

                    case WorkflowStepTypeEnum.DocumentPublished:
                        actionString = string.Format(actionString, GetString("WorfklowProperties.Published"));
                        break;

                    case WorkflowStepTypeEnum.DocumentEdit:
                        actionString = GetString("WorfklowProperties.NewVersion");
                        break;

                    default:
                        if (stepType == WorkflowStepTypeEnum.DocumentEdit)
                        {
                            actionString = GetString("WorfklowProperties.NewVersion");
                        }
                        else
                        {
                            actionString = isAutomatic ? GetString("WorfklowProperties.Automatic") : GetString("WorfklowProperties.Approved");
                        }
                        break;
                    }

                    return(actionString);
                }
                // Backward compatibility
                else
                {
                    // Return correct step title
                    switch (targetStepName.ToLowerInvariant())
                    {
                    case "archived":
                        return(GetString("WorfklowProperties.Archived"));

                    case "published":
                        return(GetString("WorfklowProperties.Published"));

                    case "edit":
                        return(GetString("WorfklowProperties.NewVersion"));

                    default:
                        if (CMSString.Equals(stepName, "edit", true))
                        {
                            return(GetString("WorfklowProperties.NewVersion"));
                        }
                        return(GetString("WorfklowProperties.Approved"));
                    }
                }
            }
            else
            {
                return(GetString("WorfklowProperties.Rejected"));
            }

        // Get approved time
        case "approvedwhen":
        case "approvedwhentooltip":
            if (string.IsNullOrEmpty(parameter.ToString()))
            {
                return(string.Empty);
            }
            else
            {
                if (currentUserInfo == null)
                {
                    currentUserInfo = MembershipContext.AuthenticatedUser;
                }

                if (currentSiteInfo == null)
                {
                    currentSiteInfo = SiteContext.CurrentSite;
                }

                if (sourceName.EqualsCSafe("approvedwhen", StringComparison.InvariantCultureIgnoreCase))
                {
                    DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
                    return(TimeZoneHelper.ConvertToUserTimeZone(time, true, currentUserInfo, currentSiteInfo));
                }
                else
                {
                    return(TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo));
                }
            }

        case "stepname":
            drv = (DataRowView)parameter;
            string step       = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "StepDisplayName"), String.Empty);
            string targetStep = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "TargetStepDisplayName"), String.Empty);
            if (!string.IsNullOrEmpty(targetStep))
            {
                step += " -> " + targetStep;
            }
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(step)));
        }
        return(parameter);
    }