Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define([
- 'dojo/_base/declare',
- 'dojo/_base/lang',
- 'dijit/Dialog',
- 'dojo/aspect',
- 'Sage/UI/SDataLookup'
- ],
- function (
- declare,
- lang,
- dialog,
- aspect,
- SDataLookup
- ) {
- // define new column type for grid
- var contactColumn = declare('FX.ContactColumn', null, {
- icon: '',
- defaultValue: '',
- constructor: function (args) {
- lang.mixin(this, args);
- },
- format: function (val, entity) {
- // column will call show in the object defined below
- var exec = "javascript:FX.ViewContacts.show('" + val + "', '" + entity.$descriptor + "')";
- return '<a href="' + exec + '">Contacts</a>';
- }
- });
- var __viewContacts = {
- show: function(accountId, accountName) {
- // define dialog
- var dlg = new dialog({
- title: 'Contacts for ' + (accountName || 'Account'),
- style: 'width: 400px;',
- content: '<i>Loading contacts...</i>'
- });
- // use SData to retrieve contacts for account
- var service = Sage.Data.SDataServiceRegistry.getSDataService('dynamic');
- var request = new Sage.SData.Client.SDataResourceCollectionRequest(service)
- .setResourceKind('contacts')
- .setQueryArg('where', 'Account.Id eq "' + accountId + '"')
- .setQueryArg('select', 'LastName,FirstName,Title');
- request.read({
- success: function (results) {
- // create content for dialog
- var content = '';
- results.$resources.forEach(function(contact) {
- content += '<li>' + contact.FirstName + ' ' + contact.LastName;
- if (contact.Title) content += ' - ' + contact.Title;
- content += ' <a href="Contact.aspx&entityId=' + contact.$key + '" tabindex="-1" title="View Contact"><i class="fa fa-external-link"></i></a></li>';
- });
- content = (content == '' ? '<i>Account does not have any contacts</i>' : '<ul>' + content + '</ul>');
- // set dialog content & show
- dlg.set('content', content);
- dlg.show();
- },
- failure: function (result) {
- Sage.UI.Dialogs.showError(result);
- }
- });
- },
- // add new column to lookups that are for accounts
- initLookupColumns: function() {
- aspect.before(SDataLookup.prototype, 'initGrid', function() {
- var col = {
- name: 'FXViewContacts',
- field: '$key',
- label: '',
- type: contactColumn,
- sortable: false,
- width: 5
- };
- if (this.sdataStore.resourceKind === 'accounts' && this.structure.filter(function(c) { return c.name === 'FXViewContacts' }).length === 0) {
- this.structure.push(col);
- }
- });
- }
- };
- __viewContacts.initLookupColumns();
- // add to window namespace so can be invoked from hyperlink
- window.FX = window.FX || {};
- window.FX.ViewContacts = __viewContacts;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement