Tuesday, September 25, 2018

Page Web parts

Page Web parts:
---------------------------------------------------------------

$(document).ready(function(){
  GetBIMResoucesItems();

});



function GetBIMResoucesItems() {

var listname = 'BIMResourceLinks';

var url ="/_api/Web/Lists/GetByTitle('"+listname +"')/Items?$select=LinkType,Title,LinkURL,IsActive&$filter=IsActive eq 1&$orderby=Created desc";
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            //console.log(data.d.results);
            IterateBIMItems(data.d.results);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}

function IterateBIMItems(result)
{
  var bimData = [];
  if(result.length > 0)
  {
     for(var i=0 ; i<result.length; i++)
{

   var LinkType = result[i].LinkType;
   var Title    = result[i].Title;
   var LinkURL  = result[i].LinkURL;
       var IsActive = result[i].IsActive;
 
       var objArry={
          LinkType : LinkType,
          Title    : Title,
          LinkURL  : LinkURL,
          IsActive : IsActive
      }
      bimData.push(objArry);
    };
  }
 
  GetLinkHeadingArr(bimData);
}

function GetLinkHeadingArr(objArry)
{
 var heads = ["BIM Resources","Trainings","Important Links"];
 
  for(var i=0 ; i<heads.length; i++)
  {
 //  var objArryFilter = objArry.filter(k=> k.LinkType==heads[i]);
 
   var objArryFilter = objArry.filter(function(k){ return k.LinkType===heads[i]});

 
for(var j=objArryFilter.length-1; j>=3; j--)
var newarr = objArryFilter.splice(j, 1); 
 
 
    CreateBIMHTML(objArryFilter,heads[i]);
  }

}

function CreateBIMHTML(objArryFilter,heads)
{
  var content ="<div class='right_title'>"+heads+"<span></span></div>";
  content +="<div class='list_view'>";
  content +="<ul>";
 
  for(var i=0 ; i<objArryFilter.length; i++)
  { 
    content +="<li><a href='"+objArryFilter[i].LinkURL+"'>"+objArryFilter[i].Title+"</a></li>";
  }
 
 
 
  if(heads ==="BIM Resources")
  {
     var url = _spPageContextInfo.webAbsoluteUrl +"/Lists/BIMResourceLinks/AllItems.aspx?FilterName=LinkType&FilterMultiValue=BIM%20Resources";
     content +="</ul><div class='more_list'><a href="+url+" target='_blank'>More<span>...</span></a></div>"; 
     $('#Bim').append(content);
  }
   
  if(heads ==="Trainings")
  {
     var url = _spPageContextInfo.webAbsoluteUrl +"/Lists/BIMResourceLinks/AllItems.aspx?FilterName=LinkType&FilterMultiValue=Trainings";
     content +="</ul><div class='more_list'><a href="+url+" target='_blank'>More<span>...</span></a></div>"; 
     $('#Traning').append(content);

  }
   
  if(heads ==="Important Links")
  {   
     var url = _spPageContextInfo.webAbsoluteUrl +"/Lists/BIMResourceLinks/AllItems.aspx?FilterName=LinkType&FilterMultiValue=Important%20Links";
     content +="</ul><div class='more_list'><a href="+url+" target='_blank'>More<span>...</span></a></div>"; 
$('#Implink').append(content);
  }
 
  content="";
}




No comments:

Post a Comment