Esempio n. 1
0
    /// <param name="addRemoveReplace">true for add, false for remove, null for replace</param>
    protected void SetLocales(List<long> selections, List<int> selectedLocales, int defaultLocale, bool? addRemoveReplace)
    {
        Ektron.Cms.Framework.Localization.LocaleManager locale = new Ektron.Cms.Framework.Localization.LocaleManager();
        Ektron.Cms.Framework.Localization.LocalizationObject lobj = new Ektron.Cms.Framework.Localization.LocalizationObject();

        List<Ektron.Cms.Localization.LocaleData> locales = locale.GetEnabledLocales();

        // Loop through each of the selected content items to try and find selected locales
        List<int> contentLocales = new List<int>();
        if (!selectedLocales.Contains(defaultLocale))
            selectedLocales.Add(defaultLocale);
        selectedLocales.Sort();

        List<int> localesToDelete = new List<int>();
        List<int> localesToAdd = new List<int>();
        List<Ektron.Cms.Localization.LocalizationObjectData> localeData = new List<Ektron.Cms.Localization.LocalizationObjectData>();

        foreach (long item in selections)
        {
            Ektron.Cms.Localization.LocalizableCmsObjectType objectType = Ektron.Cms.Localization.LocalizableCmsObjectType.Content;
            contentLocales = lobj.GetObjectLanguages(Ektron.Cms.Localization.LocalizableCmsObjectType.Content, item);
            if (contentLocales.Count == 0)
            {
                objectType = Ektron.Cms.Localization.LocalizableCmsObjectType.DmsAsset;
                contentLocales = lobj.GetObjectLanguages(Ektron.Cms.Localization.LocalizableCmsObjectType.DmsAsset, item);
            }
            bool skip = true;
            if (addRemoveReplace == null && !LocaleListsMatch(selectedLocales, contentLocales))
                skip = false;
            if (addRemoveReplace == true && !LocaleListContains(contentLocales, selectedLocales))
                skip = false;
            if (addRemoveReplace == false && LocaleListContains(contentLocales, selectedLocales))
                skip = false;

            if (!skip)
            {
                localeData = lobj.GetLocalizationObjectList(objectType, item, -1);
                localesToDelete.Clear();
                localesToAdd.Clear();
                if (addRemoveReplace == null || addRemoveReplace == true)
                    foreach (int i in selectedLocales)
                        if (!contentLocales.Contains(i))
                            localesToAdd.Add(i);
                if (addRemoveReplace == null)
                    foreach (int i in contentLocales)
                        if (!selectedLocales.Contains(i))
                            localesToDelete.Add(i);
                if (addRemoveReplace == false)
                    foreach (int i in contentLocales)
                        if (selectedLocales.Contains(i))
                            localesToDelete.Add(i);

                foreach (int i in localesToDelete)
                    foreach (Ektron.Cms.Localization.LocalizationObjectData ldata in localeData)
                        if (ldata.ObjectLanguage == i)
                            lobj.Delete(ldata.Id);

                foreach (int i in localesToAdd)
                    lobj.MarkReadyForTranslation(objectType, item, i);
            }
        }
    }
Esempio n. 2
0
    protected string CallbackDoAction(string key, Dictionary<string, string> data)
    {
        InitFromCallback(data);
        string what = data["action"];
        string sselected = data["selected"];
        List<long> selected = sselected.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll<long>(new Converter<string, long>(delegate(string s) { return long.Parse(s); }));

        Ektron.Cms.CommonApi commonApi = new CommonApi();
        Ektron.Cms.Content.EkContent contentManager = new Ektron.Cms.Content.EkContent(commonApi.RequestInformationRef);
        Ektron.Cms.API.Content.Content capi = new Ektron.Cms.API.Content.Content();
        Ektron.Cms.Framework.Localization.LocaleManager localeApi = new Ektron.Cms.Framework.Localization.LocaleManager();
        Ektron.Cms.Framework.Localization.LocalizationObject lobjApi = new Ektron.Cms.Framework.Localization.LocalizationObject();
        Ektron.Cms.API.Content.Taxonomy taxonomyApi = new Ektron.Cms.API.Content.Taxonomy();

        string title = string.Empty, html = string.Empty, okclick = string.Empty, action = string.Empty;

        switch (what)
        {
            case "locales":
                {
                    action = "showmodal";
                    bool? addRemoveReplace = null;
                    if (data.ContainsKey("mode"))
                        if (data["mode"] == "add")
                            addRemoveReplace = true;
                        else if (data["mode"] == "del")
                            addRemoveReplace = false;
                    title = (addRemoveReplace == null ? this.GetMessage("lbl Change selected locales") :
                        (addRemoveReplace == true ? "Add locale(s)" : "Remove locale(s)"))
                        + " " + this.GetMessage("generic for") + " " + (selected.Count == 1 ? "1 item" : (selected.Count.ToString() + " " + this.GetMessage("generic items")));
                    html = GenerateLocaleList(selected, CurrentLanguageId, addRemoveReplace);
                    okclick = this.ClientID + (addRemoveReplace == null ? "_LocaleSet" : (addRemoveReplace == true ? "_LocaleAdd" : "_LocaleDel"));
                }
                break;
            case "localeset":
                {
                    List<int> locales = data["locales"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>().ConvertAll<int>(new Converter<string, int>(delegate(string s) { return int.Parse(s); }));
                    bool? addRemoveReplace = null;
                    if (data.ContainsKey("mode"))
                        if (data["mode"] == "add")
                            addRemoveReplace = true;
                        else if (data["mode"] == "del")
                            addRemoveReplace = false;
                    SetLocales(selected, locales, CurrentLanguageId, addRemoveReplace);
                    action = "hidemodal";
                    title = "";
                    Fill();
                    html = RenderControl(plcRenderMe);
                    okclick = "";
                }
                break;
            case "transstatus":
                {
                    action = "showmodal";
                    title = "Set Translation Readiness";
                    // ##TODO: Check current translation status
                    html = RenderControl(pnlSetTransStatus);
                    okclick = this.ClientID + "_TransStatusSet";
                }
                break;
            case "settranstatus":
                {
                    string status = data["status"].ToLower();
                    foreach (long id in selected)
                    {
                        Ektron.Cms.Localization.LocalizableCmsObjectType objectType = Ektron.Cms.Localization.LocalizableCmsObjectType.Content;
                        Ektron.Cms.Framework.Localization.LocalizationObject lobj = new Ektron.Cms.Framework.Localization.LocalizationObject();
                        switch (status)
                        {
                            case "ready":
                                lobjApi.MarkReadyForTranslation(objectType, id, CurrentLanguageId);
                                break;
                            case "notready":
                                lobjApi.MarkNotReadyForTranslation(objectType, id, CurrentLanguageId);
                                break;
                            case "donottranslate":
                                lobjApi.MarkDoNotTranslate(objectType, id, CurrentLanguageId);
                                break;
                        }
                    }
                    action = "hidemodal";
                    title = string.Empty;
                    Fill();
                    html = RenderControl(plcRenderMe);
                    okclick = string.Empty;
                }
                break;
            case "notes":
                {
                    action = "showmodal";
                    title = "Add notes for " + (selected.Count == 1 ? "1 item" : (selected.Count.ToString() + " items"));
                    lNoteN.Visible = selected.Count > 1;

                    if (selected.Count == 1) // Load notes if there is only one piece of content
                    {
                        // ##TODO: Add this!
                    }
                    html = RenderControl(pnlNotes);
                    okclick = this.ClientID + "_NotesSet";
                }
                break;
            case "setnotes":
                {
                    string notes = data["notes"];

                    long metadataId = commonApi.EkContentRef.GetMetadataTypeId("XliffNote", CurrentLanguageId, 0);

                    foreach (long cid in selected)
                    {
                        capi.UpdateContentMetaData(cid, metadataId, notes);
                    }

                    action = "hidemodal";
                    title = string.Empty;
                    Fill();
                    html = RenderControl(plcRenderMe);
                    okclick = string.Empty;
                }
                break;
            case "pseudo":
                {
                    action = "showmodal";
                    title = "Pseudo Localize " + (selected.Count == 1 ? "1 item" : (selected.Count.ToString() + " items")) + ".";

                    Ektron.Cms.Framework.Localization.LocaleManager locale = new Ektron.Cms.Framework.Localization.LocaleManager();
                    List<Ektron.Cms.Localization.LocaleData> pseudoLocales = locale.GetEnabledLocales().FindAll(d => d.XmlLang.Contains("-x-pseudo"));

                    if (pseudoLocales.Count > 0)
                        foreach (Ektron.Cms.Localization.LocaleData pseudoLocale in pseudoLocales)
                        {
                            CheckBox pseudoLoc = new CheckBox()
                            {
                                ID = "chkPS" + pseudoLocale.Id.ToString(),
                                Checked = true,
                                Text = pseudoLocale.Loc + " " + pseudoLocale.EnglishName
                            };
                            pnlPseudo.Controls.Add(pseudoLoc);
                            pnlPseudo.Controls.Add(new LiteralControl("<br />"));
                        }
                    else
                        lblPseudoInstructions.Text = "There are no Pseudo localization enabled locales.";

                    html = RenderControl(pnlPseudo);
                    okclick = this.ClientID + "_PseudoSet";
                }
                break;
            case "setpseudo":
                {
                    action = "showmodal";
                    title = "Pseudo Localize " + (selected.Count == 1 ? "1 item" : (selected.Count.ToString() + " items")) + ".";

                    string selectedIds = string.Join(",", selected.ConvertAll<string>(delegate(long i) { return i.ToString(); }).ToArray());
                    string pseudoLocaleIds = data["locales"];

                    ektronExportPseudoIframe.Attributes["src"] = "widgets/Modal/localizationjobs.aspx?action=pseudo&contentIds=" + selectedIds + "&languageIds=" + pseudoLocaleIds;
                    html = RenderControl(pnlSetPseudo);
                    okclick = this.ClientID + "_PseudoReset";
                }
                break;
            case "pseudocomplete":
                {
                    action = "hidemodal";
                    title = string.Empty;
                    Fill();
                    html = RenderControl(plcRenderMe);
                    okclick = string.Empty;
                }
                break;
            default:
                {
                    action = "showmodal";
                    title = "Invalid selection";
                    html = "The option that was selected is not available.";
                    okclick = this.ClientID + "_CloseModalDialog";
                }
                break;
        }

        Dictionary<string, string> output = new Dictionary<string, string>();
        output["action"] = action;
        output["title"] = title;
        output["html"] = html;
        output["okclick"] = okclick;

        return ConvertDictionaryToQueryString(output);
    }
Esempio n. 3
0
 private void Do_UpdateTranslationStatus(string action)
 {
     try
     {
         long intId = Convert.ToInt64(Request.QueryString["id"].ToString());
         int intLangType = Convert.ToInt32(Request.QueryString["LangType"].ToString());
         var loc = new Ektron.Cms.Framework.Localization.LocalizationObject();
         string contType = Request.QueryString["ContType"].ToString();
         long intContType;
         Ektron.Cms.Localization.LocalizableCmsObjectType objType = Ektron.Cms.Localization.LocalizableCmsObjectType.Content;
         if (Int64.TryParse(contType, out intContType))
         {
             if (EkConstants.IsAssetContentType(intContType, false))
             {
                 objType = Ektron.Cms.Localization.LocalizableCmsObjectType.DmsAsset;
             }
             else if (intContType == EkEnumeration.CMSContentType.CatalogEntry.GetHashCode())
             {
                 objType = Ektron.Cms.Localization.LocalizableCmsObjectType.Product;
             }
         }
         switch (action)
         {
             case "translatereadystatus":
                 loc.MarkReadyForTranslation(objType, intId, intLangType);
                 break;
             case "translatenotreadystatus":
                 loc.MarkNotReadyForTranslation(objType, intId, intLangType);
                 break;
             case "translatenotallowstatus":
                 loc.MarkDoNotTranslate(objType, intId, intLangType);
                 break;
             case "translateneedstranslationstatus":
                 loc.MarkNeedsTranslation(objType, intId, intLangType);
                 break;
             case "translateoutfortranslationstatus":
                 loc.MarkOutForTranslation(objType, intId, intLangType);
                 break;
             case "translatetranslatedstatus":
                 loc.MarkTranslated(objType, intId, intLangType);
                 break;
         }
         Response.Redirect((string)("content.aspx?LangType=" + ContentLanguage + "&action=View&id=" + intId), false);
     }
     catch (Exception ex)
     {
         Utilities.ShowError(ex.Message);
     }
 }