Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonathan Roberts 409 posts 1063 karma points
    Jun 13, 2016 @ 13:34
    Jonathan Roberts
    0

    Get Datatype config settings using AngularJs

    Hi, Is it possible to get a Datatypes Config settings using AngularJs. I have a Controller that i would like to get a particular Datatype config settings so i dont have to create a the settings again - basically keeping it all in one place.

    Jon

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 13, 2016 @ 15:16
    Jan Skovgaard
    0

    Hi Jonathan

    I'm a bit unsure if you're thinking about getting settings for an already existing property editor for you in your own?

    Or is it simply some configuration settings for you own property editor?

    If so then you you can add prevalues using the package.manifest file, which you can then get access to in your controller and view for your editor using model.config.

    Here you can see what one of my package.manifest files looks like

    {
      propertyEditors: [{
        alias: "Our.Umbraco.ExtendedTextstring",
        name:  "Extended Textstring",
        icon: "icon-thumbnails",
        group: "Pickers",
        editor: {
          view: "~/App_Plugins/ExtendedTextstring/extendedtextstring.html",
          valueType: "JSON"
        },
        prevalues: {
          fields: [
                {
                    label: "Show italic",
                    description: "Should it be possible to make the text italic?",
                    key: "showItalic",
                    view: "boolean"
                },
                {
                    label: "Show bold",
                    description: "Should it be possible to make the text bold?",
                    key: "showBold",
                    view: "boolean"
                }
            ]
        },
        defaultConfig:{
            showItalic:"1"
        }
      }],
      javascript: [
        '~/App_Plugins/ExtendedTextstring/extendedtextstring.controller.js',
        '~/App_Plugins/ExtendedTextstring/extendedtextstring.prevalues.controller.js'
      ],
      "css" : [
        "~/App_Plugins/ExtendedTextstring/extendedtextstring.css"
      ]
    }
    

    The "Show italic" and "Show bold" are the prevalues I can refer to in my view and controller for my editor.

    You can find more information about how to create you own property editors here

    I hope this helps and that I have understood your question correctly.

    /Jan

  • Ian 178 posts 752 karma points
    Jun 13, 2016 @ 17:10
    Ian
    0

    Hi Jonathan, if you could give more of an idea what you are trying to do it may produce a better answer but purely based on the title of your question I would suggest this if you want to get the config settings of another data type definiton

    1. Create a PluginController which extends UmbracoAuthorizedJsonController for the backoffice
    2. Create An angular resource with a method which queries the controller for the config settings of a given datatype
    3. Inject the resource into your property editor controller and call your resource method

    I've seen this pattern else where but can't locate any links at the moment sorry.

    These are the body contents of the controller in my case which which returns the all the properties of a datatype I needed to my resource

    [HttpGet]
        public object GetDataTypeById(Guid id)
        {
            var dtd = Services.DataTypeService.GetDataTypeDefinitionById(id);
            return FormatDataType(dtd);
        }
    
        protected object FormatDataType(IDataTypeDefinition dtd)
        {
            if (dtd == null)
                throw new HttpResponseException(HttpStatusCode.NotFound);
    
            var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
    
            // Force converter before passing prevalues to view
            var preValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dtd.Id);
            var convertedPreValues = propEditor.PreValueEditor.ConvertDbToEditor(propEditor.DefaultPreValues,
                preValues);
    
            return new FormattedDataType()
            {
                Guid = dtd.Key,
                PropertyEditorAlias = dtd.PropertyEditorAlias,
                PreValues = convertedPreValues,
                View = propEditor.ValueEditor.View
            };
        }
    

    In your case you might only need the prevalues.

Please Sign in or register to post replies

Write your reply to:

Draft