DownLoad.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * 附件下载按钮
  3. **
  4. * 已修改为form加载后,自动查找附件
  5. */
  6. Ext.define('erp.view.core.button.DownLoad',{
  7. extend: 'Ext.Button',
  8. alias: 'widget.erpDownloadButton',
  9. iconCls: 'x-button-icon-download',
  10. cls: 'x-btn-gray',
  11. text: $I18N.common.button.erpDownloadButton,
  12. style: {
  13. marginLeft: '10px'
  14. },
  15. width: 100,
  16. menu: Ext.create('Ext.menu.Menu', {
  17. minWidth: 600,
  18. minHeight: 500,
  19. margin: '0 0 10 0',
  20. floating: true,
  21. items: []
  22. }),
  23. initComponent : function(){
  24. this.callParent(arguments);
  25. },
  26. listeners: {
  27. afterrender: function(btn){
  28. //btn.hide();
  29. var form = btn.ownerCt.ownerCt;
  30. var id = Ext.getCmp(form.keyField).value;
  31. if(id != null && id != 0){
  32. btn.download(id);
  33. }
  34. Ext.getCmp(btn.ownerCt.ownerCt.keyField).on('change', function(){
  35. var id = Ext.getCmp(form.keyField).value;
  36. if(id != null && id != 0){
  37. btn.menu.removeAll(true);
  38. btn.download(id);
  39. }
  40. });
  41. }
  42. },
  43. download: function(id){
  44. var attach = new Array();
  45. Ext.Ajax.request({//拿到grid的columns
  46. url : basePath + 'common/getFormAttachs.action',
  47. async: false,
  48. params: {
  49. caller: caller,
  50. keyvalue: id
  51. },
  52. method : 'post',
  53. callback : function(options,success,response){
  54. var res = new Ext.decode(response.responseText);
  55. if(res.exception || res.exceptionInfo){
  56. showError(res.exceptionInfo);
  57. return;
  58. }
  59. attach = res.attach != null ? res.attach : [];
  60. }
  61. });
  62. var items = this.menu;
  63. items.add({
  64. height: 20,
  65. width: 600,
  66. style: 'background:#CDBA96;',
  67. html: '<h3>附件:</h3>',
  68. });
  69. Ext.each(attach, function(){
  70. var path = this.fa_path;
  71. var name = '';
  72. if(contains(path, '\\', true)){
  73. name = path.substring(path.lastIndexOf('\\') + 1);
  74. } else {
  75. name = path.substring(path.lastIndexOf('/') + 1);
  76. }
  77. items.add({
  78. style: 'background:#C6E2FF;',
  79. html: '<img src="' + basePath + 'resource/images/mainpage/things.png" width=16 height=16/>' +
  80. '<span>文件:' + name + '<a href="' + basePath + "common/download.action?path=" + path + '">下载</a></span>',
  81. });
  82. });
  83. /*var win = new Ext.window.Window({
  84. title: '附件下载',
  85. id : 'win',
  86. height: "60%",
  87. width: "40%",
  88. items: items,
  89. buttonAlign: 'center',
  90. buttons: [{
  91. text: $I18N.common.button.erpCloseButton,
  92. iconCls: 'x-button-icon-close',
  93. cls: 'x-btn-gray',
  94. handler: function(){
  95. Ext.getCmp('win').close();
  96. }
  97. }]
  98. });
  99. win.show();*/
  100. if(this.menu.items.items.length == 1){
  101. items.add({
  102. html: '<img src="' + basePath + 'resource/images/mainpage/things.png" width=16 height=16/>' +
  103. '(无)'
  104. });
  105. }
  106. for(var i=0;i<10;i++){
  107. items.add({
  108. html: ''
  109. });
  110. }
  111. //this.showMenu();
  112. //this.menu.getEl().slideOut('b', { duration: 3000 });
  113. //this.hideMenu();
  114. //this.itemsize = items.length;
  115. //this.ownerCt.ownerCt.add(items);
  116. }
  117. });