UploadImage.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  3. MWF.require("MWF.widget.ImageClipper", null, false);
  4. MWF.xApplication.TeamWork.UploadImage = new Class({
  5. Extends: MPopupForm,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "width": "660",
  10. "height": "520",
  11. "hasTop": true,
  12. "hasIcon": false,
  13. "hasTopIcon" : false,
  14. "hasTopContent" : true,
  15. "hasBottom": true,
  16. "title": "上传封面",
  17. "draggable": true,
  18. "closeAction": true,
  19. "toMain" : true,
  20. "documentId" : ""
  21. },
  22. initialize: function (explorer, data, options, para) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. if( para ){
  26. if( this.options.relativeToApp ){
  27. this.app = para.app || this.explorer.app;
  28. this.container = para.container || this.app.content;
  29. this.lp = para.lp || this.explorer.lp || this.app.lp;
  30. this.css = para.css || this.explorer.css || this.app.css;
  31. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  32. }else{
  33. this.container = para.container;
  34. this.lp = para.lp || this.explorer.lp;
  35. this.css = para.css || this.explorer.css;
  36. this.actions = para.actions || this.explorer.actions;
  37. }
  38. }else{
  39. if( this.options.relativeToApp ){
  40. this.app = this.explorer.app;
  41. this.container = this.app.content;
  42. this.lp = this.explorer.lp || this.app.lp;
  43. this.css = this.explorer.css || this.app.css;
  44. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  45. }else{
  46. this.container = window.document.body;
  47. this.lp = this.explorer.lp;
  48. this.css = this.explorer.css;
  49. this.actions = this.explorer.actions;
  50. }
  51. }
  52. this.data = data || {};
  53. this.css = {};
  54. this.cssPath = "/x_component_TeamWork/$UploadImage/"+this.options.style+"/css.wcss";
  55. this.load();
  56. this.lp = this.app.lp.uploadImage
  57. },
  58. _createTableContent: function () {
  59. this.actions = MWF.Actions.get("x_file_assemble_control");
  60. // this.actions.getHotPic("CMS", this.options.documentId , function( json ){
  61. // if( json.data && json.data.length > 0 ){
  62. // this.isNew = false;
  63. // }else{
  64. // this.isNew = true;
  65. // }
  66. // this.hotPicData = (json.data && json.data.length > 0) ? json.data[0] : {};
  67. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  68. "<tr>" +
  69. //" <td styles='formTableTitle' lable='hotPicture'></td>" +
  70. " <td styles='formTableValue' item='hotPictureArea'></td>" +
  71. "</tr>"+
  72. "<tr>" +
  73. //" <td styles='formTableTitle'></td>" +
  74. " <td></td>" +
  75. "</tr>"+
  76. //"<tr>" +
  77. //" <td styles='formTableTitle'></td>" +
  78. //" <td styles='formTableValue' item='hotPictureActionArea'></td>" +
  79. //"</tr>"
  80. "</table>";
  81. this.formTableArea.set("html", html);
  82. MWF.xDesktop.requireApp("Template", "MForm", function () {
  83. this.form = new MForm(this.formTableArea, this.data, {
  84. style: "default",
  85. isEdited: true,
  86. itemTemplate: {
  87. hotPicture: { text: this.lp.hotPicture }
  88. }
  89. }, this.app, this.css);
  90. this.form.load();
  91. this.createIconNode();
  92. }.bind(this), true);
  93. // }.bind(this), null, false);
  94. },
  95. createIconNode: function(){
  96. var hotPictureArea = this.formTableArea.getElements("[item='hotPictureArea']")[0];
  97. //this.iconNode = new Element("img",{
  98. // "styles" : this.css.iconNode
  99. //}).inject(hotPictureArea);
  100. //if (this.hotPicData.pictureBase64){
  101. // this.iconNode.set("src", this.hotPicData.pictureBase64);
  102. //}
  103. MWF.require("MWF.widget.ImageClipper", function () {
  104. this.clipper = new MWF.widget.ImageClipper(hotPictureArea, {
  105. aspectRatio : 2,
  106. fromFileEnable : false,
  107. imageUrl : "",
  108. reference : this.options.documentId,
  109. referenceType : "teamworkProject"
  110. });
  111. this.clipper.load();
  112. }.bind(this));
  113. },
  114. _createBottomContent: function () {
  115. this.closeActionNode = new Element("div.formCancelActionNode", {
  116. "styles": this.css.formCancelActionNode,
  117. "text": this.lp.closeBtn
  118. }).inject(this.formBottomNode);
  119. this.closeActionNode.addEvent("click", function (e) {
  120. this.cancel(e);
  121. }.bind(this));
  122. // if( !this.isNew ){
  123. // this.cancelHotActionNode = new Element("div.formOkActionNode", {
  124. // "styles": this.css.cancelHotPicture,
  125. // "text": this.lp.cancelHotPicture
  126. // }).inject(this.formBottomNode);
  127. //
  128. // this.cancelHotActionNode.addEvent("click", function (e) {
  129. // this.cancelHotPic(e);
  130. // }.bind(this));
  131. // }
  132. this.okActionNode = new Element("div.formOkActionNode", {
  133. "styles": this.css.formOkActionNode,
  134. "text": this.lp.okBtn
  135. }).inject(this.formBottomNode);
  136. this.okActionNode.addEvent("click", function (e) {
  137. this.ok(e);
  138. }.bind(this));
  139. },
  140. ok: function (e) {
  141. this.fireEvent("queryOk");
  142. var pictureBase64 = this.clipper.getBase64Image();
  143. if( !pictureBase64 || pictureBase64 == "" ){
  144. this.app.notice(this.lp.unselectHotPic, "error");
  145. return;
  146. }
  147. this.clipper.uploadImage( function( json ){
  148. this.fireEvent("postOk", json.data.id);
  149. this.cancel();
  150. }.bind(this) );
  151. },
  152. _close: function(){
  153. this.clipper.close();
  154. }
  155. });