HotLinkForm.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. MWF.xApplication.ForumDocument = MWF.xApplication.ForumDocument || {};
  2. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  3. MWF.require("MWF.widget.ImageClipper", null, false);
  4. MWF.xApplication.ForumDocument.HotLinkForm = 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": MWF.xApplication.Forum.LP.setHotPicture,
  17. "draggable": true,
  18. "closeAction": true,
  19. "toMain" : true,
  20. "documentId" : ""
  21. },
  22. _createTableContent: function () {
  23. this.actions = MWF.Actions.get("x_hotpic_assemble_control");
  24. this.actions.getHotPic("BBS", this.options.documentId , function( json ){
  25. if( json.data && json.data.length > 0 ){
  26. this.isNew = false;
  27. }else{
  28. this.isNew = true;
  29. }
  30. this.hotPicData = (json.data && json.data.length > 0) ? json.data[0] : {};
  31. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  32. "<tr>" +
  33. //" <td styles='formTableTitle' lable='hotPicture'></td>" +
  34. " <td styles='formTableValue' item='hotPictureArea'></td>" +
  35. "</tr>"+
  36. "<tr>" +
  37. //" <td styles='formTableTitle'></td>" +
  38. " <td>"+this.lp.hotLinkDescription+"</td>" +
  39. "</tr>"+
  40. //"<tr>" +
  41. //" <td styles='formTableTitle'></td>" +
  42. //" <td styles='formTableValue' item='hotPictureActionArea'></td>" +
  43. //"</tr>"
  44. "</table>";
  45. this.formTableArea.set("html", html);
  46. MWF.xDesktop.requireApp("Template", "MForm", function () {
  47. this.form = new MForm(this.formTableArea, this.data, {
  48. style: "cms",
  49. isEdited: true,
  50. itemTemplate: {
  51. hotPicture: { text: this.lp.hotPicture }
  52. }
  53. }, this.app, this.css);
  54. this.form.load();
  55. this.createIconNode();
  56. }.bind(this), true);
  57. }.bind(this), null, false);
  58. },
  59. createIconNode: function(){
  60. var hotPictureArea = this.formTableArea.getElements("[item='hotPictureArea']")[0];
  61. //this.iconNode = new Element("img",{
  62. // "styles" : this.css.hotIconNode
  63. //}).inject(hotPictureArea);
  64. //if (this.hotPicData.pictureBase64){
  65. //this.iconNode.set("src", this.hotPicData.pictureBase64.substr( 0, 10 ) == 'data:image' ? this.hotPicData.pictureBase64 : ('data:image/png;base64,'+this.hotPicData.pictureBase64));
  66. //}
  67. MWF.require("MWF.widget.ImageClipper", function () {
  68. this.clipper = new MWF.widget.ImageClipper(hotPictureArea, {
  69. aspectRatio : 2,
  70. fromFileEnable : true,
  71. imageUrl : this.hotPicData.picId ? MWF.xDesktop.getImageSrc( this.hotPicData.picId ) : "",
  72. reference : this.options.documentId,
  73. referenceType : "forumDocument"
  74. });
  75. this.clipper.load();
  76. }.bind(this));
  77. //var hotPictureActionArea = this.formTableArea.getElements("[item='hotPictureActionArea']")[0];
  78. //var changeIconActionNode = new Element("div", {
  79. // "styles": this.css.changeIconActionNode,
  80. // "text": this.lp.selectDocPicture
  81. //}).inject(hotPictureActionArea);
  82. //changeIconActionNode.addEvent("click", function () {
  83. // this.selectDocPicture();
  84. //}.bind(this));
  85. //
  86. //
  87. //var changeIconActionNode = new Element("div", {
  88. // "styles": this.css.changeIconActionNode,
  89. // "text": this.lp.selectFilePicture
  90. //}).inject(hotPictureActionArea);
  91. //changeIconActionNode.addEvent("click", function () {
  92. // this.selectFilePicture();
  93. //}.bind(this));
  94. },
  95. //selectDocPicture: function(){
  96. // MWF.xDesktop.requireApp("Forum", "Attachment", null, false);
  97. // this.actions.listAttachment( this.options.documentId, function( json ){
  98. // this.selector_doc = new MWF.xApplication.Forum.Attachment(document.body, this, this.actions, this.lp, {
  99. // //documentId : this.data ? this.data.id : "",
  100. // isNew : false,
  101. // isEdited : false,
  102. // "onUpload" : function( attData ){
  103. // this.attachment.attachmentController.addAttachment(attData);
  104. // this.attachment.attachmentController.checkActions();
  105. // }.bind(this)
  106. // })
  107. // this.selector_doc.data = json.data || [];
  108. // this.selector_doc.loadAttachmentSelecter({
  109. // "style": "cms",
  110. // "title": "选择本文档图片",
  111. // "listStyle": "preview",
  112. // "toBase64" : true,
  113. // "selectType": "images"
  114. // }, function (url, data, base64Code) {
  115. // //if (callback)callback(url, data);
  116. // this.iconNode.set("src", base64Code || url);
  117. // this.hotPicData.pictureBase64 = base64Code || url;
  118. // }.bind(this));
  119. // }.bind(this) )
  120. //},
  121. //selectFilePicture: function () {
  122. // var _self = this;
  123. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  124. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  125. // "style" : "default",
  126. // "title": "选择云文件图片",
  127. // "toBase64" : true,
  128. // "listStyle": "preview",
  129. // "selectType" : "images",
  130. // "onPostSelectAttachment" : function(url, base64Code){
  131. // _self.iconNode.set("src", base64Code || url);
  132. // _self.hotPicData.pictureBase64 = base64Code || url;
  133. // }
  134. // });
  135. // _self.selector_cloud.load();
  136. // }, true);
  137. //},
  138. _createBottomContent: function () {
  139. this.okActionNode = new Element("div.formOkActionNode", {
  140. "styles": this.css.formOkActionNode,
  141. "text": this.lp.setHotPicture
  142. }).inject(this.formBottomNode);
  143. this.okActionNode.addEvent("click", function (e) {
  144. this.ok(e);
  145. }.bind(this));
  146. if( !this.isNew ){
  147. this.cancelHotActionNode = new Element("div.formOkActionNode", {
  148. "styles": this.css.cancelHotPicture,
  149. "text": this.lp.cancelHotPicture
  150. }).inject(this.formBottomNode);
  151. this.cancelHotActionNode.addEvent("click", function (e) {
  152. this.cancelHotPic(e);
  153. }.bind(this));
  154. }
  155. this.closeActionNode = new Element("div.formCancelActionNode", {
  156. "styles": this.css.formCancelActionNode,
  157. "text": this.lp.close
  158. }).inject(this.formBottomNode);
  159. this.closeActionNode.addEvent("click", function (e) {
  160. this.cancel(e);
  161. }.bind(this));
  162. },
  163. cancelHotPic: function(e){
  164. var _self = this;
  165. this.app.confirm("warn", e, this.lp.cancelHotPicComfirmTitle, this.lp.cancelHotPicComfirmContent, 350, 120, function(){
  166. _self._cancelHotPic(_self.data, false);
  167. this.close();
  168. }, function(){
  169. this.close();
  170. });
  171. },
  172. _cancelHotPic : function(){
  173. this.actions.removeHotPic( this.hotPicData.id , function( json ) {
  174. if (json.type == "error") {
  175. this.app.notice(json.message, "error");
  176. } else {
  177. this.formMaskNode.destroy();
  178. this.formAreaNode.destroy();
  179. this.app.notice(this.lp.cancelHotLinkSuccess, "success");
  180. }
  181. }.bind(this))
  182. },
  183. ok: function (e) {
  184. this.fireEvent("queryOk");
  185. //var data = this.form.getResult(true, ",", true, false, true);
  186. var pictureBase64 = this.clipper.getBase64Image();
  187. if( !pictureBase64 || pictureBase64 == "" ){
  188. this.app.notice(this.lp.unselectHotPic, "error");
  189. return;
  190. }
  191. this.hotPicData.pictureBase64 = pictureBase64;
  192. //var pictureBase64 =this.hotPicData.pictureBase64.replace("http://","").split("\/");
  193. //pictureBase64.shift();
  194. //this.hotPicData.pictureBase64 = "/"+ pictureBase64.join("/");
  195. this.clipper.uploadImage( function( json ){
  196. //this.hotPicData.pictureBase64 = pictureBase64;
  197. this.hotPicData.infoId = this.options.documentId;
  198. this.hotPicData.url = MWF.xDesktop.getImageSrc( json.id );
  199. this.hotPicData.picId = json.id;
  200. this.hotPicData.title = this.data.title;
  201. this.hotPicData.application = "BBS";
  202. this.hotPicData.creator = layout.desktop.session.user.distinguishedName;
  203. this.hotPicData.summary = this.options.summary;
  204. this._ok(this.hotPicData, function (json) {
  205. if (json.type == "error") {
  206. this.app.notice(json.message, "error");
  207. } else {
  208. this.formMaskNode.destroy();
  209. this.formAreaNode.destroy();
  210. this.app.notice(this.lp.setHotLinkSuccess, "success");
  211. this.fireEvent("postOk", json.data.id);
  212. }
  213. }.bind(this))
  214. }.bind(this) );
  215. },
  216. _ok: function (data, callback) {
  217. this.actions.saveHotPic( data, function(json){
  218. if( callback )callback(json);
  219. }.bind(this));
  220. },
  221. _close: function(){
  222. this.clipper.close();
  223. }
  224. });