Umbraco 4.5.2 - 创建自定义 umbraco 数据编辑器设置类型

发布于 2024-10-18 05:17:19 字数 214 浏览 8 评论 0原文

我似乎找不到任何有关如何在 umbraco 6.2 (Juno) 之前编辑数据编辑器设置的信息。有没有什么简单的办法,应该是可以的。如果您不明白我的意思,我想做与 http://www.nibble 相同的操作。 be/?p=96 - 仅适用于 umbraco 4.5.2。

谢谢 :)

I can't seem to find anything on how to edit the data editor settings before umbraco 6.2 (Juno). Is there any simple way, it must be possible. If you don't understand what i mean i want to do the same as http://www.nibble.be/?p=96 - just for umbraco 4.5.2.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还在原地等你 2024-10-25 05:17:19

您需要创建 3 个类:Class 1 DataEditor、

 public class DataEditor : System.Web.UI.UpdatePanel, umbraco.interfaces.IDataEditor
    {

        public MWCropperDataEditor(umbraco.interfaces.IData Data, string Configuration)
        {
            _data = Data;

        }

        public virtual bool TreatAsRichTextEditor
        {
            get { return false; }
        }

        public bool ShowLabel
        {
            get { return true; }
        }

        public Control Editor { get { return this; } }


        public void Save()
        {

                this._data.Value = "data;

        }

        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);

            imageUpload = new FileUpload();
            imageUpload.ID = "imageUpload";

            //shows Image
            cropImage = new System.Web.UI.WebControls.Image();
            cropImage.Width = width;
            cropImage.Height = height;
            cropImage.ImageUrl = this._data.Value.ToString();


            //Shows dropdown
            locationDropDown = new DropDownList();
            AddItemsToDropDown();

            lblInfo = new Label();
            lblInfo.Attributes.Add("id", "title" + base.ClientID);
            lblCropInfo = new Label();

            lblCropInfo.Text = "Crop Location: ";
            base.ContentTemplateContainer.Controls.Add(lblInfo);
            base.ContentTemplateContainer.Controls.Add(imageUpload);
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(lblCropInfo);
            base.ContentTemplateContainer.Controls.Add(locationDropDown);
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(cropImage);




        }

    }

Class 2 DataType、

public class MWCropperDataType : umbraco.cms.businesslogic.datatype.BaseDataType, umbraco.interfaces.IDataType
    {
        private umbraco.interfaces.IDataEditor _Editor;
        private umbraco.interfaces.IData _baseData;
        private MWCropperPrevalueEditor _prevalueeditor;

        public override umbraco.interfaces.IDataEditor DataEditor
        {
            get
            {
                if (_Editor == null)
                    _Editor = new MWCropperDataEditor(Data, ((MWCropperPrevalueEditor)PrevalueEditor).Configuration);
                return _Editor;
            }
        }

        public override umbraco.interfaces.IData Data
        {
            get
            {
                if (_baseData == null)
                    _baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
                return _baseData;
            }
        }
        public override Guid Id
        {
            get { return new Guid("71518B4E-B1A5-11DD-A22C-8AAA56D89593"); }
        }

        public override string DataTypeName
        {
            get { return "MWCropper"; }
        }

        public override umbraco.interfaces.IDataPrevalue PrevalueEditor
        {
            get
            {
                if (_prevalueeditor == null)
                    _prevalueeditor = new MWCropperPrevalueEditor(this);
                return _prevalueeditor;
            }
        }
    }

Class 3 PrevalueEditor

public class MWCropperPrevalueEditor : System.Web.UI.WebControls.PlaceHolder, umbraco.interfaces.IDataPrevalue
    {
        #region IDataPrevalue Members

        // referenced datatype
        private umbraco.cms.businesslogic.datatype.BaseDataType _datatype;


        private TextBox _txtWidth;
        private TextBox _txtHeight;
        public MWCropperPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType DataType)
        {

            _datatype = DataType;
            setupChildControls();

        }

        private void setupChildControls()
        {

            _txtWidth = new TextBox();
            _txtWidth.ID = "txtWidth";
            _txtWidth.CssClass = "umbEditorTextField";
            Controls.Add(_txtWidth);
            _txtHeight = new TextBox();
            _txtHeight.ID = "txtHeight";
            _txtHeight.CssClass = "umbEditorTextField";
            Controls.Add(_txtHeight);


        }



        public Control Editor
        {
            get
            {
                return this;
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {

                if (Configuration.Length > 0)
                {
                    string[] value = Configuration.Split(new char[]{';'});
                    _txtWidth.Text = value[0];
                    _txtHeight.Text = value[1];

                }
                else
                {
                    _txtHeight.Text = "100";
                    _txtWidth.Text = "100";
                }


            }


        }

        public void Save()
        {
            _datatype.DBType = (umbraco.cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), DBTypes.Ntext.ToString(), true);


            string data = _txtWidth.Text+";"+_txtHeight.Text;

            SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", 
                    SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId));
            SqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", 
                    SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId), SqlHelper.CreateParameter("@value", data));

        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.WriteLine("<table>");
            writer.Write("<tr><th>Width:</th><td>");
            _txtWidth.RenderControl(writer);
            writer.Write("</td></tr>");
            writer.Write("<tr><th>Height:</th><td>");
            _txtHeight.RenderControl(writer);
            writer.Write("</td></tr>");
            writer.Write("</table>");
        }

        public string Configuration
        {
            get
            {
                object conf =
                   SqlHelper.ExecuteScalar<object>("select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid",
                                           SqlHelper.CreateParameter("@datatypenodeid", _datatype.DataTypeDefinitionId));

                if (conf != null)
                    return conf.ToString();
                else
                    return "";

            }
        }

        #endregion

        public static ISqlHelper SqlHelper
        {
            get
            {
                return Application.SqlHelper;
            }
        }
    }

我希望这可以帮助您入门:)
顺便说一句,这也适用于 umbraco 6.2

You need to make 3 classes Class 1 DataEditor

 public class DataEditor : System.Web.UI.UpdatePanel, umbraco.interfaces.IDataEditor
    {

        public MWCropperDataEditor(umbraco.interfaces.IData Data, string Configuration)
        {
            _data = Data;

        }

        public virtual bool TreatAsRichTextEditor
        {
            get { return false; }
        }

        public bool ShowLabel
        {
            get { return true; }
        }

        public Control Editor { get { return this; } }


        public void Save()
        {

                this._data.Value = "data;

        }

        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);

            imageUpload = new FileUpload();
            imageUpload.ID = "imageUpload";

            //shows Image
            cropImage = new System.Web.UI.WebControls.Image();
            cropImage.Width = width;
            cropImage.Height = height;
            cropImage.ImageUrl = this._data.Value.ToString();


            //Shows dropdown
            locationDropDown = new DropDownList();
            AddItemsToDropDown();

            lblInfo = new Label();
            lblInfo.Attributes.Add("id", "title" + base.ClientID);
            lblCropInfo = new Label();

            lblCropInfo.Text = "Crop Location: ";
            base.ContentTemplateContainer.Controls.Add(lblInfo);
            base.ContentTemplateContainer.Controls.Add(imageUpload);
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(lblCropInfo);
            base.ContentTemplateContainer.Controls.Add(locationDropDown);
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
            base.ContentTemplateContainer.Controls.Add(cropImage);




        }

    }

class 2 DataType

public class MWCropperDataType : umbraco.cms.businesslogic.datatype.BaseDataType, umbraco.interfaces.IDataType
    {
        private umbraco.interfaces.IDataEditor _Editor;
        private umbraco.interfaces.IData _baseData;
        private MWCropperPrevalueEditor _prevalueeditor;

        public override umbraco.interfaces.IDataEditor DataEditor
        {
            get
            {
                if (_Editor == null)
                    _Editor = new MWCropperDataEditor(Data, ((MWCropperPrevalueEditor)PrevalueEditor).Configuration);
                return _Editor;
            }
        }

        public override umbraco.interfaces.IData Data
        {
            get
            {
                if (_baseData == null)
                    _baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
                return _baseData;
            }
        }
        public override Guid Id
        {
            get { return new Guid("71518B4E-B1A5-11DD-A22C-8AAA56D89593"); }
        }

        public override string DataTypeName
        {
            get { return "MWCropper"; }
        }

        public override umbraco.interfaces.IDataPrevalue PrevalueEditor
        {
            get
            {
                if (_prevalueeditor == null)
                    _prevalueeditor = new MWCropperPrevalueEditor(this);
                return _prevalueeditor;
            }
        }
    }

Class 3 PrevalueEditor

public class MWCropperPrevalueEditor : System.Web.UI.WebControls.PlaceHolder, umbraco.interfaces.IDataPrevalue
    {
        #region IDataPrevalue Members

        // referenced datatype
        private umbraco.cms.businesslogic.datatype.BaseDataType _datatype;


        private TextBox _txtWidth;
        private TextBox _txtHeight;
        public MWCropperPrevalueEditor(umbraco.cms.businesslogic.datatype.BaseDataType DataType)
        {

            _datatype = DataType;
            setupChildControls();

        }

        private void setupChildControls()
        {

            _txtWidth = new TextBox();
            _txtWidth.ID = "txtWidth";
            _txtWidth.CssClass = "umbEditorTextField";
            Controls.Add(_txtWidth);
            _txtHeight = new TextBox();
            _txtHeight.ID = "txtHeight";
            _txtHeight.CssClass = "umbEditorTextField";
            Controls.Add(_txtHeight);


        }



        public Control Editor
        {
            get
            {
                return this;
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {

                if (Configuration.Length > 0)
                {
                    string[] value = Configuration.Split(new char[]{';'});
                    _txtWidth.Text = value[0];
                    _txtHeight.Text = value[1];

                }
                else
                {
                    _txtHeight.Text = "100";
                    _txtWidth.Text = "100";
                }


            }


        }

        public void Save()
        {
            _datatype.DBType = (umbraco.cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(umbraco.cms.businesslogic.datatype.DBTypes), DBTypes.Ntext.ToString(), true);


            string data = _txtWidth.Text+";"+_txtHeight.Text;

            SqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", 
                    SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId));
            SqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", 
                    SqlHelper.CreateParameter("@dtdefid", _datatype.DataTypeDefinitionId), SqlHelper.CreateParameter("@value", data));

        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.WriteLine("<table>");
            writer.Write("<tr><th>Width:</th><td>");
            _txtWidth.RenderControl(writer);
            writer.Write("</td></tr>");
            writer.Write("<tr><th>Height:</th><td>");
            _txtHeight.RenderControl(writer);
            writer.Write("</td></tr>");
            writer.Write("</table>");
        }

        public string Configuration
        {
            get
            {
                object conf =
                   SqlHelper.ExecuteScalar<object>("select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid",
                                           SqlHelper.CreateParameter("@datatypenodeid", _datatype.DataTypeDefinitionId));

                if (conf != null)
                    return conf.ToString();
                else
                    return "";

            }
        }

        #endregion

        public static ISqlHelper SqlHelper
        {
            get
            {
                return Application.SqlHelper;
            }
        }
    }

I hope this can help you get started :)
Btw this also works for umbraco 6.2

桜花祭 2024-10-25 05:17:19

设置称为预值,您需要一个实现 IDataPrevalue 的 PrevalueEditor 类。看一下这篇博文中的示例:

http://www.eyecatch.no/blog/my-first-umbraco-datatype---part-2-rendering-a-recaptcha-control.aspx

Settings are called prevalues and you need a PrevalueEditor class that implements IDataPrevalue. Have a look at an example in this blog post:

http://www.eyecatch.no/blog/my-first-umbraco-datatype---part-2-rendering-a-recaptcha-control.aspx

颜漓半夏 2024-10-25 05:17:19

这篇半博文章涉及对 v4.5 及之前的版本执行类似的操作,其中还有一个针对更旧版本的链接,我不久前关注过该版本,发现非常有帮助。
http://www.nibble.be/?p=62

This nibble post concerns doing a similar thing for v4.5 and prior, there is also a link within this for an even older version that I followed a while ago and found very helpful.
http://www.nibble.be/?p=62

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文