appmsg-mul.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. $(function() {
  2. /*$("#file_upload").omFileUpload({
  3. action :"image.upload",
  4. fileExt :"*.jpg;*.png;*.gif;*.jpeg;*.bmp",
  5. fileDesc :"Image Files",
  6. sizeLimit :200 * 1024,
  7. onError : function(ID, fileObj, errorObj, event) {
  8. if (errorObj.type == "File Size") {
  9. alert("上传图片的大小不能超过200KB");
  10. }
  11. },
  12. autoUpload :true,
  13. swf :window.allBasePath + "image/admin/swf/om-fileupload.swf",
  14. method :"GET",
  15. onComplete : function(ID, fileObj, response, data, event) {
  16. var jsonData = eval("(" + response + ")");
  17. if (jsonData.error == "filetype") {
  18. alert("文件上传格式只能支持:" + jsonData.allowtype);
  19. return false;
  20. }
  21. $(".default-tip", window.appmsg).hide();
  22. $(".i-img", window.appmsg).attr("src", window.allBasePath + jsonData.fileUrl).show();
  23. $("#imgArea").show().find(" #img").attr("src", window.allBasePath + jsonData.fileUrl);
  24. $(".cover", window.appmsg).val(jsonData.fileName);
  25. $(".coverurl", window.appmsg).val(window.allBasePath + jsonData.fileUrl);
  26. }
  27. });*/
  28. $(".msg-editer #title").bind("keyup", function() {
  29. $(".i-title", window.appmsg).text($(this).val());
  30. $(".title", window.appmsg).val($(this).val());
  31. });
  32. $(".msg-editer #source_url").bind("keyup", function() {
  33. $(".sourceurl", window.appmsg).val($(this).val());
  34. });
  35. $(".msg-editer #chain").bind("keyup", function() {
  36. $(".chain", window.appmsg).val($(this).val());
  37. });
  38. $("#url-block-link").click( function() {
  39. $("#url-block").show();
  40. $(this).hide();
  41. });
  42. $("#chain-block-link").click( function() {
  43. $("#chain-block").show();
  44. $(this).hide();
  45. });
  46. $("#delImg").click( function() {
  47. $(".default-tip", window.appmsg).show();
  48. $("#imgArea").hide();
  49. $(".cover,.coverurl", window.appmsg).val("");
  50. $(".i-img", window.appmsg).hide();
  51. });
  52. $("#cancel-btn").click( function(event) {
  53. event.stopPropagation();
  54. location.href = window.allBasePath + "admin/material/list";
  55. return;
  56. });
  57. $("#appmsgItem1,.sub-msg-item").live( {
  58. mouseover : function() {
  59. $(this).addClass("sub-msg-opr-show");
  60. },
  61. mouseout : function() {
  62. $(this).removeClass("sub-msg-opr-show");
  63. }
  64. });
  65. $(".sub-add-btn").click( function() {
  66. var len = $(".sub-msg-item").size();
  67. if (len >= 7) {
  68. alert("最多只能加入8条图文信息");
  69. return;
  70. }
  71. var $lastItem = $(".sub-msg-item:last");
  72. var $newItem = $lastItem.clone();
  73. $("input,textarea", $newItem).val("");
  74. $(".i-title", $newItem).text("");
  75. $(".default-tip", $newItem).css("display", "block");
  76. $(".cover,.coverurl", $newItem).val("");
  77. $(".i-img", $newItem).hide();
  78. $(".rid", $newItem).remove();
  79. $lastItem.after($newItem);
  80. });
  81. $(".sub-msg-opr .edit-icon").live("click", function() {
  82. window.appmsg.find(".content").val(window.msg_editor.getContent());
  83. var $msgItem = $(this).closest(".appmsgItem");
  84. var index = $(".appmsgItem").index($msgItem);
  85. window.appmsgIndex = index;
  86. window.appmsg = $msgItem;
  87. $("#title").val($(".title", $msgItem).val());
  88. if ($(".coverurl", $msgItem).val() == "") {
  89. $("#imgArea").hide();
  90. } else {
  91. $("#imgArea").show().find("#img").attr("src", $(".coverurl", $msgItem).val());
  92. }
  93. if ($(".sourceurl", $msgItem).val() == "") {
  94. $("#url-block-link").show();
  95. $("#url-block").hide().find("#source_url").val("");
  96. } else {
  97. $("#url-block-link").hide();
  98. $("#url-block").show().find("#source_url").val($(".sourceurl", $msgItem).val());
  99. }
  100. if ($(".chain", $msgItem).val() == "") {
  101. $("#chain-block-link").show();
  102. $("#chain-block").hide().find("#chain").val("");
  103. } else {
  104. $("#chain-block-link").hide();
  105. $("#chain-block").show().find("#chain").val($(".chain", $msgItem).val());
  106. }
  107. window.msg_editor.setContent($(".content", $msgItem).val());
  108. computeChar();
  109. if (index == 0) {
  110. $(".msg-editer-wrapper").css("margin-top", "0px");
  111. } else {
  112. var top = 110 + $(".sub-msg-item").eq(0).outerHeight(true) * index;
  113. $(".msg-editer-wrapper").css("margin-top", top + "px");
  114. }
  115. });
  116. $(".sub-msg-opr .del-icon").live("click", function() {
  117. var len = $(".appmsgItem").size();
  118. if (len <= 2) {
  119. alert("无法删除,多条图文至少需要2条消息。");
  120. return;
  121. }
  122. if (confirm("确认删除此消息?")) {
  123. var $msgItem = $(this).closest(".sub-msg-item");
  124. if ($(".rid", $msgItem).size() > 0) {
  125. window.delResId.push($(".rid", $msgItem).val());
  126. }
  127. $msgItem.remove();
  128. }
  129. });
  130. window.appmsgIndex = 0;
  131. window.appmsg = $("#appmsgItem1");
  132. window.delResId = [];
  133. window.msg_editor = new UE.ui.Editor({
  134. initialFrameWidth :498
  135. });
  136. window.msg_editor.render("editor");
  137. function computeChar() {
  138. var len = msg_editor.getContent().length;
  139. if (len > charLimit) {
  140. $(".editor-bottom-bar").html(
  141. "<span style='color:red;'>你输入的字符个数(" + len
  142. + ")已经超出最大允许值!</span>");
  143. } else {
  144. $(".editor-bottom-bar").html(
  145. "当前已输入<span class='char_count'>" + len
  146. + "</span>个字符, 您还可以输入<span class='char_remain'>"
  147. + (charLimit - len) + "</span>个字符。");
  148. }
  149. }
  150. window.msg_editor.addListener("keyup", function(type, evt) {
  151. computeChar();
  152. });
  153. $("#save-btn").click(function() {
  154. var $btn = $(this);
  155. if ($btn.hasClass("disabled")) {
  156. return;
  157. }
  158. window.appmsg.find(".content").val(window.msg_editor.getContent());
  159. var valid = true;
  160. var $msgItem;
  161. var jsonData = [];
  162. $(".appmsgItem").each( function(index, msgItem) {
  163. $msgItem = $(msgItem);
  164. var title = $("input.title", $msgItem).val();
  165. var cover = $("input.cover", $msgItem).val();
  166. var content = $("textarea.content", $msgItem).val();
  167. var sourceurl = $("input.sourceurl", $msgItem).val();
  168. var chain = $("input.chain", $msgItem).val();
  169. if (title == "") {
  170. alert("标题不能为空");
  171. valid = false;
  172. return false;
  173. }
  174. if (cover == "") {
  175. alert("必须上传一个封面图片");
  176. valid = false;
  177. return false;
  178. }
  179. if (chain == "" && content == "") {
  180. alert("正文内容或者外链至少要填写一个。");
  181. valid = false;
  182. return false;
  183. }
  184. jsonData[index] = {
  185. title :title,
  186. cover :cover,
  187. content :content,
  188. sourceurl :sourceurl,
  189. chain :chain
  190. };
  191. if ($(".rid", $msgItem).size() > 0) {
  192. jsonData[index].rid = $(".rid", $msgItem).val();
  193. } else {
  194. jsonData[index].rid = '';
  195. }
  196. });
  197. if (!valid) {
  198. $(".edit-icon", $msgItem).click();
  199. return false;
  200. }
  201. var sumbitData = {
  202. jsonData :$.toJSON(jsonData),
  203. action :$("#action").val()
  204. };
  205. if (window.delResId.length > 0) {
  206. sumbitData.delResId = $.toJSON(window.delResId);
  207. }
  208. $btn.addClass("disabled");
  209. $.post(window.allBasePath + "admin/material/addOrUpdateImgMore", sumbitData, function(data) {
  210. $btn.removeClass("disabled");
  211. if (data != null && data == true) {
  212. location.href = window.allBasePath + "admin/material/list";
  213. } else {
  214. alert("保存失败");
  215. /*if ("1" == data.errorCode) {
  216. alert("图文条数已经达到上限100条了!");
  217. } else {
  218. alert("保存失败");
  219. }*/
  220. }
  221. }, "json");
  222. });
  223. });