ImageClipper.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. this.setOptions(options);
  18. this.app = designer;
  19. this.path = "/x_component_process_Xform/widget/$ImageClipper/";
  20. this.cssPath = "/x_component_process_Xform/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 = "668";
  27. var height = "510";
  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. if( _self.image.getResizedImage() ){
  58. _self.image.uploadImage( function( json ){
  59. _self.imageSrc = MWF.xDesktop.getImageSrc( json.id );
  60. _self.imageId = json.id;
  61. _self.fireEvent("change");
  62. this.close();
  63. }.bind(this));
  64. }else{
  65. _self.imageSrc = "";
  66. _self.imageId = "";
  67. _self.fireEvent("change");
  68. this.close();
  69. }
  70. }
  71. },
  72. {
  73. "text": MWF.LP.process.button.cancel,
  74. "action": function () {
  75. this.close();
  76. }
  77. }
  78. ]
  79. });
  80. dlg.show();
  81. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  82. "aspectRatio": this.options.aspectRatio,
  83. "description" : this.options.description,
  84. "imageUrl" : this.options.imageUrl,
  85. "resultMaxSize" : this.options.resultMaxSize,
  86. "reference" : this.options.reference,
  87. "referenceType": this.options.referenceType,
  88. "resetEnable" : true
  89. });
  90. this.image.load(this.data);
  91. }.bind(this))
  92. }
  93. });