PhotoField.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. Ext.define('erp.view.core.form.PhotoField', {
  2. extend: 'Ext.form.FieldContainer',
  3. alias: 'widget.photofield',
  4. layout: 'column',
  5. labelAlign:'top',
  6. defaults:{
  7. hideLabel: true
  8. },
  9. initComponent : function(){
  10. this.callParent(arguments);
  11. var basefield=this;
  12. var me = this;
  13. me.insert(0,{
  14. xtype:'form',
  15. layout:'column',
  16. id:'baseform',
  17. bodyStyle: 'background: transparent no-repeat 0 0;border: none;',
  18. items: [{
  19. xtype: 'hidden',
  20. value: '',
  21. name :me.name
  22. },{
  23. columnWidth:0.5,
  24. xtype: 'htmleditor',
  25. name:'msg',
  26. fieldSubTpl: [
  27. '<textarea id="{cmpId}-textareaEl" name="{name}" tabIndex="-1" class="{textareaCls}" ',
  28. 'style="{size}" autocomplete="off"></textarea>',
  29. '<iframe id="{cmpId}-iframeEl" name="{iframeName}" frameBorder="0" style="overflow:auto;{size}" src="{iframeSrc}"></iframe>',
  30. '<div id="{cmpId}-toolbarWrap" class="{toolbarWrapCls}"></div>',
  31. {
  32. compiled: true,
  33. disableFormats: true
  34. }
  35. ],
  36. createToolbar : function(editor){
  37. var me = this,
  38. items = [],
  39. tipsEnabled = Ext.tip.QuickTipManager && Ext.tip.QuickTipManager.isEnabled(),
  40. baseCSSPrefix = Ext.baseCSSPrefix,
  41. fontSelectItem, toolbar, undef;
  42. toolbar = Ext.widget('toolbar', {
  43. renderTo: me.toolbarWrap,
  44. dock: 'bottom',
  45. enableOverflow: true,
  46. items:[{
  47. xtype:'button',
  48. iconCls:'x-form-search-trigger',
  49. handler:function(){
  50. var img=Ext.getCmp('baseform').ownerCt.ownerCt.down('htmleditor[name=msg]').getEl().dom.getElementsByTagName('iframe')[0].contentWindow.document.body.getElementsByTagName('img')[0];
  51. img.style.width='';
  52. img.style.height='';
  53. var win = new Ext.window.Window({
  54. id : 'photowin',
  55. height: '100%',
  56. width: '100%',
  57. title:'放大图片',
  58. maximizable : true,
  59. items:[{
  60. html: img.outerHTML,
  61. autoScroll:true,
  62. height:'100%'
  63. }],
  64. buttonAlign : 'center',
  65. layout : 'anchor',
  66. listeners:{
  67. close:function(){
  68. img.style.width='100%';
  69. img.style.height='100%';
  70. }
  71. }
  72. });
  73. win.show();
  74. }
  75. },{
  76. id:'fileform',
  77. xtype:'form',
  78. layout:'column',
  79. bodyStyle: 'background: transparent no-repeat 0 0;border: none;',
  80. items: [{
  81. xtype: 'filefield',
  82. name: 'file',
  83. buttonOnly: true,
  84. hideLabel: true,
  85. width: 90,
  86. height: 17,
  87. buttonConfig: {
  88. iconCls: 'x-button-icon-pic',
  89. text: '设置图像',
  90. id:'photobutton'
  91. },
  92. listeners: {
  93. change: function(field){
  94. field.ownerCt.getForm().submit({
  95. url: basePath + 'common/uploadPic.action?em_code=' + em_code,
  96. waitMsg: "正在解析图片信息",
  97. success: function(fp, o){
  98. if(o.result.error){
  99. showError(o.result.error);
  100. } else {
  101. var msg = Ext.getCmp('baseform').ownerCt.ownerCt.down('htmleditor[name=msg]');
  102. var imgel=msg.getEl().dom.getElementsByTagName('iframe')[0].contentWindow.document.body;
  103. if(imgel.getElementsByTagName('img').length>0){
  104. imgel.removeChild(imgel.getElementsByTagName('img')[0]);
  105. }
  106. //Ext.getCmp('baseform').ownerCt.ownerCt.down('hidden').setValue('../../../'+o.result.path);
  107. Ext.getCmp('baseform').ownerCt.ownerCt.down('hidden').setValue(o.result.path);
  108. var element = document.createElement("img");
  109. element.src = basePath + 'common/download.action?path=' + o.result.path.replace(/\+/g, '%2B');
  110. element.style="width:100%;height:100%";
  111. element.title = '&img' + o.result.filepath + ";";
  112. msg.setValue('<img src="'+element.src+'" style=width:100%;height:100%;>');
  113. Ext.getCmp('photobutton').setText('更改图像');
  114. }
  115. }
  116. });
  117. }
  118. }}]
  119. }]
  120. });
  121. me.toolbar = toolbar;
  122. },
  123. fieldStyle: 'border-bottom: none;',
  124. }]
  125. });
  126. },
  127. listeners : {
  128. afterrender: function(f){
  129. this.getEl().dom.childNodes[1].style.overflow = 'hidden';
  130. var form = f.ownerCt;
  131. if(f.value){
  132. Ext.getCmp('photobutton').setText('更换图片');
  133. var msg = Ext.getCmp('baseform').ownerCt.ownerCt.down('htmleditor[name=msg]').setValue('<img src="'+basePath+f.value+'" style=width:100%;height:100%;>');
  134. }
  135. },
  136. }
  137. });