HotLinkForm.js 9.2 KB

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