0

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 :)

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

This link no longer exists, can you fix it? Also, while there, can you update so it's not just a link and the answer contains the actual code?
6 years on this is no longer relevant. Cached version: webcache.googleusercontent.com/…
0

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

1 Comment

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.