SharePoint 2013 Discussion Board Customizations



  • So, by virtue of being our only programmer, I've been voluntold that I'm now managing our SharePoint customizations.

    We are trying to add new display columns to the Discussion Board (we want to add a category column with a filter). I've been able to add the filter to the view and the column to the list, but when I tried to update the sp.ui.discussions.js file so that the renderer displays the column, it broke the automatic redirection to the individual thread view when you click the title link of the discussion (in the default config, this redirects from AllItems.aspx to Flat.aspx). It seems the redirect either happens as an ajax update or a 302 redirect depending on if you have partial rendering enabled or not (respectively) but I have no clue where/how this is configured in sharepoint or what I did to screw the default rendering up.

    If anyone has any experience dealing with this kind of customization, help would be most appreciated.

    It should be noted that this is on a hosted SharePoint 2013 Foundation instance - I have no access to the server directly, I can only edit files through SharePoint Designer.



  • I call for a prayer for this poor lost soul, taken from life so suddenly. Long will we remember the sacrifice made this day.



  • Just wait until he has to integrate Navision (or whatever is called today). I think he's pretty much on the third or fourth circle.



  • :wtf:

    #Listen, this is Coding Help, if you aren't going to be constructive, could you please at least not waste my time?



  • My sharepoint knowledge is limited, but what I have was eliminated when you said you only have access to the designer. My previous comment was meant as a warning: among the small subset of programmers who know sharepoint, you need to talk to the small subset who only have access to the designer - and by posing here, you will only receive information from the small subset of that group who uses this site.

    It is possible that someone here can help you, but you'd probably be better off asking a community devoted to sharepoint.



  • @Magus said:

    My sharepoint knowledge is limited, but what I have was eliminated when you said you only have access to the designer. My previous comment was meant as a warning: among the small subset of programmers who know sharepoint, you need to talk to the small subset who only have access to the designer - and by posing here, you will only receive information from the small subset of that group who uses this site.

    It is possible that someone here can help you, but you'd probably be better off asking a community devoted to sharepoint.

    Oh I've seen tons of :wtf: answers in those forums. And when somebody actually gets some of it up and running, they eventually run into my same problem and then it's nothing but :crickets:



  • Do you at least know how the 302 redirect get associated to the Discussion content type so that the default view for it is Flat instead of AllItems? If I could figure out where the association happens, I might be able to begin to solve the problem.

    I mean, I could always hack a solution together by just regex replacing allitems with flat in the url, but that seems horribly flawed to me.



  • Ok, so I created a new js file and included it after the sp.ui.discussions.js file, and in it overrode the following functions:
    ###SP.UI.Discussions.Helpers.getFolderUrl:

    SP.UI.Discussions.Helpers.getFolderUrl = function SP_UI_Discussions_Helpers$getFolderUrl(context) {
        var $v_0 = [];
    
        FolderUrl(context.CurrentItem, context.ListSchema, $v_0);
            $v_0[0] = $v_0[0].replace("AllItems", "Flat");
            if($v_0.indexOf("&View=") > 0) {
        	$v_0.splice($v_0.indexOf("&View="), 2);
            }
            return $v_0.join('');
    };
    

    ###SP.UI.Discussions.PostBehavior.$2w_0

    SP.UI.Discussions.PostBehavior.prototype.$2w_0 = function SP_UI_Discussions_PostBehavior$$2w_0($p0, $p1) {
            if ($p1.get_$s_0()) {
                $p0.addCommunitiesCssClass('postListItem');
                $p0.addAttribute('id', this.getPostElementID('Root'));
                $p0.renderBeginTag('li');
            }
            $p0.addAttribute('title', STSHtmlEncode(this.jsonItem['Title']));
            $p0.addCssClass('ms-accessible');
            $p0.renderBeginTag('div');
            $p0.renderEndTag();
            this.$2y_0($p0);
            $p0.addCommunitiesCssClass('postMainContainer');
            $p0.addCommunitiesCssClass('postSubjectColumn');
            $p0.renderBeginTag('div');
            this.$21_0($p0, true, $p1);
            //REGION ADDED
            $p0.addCssClass('ms-metadata');
            $p0.renderBeginTag('div');
            $p0.addCssClass('ms-comm-metalineList');
            $p0.addCssClass('ms-noList');
            $p0.renderBeginTag('ul');
            this.$90_0($p0); //Category
            $p0.renderEndTag();
            $p0.renderEndTag();
            //END ADDED
            this.$1t_0($p0, true, $p1);
            $p0.addCssClass('ms-clear');
            $p0.renderBeginTag('div');
            $p0.renderEndTag();
            $p0.addCssClass('ms-metadata');
            $p0.renderBeginTag('div');
            this.$2v_0($p0, $p1);
            $p0.renderEndTag();
            $p0.renderEndTag();
            if ($p1.get_$s_0()) {
                $p0.renderEndTag();
            }
        },
    

    I then added a new function
    ###SP.UI.Discussions.PostBehavior.prototype.$90_0

    SP.UI.Discussions.PostBehavior.prototype.$90_0 = function SP_UI_Discussions_PostBehavior$$90_0($p0) {
            //Category
            var $i0 = this.jsonItem["Category"];
            if (!$i0 || $i0.length === 0) { return; }
            if ($i0 instanceof Array) {
                $i0 = $i0.join(", ");
            }
            $p0.addCssClass('ms-comm-metalineItem');
            $p0.renderBeginTag('li');
            $p0.writeEncoded("Category: " + $i0);
            $p0.renderEndTag();
        };
    

    Finally, I added a Column named "Category" as a "Choose Item". They wanted to allow multiples, so I checked allowed multiples. I then edited the Subject layout to include the column in SharePoint Designer.

    I'm sure this will end up breaking a ton of things, but bosses were happy. Though, this means they'll probably continue to hand this kind of layout update crap to me ....


    Here's the javascript to add the filter:

    ###filter.js

    (function(jq){
    	var filterFieldsParams = "";
    	var allVars = $().SPServices.SPGetQueryString();
    	
    	jq(document).ready(function() {
    		$.each(allVars, function( objKey, objValue ){
    			if(objKey.substr(0,11).toLowerCase()=="filterfield" || objKey.substr(0,11).toLowerCase()=="filtervalue"){
    				filterFieldsParams+="&"+objKey+"="+objValue;
    			}
    		});
            $.each($("[webpartid]"), function() {
    		    var obj = jq("<div class=\"list-filter\" data-wpt=\"{" + jq(this).attr("webpartid") + "}\" data-vid=\"" + _spPageContextInfo.pageListId + "\"></div>");
    		    jq(this).prepend(obj);
    		});
    	});
    
    	jq.customfilters = jq.customfilters || {};
    	jq.customfilters.getAjaxFilter = function(container, name, internalName) {
    		var listID = container.attr("data-vid");
    		var viewID = container.attr("data-wpt");
    		jq.ajax({
    			url: jq().SPServices.SPGetCurrentSite()+'/_layouts/filter.aspx?ListId='+listID+'&FieldInternalName='+internalName+'&ViewId='+viewID+'&FilterOnly=1&Filter=1'+filterFieldsParams,
    			success: function(data) {
    				// replace"<b>"+name+": </b>" with your own code if required
    				jq('#filterField'+internalName).html("<div><label>"+name+": </label></div>").append($("<div></div>").append(data).find("select, img"));
    				//clear current onChange event
    				jq("#diidFilter"+internalName).attr("onchange", '');
    				jq("#diidFilter"+internalName).off("change");
    				// add change event
    				jq("#diidFilter"+internalName).on("change", function() {
    					FilterFieldV3(viewID,internalName,this.options[this.selectedIndex].value, this.selectedIndex);
    				});
    			}
    		});
    	}
        var filters = [{ name: 'Category', internal: 'Category' }];
        jq(document).ready(function () {
            jq("#contentBox [webpartid]").each(function () {
    
                for (var i = 0, l = filters.length; i < l; i++) {
                	var filter = jq(this).find(".list-filter");
                    filter.append("<div id=\"filterField" + filters[i].internal + "\"></div>");
                    jq.customfilters.getAjaxFilter(filter, filters[i].name, filters[i].internal);
                }
            });
        });
    })(jQuery);
    
    

    it requires jquery 1.11.0 and SPServices. See here

    I based the filter script on code from:



  • @rad131304 said:

    So, by virtue of being our only programmer, I've been voluntold that I'm now managing our SharePoint customizations.

    Me too, uncluky.

    @rad131304 said:

    It should be noted that this is on a hosted SharePoint 2013 Foundation instance - I have no access to the server directly, I can only edit files through SharePoint Designer.

    That's not good...

    You don't really want to do it this way. Ideally you'd be creating a new view for the discussion board through the admin system and only modifying the template for stylistic changes. It's quicker, easier and safer this way (And I could talk you through it).



  • It would be much appreciated - or at least point me in the direction to learn it.

    What you're talking about can be done on a Hosted Sharepoint 2013 Foundation? (i.e. one where I can't install any custom webparts)

    Edit: if you're talking about using "creating a view" from the front end and then adding custom scripts through jslink, that's how I ultimately implemented it when I went to production to perform the mods.



  • Never had to add any custom JS scripts to ours, we're quite out of the box. Plus I have no idea what jslink is.



  • Client Side Rendering. In short: Every (or almost) webpart has a JS Link field that allows to link up a javascript file to be executed when that webpart loads. It allows for example to transform the way the webpart data is displayed.

    Certainly a great tool in hosted SharePoint or 356.

    See https://msdn.microsoft.com/en-us/magazine/dn745867.aspx



  • This post is deleted!


  • @Shravani_Sri said:

    mod: PJH - spammy content removed.

    I think you may have missed what I was trying to do given these links; I'm way beyond simply setting up a discussion board and setting a default view. My job was to get additional information to display in the discussion board view, and apply filtering to the view. I'm, also, not about to pay for a class on it, either, unless my company is willing to spend the money (which they are not).


  • mod

    @rad131304 said:

    I think you may have missed what I was trying to do

    I think that might be a spambot.



  • @Yamikuronue said:

    I think that might be a spambot.

    Seems so, since @PJH nuked it.

    Maybe we need a new badge: spambot woosh?



  • Hi,

    Please refer this article http://sabinatechdiary.blogspot.in/2015/08/how-to-modify-existing.html


    Please don't flag this post, people. It looks kind of spammy, but it also appears to be relevant to the question. -bz



  • The spambots really love this topic for some reason.

    The blog article also seems vaguely on topic... Are they getting smarter, or what?



  • @SabinaTechDiary said:

    It looks kind of spammy

    Let's see... First post with a blog link, coming from an account named after the blog - it might be a person trying to advertise manually, but it's still spam.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.