Created
November 13, 2017 21:51
-
-
Save jsmithdev/132e4d479cfa1bf2ba39fd65f754fd89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//page | |
function Buyer_Prospect__c(u, rec){ | |
this.Id = rec | |
this.Responsible_Broker__c = u | |
} | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.BuyerProspectList_ext.getUsers}', | |
(res, err) => { | |
if(err.status){ | |
const contain = document.createElement('div') | |
let select = `<select onchange="saveBpUser(e)">` | |
select += `<option value="null">--None--</option>` | |
let opts = res.map(x => select += `<option value="${x.Id}">${x.Name}</option>`); | |
select += '</select>' | |
contain.innerHTML = select | |
select = contain.childNodes[0] | |
const saveBpUser = (e) => { | |
console.log(`This was changed ${e.target.value} for record ${e.target.parentElement.dataset.id}`) | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.BuyerProspectList_ext.saveBpUser}', | |
new Buyer_Prospect__c(e.target.value, e.target.parentElement.dataset.id), | |
(r, e) => e.status ? console.log(r) : console.error(e) | |
) | |
} | |
const brokers = Array.from(document.getElementsByClassName('broker')) | |
brokers.map(x => { | |
const newSelect = select.cloneNode(true); | |
newSelect.onchange = saveBpUser | |
if(x.innerHTML){ | |
newSelect.value = x.innerHTML | |
x.parentElement.replaceChild(newSelect, x) | |
} | |
else { | |
x.parentElement.replaceChild(newSelect, x) | |
} | |
}) | |
} | |
else { | |
console.error(err.message); | |
} | |
} | |
); | |
//controller | |
@remoteAction | |
public static List<User> getUsers(){ | |
return [SELECT Id, Name FROM User WHERE isActive = true]; | |
} | |
@remoteAction | |
public static String saveBpUser(Buyer_Prospect__c bp){ | |
update bp; | |
return 'Updated BP w user'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment