ImageClipper.js 2.6 KB

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