Guest User

ex

a guest
Jul 26th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.         var vehicleCreateDialog, vehicleEditDialog;
  3.  
  4.         $(function () {
  5.             $('#vehicleTable').DataTable({
  6.                 processing: true,
  7.                 serverSide: true,
  8.                 ajax: {
  9.                     "url": "@(Url.Action("GetAllForDataTable", "Vehicles"))",
  10.                     "type": "POST",
  11.                     "datatype": "json",
  12.                     "data": function (data) {
  13.                         data.MinYearOfProduction = document.getElementById("vehicleFilters_MinYearOfProduction").value;
  14.                         data.MaxYearOfProduction = document.getElementById("vehicleFilters_MaxYearOfProduction").value;
  15.                         data.ChassisNumber = document.getElementById("vehicleFilters_ChassisNumber").value;
  16.                         data.TypeOfDrive = document.getElementById("vehicleFilters_TypeOfDrive").value;
  17.                         data.MinAllowedPackage = document.getElementById("vehicleFilters_MinAllowedPackage").value;
  18.                         data.MaxAllowedPackage = document.getElementById("vehicleFilters_MaxAllowedPackage").value;
  19.                         data.VehicleMarkingType = document.getElementById("vehicleFilters_VehicleMarkingType").value;
  20.                         data.MinNumberOfSeats = document.getElementById("vehicleFilters_MinNumberOfSeats").value;
  21.                         data.MaxNumberOfSeats = document.getElementById("vehicleFilters_MaxNumberOfSeats").value;
  22.                         data.TypeOfPurchase = document.getElementById("vehicleFilters_TypeOfPurchase").value;
  23.                         data.Description = document.getElementById("vehicleFilters_Description").value;
  24.                     }
  25.                 },
  26.                 columnDefs: [
  27.                     { "targets": [0], "visible": false, "searchable": false },
  28.                     { "targets": [1], "visible": true, "searchable": true },
  29.                     { "targets": [2], "visible": true, "searchable": true },
  30.                     { "targets": [3], "visible": true, "searchable": true },
  31.                     { "targets": [4], "visible": true, "searchable": true },
  32.                     { "targets": [5], "visible": true, "searchable": true },
  33.                     { "targets": [6], "visible": true, "searchable": true },
  34.                     { "targets": [7], "visible": true, "searchable": true },
  35.                     { "targets": [8], "visible": true, "searchable": true },
  36.                     { "targets": [9], "visible": true, "searchable": false, "orderable": false },
  37.                 ],
  38.                 columns: [
  39.                     { "data": "id", "name": "Id", "autoWidth": true },
  40.                     { "data": "institutionName", "name": "Lokalizacja", "autoWidth": true },
  41.                     { "data": "group", "name": "Grupa", "autoWidth": true },
  42.                     { "data": "producer", "name": "Marka", "autoWidth": true },
  43.                     { "data": "model", "name": "Model", "autoWidth": true },
  44.                     { "data": "registrationNumber", "name": "Numer rej.", "autoWidth": true },
  45.                     { "data": "lastOdometerValue", "name": "Przebieg", "autoWidth": true },
  46.                     { "data": "status", "name": "Status", "autoWidth": true },
  47.                     { "data": "isAvailable", "name": "Czy dostępny", "autoWidth": true },
  48.                     {
  49.                         data: "id", name: "Actions", autoWidth: true,
  50.                         render: function (data, row) {
  51.                             var mainDiv = $("<div>", {
  52.                                 class: "dropdown"
  53.                             })
  54.                             $("<button>", {
  55.                                 class: "btn btn-primary dropdown-toggle",
  56.                                 attr: {
  57.                                     type: "button",
  58.                                     "data-toggle": "dropdown",
  59.                                 }
  60.                             }).text("Akcje").appendTo(mainDiv);
  61.                             var mainUl = $("<ul>", {
  62.                                 class: "dropdown-menu"
  63.                             });
  64.  
  65.                             if ("@((
  66.                                    User.IsInRole(Roles.Admin) ||
  67.                                    User.IsInRole(Roles.Tab_MobileResources_EditBasicData) ||
  68.                                    User.IsInRole(Roles.Tab_MobileResources_ChangeInstitution) ||
  69.                                    User.IsInRole(Roles.Tab_MobileResources_ChangeOdometerValue) ||
  70.                                    User.IsInRole(Roles.Tab_MobileResources_ChangeTechnicalInspectionExpiration)
  71.                                    ) ? "1" : "0")" === "1") {
  72.                                 var menuSep = $("<div>", {
  73.                                     class: "dropdown-header",
  74.                                     css: {
  75.                                         color: "green"
  76.                                     }
  77.                                 }).text("Podstawowe")
  78.                                 mainUl.append(menuSep);
  79.  
  80.                                 if ("@((User.IsInRole(Roles.Tab_MobileResources_EditBasicData) || User.IsInRole(Roles.Admin)) ? "1" : "0")" === "1"){
  81.                                     menuSep.append(
  82.                                         $("<button>", {
  83.                                             class: "dropdown-item btn btn-outline",
  84.                                             type: "button",
  85.                                         })
  86.                                             .text("Edytuj pojazd")
  87.                                             .on('click', function (e) {
  88.                                                 console.log("test");
  89.                                             })
  90.                                     );
  91.                                 }
  92.                                 if ("@((User.IsInRole(Roles.Tab_MobileResources_ChangeInstitution) || User.IsInRole(Roles.Admin)) ? "1" : "0")" === "1") {
  93.                                     menuSep.append(
  94.                                         $("<li>").html(
  95.                                             $("<button>", {
  96.                                                 class: "dropdown-item btn btn-outline",
  97.                                                 type: "button"
  98.                                             }).text("Zmień lokalizację")
  99.                                         ));
  100.                                 }
  101.                                 if ("@((User.IsInRole(Roles.Tab_MobileResources_ChangeOdometerValue) || User.IsInRole(Roles.Admin)) ? "1" : "0")" === "1") {
  102.                                     menuSep.append(
  103.                                         $("<li>").html(
  104.                                             $("<button>", {
  105.                                                 class: "dropdown-item btn btn-outline",
  106.                                                 type: "button"
  107.                                             }).text("Zmień wartość licznika")
  108.                                         ));
  109.                                 }
  110.                                 if ("@((User.IsInRole(Roles.Tab_MobileResources_ChangeTechnicalInspectionExpiration) || User.IsInRole(Roles.Admin)) ? "1" : "0")" === "1") {
  111.                                     menuSep.append(
  112.                                         $("<li>").html(
  113.                                             $("<button>", {
  114.                                                 class: "dropdown-item btn btn-outline",
  115.                                                 type: "button"
  116.                                             }).text("Zmień termin badań technicznych")
  117.                                         ));
  118.                                 }
  119.                             }
  120.  
  121.                             mainDiv.append(mainUl);
  122.                             return mainDiv.html();
  123.                         }
  124.                     },
  125.                 ],
  126.                 initComplete: function () {
  127.                     var col_Id = this.api().columns(0);
  128.                     var col_institutionName = this.api().columns(1);
  129.                     var col_group = this.api().columns(2);
  130.                     var col_producer = this.api().columns(3);
  131.                     var col_model = this.api().columns(4);
  132.                     var col_registrationNumber = this.api().columns(5);
  133.                     var col_lastOdometerValue = this.api().columns(6);
  134.                     var col_status = this.api().columns(7);
  135.                     var col_isAvailable = this.api().columns(8);
  136.                     //====================================== 1
  137.                     $("<input>", {
  138.                         id: "col1_filter",
  139.                         class: "column_filter form-control form-control-sm",
  140.                         attr: {
  141.                             type: "text",
  142.                             placeholder: "Wyszukaj"
  143.                         }
  144.                     })
  145.                         .appendTo($(col_institutionName.footer()).empty())
  146.                         .on('change', function () {
  147.                             col_institutionName.search(
  148.                                 $('#col1_filter').val()
  149.                             ).draw();
  150.                         });
  151.  
  152.                     //====================================== 2
  153.                     $("<input>", {
  154.                         id: "col2_filter",
  155.                         class: "column_filter form-control form-control-sm",
  156.                         attr: {
  157.                             type: "text",
  158.                             placeholder: "Wyszukaj"
  159.                         }
  160.                     })
  161.                         .appendTo($(col_institutionName.footer()).empty())
  162.                         .on('change', function () {
  163.                             col_institutionName.search(
  164.                                 $('#col2_filter').val()
  165.                             ).draw();
  166.                         });
  167.  
  168.                     //====================================== 3
  169.                     $("<input>", {
  170.                         id: "col3_filter",
  171.                         class: "column_filter form-control form-control-sm",
  172.                         attr: {
  173.                             type: "text",
  174.                             placeholder: "Wyszukaj"
  175.                         }
  176.                     })
  177.                         .appendTo($(col_group.footer()).empty())
  178.                         .on('change', function () {
  179.                             col_group.search(
  180.                                 $('#col3_filter').val()
  181.                             ).draw();
  182.                         });
  183.  
  184.                     //====================================== 4
  185.                     $("<input>", {
  186.                         id: "col4_filter",
  187.                         class: "column_filter form-control form-control-sm",
  188.                         attr: {
  189.                             type: "text",
  190.                             placeholder: "Wyszukaj"
  191.                         }
  192.                     })
  193.                         .appendTo($(col_producer.footer()).empty())
  194.                         .on('change', function () {
  195.                             col_producer.search(
  196.                                 $('#col4_filter').val()
  197.                             ).draw();
  198.                         });
  199.  
  200.                     //====================================== 5
  201.                     $("<input>", {
  202.                         id: "col5_filter",
  203.                         class: "column_filter form-control form-control-sm",
  204.                         attr: {
  205.                             type: "text",
  206.                             placeholder: "Wyszukaj"
  207.                         }
  208.                     })
  209.                         .appendTo($(col_model.footer()).empty())
  210.                         .on('change', function () {
  211.                             col_model.search(
  212.                                 $('#col5_filter').val()
  213.                             ).draw();
  214.                         });
  215.  
  216.                     //====================================== 6
  217.                     $("<input>", {
  218.                         id: "col6_filter",
  219.                         class: "column_filter form-control form-control-sm",
  220.                         attr: {
  221.                             type: "text",
  222.                             placeholder: "Wyszukaj"
  223.                         }
  224.                     })
  225.                         .appendTo($(col_registrationNumber.footer()).empty())
  226.                         .on('change', function () {
  227.                             col_registrationNumber.search(
  228.                                 $('#col6_filter').val()
  229.                             ).draw();
  230.                         });
  231.  
  232.                 },
  233.             });
Add Comment
Please, Sign In to add comment