web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Chart

(0) ShareShare
ReportReport
Posted on by 250

Hello everyone, i have a code to make a chart but its working but when the phone field, have spaces the chart its not created, so i have to a replace to eliminate spaces i ve tried to make a a getattribute to take the field value and them set a replace but its no working. can anyone help me

code:

html = "";
scale = 1.0;
jQuery(document).ready(function(){
 
 //Escondendo Elementos
  $(".navbar").hide();
  $("#gethelp").hide();
  $("footer").hide();
  $("#resultFetch").hide();
 
 
  //Convertendo o JSON
  var result = $("#resultFetch").text();
  var jsonObj = $.parseJSON(result);
 
  var qtdEmp = montandoHtmlOrg(jsonObj);
 
  //Pesquisa
  $("#aSearch").on("click", function (event) {
            $(".searchonwebpage-highlighted").removeClass("searchonwebpage-highlighted").removeClass("match");
            if (!searchAndHighlight($('#txtSearch').val(), 'wrapper')) {
                alert('Nao Encontrado!');
            }
        });
       
  defineScale('container_org' , false);
});

function defineScale(idElemento, isModal){
 //Largura
  var larguraContentOrg = 0;
  $("#" + idElemento).width(100000000);
  var filhos = $("#" + idElemento).children("ul").children("li").each(function(){
   larguraContentOrg += $(this).width();
  });
  larguraContentOrg += larguraContentOrg * 0.15;
 if(larguraContentOrg < 600 )
  larguraContentOrg = 600;
 $("#" + idElemento).width(larguraContentOrg);
 
 // Define o Scale do Organograma para a visao default
 var widthTela = $(window).width();
  if(isModal == true){
   widthTela = widthTela * 0.88;
  }
 
 var scaleOrg = (widthTela / larguraContentOrg);
 $("#" + idElemento).css({
   'transform': 'scale(' + scaleOrg + ')',
   '-ms-transform': 'scale(' + scaleOrg + ')',
   '-moz-transform': 'scale(' + scaleOrg + ')',
   '-webkit-transform': 'scale(' + scaleOrg + ')'
  } );
}
function montandoHtmlOrg(jsonObj){
 html = '<div id="wrapper"><div id="container_org" class="tree"><ul>';
  var qtdEmp = countChildren(jsonObj , "");
 
 if( qtdEmp <= 1 ){
   $.each(jsonObj , function(index , empregado)
   {
    if(empregado.contato_primario === "")
    {
     //qtdEmp = countChildren(jsonObj , empregado.contactid);
      insertHTML(empregado);
      writeChildrenHTML(jsonObj , empregado.contactid );
      return false;
    }
  });
 }
 else{
 html += "<li><ul>";
 //Inserindo os empregados sem superior
 $.each(jsonObj , function(index , empregado)
 {
  if(empregado.contato_primario === '')
  {
    insertHTML(empregado);
    //Pesquisando se possui filho
    if(hasChildren(jsonObj , empregado.contactid) === true)
   writeChildrenHTML(jsonObj , empregado.contactid);
    html += "</li>";
  }
 });
    }
  html += "</li></ul></div></div>";
 $("#org_content").append(html);
 
  return qtdEmp;
}

//Busca
function searchAndHighlight(searchTerm, selector) {
  if (searchTerm) {
   var searchTermRegEx = new RegExp(searchTerm, "ig");
   var matches = $("#" + selector).text().match(searchTermRegEx);
   if (matches != null && matches.length > 0) {
    $('.searchonwebpage-highlighted').removeClass('searchonwebpage-highlighted');
    
    //Remove the previous matches
    $('.match').removeClass('match'); //Remove old search highlights
    if (searchTerm === "&") {
     searchTerm = "&amp;";
     searchTermRegEx = new RegExp(searchTerm, "ig");
    }
    $("#" + selector + " p,h6").each(function(){
     if($(this).text().toUpperCase().indexOf(searchTerm.toUpperCase()) >= 0 )
      $(this).addClass("match");
    });
    $('.match:first').closest('div.contato').closest('a').addClass('searchonwebpage-highlighted');
    var i = 0;
    $('#aNext').off('click').on('click', function () {
     i++;
     if (i >= $('.match').length) i = 0;
     $('.match:first').closest('div.contato').closest('a').removeClass('searchonwebpage-highlighted');
     $('.match').closest('div.contato').closest('a').eq(i-1).removeClass('searchonwebpage-highlighted');
     $('.match').closest('div.contato').closest('a').eq(i).addClass('searchonwebpage-highlighted');
     $('.tree').animate({
      scrollTop: $('.match').eq(i).offset().top
     }, 300);
    });
    if ($('.searchonwebpage-highlighted:first').length) { //if match found, scroll to where the first one appears
     $(window).scrollTop($('.searchonwebpage-highlighted:first').position().top);
    }
    return true;
   }
  }
  return false;
 }
 //Detalhes da Busca(Modal)
function htmlModalSearch(){
 var htmlFuncionario = $(".searchonwebpage-highlighted").html();
 var htmlSuperior = $(".searchonwebpage-highlighted").closest('ul').prev('a').html();
 var empregados = $(".searchonwebpage-highlighted").parent("li").children("ul").children("li").children("a");
 var qtdEmp = empregados.length;
 var htmlModal = '<button type="button" class="close" onclick="closeModal()" style="top: 5px; right: 10px; position: absolute; cursor: pointer;"><span>&times;</span></button><button type="button" class="close" onclick="zoomModal()" style="top: 5px; left:10px; position: absolute; cursor: pointer;"><span>+</span></button><div id="wrapper"><div class="container_org" id="container_modal"><ul class="tree"><li><a>';
 if(htmlSuperior != null)
  htmlModal += htmlSuperior + '</a><ul><li><a>' + htmlFuncionario + '</a>';
 else
   htmlModal += htmlFuncionario ;
 if(qtdEmp > 0){
 htmlModal += '<ul>';
   $.each(empregados , function(index, emp){
    htmlModal += '<li>' + emp.outerHTML + '</li>';
  });
 htmlModal += '</ul>';
 }
 if(htmlSuperior != null)
 htmlModal += '</li></ul>';
 
 htmlModal += '</li></ul></li></div></div>';
 $("#org_modal").html(htmlModal);
 
 $("#myModal").css("display" , "block");
 
 defineScale('container_modal' , true);
}
function closeModal(){
  $("#myModal").css("display" , "none");
}
function zoomModal(){
  $("#container_modal").css('transform' , 'scale(1.5)');
}
//Impressão
function printOrg(){
    scale = 1.0;
    $("#org_content").css({
   'transform': 'scale(' + scale + ')',
   '-ms-transform': 'scale(' + scale + ')',
   '-moz-transform': 'scale(' + scale + ')',
   '-webkit-transform': 'scale(' + scale + ')'
  } , {'transform-origin': 'top left' , '-webkit-transform-origin' : 'top left' , '-moz-transform-origin' : 'top left' , '-ms-transform-origin' : 'top left' , '-o-transform-origin': 'top left' , 'transform-origin': 'top left' });
  window.print();
}
//Zoom
function ZoomMinMax(mode , idElemento){
 if(mode == "min"){
  if(scale > 0.3)
    scale -= 0.2;
 }
 else if(mode == "max"){
    scale += 0.2;
 }
 else if(mode == "red"){
  scale = 1.0;
  window.scrollTo(0,0);
 }
  
  
 $("#" + idElemento).css({
   'transform': 'scale(' + scale + ')',
   '-ms-transform': 'scale(' + scale + ')',
   '-moz-transform': 'scale(' + scale + ')',
   '-webkit-transform': 'scale(' + scale + ')'
  } ,
  {'transform-origin': 'top left' ,
  '-webkit-transform-origin' : 'top left' ,
  '-moz-transform-origin' : 'top left' ,
  '-ms-transform-origin' : 'top left' ,
  '-o-transform-origin': 'top left' ,
  'transform-origin': 'top left' });
}
//Composição do HTML do Organograma
function writeChildrenHTML(jsonObj , idContato){
  html += "<ul>";
  $.each(jsonObj , function(index , contato)
  {
    if(idContato == contato.contato_primario)
 {
      insertHTML(contato);
   if(hasChildren(jsonObj , contato.contactid))
        writeChildrenHTML(jsonObj , contato.contactid);
    }
    html += "</li>";
  });
  html += "</ul>";
}
function insertHTML(contato){
  if(contato.urlImage == "data:image/jpeg;base64,")
    contato.urlImage = "/person_icon";
  if(contato.funcaoColor == '')
   contato.funcaoColor = "#ECECEC";
    
   html += '<li><a style="background-color:' + contato.funcaoColor +';"><div class="contato"><div class="item"><div class="itemLine"><div class="image"><img src="' + contato.urlImage + '" alt="imagem"></div><div class="name"><h6>' + contato.fullname + '</h6></div></div><div class="itemLine"><h6>' + contato.jobtitle + '</h6><p>Tel.:' + contato.mobilephone + '</p><p>Email:' + contato.emailaddress1 + '</p></div></div></div></a>';
}
function hasChildren(jsonObj , idContato){
 var children = false;
 $.each(jsonObj , function(indexChildren , contactChildren)
      {
        if(idContato == contactChildren.contato_primario)
  {
   children = true;
   return children;
  }
      });
  //Nao encontrou nenhum filho
 return children;
}
function countChildren(jsonObj , contactID){
var qtdEmp = 0;
$.each(jsonObj , function(index, contato){
  if(contato.contato_primario === contactID )
   qtdEmp ++;
 });
 return qtdEmp;
}

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans