market.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. let pluginsTable;
  2. $(document).ready(function() {
  3. $('.box-body').css('min-height', $('.content-wrapper').height() - $('.content-header').outerHeight() - 120);
  4. pluginsTable = $('#plugin-table').DataTable({
  5. language: trans('vendor.datatables'),
  6. responsive: true,
  7. autoWidth: false,
  8. processing: true,
  9. ordering: false,
  10. serverSide: false, //未知原因,开了这个会有问题
  11. ajax: {
  12. url: '/plugins-market/controllers/market/ajaxPluginList',
  13. dataSrc: ''
  14. },
  15. createdRow: function (row, data, index) {},
  16. columnDefs: [
  17. {
  18. targets: 0,
  19. title: trans('market.market.title'),
  20. data: 'title'
  21. },
  22. {
  23. targets: 1,
  24. title: trans('market.market.description'),
  25. data: 'description',
  26. width: '40%'
  27. },
  28. {
  29. targets: 2,
  30. title: trans('market.market.author'),
  31. data: 'author',
  32. width: '10%'
  33. },
  34. {
  35. targets: 3,
  36. title: trans('market.market.version'),
  37. data: 'version',
  38. width: '9%',
  39. render: function (data, type, row, meta) {
  40. options = '';
  41. for (var i = data.length - 1; i >= 0; i--) {
  42. options += '<option>' + data[i] + '</option>';
  43. }
  44. return '<select id="plugin-' + row.name + '-vers" class="form-control">' + options + '</select>';
  45. }
  46. },
  47. {
  48. targets: 4,
  49. title: trans('market.market.size'),
  50. data: 'size',
  51. width: '8%'
  52. },
  53. {
  54. targets: 5,
  55. title: trans('market.market.operations'),
  56. data: 'brief',
  57. width: '20%',
  58. render: function (data, type, row, meta) {
  59. let downloadButtonClass = 'btn-primary';
  60. let downloadButtonHint = '';
  61. switch (row.versionStatus) {
  62. case 'preview':
  63. downloadButtonClass = 'btn-warning';
  64. downloadButtonHint = trans('market.market.versionPre');
  65. break;
  66. case 'new':
  67. downloadButtonClass = 'btn-success';
  68. downloadButtonHint = trans('market.market.versionNew');
  69. break;
  70. default:
  71. break;
  72. }
  73. let downloadButton = '<input type="button" id="plugin-' + row.name + '" class="btn ' + downloadButtonClass + ' btn-sm" title="' + downloadButtonHint + '"' +
  74. ' onclick="readyToDownload(\'' + row.name + '\',\'' + row.title + '\',\'' + row.versionStatus + '\');" value="' + trans('market.market.download') + '">';
  75. let briefButton = '<a class="btn btn-default btn-sm" href="' + data + '" target="_blank" title="' + trans('market.market.briefHint') + '">' + trans('market.market.viewBrief') + '</a>'
  76. return downloadButton + briefButton;
  77. }
  78. }
  79. ]
  80. });
  81. });
  82. function readyToDownload(pluginName, pluginTitle, versionStatus) {
  83. if (versionStatus == 'preview') {
  84. swal({
  85. title: trans('market.preview.title'),
  86. text: trans('market.preview.text'),
  87. type: 'warning',
  88. showCancelButton: true,
  89. confirmButtonText: trans('market.preview.confirmButton'),
  90. cancelButtonText: trans('market.preview.cancelButton')
  91. }).then(function () { return download(pluginName, pluginTitle); });
  92. } else {
  93. let version = $('select#plugin-' + pluginName + '-vers').val();
  94. return download(pluginName, pluginTitle, version);
  95. }
  96. };
  97. function download(pluginName, pluginTitle, version) {
  98. $('input#plugin-' + pluginName).attr({ disabled: true });
  99. $('input#plugin-' + pluginName).val(trans('market.downloading'));
  100. toastr.info(trans('market.readyToDownload', { 'plugin-name': pluginTitle }));
  101. $.post(
  102. '/admin/plugins-market/download',
  103. { name: pluginName, version: version },
  104. function (data) {
  105. switch (data.code) {
  106. case -1:
  107. toastr.error(trans('market.failedDownload', { 'message': trans('market.error.requestPermission') }));
  108. break;
  109. case 0:
  110. if (data.enable) {
  111. $.post('/admin/plugins/manage', { action: 'enable', name: pluginName }, function (data) {});
  112. }
  113. toastr.success(trans('market.completeDownload', { 'plugin-name': pluginTitle }));
  114. break;
  115. case 1:
  116. toastr.error(trans('market.failedDownload', { 'message': trans('market.error.writePermission') }));
  117. break;
  118. case 2:
  119. toastr.error(trans('market.failedDownload', { 'message': trans('market.error.connection') }));
  120. break;
  121. case 3:
  122. toastr.error(trans('market.failedDownload', { 'message': trans('market.error.download') }));
  123. break;
  124. case 4:
  125. toastr.error(trans('market.failedDownload', { 'message': trans('market.error.unzip') }));
  126. break;
  127. default:
  128. toastr.error(trans('market.error.unknown'));
  129. break;
  130. };
  131. $('input#plugin-' + pluginName).attr({ disabled: false });
  132. $('input#plugin-' + pluginName).val(trans('market.download'));
  133. });
  134. };