UploadImage.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.rootActions = this.app.rootActions;
  54. this.css = {};
  55. this.cssPath = "../x_component_TeamWork/$UploadImage/"+this.options.style+"/css.wcss";
  56. this.load();
  57. this.lp = this.app.lp.uploadImage
  58. },
  59. _createTableContent: function () {
  60. this.actions = MWF.Actions.get("x_file_assemble_control");
  61. // this.actions.getHotPic("CMS", this.options.documentId , function( json ){
  62. // if( json.data && json.data.length > 0 ){
  63. // this.isNew = false;
  64. // }else{
  65. // this.isNew = true;
  66. // }
  67. // this.hotPicData = (json.data && json.data.length > 0) ? json.data[0] : {};
  68. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  69. "<tr>" +
  70. //" <td styles='formTableTitle' lable='hotPicture'></td>" +
  71. " <td styles='formTableValue' item='hotPictureArea'></td>" +
  72. "</tr>"+
  73. "<tr>" +
  74. //" <td styles='formTableTitle'></td>" +
  75. " <td></td>" +
  76. "</tr>"+
  77. //"<tr>" +
  78. //" <td styles='formTableTitle'></td>" +
  79. //" <td styles='formTableValue' item='hotPictureActionArea'></td>" +
  80. //"</tr>"
  81. "</table>";
  82. this.formTableArea.set("html", html);
  83. MWF.xDesktop.requireApp("Template", "MForm", function () {
  84. this.form = new MForm(this.formTableArea, this.data, {
  85. style: "default",
  86. isEdited: true,
  87. itemTemplate: {
  88. hotPicture: { text: this.lp.hotPicture }
  89. }
  90. }, this.app, this.css);
  91. this.form.load();
  92. this.createIconNode();
  93. }.bind(this), true);
  94. // }.bind(this), null, false);
  95. },
  96. createIconNode: function(){
  97. var hotPictureArea = this.formTableArea.getElements("[item='hotPictureArea']")[0];
  98. //this.iconNode = new Element("img",{
  99. // "styles" : this.css.iconNode
  100. //}).inject(hotPictureArea);
  101. //if (this.hotPicData.pictureBase64){
  102. // this.iconNode.set("src", this.hotPicData.pictureBase64);
  103. //}
  104. MWF.require("MWF.widget.ImageClipper", function () {
  105. this.clipper = new MWF.widget.ImageClipper(hotPictureArea, {
  106. aspectRatio : 2,
  107. fromFileEnable : false,
  108. imageUrl : "",
  109. reference : this.options.documentId,
  110. referenceType : "teamworkProject"
  111. });
  112. this.clipper.load();
  113. }.bind(this));
  114. },
  115. _createBottomContent: function () {
  116. this.closeActionNode = new Element("div.formCancelActionNode", {
  117. "styles": this.css.formCancelActionNode,
  118. "text": this.lp.closeBtn
  119. }).inject(this.formBottomNode);
  120. this.closeActionNode.addEvent("click", function (e) {
  121. this.cancel(e);
  122. }.bind(this));
  123. // if( !this.isNew ){
  124. // this.cancelHotActionNode = new Element("div.formOkActionNode", {
  125. // "styles": this.css.cancelHotPicture,
  126. // "text": this.lp.cancelHotPicture
  127. // }).inject(this.formBottomNode);
  128. //
  129. // this.cancelHotActionNode.addEvent("click", function (e) {
  130. // this.cancelHotPic(e);
  131. // }.bind(this));
  132. // }
  133. this.okActionNode = new Element("div.formOkActionNode", {
  134. "styles": this.css.formOkActionNode,
  135. "text": this.lp.okBtn
  136. }).inject(this.formBottomNode);
  137. this.okActionNode.addEvent("click", function (e) {
  138. this.ok(e);
  139. }.bind(this));
  140. },
  141. ok: function (e) {
  142. this.fireEvent("queryOk");
  143. var pictureBase64 = this.clipper.getBase64Image();
  144. if( !pictureBase64 || pictureBase64 == "" ){
  145. this.app.notice(this.lp.unselectHotPic, "error");
  146. return;
  147. }
  148. this.clipper.uploadImage( function( json ){
  149. this.fireEvent("postOk", json.data.id);
  150. this.cancel();
  151. }.bind(this) );
  152. },
  153. _close: function(){
  154. this.clipper.close();
  155. }
  156. });