Esempio n. 1
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "resubmitaction":
        case "processaction":
        case "cancelaction":
            ImageButton img = sender as CMSImageButton;
            if (img != null)
            {
                img.Enabled = modifyAllowed;

                GridViewRow gvr = parameter as GridViewRow;
                if (gvr != null)
                {
                    DataRowView drv = gvr.DataItem as DataRowView;
                    if (drv != null)
                    {
                        TranslationStatusEnum status = (TranslationStatusEnum)ValidationHelper.GetInteger(drv["SubmissionStatus"], 0);
                        switch (sourceName.ToLowerCSafe())
                        {
                        case "resubmitaction":
                            img.Enabled = modifyAllowed && (status == TranslationStatusEnum.WaitingForTranslation) || (status == TranslationStatusEnum.SubmissionError);
                            break;

                        case "processaction":
                            img.Enabled = modifyAllowed && (status == TranslationStatusEnum.TranslationReady) || (status == TranslationStatusEnum.TranslationCompleted) || (status == TranslationStatusEnum.ProcessingError);
                            break;

                        case "cancelaction":
                            img.Enabled = modifyAllowed && (status == TranslationStatusEnum.WaitingForTranslation);
                            break;
                        }
                    }
                }
            }
            return(img);

        case "submissionstatus":
            TranslationStatusEnum submissionstatus = (TranslationStatusEnum)ValidationHelper.GetInteger(parameter, 0);
            return(TranslationServiceHelper.GetFormattedStatusString(submissionstatus));

        case "submissionprice":
            string price    = GetString("general.notavailable");
            double priceVal = ValidationHelper.GetDouble(parameter, -1);
            if (priceVal >= 0)
            {
                price = priceVal.ToString();
            }
            return(price);
        }
        return(parameter);
    }
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // For all actions
        if (sourceName.EndsWith("action", StringComparison.OrdinalIgnoreCase))
        {
            var img = sender as CMSGridActionButton;
            if (img != null)
            {
                img.Enabled = !IsRunningThread();
            }
        }

        switch (sourceName.ToLowerInvariant())
        {
        case "resubmitaction":
        case "processaction":
        case "cancelaction":
            var img = sender as CMSGridActionButton;
            if (img != null)
            {
                img.Enabled &= modifyAllowed;

                var gvr = parameter as GridViewRow;
                if (gvr == null)
                {
                    return(img);
                }

                var drv = gvr.DataItem as DataRowView;
                if (drv == null)
                {
                    return(img);
                }

                var status = (TranslationStatusEnum)ValidationHelper.GetInteger(drv["SubmissionStatus"], 0);

                switch (sourceName.ToLowerInvariant())
                {
                case "resubmitaction":
                    img.Enabled &= modifyAllowed && ((status == TranslationStatusEnum.WaitingForTranslation) || (status == TranslationStatusEnum.SubmissionError));
                    break;

                case "processaction":
                    img.Enabled &= modifyAllowed && ((status == TranslationStatusEnum.TranslationReady) || (status == TranslationStatusEnum.TranslationCompleted) || (status == TranslationStatusEnum.ProcessingError));
                    break;

                case "cancelaction":
                    var service = TranslationServiceInfoProvider.GetTranslationServiceInfo(ValidationHelper.GetInteger(drv["SubmissionServiceID"], 0));
                    if (service != null)
                    {
                        bool serviceSupportsCancel = service.TranslationServiceSupportsCancel;

                        img.Enabled &= modifyAllowed && (status == TranslationStatusEnum.WaitingForTranslation) && serviceSupportsCancel;

                        if (!serviceSupportsCancel)
                        {
                            // Display tooltip for disabled cancel
                            img.ToolTip = String.Format(GetString("translationservice.cancelnotsupported"), service.TranslationServiceDisplayName);
                        }
                    }
                    break;
                }
            }
            return(img);

        case "submissionstatus":
            TranslationStatusEnum submissionstatus = (TranslationStatusEnum)ValidationHelper.GetInteger(parameter, 0);
            return(TranslationServiceHelper.GetFormattedStatusString(submissionstatus));

        case "submissionprice":
            string price    = GetString("general.notavailable");
            double priceVal = ValidationHelper.GetDouble(parameter, -1);
            if (priceVal >= 0)
            {
                price = priceVal.ToString();
            }
            return(price);

        case "submissiontargetculture":
        {
            string[] cultureCodes = ValidationHelper.GetString(parameter, "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            StringBuilder sb = new StringBuilder();

            int count   = cultureCodes.Length;
            int counter = 0;
            foreach (var cultureCode in cultureCodes)
            {
                // Limit cultures list
                if (counter == 5)
                {
                    sb.Append(" ");
                    sb.AppendFormat(ResHelper.GetString("translationservices.submissionnamesuffix"), count - 5);
                    break;
                }
                // Separate cultures by comma
                if (counter > 0)
                {
                    sb.Append(", ");
                }

                var culture = CultureInfoProvider.GetCultureInfo(cultureCode);
                if (culture == null)
                {
                    continue;
                }

                sb.AppendFormat("<span title=\"{0}\"><img class=\"cms-icon-80\" src=\"{1}\" alt=\"{2}\" />&nbsp;{3}</span>", HTMLHelper.EncodeForHtmlAttribute(culture.CultureName), UIHelper.GetFlagIconUrl(null, culture.CultureCode, "16x16"), HTMLHelper.EncodeForHtmlAttribute(culture.CultureName), HTMLHelper.HTMLEncode(culture.CultureShortName));
                ++counter;
            }

            return(sb.ToString());
        }
        }

        return(parameter);
    }
Esempio n. 3
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "resubmitaction":
        case "processaction":
        case "cancelaction":
            CMSGridActionButton img = sender as CMSGridActionButton;
            if (img != null)
            {
                img.Enabled = modifyAllowed;

                GridViewRow gvr = parameter as GridViewRow;
                if (gvr == null)
                {
                    return(img);
                }

                DataRowView drv = gvr.DataItem as DataRowView;
                if (drv == null)
                {
                    return(img);
                }

                TranslationStatusEnum status = (TranslationStatusEnum)ValidationHelper.GetInteger(drv["SubmissionStatus"], 0);
                switch (sourceName.ToLowerCSafe())
                {
                case "resubmitaction":
                    img.Enabled = modifyAllowed && ((status == TranslationStatusEnum.WaitingForTranslation) || (status == TranslationStatusEnum.SubmissionError));
                    break;

                case "processaction":
                    img.Enabled = modifyAllowed && ((status == TranslationStatusEnum.TranslationReady) || (status == TranslationStatusEnum.TranslationCompleted) || (status == TranslationStatusEnum.ProcessingError));
                    break;

                case "cancelaction":
                    TranslationServiceInfo service = TranslationServiceInfoProvider.GetTranslationServiceInfo(ValidationHelper.GetInteger(drv["SubmissionServiceID"], 0));
                    if (service != null)
                    {
                        bool serviceSupportsCancel = service.TranslationServiceSupportsCancel;

                        img.Enabled = modifyAllowed && (status == TranslationStatusEnum.WaitingForTranslation) && serviceSupportsCancel;

                        if (!serviceSupportsCancel)
                        {
                            // Display tooltip for disabled cancel
                            img.ToolTip = String.Format(GetString("translationservice.cancelnotsupported"), service.TranslationServiceDisplayName);
                        }
                    }
                    break;
                }
            }
            return(img);

        case "submissionstatus":
            TranslationStatusEnum submissionstatus = (TranslationStatusEnum)ValidationHelper.GetInteger(parameter, 0);
            return(TranslationServiceHelper.GetFormattedStatusString(submissionstatus));

        case "submissionprice":
            string price    = GetString("general.notavailable");
            double priceVal = ValidationHelper.GetDouble(parameter, -1);
            if (priceVal >= 0)
            {
                price = priceVal.ToString();
            }
            return(price);
        }
        return(parameter);
    }