????

Your IP : 3.138.101.1


Current Path : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/public/js/sohoa/
Upload File :
Current File : C:/inetpub/vhost/sdoc.gdtsolutions.vn/package/public/js/sohoa/suahoso.js

$(function () {
  moment.locale("vi");
  var fileVM = kendo.observable({
    file: {},
    getStartDate: function () {
      return this.get("file").StartDate ? moment(this.get("file").StartDate).format("DD/MM/YYYY") : "";
    },
    getEndDate: function () {
      return this.get("file").EndDate ? moment(this.get("file").EndDate).format("DD/MM/YYYY") : "";
    }
  });
  kendo.bind($("#edit-file-form"), fileVM);
  var docVM = kendo.observable({
    doc: {},
    organs: new kendo.data.DataSource({
      serverFiltering: true,
      transport: {
        read: "/sohoa/taovanban/coquan",
        cache: true
      }
    }),
    getIssuedDate: function () {
      return this.get("doc").IssuedDate ? moment(this.get("doc").IssuedDate).format("DD/MM/YYYY") : "";
    },
    addOrgan: function () {
      var organs = this.get("organs");
      var organ = this.get("doc").OrganName;
      if (!organs.find(function (x) { return x.OrganName == organ })) {
        organs.push(this.get("doc").OrganName);
        this.set("organs", organs);
      }
    },
  });
  kendo.bind($("#edit-doc-form"), docVM);
  //Xóa, sửa hồ sơ
  $("#fileTable").on("click", ".delete-btn", function (e) {
    var data = $("#fileTable").DataTable().row($(this).closest("tr")).data();
    Swal.fire({
      title: 'Xác nhận',
      text: 'Chức năng này sẽ xóa hồ sơ và tất cả văn bản thuộc hồ sơ được lưu trữ trên hệ thống',
      type: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#cd201f',
      cancelButtonColor: '#467fcf',
      confirmButtonText: 'Xóa hồ sơ',
      cancelButtonText: 'Đóng lại'
    }).then(function (result) {
      if (result.value) {
        $.ajax({
          url: "/sohoa/hoso",
          type: "DELETE",
          data: { id: data.UUID },
          headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
          success: function (data, textStatus, jqXHR) {
            Swal.fire({
              text: jqXHR.responseText,
              type: 'info',
              showConfirmButton: false,
              timer: 1500
            }).then(function () { $("#fileTable").DataTable().ajax.reload(null, false) })
          },
          error: function (jqXHR, textStatus, err) {
            Swal.fire({
              text: jqXHR.responseText,
              type: 'error',
              showConfirmButton: false,
              timer: 1500
            })
          }
        });
      }
    })
  });
  //Xử lý chỉnh sửa hồ sơ
  $('#edit-file-win').kendoWindow({
    width: '90%',
    position: { top: 0, left: '5%' },
    title: 'Danh sách văn bản trong hồ sơ',
    animation: {
      open: { duration: 500 },
      close: { duration: 500 }
    },
    modal: true,
    visible: false,
    actions: ['Pin', 'Minimize', 'Maximize', 'Close']
  });
  $("#fileTable").on("click", ".edit-btn", function (e) {
    e.stopPropagation();
    var data = $("#fileTable").DataTable().row($(this).closest("tr")).data();
    fileVM.set("file", data);
    $("#edit-language").val(data.Language).trigger("change");
    $("#edit-right").val(data.Rights).trigger("change");
    $("#edit-keyword").tagsinput("add", data.Keyword);
    $("#edit-fond").val(data.FondCode).trigger("change");
    $("#edit-file-modal").modal("show");
  });
  $("#edit-file-form").validate({
    validClass: "success",
    messages: {
      catalog: {
        required: "Không được để trống",
        number: "Chỉ được nhập số"
      },
      box: {
        required: "Không được để trống",
        number: "Chỉ được nhập số"
      },
      year: {
        required: "Không được để trống",
        number: "Chỉ được nhập số"
      }
    },
    highlight: function (element) {
      $(element).closest(".form-group").removeClass("has-primary").addClass("has-error");
    },
    unhighlight: function (element) {
      $(element).closest(".form-group").removeClass("has-error").addClass("has-primary");
    },
    errorPlacement: function (error, element) {
      $(element).closest(".form-group").append(error);
    },
    submitHandler: function (domForm) {
      $.ajax({
        url: "/sohoa/hoso",
        method: "PUT",
        data: $(domForm).serialize(),
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success: function (data, textStatus, jqXHR) {
          $("#edit-file-modal").modal("hide");
          $("#fileTable").DataTable().ajax.reload(null, false);
        },
        error: function (jqXHR, textStatus, err) {
          Swal.fire({
            text: jqXHR.responseText,
            type: 'error',
            showConfirmButton: false,
            timer: 1500
          })
        }
      });
    }
  });
  //Form sửa thông tin hồ sơ
  $("#edit-keyword").tagsinput({
    tagClass: "badge badge-primary"
  });
  $("#doc-date").datepicker({
    format: "dd/mm/yyyy",
    autoclose: true,
    language: "vi"
  });
  $("#doc-date").inputmask('datetime', { inputFormat: "dd/mm/yyyy" });
  $.getJSON("/danhmuc/phong", function (data, textStatus, jqXHR) {
    $("#edit-fond").select2({
      data: data.map(function (x) { x.id = x.FondCode; return x }),
      theme: "bootstrap4",
      templateResult: function (fond) {
        if (!fond.id) {
          return fond.FondName;
        }
        var html = `<div class='w-100'><span class='badge pull-right ${fond.State ? "badge-danger'>Đóng" : "badge-success'>Mở"}</span> ${fond.FondName}<small class='text-warning d-block'>Mã phông: ${fond.FondCode}</small></div>`;
        return $(html);
      },
      templateSelection: function (fond) {
        if (!fond.id) {
          return fond.FondName;
        }
        var html = `<div class='w-100'><span class='badge ${fond.State ? "badge-danger'>Đóng" : "badge-success'>Mở"}</span> ${fond.FondName}</div>`;
        return $(html);
      }
    });
  });
  $("#edit-fond").on("change", function (e) {
    $.getJSON("/danhmuc/nhomtailieu", function (data, text, jqXHR) {
      $("#edit-group").select2({
        data: data.map(function (x) { return { id: x.Id, text: x.GroupName } }),
        theme: "bootstrap4"
      });
    }).fail(function (jqXHR, err) {
      $('<span/>').kendoNotification({
        position: { top: 20 }
      }).data('kendoNotification').show(jqXHR.responseText, 'error');
    });
  });
  $.getJSON("/danhmuc/ngonngu", function (data, textStatus, jqXHR) {
    $("#edit-language").select2({
      data: data.map(function (x) { return { id: x.LangCode, text: x.LangName } }),
      allowClear: true,
      theme: "bootstrap4"
    })
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });;
  $.getJSON("/danhmuc/quyentailieu", function (data, textStatus, jqXHR) {
    $("#edit-right").select2({
      data: data.map(function (x) { return { id: x.ModeName, text: x.ModeName } }),
      theme: "bootstrap4"
    })
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });;
  //Sửa, xóa văn bản
  $.getJSON("/danhmuc/loaivanban", function (data, textStatus, jqXHR) {
    var docType = [
      {
        text: "Văn bản hành chính",
        children: data.filter(function (x) { return x.TypeGroup == 2 }).map(function (x) { return { id: x.Id, text: x.TypeName } })
      },
      {
        text: "Văn bản quy phạm pháp luật",
        children: data.filter(function (x) { return x.TypeGroup == 1 }).map(function (x) { return { id: x.Id, text: x.TypeName } })
      }
    ];
    $("#doc-type").select2({
      data: docType,
      theme: "bootstrap4",
      allowClear: true,
      placeholder: "Chọn loại văn bản",
      dropdownParent: $("#edit-doc-modal")
    });
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });
  $.getJSON("/danhmuc/ngonngu", function (data, textStatus, jqXHR) {
    $("#doc-language").select2({
      data: data.map(function (x) { return { id: x.LangCode, text: x.LangName } }),
      theme: "bootstrap4"
    });
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });
  $.getJSON("/danhmuc/quyentailieu", function (data, textStatus, jqXHR) {
    $("#doc-mode").select2({
      data: data.map(function (x) { return { id: x.Id, text: x.ModeName } }),
      theme: "bootstrap4",
      minimumResultsForSearch: -1
    });
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });
  $.getJSON("/danhmuc/dotincay", function (data, text, jqXHR) {
    $("#doc-level").select2({
      data: data.map(function (x) { return { id: x.Id, text: x.Name } }),
      theme: "bootstrap4",
      minimumResultsForSearch: -1
    });
  }).fail(function (jqXHR, err) {
    $('<span/>').kendoNotification({
      position: { top: 20 }
    }).data('kendoNotification').show(jqXHR.responseText, 'error');
  });
  $("#doc-keyword").tagsinput({ tagClass: "badge badge-secondary" });
  //Xử lý sự kiện
  $("#detailTable").on("click", ".edit-btn", function (e) {
    var doc = $("#detailTable").DataTable().row($(this).closest("tr")).data();
    $("#edit-doc-form").trigger("reset");
    docVM.set("doc", doc);
    $("#doc-type").val(doc.DocType || "").trigger("change");
    $("#doc-language").val(doc.Language).trigger("change");
    $("#doc-mode").val(doc.ModeId).trigger("change");
    $("#doc-level").val(doc.ConfidenceLevelId).trigger("change");
    $("#doc-keyword").tagsinput("add", doc.Keyword);
    $("#edit-doc-modal").modal("show");
  });
  $("#detailTable").on("click", ".delete-btn", function (e) {
    var doc = $("#detailTable").DataTable().row($(this).closest("tr")).data();
  });
  //Form chỉnh sửa văn bản
  var editDocForm = $("#edit-doc-form").validate({
    validClass: "success",
    highlight: function (element) {
      $(element).closest(".form-group").removeClass("has-primary").addClass("has-error");
    },
    unhighlight: function (element) {
      $(element).closest(".form-group").removeClass("has-error").addClass("has-primary");
    },
    errorPlacement: function (error, element) {
      $(element).closest(".form-group").append(error);
    },
    submitHandler: function (domForm) {
      var formData = new FormData(domForm);
      $.ajax({
        url: "/sohoa/vanban",
        method: "PUT",
        processData: false,
        contentType: false,
        data: formData,
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success: function (data, textStatus, jqXHR) {
          $("#edit-doc-modal").modal("hide");
          $("#detailTable").DataTable().ajax.reload(null, false);
        },
        error: function (jqXHR, textStatus, err) {
          Swal.fire({
            text: jqXHR.responseText,
            type: 'error',
            showConfirmButton: false,
            timer: 1500
          })
        }
      });
    }
  });
});