ImageClipper.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. MWF.xDesktop.requireApp("process.Xform", "ImageClipper", null, false);
  2. MWF.xApplication.cms.Xform.ImageClipper = MWF.CMSImageClipper = new Class({
  3. Extends: MWF.APPImageClipper,
  4. selectImage: function(d, callback){
  5. var clipperType = this.json.clipperType || "unrestricted";
  6. var ratio = 1;
  7. var description = "";
  8. var maxSize = 500;
  9. if( clipperType == "unrestricted" ){
  10. ratio = 0;
  11. }else if( clipperType == "size" ){
  12. var width = ( this.json.imageWidth ) ? this.json.imageWidth.toInt() : 600;
  13. var height = ( this.json.imageHeight ) ? this.json.imageHeight.toInt() : 500;
  14. ratio = width / height;
  15. //maxSize = Math.max( width, height );
  16. if( !isNaN( width ) && !isNaN( height ) ){
  17. description = MWF.LP.widget.pictureSize.replace(/{width}/g, width).replace(/{height}/g, height);
  18. }
  19. }else if( clipperType == "ratio" ){
  20. ratio = this.json.imageRatio || 1;
  21. description = MWF.LP.widget.pictureRatio.replace(/{ratio}/g, ratio);
  22. }
  23. MWF.xDesktop.requireApp("process.Xform", "widget.ImageClipper", function(){
  24. this.imageClipper = new MWF.xApplication.process.Xform.widget.ImageClipper(this.form.app, {
  25. "style": "default",
  26. "aspectRatio" : ratio,
  27. "description" : description,
  28. "imageUrl" : d ? MWF.xDesktop.getImageSrc( d ) : "",
  29. "reference" : this.form.businessData.document.id,
  30. "referenceType": "cmsDocument",
  31. "resultMaxSize" : maxSize,
  32. "onChange" : function(){
  33. callback( { src : this.imageClipper.imageSrc, id : this.imageClipper.imageId } );
  34. }.bind(this)
  35. });
  36. this.imageClipper.load();
  37. }.bind(this));
  38. },
  39. validationConfigItem: function(routeName, data){
  40. var flag = (data.status=="all") ? true: (routeName == "publish");
  41. if (flag){
  42. var n = this.getData();
  43. var v = (data.valueType=="value") ? n : n.length;
  44. switch (data.operateor){
  45. case "isnull":
  46. if (!v){
  47. this.notValidationMode(data.prompt);
  48. return false;
  49. }
  50. break;
  51. case "notnull":
  52. if (v){
  53. this.notValidationMode(data.prompt);
  54. return false;
  55. }
  56. break;
  57. case "gt":
  58. if (v>data.value){
  59. this.notValidationMode(data.prompt);
  60. return false;
  61. }
  62. break;
  63. case "lt":
  64. if (v<data.value){
  65. this.notValidationMode(data.prompt);
  66. return false;
  67. }
  68. break;
  69. case "equal":
  70. if (v==data.value){
  71. this.notValidationMode(data.prompt);
  72. return false;
  73. }
  74. break;
  75. case "neq":
  76. if (v!=data.value){
  77. this.notValidationMode(data.prompt);
  78. return false;
  79. }
  80. break;
  81. case "contain":
  82. if (v.indexOf(data.value)!=-1){
  83. this.notValidationMode(data.prompt);
  84. return false;
  85. }
  86. break;
  87. case "notcontain":
  88. if (v.indexOf(data.value)==-1){
  89. this.notValidationMode(data.prompt);
  90. return false;
  91. }
  92. break;
  93. }
  94. }
  95. return true;
  96. }
  97. });