ImageClipper.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. getReferencetypeForMobile: function() {
  40. return "cmsDocument";
  41. },
  42. getReferenceForMobile: function() {
  43. return this.form.businessData.document.id;
  44. },
  45. validationConfigItem: function(routeName, data){
  46. var flag = (data.status=="all") ? true: (routeName == "publish");
  47. if (flag){
  48. var n = this.getData();
  49. var v = (data.valueType=="value") ? n : n.length;
  50. switch (data.operateor){
  51. case "isnull":
  52. if (!v){
  53. this.notValidationMode(data.prompt);
  54. return false;
  55. }
  56. break;
  57. case "notnull":
  58. if (v){
  59. this.notValidationMode(data.prompt);
  60. return false;
  61. }
  62. break;
  63. case "gt":
  64. if (v>data.value){
  65. this.notValidationMode(data.prompt);
  66. return false;
  67. }
  68. break;
  69. case "lt":
  70. if (v<data.value){
  71. this.notValidationMode(data.prompt);
  72. return false;
  73. }
  74. break;
  75. case "equal":
  76. if (v==data.value){
  77. this.notValidationMode(data.prompt);
  78. return false;
  79. }
  80. break;
  81. case "neq":
  82. if (v!=data.value){
  83. this.notValidationMode(data.prompt);
  84. return false;
  85. }
  86. break;
  87. case "contain":
  88. if (v.indexOf(data.value)!=-1){
  89. this.notValidationMode(data.prompt);
  90. return false;
  91. }
  92. break;
  93. case "notcontain":
  94. if (v.indexOf(data.value)==-1){
  95. this.notValidationMode(data.prompt);
  96. return false;
  97. }
  98. break;
  99. }
  100. }
  101. return true;
  102. }
  103. });