notify_edit.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. $(function () {
  2. $("#allBuilds").click(function () {
  3. if (this.checked) {
  4. $("#pushBuildsList :checkbox").prop("checked", true);
  5. } else {
  6. $("#pushBuildsList :checkbox").prop("checked", false);
  7. }
  8. });
  9. $("#form-notify-edit").validate({
  10. rules: {
  11. title: {
  12. required: true,
  13. maxlength: 255
  14. },
  15. content: {
  16. required: true
  17. },
  18. type: {
  19. required: true
  20. }
  21. },
  22. onkeyup: false,
  23. focusCleanup: true,
  24. success: "valid",
  25. submitHandler: function (form) {
  26. // $(form).find(":submit").attr("disabled", true);
  27. if ($("#isPush").val() == "true") {
  28. if ($("#pushStreetIds").val() == "" && $("#pushBuildIds").val() == "" && $("#pushCompanyIds").val() == "") {
  29. sadMessage("请选择推送单位!");
  30. return false;
  31. }
  32. }
  33. //如果摘要没填写,取正文前50个字
  34. if($.trim($("#notify_abstract").val())==""){
  35. var content = $("#content").val();
  36. if($.trim(content)!=""){
  37. var defaultAbstract = "";
  38. //去除标签
  39. var cleanContent = content.replace(/<\/?.+?>/g,""); //去标签
  40. cleanContent = cleanContent.replace(/(^\s+)|(\s+$)/g,""); //去空格
  41. cleanContent = cleanContent.replace(/(\r)|(\n)/g,""); //去回车
  42. cleanContent = cleanContent.replace(/&nbsp;/ig,''); //去掉&nbsp;
  43. if(cleanContent.length>50){
  44. defaultAbstract = cleanContent.substring(0,50);
  45. defaultAbstract += "...";
  46. }else{
  47. defaultAbstract = cleanContent;
  48. }
  49. $("#notify_abstract").val(defaultAbstract);
  50. }
  51. }
  52. $(form).ajaxSubmit({
  53. type: 'post',
  54. url: pagePath + "/government/notify/update",
  55. dataType: "json",
  56. data: {
  57. isPush: $("#isPush").val()
  58. },
  59. success: function (result) {
  60. if (result.success) {
  61. succeedMessage(result.message);
  62. setTimeClose();
  63. } else {
  64. // $(form).find(":submit").attr("disabled", false);
  65. errorMessage(result.message);
  66. }
  67. },
  68. error: function () {
  69. errorMessage('系统错误!');
  70. }
  71. });
  72. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  73. },
  74. errorPlacement: function (error, element) {
  75. if (element.attr('id') == 'content') {
  76. error.addClass(' label_error')
  77. }
  78. error.appendTo(element.parent());
  79. }
  80. });
  81. });
  82. function getPushBuildsIds() {
  83. var chlength = $('#pushBuildsList').find('input[type="checkbox"]:checked').length;
  84. var build_ids = '';
  85. $('#pushBuildsList').find('input[type="checkbox"]:checked').each(function (i, item) {
  86. build_ids = build_ids + $(this).attr("value") + ",";
  87. });
  88. build_ids = build_ids.substring(0, build_ids.length - 1);
  89. return build_ids;
  90. }
  91. function sendNotify() {
  92. $("#isPush").val(true);
  93. if ($("#pushStreetIds").val() == "" && $("#pushBuildIds").val() == "" && $("#pushCompanyIds").val() == "") {
  94. sadMessage("请选择推送单位!");
  95. return false;
  96. }
  97. }
  98. /*
  99. 参数解释:
  100. title 标题
  101. url 请求的url
  102. id 需要操作的数据id
  103. w 弹出层宽度(缺省调默认值)
  104. h 弹出层高度(缺省调默认值)
  105. */
  106. /*管理员-*/
  107. function notify_addPush(title, url, w, h) {
  108. layer_show(title, pagePath + url, w, h);
  109. }