HotLinkForm.js 11 KB

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