HotLinkForm.js 9.2 KB

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