persone.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. CKEDITOR.dialog.add( 'personeDialog', function( editor ) {
  2. // $.getJSON( "/person/Ajaxlist", function( data, ok ) {
  3. //
  4. // for (var key in data) {
  5. // persone = '<option value="'+data[key]['alias']+'">'+data[key]['name']+'</option>';
  6. // $('select.cke_dialog_ui_input_select').append(persone);
  7. // }
  8. //
  9. // });
  10. let selection = '';
  11. return {
  12. title: 'Добавить персону',
  13. minWidth: 400,
  14. minHeight: 200,
  15. contents: [
  16. {
  17. id: 'tab',
  18. label: 'first tab',
  19. elements: [
  20. {
  21. type : 'select',
  22. id: null,
  23. label: 'Выберите из списка',
  24. items : [],
  25. 'default' : '',
  26. }]
  27. }],
  28. onOk : function()
  29. {
  30. if(selection!==''){
  31. const selectionText = editor.getSelection();
  32. const person = editor.document.createElement( 'a' );
  33. if(selectionText.getSelectedText()===''){
  34. person.setAttribute( 'href', selection.alias );
  35. person.setAttribute( 'class', 'person-inject' );
  36. person.setHtml( selection.name );
  37. editor.insertElement( person );
  38. } else {
  39. person.setAttribute( 'href', selection.alias );
  40. person.setAttribute( 'class', 'person' );
  41. person.setHtml( selectionText.getSelectedText() );
  42. editor.insertElement( person );
  43. }
  44. }
  45. },
  46. onShow: function () {
  47. $('.cke_dialog_ui_input_select').css({width:"100%"});
  48. $('select.cke_dialog_ui_input_select').select2({
  49. language: "ru",
  50. ajax: {
  51. url: "/person/Ajaxlist",
  52. dataType: 'json',
  53. delay: 250,
  54. data: function (params) {
  55. return {
  56. q: params.term,
  57. page: params.page
  58. };
  59. },
  60. processResults: function (data, params) {
  61. params.page = params.page || 1;
  62. return {
  63. results: data.items,
  64. };
  65. },
  66. cache: true
  67. },
  68. placeholder: 'Поиск персоны',
  69. minimumInputLength: 1,
  70. templateResult: formatRepo,
  71. templateSelection: formatRepoSelection
  72. });
  73. function formatRepo (repo) {
  74. if (repo.loading) {
  75. return repo.text;
  76. }
  77. var $container = $(
  78. "<div class='select2-result-repository clearfix'>" +
  79. "<div class='select2-result-repository__avatar' style='width: 70px; height: 70px; overflow: hidden; float: left; margin-right: 20px;'><img style='width: 100%; height: auto;' src='" + repo.avatar_url + "' /></div>" +
  80. "<div class='select2-result-repository__meta'>" +
  81. "<div class='select2-result-repository__title' style='font-weight: bold;'></div>" +
  82. "<div class='select2-result-repository__description'></div>" +
  83. "</div>" +
  84. "</div>"
  85. );
  86. $container.find(".select2-result-repository__title").text(repo.name);
  87. $container.find(".select2-result-repository__description").text(repo.description);
  88. return $container;
  89. }
  90. function formatRepoSelection (repo) {
  91. selection = repo;
  92. return repo.name || repo.text;
  93. }
  94. }
  95. };
  96. });