Guest User

Untitled

a guest
Nov 22nd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. $(function () {
  2. initializePeoplePicker('peoplePickerDiv');
  3.  
  4. // Render and initialize the client-side People Picker.
  5. function initializePeoplePicker(peoplePickerElementId) {
  6.  
  7. // Create a schema to store picker properties, and set the properties.
  8. var schema = {};
  9. schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
  10. schema['SearchPrincipalSource'] = 15;
  11. schema['ResolvePrincipalSource'] = 15;
  12. schema['AllowMultipleValues'] = false;
  13. schema['MaximumEntitySuggestions'] = 50;
  14. schema['Width'] = '280px';
  15.  
  16. // Render and initialize the picker.
  17. // Pass the ID of the DOM element that contains the picker, an array of initial
  18. // PickerEntity objects to set the picker value, and a schema that defines
  19. // picker properties.
  20. SPSODAction(["sp.js", "clienttemplates.js", "clientforms.js",
  21. "clientpeoplepicker.js", "autofill.js"
  22. ], function () {
  23. SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
  24. });
  25. }
  26.  
  27. function SPSODAction(sodScripts, onLoadAction) {
  28. var x;
  29. if (SP.SOD.loadMultiple) {
  30. for (x = 0; x < sodScripts.length; x = x + 1) {
  31. if (!_v_dictSod[sodScripts[x]]) {
  32. SP.SOD.registerSod(sodScripts[x], '/_layouts/15/' + sodScripts[x]);
  33. }
  34. }
  35. SP.SOD.loadMultiple(sodScripts, onLoadAction);
  36. } else {
  37. ExecuteOrDelayUntilScriptLoaded(onLoadAction, sodScripts[0]);
  38. }
  39. }
  40.  
  41. // Query the picker for user information.
  42. function getUserInfo() {
  43.  
  44. showBrowserDialog()
  45.  
  46. // Get the people picker object from the page.
  47. var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
  48.  
  49. // Get information about all users.
  50. var users = peoplePicker.GetAllUserInfo();
  51. var userInfo = '';
  52. for (var i = 0; i < users.length; i++) {
  53. var user = users[i];
  54. for (var userProperty in user) {
  55. userInfo += userProperty + ': ' + user[userProperty] + '<br>';
  56. }
  57. }
  58. $('#resolvedUsers').html(userInfo);
  59.  
  60. // Get user keys.
  61. var keys = peoplePicker.GetAllUserKeys();
  62. $('#userKeys').html(keys);
  63. }
  64.  
  65. function showBrowserDialog() {
  66. var defaultSearch = '';
  67. var sDialogUrl = '\u002fsites\u002fpriceToWinDealDB\u002f_layouts\u002f15\u002fPicker.aspx?MultiSelect=False\u0026CustomProperty=User\u00252CSecGroup\u00252CSPGroup\u00252CDL\u00253B\u00253B1\u00253B\u00253B\u00253BFalse\u0026DialogTitle=Select\u002520People\u002520and\u002520Groups\u0026DialogImage=\u00252F\u00255Flayouts\u00252F15\u00252Fimages\u00252Fppeople\u00252Egif\u0026PickerDialogType=Microsoft\u00252ESharePoint\u00252EWebControls\u00252EPeoplePickerDialog\u00252C\u002520Microsoft\u00252ESharePoint\u00252C\u002520Version\u00253D16\u00252E0\u00252E0\u00252E0\u00252C\u002520Culture\u00253Dneutral\u00252C\u002520PublicKeyToken\u00253D71e9bce111e9429c\u0026ForceClaims=False\u0026DisableClaims=False\u0026EnabledClaimProviders=\u0026EntitySeparator=\u00253B\u0025EF\u0025BC\u00259B\u0025EF\u0025B9\u002594\u0025EF\u0025B8\u002594\u0025E2\u00258D\u0025AE\u0025E2\u002581\u00258F\u0025E1\u00258D\u0025A4\u0025D8\u00259B';
  68. // var sDialogUrl = escape("/sites/priceToWinDealDB/_layouts/15/Picker.aspx?MultiSelect=False&CustomProperty=User,SecGroup,SPGroup,DL;;1;;;False&DialogTitle=Select People and Groups")
  69. sDialogUrl = sDialogUrl + '&DefaultSearch=' + escapeProperly(defaultSearch);
  70. var dialogWidth = 575;
  71. var dialogHeight = 500;
  72. var options = {
  73. title: "Select People and Groups",
  74. width: dialogWidth,
  75. height: dialogHeight,
  76. resizeable: true,
  77. url: sDialogUrl,
  78. dialogReturnValueCallback: function (status, data, cc) {
  79. console.log(data, status, cc)
  80. }
  81. };
  82. var rv = EnsureScriptParams("SP.UI.Dialog.js", "SP.UI.ModalDialog.showModalDialog", options);
  83. }
  84.  
  85. $('#btn_getUserInfo').on('click', getUserInfo)
  86. })
Add Comment
Please, Sign In to add comment