ImageClipper.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.ImageClipper", null, false);
  3. MWF.xApplication.process.FormDesigner.widget.ImageClipper = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "title": "Select Image",
  8. "style": "default",
  9. "width": "92",
  10. "height": "73",
  11. "referenceType": "",
  12. "reference": "",
  13. "imageUrl":""
  14. },
  15. initialize: function(designer, options){
  16. debugger;
  17. this.setOptions(options);
  18. this.app = designer;
  19. this.path = "/x_component_process_FormDesigner/widget/$ImageClipper/";
  20. this.cssPath = "/x_component_process_FormDesigner/widget/$ImageClipper/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. },
  23. load: function(data){
  24. this.data = data;
  25. var options = {};
  26. var width = options.width || "770";
  27. var height = options.height || "580";
  28. width = width.toInt();
  29. height = height.toInt();
  30. var size = this.app.content.getSize();
  31. var x = (size.x-width)/2;
  32. var y = (size.y-height)/2;
  33. if (x<0) x = 0;
  34. if (y<0) y = 0;
  35. if (layout.mobile){
  36. x = 20;
  37. y = 0;
  38. }
  39. var _self = this;
  40. MWF.require("MWF.xDesktop.Dialog", function() {
  41. var dlg = new MWF.xDesktop.Dialog({
  42. "title": this.options.title || "Select Image",
  43. "style": options.style || "image",
  44. "top": y,
  45. "left": x - 20,
  46. "fromTop": y,
  47. "fromLeft": x - 20,
  48. "width": width,
  49. "height": height,
  50. "html": "<div></div>",
  51. "maskNode": this.app.content,
  52. "container": this.app.content,
  53. "buttonList": [
  54. {
  55. "text": MWF.LP.process.button.ok,
  56. "action": function () {
  57. _self.image.uploadImage( function( json ){
  58. _self.imageSrc = MWF.xDesktop.getImageSrc( json.id );
  59. _self.imageId = json.id;
  60. _self.fireEvent("change");
  61. this.close();
  62. }.bind(this));
  63. //_self.uploadImage();
  64. //_self.data = _self.image.getBase64Image();
  65. //_self.fireEvent("change");
  66. this.close();
  67. }
  68. },
  69. {
  70. "text": MWF.LP.process.button.cancel,
  71. "action": function () {
  72. this.close();
  73. }
  74. }
  75. ]
  76. });
  77. dlg.show();
  78. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  79. "aspectRatio": this.options.width.toInt()/this.options.height.toInt(),
  80. "imageUrl" : this.options.imageUrl,
  81. "reference" : this.options.reference,
  82. "referenceType": this.options.referenceType,
  83. "resetEnable" : true
  84. });
  85. this.image.load(this.data);
  86. }.bind(this))
  87. },
  88. uploadImage: function(){
  89. }
  90. });