common.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * Created by simon on 2015/4/22.
  3. */
  4. /*ajax设置项*/
  5. $(function () {
  6. /*ajax设置项*/
  7. $.ajaxSetup({
  8. headers: {
  9. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  10. }
  11. });
  12. $("#sliderbar_control").click(function(){
  13. var sidebar_collapse = 0;
  14. if($('body').hasClass('sidebar-collapse')){
  15. sidebar_collapse = 1;
  16. }
  17. $.get(site_url+'/admin/index/sidebar?collapse='+sidebar_collapse,function(msg){
  18. console.log(msg);
  19. });
  20. });
  21. //Enable iCheck plugin for checkboxes
  22. //iCheck for checkbox and radio inputs
  23. $('input[type="checkbox"]').iCheck({
  24. checkboxClass: 'icheckbox_minimal-blue',
  25. radioClass: 'iradio_minimal-blue'
  26. });
  27. //全部选中checkbox
  28. $('.checkbox-toggle').on('ifChecked', function(event){
  29. $("input[type='checkbox'][class!='checkbox-toggle']").iCheck('check');
  30. });
  31. //全部取消选中checkbox
  32. $('.checkbox-toggle').on('ifUnchecked', function(event){
  33. $("input[type='checkbox'][class!='checkbox-toggle']").iCheck('uncheck');
  34. });
  35. /*daterange控件*/
  36. $('#date_range').daterangepicker({
  37. format: 'YYYY-MM-DD',
  38. locale: {
  39. applyLabel: '确认',
  40. cancelLabel: '取消',
  41. fromLabel: '从',
  42. toLabel: '到',
  43. weekLabel: '星期',
  44. customRangeLabel: '自定义范围',
  45. daysOfWeek: moment.weekdaysMin(),
  46. monthNames: moment.monthsShort(),
  47. firstDay: moment.localeData()._week.dow
  48. }
  49. });
  50. // 举报相关
  51. $("#report_reason").hide();
  52. $(".reportRadioItem").change(function() {
  53. var id = $("input[name='report_type']:checked").val();
  54. if (id == 99){
  55. $("#report_reason").show();
  56. }else{
  57. $("#report_reason").hide();
  58. }
  59. });
  60. $(".report_btn").click(function () {
  61. var source_type = $(this).data('source_type');
  62. var source_id = $(this).data('source_id');
  63. $("input[name='source_type']").val(source_type);
  64. $("input[name='source_id']").val(source_id);
  65. console.log(source_type);
  66. if (source_type == 'article'){
  67. $("#reportModalLabel").text("举报此文章");
  68. }else if(source_type == 'answer') {
  69. $("#reportModalLabel").text("举报此回答");
  70. }else if(source_type == 'question')
  71. {
  72. $("#reportModalLabel").text("举报此问题");
  73. }
  74. });
  75. $("#report_submit_button").click(function () {
  76. var report_type = $("input[name='report_type']:checked").val();
  77. if(typeof(report_type) == "undefined"){
  78. alert('请填写举报原因');
  79. }
  80. $("#report_form").submit();
  81. });
  82. });
  83. /**
  84. * 编辑器图片图片文件方式上传
  85. * @param file
  86. * @param editor
  87. * @param welEditable
  88. */
  89. function upload_editor_image(file,editorId){
  90. data = new FormData();
  91. data.append("file", file);
  92. $.ajax({
  93. data: data,
  94. type: "POST",
  95. dataType : 'text',
  96. url: "/image/upload",
  97. cache: false,
  98. contentType: false,
  99. processData: false,
  100. success: function(url) {
  101. $('#'+editorId).summernote('insertImage', url, function ($image) {
  102. $image.css('width', $image.width() / 2);
  103. $image.addClass('img-responsive');
  104. });
  105. }
  106. });
  107. }
  108. /*删除确认*/
  109. function confirm_delete(message){
  110. if(!confirm(message)){
  111. return false;
  112. }
  113. $("#item_form").submit();
  114. }
  115. /*确认提交表单*/
  116. function confirm_submit(form_id,action_url,message){
  117. if(!confirm(message)){
  118. return false;
  119. }
  120. $("#"+form_id).attr("action",action_url);
  121. $("#"+form_id).submit();
  122. }
  123. /**
  124. * 设置当前页面高亮的菜单
  125. * @param $parentid
  126. * @param $url
  127. */
  128. function set_active_menu(parent_id,url){
  129. $("#"+parent_id+">li>a[href='"+url+"']",0).parent().addClass("active");
  130. $("#"+parent_id).parent().addClass("active");
  131. }