HotLinkForm.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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": "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. _createTableContent: function () {
  23. this.actions = MWF.Actions.get("x_hotpic_assemble_control");
  24. this.actions.getHotPic("CMS", 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.iconNode
  63. //}).inject(hotPictureArea);
  64. //if (this.hotPicData.pictureBase64){
  65. // this.iconNode.set("src", 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 : "cmsDocument"
  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("cms.Document", "Attachment", function(){
  97. // this.actions.listAttachment( this.options.documentId, function( json ){
  98. // this.selector_doc = new MWF.xApplication.cms.Document.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. // "selectType": "images"
  113. // }, function (url, data, base64Code) {
  114. // //if (callback)callback(url, data);
  115. // this.iconNode.set("src", base64Code || url);
  116. // this.hotPicData.pictureBase64 = base64Code || url;
  117. // }.bind(this));
  118. // }.bind(this) )
  119. // }.bind(this), true);
  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. // "listStyle": "preview",
  128. // "toBase64" : true,
  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.closeActionNode = new Element("div.formCancelActionNode", {
  140. "styles": this.css.formCancelActionNode,
  141. "text": this.lp.close
  142. }).inject(this.formBottomNode);
  143. this.closeActionNode.addEvent("click", function (e) {
  144. this.cancel(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.okActionNode = new Element("div.formOkActionNode", {
  156. "styles": this.css.formOkActionNode,
  157. "text": this.lp.setHotPicture
  158. }).inject(this.formBottomNode);
  159. this.okActionNode.addEvent("click", function (e) {
  160. this.ok(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 || this.formMarkNode).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 pictureBase64 = this.clipper.getBase64Image();
  186. if( !pictureBase64 || pictureBase64 == "" ){
  187. this.app.notice(this.lp.unselectHotPic, "error");
  188. return;
  189. }
  190. this.clipper.uploadImage( function( json ){
  191. //this.hotPicData.pictureBase64 = pictureBase64;
  192. this.hotPicData.infoId = this.options.documentId;
  193. this.hotPicData.url = MWF.xDesktop.getImageSrc( json.id );
  194. this.hotPicData.picId = json.id;
  195. this.hotPicData.title = this.data.title;
  196. this.hotPicData.application = "CMS";
  197. this.hotPicData.creator = layout.desktop.session.user.distinguishedName;
  198. this._ok(this.hotPicData, function (json) {
  199. if (json.type == "error") {
  200. this.app.notice(json.message, "error");
  201. } else {
  202. (this.formMaskNode || this.formMarkNode).destroy();
  203. this.formAreaNode.destroy();
  204. this.app.notice(this.lp.setHotLinkSuccess, "success");
  205. this.fireEvent("postOk", json.data.id);
  206. }
  207. }.bind(this))
  208. }.bind(this) );
  209. },
  210. _ok: function (data, callback) {
  211. this.actions.saveHotPic( data, function(json){
  212. if( callback )callback(json);
  213. }.bind(this));
  214. },
  215. _close: function(){
  216. this.clipper.close();
  217. }
  218. });