appmsg.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. $( function() {
  2. //文件上传
  3. $("#file_upload").omFileUpload({
  4. action :"image.upload",
  5. fileExt :"*.jpg;*.png;*.gif;*.jpeg;*.bmp",
  6. fileDesc :"Image Files",
  7. fileDataName :"myFile",
  8. sizeLimit :200 * 1024,
  9. onError : function(ID, fileObj, errorObj, event) {
  10. if (errorObj.type == "File Size") {
  11. alert("上传图片的大小不能超过200KB");
  12. }
  13. },
  14. autoUpload :true,
  15. swf :window.allBasePath + "image/admin/swf/om-fileupload.swf",
  16. method :"GET",
  17. onComplete : function(ID, fileObj, response, data, event) {
  18. var jsonData = eval("(" + response + ")");
  19. if (jsonData.error == "filetype") {
  20. alert("文件上传格式只能支持:" + jsonData.allowtype);
  21. return false;
  22. }
  23. // alert(jsonData.fileUrl);
  24. $(".cover .i-img").attr("src", window.allBasePath + jsonData.fileUrl).show();
  25. $("#imgArea").show().find(" #img").attr("src", window.allBasePath + jsonData.fileUrl);
  26. $("#coverurl").val(jsonData.fileName);
  27. // alert(jsonData.fileName);
  28. $(".default-tip").hide();
  29. }
  30. });
  31. $(".msg-editer #title").bind("keyup", function() {
  32. $(".i-title").text($(this).val());
  33. });
  34. $(".msg-editer #summary").bind("keyup", function() {
  35. $(".msg-text").html($.htmlEncode($(this).val()));
  36. });
  37. $("#desc-block-link").click( function() {
  38. $("#desc-block").show();
  39. $(this).hide();
  40. });
  41. $("#url-block-link").click( function() {
  42. $("#url-block").show();
  43. $(this).hide();
  44. });
  45. $("#chain-block-link").click( function() {
  46. $("#chain-block").show();
  47. $(this).hide();
  48. });
  49. $("#delImg").click( function() {
  50. $(".default-tip").show();
  51. $("#imgArea").hide();
  52. $("#coverurl").val("");
  53. $(".cover .i-img").hide();
  54. });
  55. $("#cancel-btn").click( function(event) {
  56. event.stopPropagation();
  57. location.href = "imagetextinfo_doList.action";
  58. return;
  59. });
  60. var validator = $("#appmsg-form").validate({
  61. rules : {
  62. title : {
  63. required :true,
  64. maxlength :64
  65. },
  66. summary : {
  67. maxlength :120
  68. },
  69. source_url : {
  70. url :true
  71. },
  72. chain : {
  73. url :true
  74. }
  75. },
  76. messages : {
  77. title : {
  78. required :"请输入标题",
  79. maxlength :"标题不能超过64个字"
  80. },
  81. summary : {
  82. maxlength :"标题不能超过120个字"
  83. },
  84. source_url : {
  85. url :"必须输入正确的url格式"
  86. },
  87. chain : {
  88. url :"必须输入正确的url格式"
  89. }
  90. },
  91. showErrors : function(errorMap, errorList) {
  92. if (errorList && errorList.length > 0) {
  93. $.each(errorList, function(index, obj) {
  94. var item = $(obj.element);
  95. item.closest(".control-group").addClass("error");
  96. item.attr("title", obj.message);
  97. });
  98. } else {
  99. var item = $(this.currentElements);
  100. item.closest(".control-group").removeClass("error");
  101. item.removeAttr("title");
  102. }
  103. },
  104. submitHandler : function() {
  105. if ($("#coverurl").val() == "") {
  106. alert("必须上传一张图片");
  107. return false;
  108. }
  109. var editorContent = msg_editor.getContent();
  110. var chain = $("#chain").val();
  111. var len = editorContent.length;
  112. if (chain == "" && len == 0) {
  113. alert("正文内容或者外链至少要填写一个。");
  114. msg_editor.focus();
  115. return false;
  116. }
  117. if (len > charLimit) {
  118. alert("正文的内容不能超过" + charLimit + "个字");
  119. msg_editor.focus();
  120. return false;
  121. }
  122. var $form = $("#appmsg-form");
  123. var $btn = $("#save-btn");
  124. if ($btn.hasClass("disabled")) {
  125. return;
  126. }
  127. var submitData = {
  128. title :$("input[name='title']", $form).val(),
  129. summary :$("textarea[name='summary']", $form).val(),
  130. coverurl :$("input[name='coverurl']", $form).val(),
  131. source_url :$("input[name='source_url']", $form).val(),
  132. chain :$("#chain", $form).val(),
  133. link :$("input[name='link']", $form).val(),
  134. rid :$("input[name='rid']", $form).val(),
  135. action :$("input[name='action']", $form).val(),
  136. maincontent :editorContent
  137. };
  138. $btn.addClass("disabled");
  139. $.post(window.allBasePath + "admin/material/addOrUpdate", submitData, function(data) {
  140. $btn.removeClass("disabled");
  141. if (data !=null && data == true) {
  142. alert("保存成功");
  143. location.href = window.allBasePath + "admin/material/list";
  144. } else {
  145. alert("保存失败");
  146. /*if ("1" == data.errorCode) {
  147. alert("图文条数已经达到上限!");
  148. } else {
  149. alert("保存失败");
  150. }*/
  151. }
  152. }, "json");
  153. return false;
  154. }
  155. });
  156. window.msg_editor = new UE.ui.Editor({
  157. initialFrameWidth :498
  158. });
  159. window.msg_editor.render("editor");
  160. function computeChar() {
  161. var len = msg_editor.getContent().length;
  162. if (len > charLimit) {
  163. $(".editor-bottom-bar").html(
  164. "<span style='color:red;'>你输入的字符个数(" + len
  165. + ")已经超出最大允许值!</span>");
  166. } else {
  167. $(".editor-bottom-bar").html(
  168. "当前已输入<span class='char_count'>" + len
  169. + "</span>个字符, 您还可以输入<span class='char_remain'>"
  170. + (charLimit - len) + "</span>个字符。");
  171. }
  172. }
  173. window.msg_editor.addListener("keyup", function(type, evt) {
  174. computeChar();
  175. });
  176. });