ImageClipper.js 3.0 KB

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