Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. // Change these things here (entity = "ModuleName.EntityName")
  2. var entity = "MyFirstModule.Audit";
  3. var typeAttr = "DownloadType";
  4. var pageAttr = "Page";
  5. // Don't change things below
  6.  
  7. function getContentForm() {
  8. if (mx.router && mx.router.getContentForm) {
  9. return mx.router.getContentForm();
  10. }
  11. if (mx.ui && mx.ui.getContentForm) {
  12. return mx.ui.getContentForm();
  13. }
  14. if (mx.ui && mx.ui.getCurrentForm) {
  15. return mx.ui.getCurrentForm();
  16. }
  17. return {
  18. path: 'unknown'
  19. };
  20. }
  21.  
  22. var widget = this;
  23.  
  24. $(function () {
  25. var buttonCSV = $('.export-csv, .export-excel');
  26.  
  27. if (buttonCSV) {
  28. buttonCSV.each(function () {
  29. var $this = $(this);
  30. var type = $this.hasClass('export-csv') ? 'CSV' : 'EXCEL';
  31. var buttonWidget;
  32.  
  33. try {
  34. buttonWidget = dijit.registry.byNode($this.get(0));
  35. } catch (e) {
  36. console.error('Cannot find widget with class: ' + identifier);
  37. }
  38.  
  39. if (buttonWidget) {
  40. buttonWidget.connect(buttonWidget, 'onClick', function () {
  41. if (!widget._contextObj) {
  42. console.warn('no obj');
  43. return;
  44. }
  45. mx.data.create({
  46. entity: entity,
  47. callback: function (obj) {
  48. obj.set(typeAttr, type);
  49. obj.set(pageAttr, getContentForm().path);
  50.  
  51. mx.data.commit({
  52. mxobj: obj,
  53. callback: function () {
  54. mx.data.save({
  55. mxobj: obj,
  56. callback: function () {},
  57. error: function (err) {
  58. console.error(err);
  59. }
  60. })
  61. },
  62. error: function (err) {
  63. console.error(err);
  64. }
  65. });
  66. },
  67. error: function (err) {
  68. console.error(err);
  69. }
  70. })
  71. });
  72. } else {
  73. console.log('Cannot find widget for', $this);
  74. }
  75. })
  76. }
  77. });
Add Comment
Please, Sign In to add comment