アクションエディタの作成

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

アクションエディタは、保存アクションの一部のパラメータを設定できるダイアログボックスです。カスタム保存アクションのアクションエディタを作成できます。

アクション エディターを作成する前に、Sitecore Developer NetworkのWebサイトで XMLコントロール XMLアプリケーションに関する情報を参照してください。

アクションエディタは、次の作業ロジックを使用します。

  • OnLoadメソッドのsaveアクション・パラメータを読み取ります。

  • これは、保存アクション・パラメーターをユーザーに示します。

  • ユーザーがパラメーターを編集した後、OnOkメソッドを使用してWebフォームのSave Actionsフィールドに保存します。

アクションエディタを実装する前に、次のコードのヒントをよく理解しておく必要があります。

  • 現在の保存アクション・パラメータを取得するには、次のようにします。

    string params=HttpContext.Current.Session[Sitecore.Web.WebUtil.GetQueryString("params")] as string;
    NameValueCollection nvParams=ParametersUtil.XmlToNameValueCollection(params);
  • パラメータ値を保存するには、OnOkメソッドをオーバーライドします。

    protected override void OnOK(object sender, EventArgs args)
        {      
          string str3 = ParametersUtil.NameValueCollectionToXml(this.nvParams ?? new NameValueCollection());
          if (str3.Length == 0)
          {
            str3 = "-";
          }
          SheerResponse.SetDialogValue(str3);
          base.OnOK(sender, args);
        }
  • 現在のWebフォーム アイテムIDを取得するには:

    Sitecore.Web.WebUtil.GetQueryString("id");
  • 現在の言語を取得するには:

    Sitecore.Web.WebUtil.GetQueryString("la", "en");
  • 現在のSitecoreデータベースを取得するには:

    Sitecore.Web.WebUtil.GetQueryString("db");

アクションエディタを作成するには:

  1. ダイアログレイアウトを含むXMLファイルを作成します。

    <?xml version="1.0" encoding="utf-8" ?>
    <control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense">
       <SimpleEditor>
          <Stylesheet>
            .scfContent {
            padding-top : 15px;
            }
            .scfFieldScope{ 
            width:100%; margin:7px; 
            }
            .scfFieldLabel { 
            width:40%; 
            } 
            .scfFieldSelect { 
            width:58%;
            position:absolute;
            right:0;
            margin-right:20px; 
            }
          </Stylesheet>
          <FormDialog ID="Dialog" Icon="Software/32x32/step_new.png">
             <CodeBeside Type="Sitecore.Forms.Sample.SimpleEditor,Sitecore.Forms.Sample"/>
            <Border Class="scfContent" Width="100%"  Align="left" Style="overflow:none;">
              <Literal ID="name" Text="Login:" Class="scfFieldLabel"/>
              <Combobox runat="server" ID="login"/>
            </Border>
            <Border Class="scfContent" Width="100%"  Align="left" Style="overflow:none;">
              <Literal ID="pass" Text="Password:" Class="scfFieldLabel"/>
              <Combobox runat="server" ID="password"/>
            </Border>
             <Border Class="scfContent" Width="100%"  Align="left" Style="overflow:none;">
               <Literal ID="domLiteral" Text="Default domain:" Class="scfFieldLabel"/>
               <Combobox runat="server" ID="domain"/>                      
             </Border>
          </FormDialog>
       </SimpleEditor>
    </control>
  2. Sitecore.Web.UI.Pages.DialogFormに基づいてアクション エディター クラスを作成します。作成したクラスをXMLファイルでCodeBesideとして指定します。次のコード サンプルは、アクション エディター クラス用です。

    public class SimpleEditor : DialogForm   
    {
        protected Combobox domain;
        protected Combobox login;
        protected Combobox password;
        private NameValueCollection nvParams;
        protected override void OnLoad(EventArgs e)
        {
          base.OnLoad(e);
          if (!Context.ClientPage.IsEvent)
          {
            foreach (Domain d in DomainManager.GetDomains())
            {
              Sitecore.Web.UI.HtmlControls.ListItem item = new Web.UI.HtmlControls.ListItem();          
              item.Value = d.Name;
              item.Header = d.Name;
              domain.Controls.Add(item);
            }
            foreach (FieldItem f in this.CurrentForm.Fields)
            {
              Sitecore.Web.UI.HtmlControls.ListItem item = new Web.UI.HtmlControls.ListItem();
              item.Value = f.ID.ToString();
              item.Header = f.DisplayName;
              login.Controls.Add(item);
              item = new Web.UI.HtmlControls.ListItem();
              item.Value = f.ID.ToString();
              item.Header = f.DisplayName;
              password.Controls.Add(item);
            }
            domain.Value = this.GetValueByKey("DefaultDomain") ?? string.Empty;
            login.Value = this.GetValueByKey("Login") ?? string.Empty;
            password.Value=this.GetValueByKey("Password") ??string.Empty;
          }
        }
        protected void SaveValues()
        {
          this.SetValue("DefaultDomain", domain.Value);
          this.SetValue("Login", login.Value);
          this.SetValue("Password", password.Value);
        }
        protected override void OnOK(object sender, EventArgs args)
        {
          this.SaveValues();
          string str3 = ParametersUtil.NameValueCollectionToXml(this.nvParams ?? new NameValueCollection());
          if (str3.Length == 0)
          {
            str3 = "-";
          }
          SheerResponse.SetDialogValue(str3);
          base.OnOK(sender, args);
        } 
        public void SetValue(string key, string value)
        {
          if (this.nvParams == null)
          {
            this.nvParams = ParametersUtil.XmlToNameValueCollection(this.Params);
          }
          this.nvParams[key] = value;
        }
        public string GetValueByKey(string key)
        {
          if (this.nvParams == null)
          {
            this.nvParams = ParametersUtil.XmlToNameValueCollection(this.Params);
          }
          return (this.nvParams[key] ?? string.Empty);
        }  
        public string Params
        {
          get
          {
            return (HttpContext.Current.Session[Sitecore.Web.WebUtil.GetQueryString("params")] as string);
          }
        }   
        public string CurrentID
        {
          get
          {
            return Sitecore.Web.WebUtil.GetQueryString("id");
          }
        }
        public FormItem CurrentForm
        {
          get
          {
            if (!string.IsNullOrEmpty(this.CurrentID))
            {
              Item innerItem = this.CurrentDatabase.GetItem(this.CurrentID, this.CurrentLanguage);
              if (innerItem != null)
              {
                return new FormItem(innerItem);
              }
            }
            return null;
          }
        }
        public virtual Database CurrentDatabase
        {
          get
          {
            return Factory.GetDatabase(Sitecore.Web.WebUtil.GetQueryString("db"));
          }
        }
        public virtual Language CurrentLanguage
        {
          get
          {
            return Language.Parse(Sitecore.Web.WebUtil.GetQueryString("la", "en"));
          }
        }
      }
  3. 適切な「Save Action」項目の「 Editor 」フィールドで、作成したエディターを指定します。

この記事を改善するための提案がある場合は、 お知らせください!