var Tower =[];
var Category = [];
var info=[];
var ddl_Tower;
var ddl_Category;
var ddl_Info;
$(document).ready(function () {
$('div[Id^="Tower"],div[Id^="Category"],div[Id^="Info"]').hide();
ddl_Tower = $('<select id="ddlTower" onchange="getTowerval(this,true);"/>');
$('<option />', {value:"Select", text: "Select"}).appendTo(ddl_Tower);
$('div[title="Tower1"]').closest("td").append(ddl_Tower);
ddl_Category = $('<select id="ddlCategory" onchange="getCategoryval(this,true);"/>');
$('<option />', {value:"Select", text: "Select"}).appendTo(ddl_Category);
$('div[title="Category1"]').closest("td").append(ddl_Category);
ddl_Info = $('<select id="ddlInfo" onchange="getInfoval(this,true);"/>');
$('<option />', {value: "Select", text: "Select"}).appendTo(ddl_Info);
$('div[title="Info1"]').closest("td").append(ddl_Info);
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", function () {
$.getScript(scriptbase + "SP.Taxonomy.js", function () {
context = SP.ClientContext.get_current();
//Call your code here.
execOperation();
});
});
});
});
function execOperation(){
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStoreColl = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStoreT = termStoreColl.getByName("Managed Metadata Service");
//GUID of Term Set from which to get the Terms.
var termSetT = termStoreT.getTermSet("257bfe19-ff48-482f-bc22-72cd5f471320");
var termsT = termSetT.getAllTerms();
context.load(termsT);
context.executeQueryAsync(function(){
var termEnumerator = termsT.getEnumerator();
var termList = "Terms: \n";
while(termEnumerator.moveNext()){
var currentTerm = termEnumerator.get_current();
termList += currentTerm.get_name() + "\n";
var currentTermValue = currentTerm.get_pathOfTerm().split(';');
var currentTermId=currentTerm.get_id().toString();
if(currentTermValue.length==1)
{
var temTower={
Tower:currentTermValue[0],
TowerId:currentTermId
};
Tower.push(temTower);
}
else if(currentTermValue.length==2){
var tempCat={
Tower:currentTermValue[0],
Category:currentTermValue[1],
CategoryId:currentTermId
}
Category.push(tempCat);
}
else if(currentTermValue.length==3){
var tempInfo={
Tower:currentTermValue[0],
Category:currentTermValue[1],
info:currentTermValue[2],
infoId:currentTermId
}
info.push(tempInfo);
}
}
for(var val in Tower)
{
$('<option />', {value: Tower[val].TowerId, text: Tower[val].Tower}).appendTo(ddl_Tower);
}
LoadTermStoreData();
console.log(termList);
},function(sender,args){
console.log(args.get_message());
});
}
function getTowerval(sel,Change)
{
$('#ddlCategory option').remove();
$('<option />', {value:"Select", text: "Select"}).appendTo(ddl_Category);
$('#ddlInfo option').remove();
$('<option />', {value:"Select", text: "Select"}).appendTo(ddl_Info);
var TowerData = sel.options[sel.selectedIndex].text;
var TowerId=sel.value;
for(var i=0;i<Category.length;i++){
if(Category[i].Tower==TowerData){
$('<option />', {value: Category[i].CategoryId, text: Category[i].Category}).appendTo(ddl_Category);
}
}
if(TowerData=="Select"&&Change){
$('div[id^="Tower"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Tower1_']").val("");
}else if(Change){
$('div[id^="Tower"]').find('.ms-taxonomy-writeableregion')[0].innerText = TowerData;
$("input[id^='Tower1_']").val(TowerData+"|"+TowerId);
$('div[id^="Category"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Category1_']").val("");
$('div[id^="Info"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Info1_']").val("");
}
}
function getCategoryval(sel,Change)
{
$('#ddlInfo option').remove();
$('<option />', {value:"Select", text: "Select"}).appendTo(ddl_Info);
var CatDATA = sel.options[sel.selectedIndex].text;
var CatId=sel.value;
var Tower=$("#ddlTower option:selected").text();
for(var i=0;i<info.length;i++){
if(info[i].Category== CatDATA && info[i].Tower==Tower){
$('<option />', {value: info[i].infoId, text: info[i].info}).appendTo(ddl_Info);
}
}
if(CatDATA=="Select"&&Change){
$('div[id^="Category"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Category1_']").val("");
}else if(Change){
$('div[id^="Category"]').find('.ms-taxonomy-writeableregion')[0].innerText = CatDATA;
$("input[id^='Category1_']").val(CatDATA+"|"+CatId);
$('div[id^="Info"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Info1_']").val("");
}
}
function getInfoval(sel,Change){
var InfoData=sel.options[sel.selectedIndex].text;
var InfoId=sel.value;
if(InfoData=="Select"&&Change){
$('div[id^="Info"]').find('.ms-taxonomy-writeableregion')[0].innerText = "";
$("input[id^='Info1_']").val("");
}
else if(Change){
$('div[id^="Info"]').find('.ms-taxonomy-writeableregion')[0].innerText = InfoData;
$("input[id^='Info1_']").val(InfoData+"|"+InfoId);
}
}
function LoadTermStoreData(){
var TowerSelected=$("input[id^='Tower1_']").val().split("|");
if(TowerSelected.length==2){
$("#ddlTower").val(TowerSelected[1]);
getTowerval($("#ddlTower")[0],false);
var CategorySel=$("input[id^='Category1_']").val().split("|");
if(CategorySel.length==2){
$("#ddlCategory").val(CategorySel[1]);
getCategoryval($("#ddlCategory")[0],false);
var InfoSel=$("input[id^='Info1_']").val().split("|");
if(InfoSel.length==2){
$("#ddlInfo").val(InfoSel[1]);
}
}
}
}
No comments:
Post a Comment