/// <summary>
    /// Creates buttons in header actions
    /// </summary>
    private void CreateButtons()
    {
        var updateAction = new HeaderAction
        {
            ButtonStyle = ButtonStyle.Default,
            CommandName = UPDATE_STATUSES_ACTION,
            Tooltip     = GetString("translationservice.updatestatusestooltip"),
            Text        = GetString("translationservice.updatestatuses"),
            Enabled     = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.TranslationServices", "Modify") && !Grid.IsEmpty
        };

        string translateUrl = ApplicationUrlHelper.ResolveDialogUrl("~/CMSModules/Translations/Pages/TranslateDocuments.aspx") + "?select=1&dialog=1";

        translateUrl = URLHelper.AddParameterToUrl(translateUrl, "hash", QueryHelper.GetHash(URLHelper.GetQuery(translateUrl)));

        // Check if any human translation is enabled
        bool enabled = TranslationServiceInfoProvider.GetTranslationServices("(TranslationServiceEnabled = 1) AND (TranslationServiceIsMachine = 0)", null, 0, "TranslationServiceID, TranslationServiceName").Any(t => TranslationServiceHelper.IsServiceAvailable(t.TranslationServiceName, SiteContext.CurrentSiteName));

        var submitAction = new HeaderAction
        {
            OnClientClick = "modalDialog('" + translateUrl + "', 'SubmitTranslation', 988, 640);",
            Tooltip       = GetString(enabled ? "translationservice.submittranslationtooltip" : "translationservice.noenabledservices"),
            Text          = GetString("translationservice.submittranslation"),
            Enabled       = enabled && MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Content", "SubmitForTranslation")
        };

        AddHeaderAction(submitAction);
        AddHeaderAction(updateAction);

        HeaderActions.ReloadData();
    }
Exemple #2
0
    /// <summary>
    /// Returns rendered panel with translation services
    /// </summary>
    public void RegisterTranslationServicesActions()
    {
        string currentSiteName = SiteContext.CurrentSiteName;

        if (TranslationServiceHelper.IsTranslationAllowed(currentSiteName))
        {
            string where = "TranslationServiceEnabled = 1 AND TranslationServiceIsMachine = 1";

            foreach (TranslationServiceInfo tsi in TranslationServiceInfoProvider.GetTranslationServices(where, "TranslationServiceDisplayName", 0, "TranslationServiceDisplayName, TranslationServiceName"))
            {
                AddTranslationControl(tsi, currentSiteName);
            }
        }
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        ScriptHelper.RegisterDialogScript(Page);

        HeaderAction updateAction = new HeaderAction
        {
            OnClientClick = ControlsHelper.GetPostBackEventReference(btnUpdateStatuses),
            Tooltip       = GetString("translationservice.updatestatusestooltip"),
            Text          = GetString("translationservice.updatestatuses"),
            Enabled       = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.TranslationServices", "Modify") && !listElem.Grid.IsEmpty
        };

        string translateUrl = AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Translations/Pages/TranslateDocuments.aspx") + "?select=1&dialog=1";

        translateUrl = URLHelper.AddParameterToUrl(translateUrl, "hash", QueryHelper.GetHash(URLHelper.GetQuery(translateUrl)));

        // Check if any human translation is enabled
        bool enabled = TranslationServiceInfoProvider.GetTranslationServices("(TranslationServiceEnabled = 1) AND (TranslationServiceIsMachine = 0)", null, 0, "TranslationServiceID, TranslationServiceName").Any(t => TranslationServiceHelper.IsServiceAvailable(t.TranslationServiceName, SiteContext.CurrentSiteName));

        HeaderAction submitAction = new HeaderAction
        {
            OnClientClick = "modalDialog('" + translateUrl + "', 'SubmitTranslation', 988, 634);",
            Tooltip       = GetString(enabled ? "translationservice.submittranslationtooltip" : "translationservice.noenabledservices"),
            Text          = GetString("translationservice.submittranslation"),
            Enabled       = enabled && MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Content", "SubmitForTranslation")
        };

        AddHeaderAction(submitAction);
        AddHeaderAction(updateAction);

        CurrentMaster.HeaderActions.ReloadData();

        if (!listElem.Grid.IsEmpty)
        {
            string statusCheck = SettingsKeyInfoProvider.GetStringValue("CMSTranslationsLastStatusCheck");
            if (string.IsNullOrEmpty(statusCheck))
            {
                statusCheck = GetString("general.notavailable");
            }

            ShowInformation(string.Format(GetString("translationservice.laststatuscheck"), statusCheck));
        }
    }
    /// <summary>
    /// Selects correct value.
    /// </summary>
    private void ReloadData()
    {
        string where = "TranslationServiceEnabled = 1";
        if (!DisplayMachineServices)
        {
            where += " AND TranslationServiceIsMachine = 0";
        }

        // Get services
        var data = TranslationServiceInfoProvider.GetTranslationServices(where, "TranslationServiceIsMachine DESC, TranslationServiceDisplayName ASC", 0, "TranslationServiceDisplayName, TranslationServiceName, TranslationServiceIsMachine, TranslationServiceSupportsPriority, TranslationServiceSupportsInstructions, TranslationServiceSupportsDeadline, TranslationServiceGenerateTargetTag");

        if (DataHelper.DataSourceIsEmpty(data))
        {
            return;
        }

        bool   allowBinary     = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSAllowAttachmentTranslation");
        string selected        = SelectedService;
        string lastDisplayName = null;

        int i = 0;

        string machSelectScript = null;

        ltlServices.Text += "<div class=\"radio-list-vertical\">";

        foreach (DataRow dr in data.Tables[0].Rows)
        {
            string codeName = ValidationHelper.GetString(dr["TranslationServiceName"], "");

            // Check availability
            if (!TranslationServiceHelper.IsServiceAvailable(codeName, SiteContext.CurrentSiteName))
            {
                continue;
            }

            if (string.IsNullOrEmpty(selected) && (i == 0))
            {
                selected = codeName;
            }

            bool   isMachine            = ValidationHelper.GetBoolean(dr["TranslationServiceIsMachine"], false);
            string displayName          = ValidationHelper.GetString(dr["TranslationServiceDisplayName"], "");
            bool   supportsInstructions = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsInstructions"], false);
            bool   supportsPriority     = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsPriority"], false);
            bool   supportsDeadline     = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsDeadline"], false);

            if (isMachine && !string.IsNullOrEmpty(MachineServiceSuffix))
            {
                displayName += MachineServiceSuffix;
            }

            string selectScript = string.Format("SelectService({0}, {1}, {2}, {3}, {4}, {5})", ScriptHelper.GetString(codeName), (!isMachine && DisplaySeparateSubmissionOption ? "true" : "false"), (supportsInstructions ? "true" : "false"), (supportsPriority ? "true" : "false"), (!isMachine && allowBinary ? "true" : "false"), (supportsDeadline ? "true" : "false"));

            bool isSelected = selected.Equals(codeName, StringComparison.CurrentCultureIgnoreCase);
            if (isSelected)
            {
                SelectedService = selected;
                if (string.IsNullOrEmpty(machSelectScript))
                {
                    machSelectScript = selectScript;
                }
            }

            string radioBtn = "<div class=\"radio\"><input id=\"rad" + codeName + "\" " + (isSelected ? "checked=\"checked\"" : "") + " type=\"radio\" name=\"services\" value=\"" + codeName + "\" onclick=\"" + selectScript + "\" />";
            radioBtn       += "<label for=\"rad" + codeName + "\">" + HTMLHelper.HTMLEncode(displayName) + "</label></div>";
            lastDisplayName = displayName;

            mAnyServiceAvailable = true;

            ltlServices.Text += radioBtn;
            i++;
        }

        ltlServices.Text += "</div>";

        // If only one service is available, display it in a different way
        if (i == 1)
        {
            DisplayedServiceName = lastDisplayName;
            ltlServices.Text     = DisplayOnlyServiceName ? "<strong>" + HTMLHelper.HTMLEncode(lastDisplayName) + "</strong>" : String.Empty;
        }

        if (!String.IsNullOrEmpty(machSelectScript))
        {
            // Register selection script for first service
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "TranslationServiceSelectorSelection", machSelectScript, true);
        }

        DisplayedServicesCount = i;
    }
    /// <summary>
    /// Selects correct value.
    /// </summary>
    private void ReloadData()
    {
        string where = "TranslationServiceEnabled = 1";
        if (!DisplayMachineServices)
        {
            where += " AND TranslationServiceIsMachine = 0";
        }

        bool allowBinary = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSAllowAttachmentTranslation");

        DataSet ds = TranslationServiceInfoProvider.GetTranslationServices(where, "TranslationServiceIsMachine DESC, TranslationServiceDisplayName ASC", 0, "TranslationServiceDisplayName, TranslationServiceName, TranslationServiceIsMachine, TranslationServiceSupportsPriority, TranslationServiceSupportsInstructions, TranslationServiceSupportsDeadline, TranslationServiceGenerateTargetTag");

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            string selected        = hdnSelectedName.Value;
            string lastDisplayName = null;

            int i     = 0;
            int count = ds.Tables[0].Rows.Count;

            string machSelectScript = null;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string codeName = ValidationHelper.GetString(dr["TranslationServiceName"], "");

                // Check availability
                if (TranslationServiceHelper.IsServiceAvailable(codeName, CMSContext.CurrentSiteName))
                {
                    if (string.IsNullOrEmpty(selected) && (i == 0))
                    {
                        selected = codeName;
                    }

                    bool   isMachine            = ValidationHelper.GetBoolean(dr["TranslationServiceIsMachine"], false);
                    string displayName          = ValidationHelper.GetString(dr["TranslationServiceDisplayName"], "");
                    bool   supportsInstructions = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsInstructions"], false);
                    bool   supportsPriority     = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsPriority"], false);
                    bool   supportsDeadline     = ValidationHelper.GetBoolean(dr["TranslationServiceSupportsDeadline"], false);
                    bool   generateTargetTag    = ValidationHelper.GetBoolean(dr["TranslationServiceGenerateTargetTag"], false);

                    if (isMachine && !string.IsNullOrEmpty(MachineServiceSuffix))
                    {
                        displayName += MachineServiceSuffix;
                    }

                    string selectScript = "SelectService(" + ScriptHelper.GetString(codeName) + ", " + (supportsInstructions ? "true" : "false") + ", " +
                                          (supportsPriority ? "true" : "false") + ", " + (!isMachine && allowBinary ? "true" : "false") + ", " +
                                          (supportsDeadline ? "true" : "false") + ", " + (generateTargetTag ? "true" : "false") + ")";

                    bool isSelected = selected.Equals(codeName, StringComparison.CurrentCultureIgnoreCase);
                    if (isSelected)
                    {
                        hdnSelectedName.Value = selected;
                        if (string.IsNullOrEmpty(machSelectScript))
                        {
                            machSelectScript = selectScript;
                        }
                    }

                    string radioBtn = "<input id=\"rad" + codeName + "\" " + (isSelected ? "checked=\"checked\"" : "") + " type=\"radio\" name=\"services\" value=\"" + codeName + "\" onclick=\"" + selectScript + "\" />";
                    radioBtn       += "<label for=\"rad" + codeName + "\">" + HTMLHelper.HTMLEncode(displayName) + "</label>";
                    lastDisplayName = displayName;

                    mAnyServiceAvailable = true;

                    ltlServices.Text += radioBtn + (i < count - 1 ? "<br />" : "");
                    i++;
                }
            }

            // If only one service is available, display it in a different way
            if (i == 1)
            {
                DisplayedServiceName = lastDisplayName;
                if (DisplayOnlyServiceName)
                {
                    ltlServices.Text = "<strong>" + HTMLHelper.HTMLEncode(lastDisplayName) + "</strong>";
                }
                else
                {
                    ltlServices.Text = "";
                }
            }

            if ((i > 1) && !string.IsNullOrEmpty(machSelectScript))
            {
                // Register script if more than one service is available
                ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "TranslationServiceSelectorSelection", machSelectScript, true);
            }

            DisplayedServicesCount = i;
        }
    }