Copied to clipboard

Flag this post as spam?

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


  • Tom Norwood 29 posts 60 karma points
    Jul 02, 2015 @ 18:10
    Tom Norwood
    0

    Event before record is retrieved?

    Hi !

    In a similar vain to this post: https://our.umbraco.org/forum/umbraco-pro/contour/48123-Event-when-entry-is-deleted

    Can we get an event raised before a record is retrieved? It seems Umbraco Forms v4.0.3 does not support getting data from an external data source, only sending data there and then using it's local RecordStorage. If I had an event before it retrieves the record I could refresh the RecordStorage from the external data source.

    These events seemed to exist in Umbraco 6.

    Cheers!

    Tom

  • Comment author was deleted

    Jul 03, 2015 @ 07:59

    Sure thing, would you mind creating it as a feature request at http://issues.umbraco.org/issues/CON

  • Tom Norwood 29 posts 60 karma points
    Jul 03, 2015 @ 09:07
  • Tom Norwood 29 posts 60 karma points
    Jul 03, 2015 @ 08:43
    Tom Norwood
    0

    Great, thanks!

  • Comment author was deleted

    Jul 03, 2015 @ 09:23

    Thanks, I'll assign this to version 4.2 (the next upcoming version)

  • Tom Norwood 29 posts 60 karma points
    Jul 07, 2015 @ 15:55
    Tom Norwood
    0

    Do you know when this is due for release?

  • Comment author was deleted

    Jul 07, 2015 @ 16:02

    Will add the event in this week then you can update to a nightly build. Will report back here when that is done

  • Comment author was deleted

    Jul 10, 2015 @ 11:04

    Just looking in the code but unsure where to place the event, so you want to have it before the records get retrieved (so the place where they get retrieved is the records viewer)

  • Tom Norwood 29 posts 60 karma points
    Jul 10, 2015 @ 11:20
    Tom Norwood
    0

    Yes, I think before as a synchronous event.

    I need to be able to refresh the data storage from an external data source when this event is fired so that my data is up to date. Does that make sense?

  • Comment author was deleted

    Jul 10, 2015 @ 11:37

    So instead of fetching the records from the forms storage you want to bypass that and return data from a custom source (and this is for use in the entries viewer)

  • Comment author was deleted

    Jul 10, 2015 @ 11:42

    Wouldn't it be easier to just create your own entries viewer? And hook into the menu rendering to show your own viewer instead of the default one

  • Tom Norwood 29 posts 60 karma points
    Jul 10, 2015 @ 13:59
    Tom Norwood
    0

    OK that could work but I'm not sure exactly what you mean. Could you show me some example code?

  • Comment author was deleted

    Jul 10, 2015 @ 14:04

    Hook into menu rendering example is on the bottom of this page https://our.umbraco.org/documentation/Extending-Umbraco/Section-Trees/trees-v7

  • Tom Norwood 29 posts 60 karma points
    Jul 10, 2015 @ 14:16
    Tom Norwood
    0

    OK I've added the following code but the event is not firing when I load the form:

    class EventHandlers : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            TreeControllerBase.MenuRendering += TreeControllerBase_MenuRendering;
            base.ApplicationStarted(umbracoApplication, applicationContext);
        }
    
        void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
    
        }
     }
    
  • Tom Norwood 29 posts 60 karma points
    Jul 10, 2015 @ 14:17
    Tom Norwood
    0

    Forgive me - I'm new to Umbraco! :)

  • Tom Norwood 29 posts 60 karma points
    Jul 13, 2015 @ 10:13
    Tom Norwood
    0

    OK I can see the TreeNodesRendering event fired when you are in the back office. How do I create my own records viewer and hook this in? Will I be able to extend the existing one? Can you please provide more detailed code example.

  • Comment author was deleted

    Jul 13, 2015 @ 12:03

    You can basically create your own angularjs view and controller, and point to that from your menu option

    Will get some code snippets together

  • Comment author was deleted

    Jul 13, 2015 @ 12:41

    Ok this is the code snippet that will update the entries node to go to a custom view

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Core;
    using Umbraco.Web.Models.Trees;
    using Umbraco.Web.Trees;
    
    namespace SupportFormsCustomEntriesViewer
    {
    public class Events: ApplicationEventHandler
    {
    
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
    
            TreeControllerBase.TreeNodesRendering += TreeControllerBase_TreeNodesRendering;
        }
    
        void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            if (sender.TreeAlias == "form" && e.Nodes.Count == 2)
            {
                var formId = e.QueryStrings.Single(qs => qs.Key == "id").Value;
                var entriesNode = e.Nodes.Single(node => node.Name.StartsWith("Entries"));
                entriesNode.RoutePath = "forms/form/customentries/" + formId.ToString();
    
            }
        }
    
    
    }
    }
    

    so then it's a matter of creating the file /App_Plugins/UmbracoForms/backoffice/form/customentries.html and implementing your own records viewer

  • Comment author was deleted

    Jul 13, 2015 @ 12:43

    Then you'll need to inject a angularjs controller, and you'll also need an api controller that will feed the data to the controller, will also get you some sample code of that

  • Tom Norwood 29 posts 60 karma points
    Jul 13, 2015 @ 13:12
    Tom Norwood
    0

    OK thanks for that. But this is just implementing a new back office entries viewer. I need the actual form that the user of my website sees to display the correct data that comes from an external source. Umbraco Forms does not currently support this and changes to the external data are not picked up and there is no way for me to retrieve them.

    i.e. when they navigate to: www.mywebsite.com/myform?recordid=1

    I have two options:

    1. Hook into a synchronous event before any records are received and use the RecordService to update the records from the external source.
    2. Hook into the an event the retrieves the Records and return the correct data then.

    If you can help me implement either of these it would be greatly appreciated!

  • Comment author was deleted

    Jul 13, 2015 @ 13:24

    Ok I understand better now, 2 is probably the easiest solution, will look into that.

    If you are still interested in how you can return your own entries viewer here are the bits

    Angularjs controller:

    angular.module("umbraco").controller("SupportFormsCustomEntriesViewer.EntriesController",
    function ($scope, $routeParams, recordResource, formResource, dialogService, editorState, $http) {
        formResource.getByGuid($routeParams.id)
        .then(function (response) {
            $scope.form = response.data;
    
            $http.get("backoffice/Custom/EntriesApi/GetAllEntries?formid=" + $scope.form.id)
                .then(function (res) {
                    $scope.entries = res.data;
                });
    
            $scope.loaded = true;
        });
    
    });
    

    angujarjs view:

    <div novalidate name="contentForm"
     ng-controller="SupportFormsCustomEntriesViewer.EntriesController"
     ng-show="loaded">
    
    <umb-panel>
        <umb-header>
            <div class="span12">
                <h1>{{form.name}} form entries</h1>
            </div>
        </umb-header>
        <div class="umb-panel-body umb-scrollable row-fluid umb-forms-entries">
    
            {{entries | json}}
        </div>
    </umb-panel>
    

    api controller that returns the record data:

    [PluginController("Custom")]
    public class EntriesApiController : UmbracoAuthorizedJsonController  
    {
        Entry[] entries = new Entry[] 
        { 
            new Entry { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, 
            new Entry { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, 
            new Entry { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } 
        };
    
        public IEnumerable<Entry> GetAllEntries(string formId)
        {
            return entries;
    
        }
    
        public Entry GetEntryById(int id)
        {
            var entry = entries.FirstOrDefault((p) => p.Id == id);
            if (entry == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return entry;
        }
    
    }
    

    Entry model

    public class Entry
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Category { get; set; }
        public decimal Price { get; set; }
    }
    

    package manifest

    {
    "javascript": [
    "~/App_Plugins/Custom/entries.controller.js"
    ]
    }
    
  • Tom Norwood 29 posts 60 karma points
    Jul 13, 2015 @ 13:25
    Tom Norwood
    0

    Cheers Tim. Look forward to your response!

  • Comment author was deleted

    Jul 13, 2015 @ 14:01

    Ok added the event RecordFetching on Umbraco.Forms.Data.Storage.RecordStorage

    You can upgrade to the latest nightly build to make use of it http://nightly.umbraco.org/UmbracoForms/nightlies/UmbracoForms.Files.4.2.0-WIP.Build.65.zip

  • Tom Norwood 29 posts 60 karma points
    Jul 13, 2015 @ 16:06
    Tom Norwood
    0

    OK great thanks!

  • Tom Norwood 29 posts 60 karma points
    Jul 20, 2015 @ 08:27
    Tom Norwood
    0

    That works fine for the nightly build :)

  • Tom Norwood 29 posts 60 karma points
    Aug 13, 2015 @ 09:45
    Tom Norwood
    0

    any idea when the 4.2.0 build will be officially released? (including nuget)

Please Sign in or register to post replies

Write your reply to:

Draft