HotLinkForm.js 9.5 KB

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