Showing posts with label Geolocation. Show all posts
Showing posts with label Geolocation. Show all posts

Friday, November 9, 2012

Sharepoint 2013 - Add Geolocation Field in the display view of a discussion List

Imagine the scenario : You 'are on a community, you want to be able to post your position on a post to show the other users your localization. (FB like).

The idea WOULD be :
  • Add a geolocation field
  • Add the field to the display
  • TADAAM it works...
Well obviously, it doesn't!

The method is a bit more complicated. We've worked on it with Laurent Fauret (also from Sogeti) who made the js updates :

Step 1 : Create a site Column Geolocation field
The geolocation fields can't be created manually. So you have to create them using A powershell script or Using Create Geolocation field projet on Code.msdn.microsoft. Add a field in yor discussion list.

Step 2 : Update the discussion display file
The problem is that you never open the viewItems.aspx form when you navigate inside a discussion, you are always on a custom view, so the field you have added on your list, will never show up! So, it means that you have to modify the display js file!

This is not a good way of doing but it's a fast one! You should never touch the standard file of sharepoint, but instead create your owns specific but in this case we will do it for demo purpose (the good way would be to create a discussion list type based on the new display js file!)

So you have to modify the sp.ui.discussions.js located in the 15/TEMPLATE/Layouts. It manages the display of the discussion list. (use the sp.ui.discussions.debug.js to have the indented version).

  • Add your field in the viewfields list in the function
     SP.UI.Discussions.Helpers.$1f = function (m, i) 
  • Change the $2u_0: function (a, d)  to
     $2u_0: function (a, d) {
        ULS06I:;
        this.populateFolderMetalineItems(d);
        a.addCssClass("ms-comm-metalineList ms-noList");

        a.renderBeginTag("ul");
        if (this.jsonItem["My_x0020_Location"]) {
            a.addCssClass("ms-comm-metalineItemSeparator");
            a.addCssClass("ms-comm-metalineItem");
            a.renderBeginTag("li");
            a.write(spMgr.RenderFieldByName(this.$0_0, "My_x0020_Location", this.jsonItem, this.$0_0.ListSchema))
            a.renderEndTag()
        }
        for (var b = 0, c = this.$R_0.length; b < c; b++) {
            b !== c - 1 && a.addCssClass("ms-comm-metalineItemSeparator");
            a.addCssClass("ms-comm-metalineItem");
            a.renderBeginTag("li");
            a.write(this.$R_0[b]);
            a.renderEndTag()
        }
        a.renderEndTag()

    },

  • Change the $2y_0: function (a) { to$2y_0: function (a) {
            ULS06I:;
            var loc = spMgr.RenderFieldByName(this.$0_0, "My_x0020_Location", this.jsonItem, this.$0_0.ListSchema);
            if (loc) {
                a.addCssClass("ms-metadata");
                a.addCssClass("ms-comm-cmdSpaceListItem");
                a.renderBeginTag("span");
                a.write(loc);
                a.renderEndTag();
            }
        a.addCssClass("ms-metadata");
        a.addCssClass("ms-comm-cmdSpaceListItem");
        a.renderBeginTag("span");
        var b = spMgr.RenderFieldByName(this.$0_0, "Created", this.jsonItem, this.$0_0.ListSchema);
        a.write(b);
        a.renderEndTag()
    },



Note :We have called our column "My Location".



Step 3 : Test
It works only on your /discussion%20List/forms/allitems.aspx ... but it f you want to see it working on your site homepage (where the discussion list is already put), you have to revalidate the "subject" view on the discussion list Webpart for the view to be updated with your new field.
An now you will see your GeoLoc picto on your discussion!


And on the click