ImageClipper.js 3.5 KB

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