+ Start a Discussion
Kevin Chiles 930Kevin Chiles 930 

How to Convert Java Script Button to Lightning Action

Hello!
I am trying to convert a button from Java script to a lighting component but am having no luck.  I am hoping for some pointers that could help me get this going.  I was hoping this would be much easier that is has turned out to be 
 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

var ___spinner_id = '___spinner';
 
function showSimpleSpinner() {
   
  if (document.getElementById(___spinner_id)==null) {
    var _spinnerHtml = '<div id="' + ___spinner_id + '" style="width:100%; height:100%; z-index:1001; width:100%; height:100%; top: 0px; left:0px; position:fixed;">' +
                         '<div style="background-color:#333; opacity:0.4; width:100%; height:100%; "></div>' +
                         '<div style="display:block; position: fixed;background-image:url(/img/loading32.gif); top: 50%; left:50%; margin-left:-16px; margin-top: -16px;width: 32px; height:32px;"/>' +
                       '</div>';
    var _tmp = document.createElement('div');
    _tmp.innerHTML = _spinnerHtml;
    document.body.appendChild(_tmp.firstChild);
  }
   
  document.getElementById(___spinner_id).style.display = 'block';
}
 
function hideSimpleSpinner() {
  document.getElementById(___spinner_id).style.display = 'none';
}

showSimpleSpinner();

try{
if ( {!Opportunity.IsClosed} ) {
alert('Can not change Purchase Path if Opportunity is closed');
hideSimpleSpinner();
} else {
sforce.apex.execute("trac_OpportunityHelper","rebuildPurchasePath",{oppId:'{! Opportunity.Id }'});
window.location.href = window.location.href;
}
}catch(e){
alert(e);
hideSimpleSpinner();
}