Created
April 18, 2015 15:23
-
-
Save keirbowden/c99015c1006f7a14f08d to your computer and use it in GitHub Desktop.
Accounts List JavaScript Component
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
<apex:component > | |
<script> | |
var accsListCtrl={ | |
// renders the HTML to display the supplied accounts in bootstrap panels | |
renderAccs : function(accounts) { | |
var markup=''; | |
$.each(accounts, function(idx, acc) { | |
markup+= ' <div class="row-fluid"> \n' + | |
' <div class="col-xs-12 fullwidth"> \n' + | |
' <div class="panel panel-primary"> \n' + | |
' <div class="panel-heading"> \n' + | |
' <h3 class="panel-title">' + acc.Name + '</h3> \n' + | |
' </div> \n' + | |
' <div class="panel-body"> \n' + | |
' <div class="top-buffer table-responsive"> ' + | |
' <label>Industry: </label>' + acc.Industry + | |
' </div> \n' + | |
' </div> \n' + | |
' <div class="panel-footer"> \n' + | |
' </div> \n' + | |
' </div> \n' + | |
' </div> \n' + | |
' </div> \n' + | |
' <div class="fluid-row"> \n' + | |
' <div class="col-xs-12 top-buffer"> \n ' + | |
' </div> \n' + | |
' </div> \n'; | |
}); | |
$('#accountsPanel').html(markup); | |
}, | |
// get the latest accounts from the server | |
getAccounts : function() { | |
AccountsListController.GetAccounts(accsListCtrl.handleAccs); | |
}, | |
handleAccs : function (result, event) { | |
if (event.status) | |
{ | |
accsListCtrl.renderAccs(result); | |
} | |
else if (event.type === 'exception') | |
{ | |
alert('Exception in Remote Action\n\nMessage: ' + event.message + '\n\nWhere: ' + event.where); | |
} | |
else | |
{ | |
alert('Something else went wrong'); | |
} | |
} | |
}; | |
$(document).ready(function() { | |
accsListCtrl.getAccounts(); | |
}); | |
</script> | |
</apex:component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment