notice_info.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * 初始化通知详情对话框
  3. */
  4. var NoticeInfoDlg = {
  5. noticeInfoData: {},
  6. editor: null,
  7. validateFields: {
  8. title: {
  9. validators: {
  10. notEmpty: {
  11. message: '标题不能为空'
  12. }
  13. }
  14. }
  15. }
  16. };
  17. /**
  18. * 清除数据
  19. */
  20. NoticeInfoDlg.clearData = function () {
  21. this.noticeInfoData = {};
  22. }
  23. /**
  24. * 设置对话框中的数据
  25. *
  26. * @param key 数据的名称
  27. * @param val 数据的具体值
  28. */
  29. NoticeInfoDlg.set = function (key, value) {
  30. this.noticeInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
  31. return this;
  32. }
  33. /**
  34. * 设置对话框中的数据
  35. *
  36. * @param key 数据的名称
  37. * @param val 数据的具体值
  38. */
  39. NoticeInfoDlg.get = function (key) {
  40. return $("#" + key).val();
  41. }
  42. /**
  43. * 关闭此对话框
  44. */
  45. NoticeInfoDlg.close = function () {
  46. parent.layer.close(window.parent.Notice.layerIndex);
  47. }
  48. /**
  49. * 收集数据
  50. */
  51. NoticeInfoDlg.collectData = function () {
  52. this.noticeInfoData['content'] = NoticeInfoDlg.editor.txt.html();
  53. this.set('id').set('title');
  54. }
  55. /**
  56. * 验证数据是否为空
  57. */
  58. NoticeInfoDlg.validate = function () {
  59. $('#noticeInfoForm').data("bootstrapValidator").resetForm();
  60. $('#noticeInfoForm').bootstrapValidator('validate');
  61. return $("#noticeInfoForm").data('bootstrapValidator').isValid();
  62. };
  63. /**
  64. * 提交添加
  65. */
  66. NoticeInfoDlg.addSubmit = function () {
  67. this.clearData();
  68. this.collectData();
  69. if (!this.validate()) {
  70. return;
  71. }
  72. //提交信息
  73. var ajax = new $ax(Feng.ctxPath + "/notice/add", function (data) {
  74. Feng.success("添加成功!");
  75. window.parent.Notice.table.refresh();
  76. NoticeInfoDlg.close();
  77. }, function (data) {
  78. Feng.error("添加失败!" + data.responseJSON.message + "!");
  79. });
  80. ajax.set(this.noticeInfoData);
  81. ajax.start();
  82. }
  83. /**
  84. * 提交修改
  85. */
  86. NoticeInfoDlg.editSubmit = function () {
  87. this.clearData();
  88. this.collectData();
  89. if (!this.validate()) {
  90. return;
  91. }
  92. //提交信息
  93. var ajax = new $ax(Feng.ctxPath + "/notice/update", function (data) {
  94. Feng.success("修改成功!");
  95. window.parent.Notice.table.refresh();
  96. NoticeInfoDlg.close();
  97. }, function (data) {
  98. Feng.error("修改失败!" + data.responseJSON.message + "!");
  99. });
  100. ajax.set(this.noticeInfoData);
  101. ajax.start();
  102. }
  103. $(function () {
  104. Feng.initValidator("noticeInfoForm", NoticeInfoDlg.validateFields);
  105. //初始化编辑器
  106. var E = window.wangEditor;
  107. var editor = new E('#editor');
  108. editor.create();
  109. editor.txt.html($("#contentVal").val());
  110. NoticeInfoDlg.editor = editor;
  111. });