jraavis

crud

May 12th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 29.79 KB | None | 0 0
  1. {% extends "index.html" %}
  2. {% block pageTitleBlock %}
  3. {% with pageTitle='UNIX Data :: Patch Exclusions' %}
  4. {{ block.super }}
  5. {% endwith %}
  6. {% endblock pageTitleBlock %}
  7. {% load static %}
  8. {% block head %}
  9. <link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css" />
  10. <link rel="stylesheet" href="//cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css" />
  11. <link rel="stylesheet" href="//cdn.datatables.net/fixedheader/3.1.6/css/fixedHeader.bootstrap.min.css" />
  12. <link rel="stylesheet" href="//cdn.datatables.net/scroller/2.0.1/css/scroller.dataTables.min.css" />
  13. <script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  14. <script src="//cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
  15. <script src="//cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>
  16. <script src="//cdn.datatables.net/fixedheader/3.1.6/js/fixedHeader.bootstrap.min.js"></script>
  17. <script src="//cdn.datatables.net/scroller/2.0.1/js/dataTables.scroller.min.js"></script>
  18. <script src="{% static 'js/xlsx.js' %}"></script>
  19.  
  20. <style type="text/css">
  21. th, .table-striped>tbody>tr td:first-child {
  22.     vertical-align: middle !important;
  23.     text-transform: capitalize !important;
  24. }
  25. .table-striped>tbody>tr td:first-child {
  26.     text-align: center;
  27. }
  28. tr.sort-header th {
  29.     font-size: 12px;
  30. }
  31. tr.filter-header th{
  32.     font-size: 10px;
  33.     padding: 0px;
  34. }
  35. thead .sorting:after {
  36.    
  37. }
  38. table.table-bordered.dataTable tbody th, table.table-bordered.dataTable tbody td {
  39.     vertical-align: middle;
  40. }
  41. div.dts div.dataTables_scrollBody {
  42.     background: #fff !important;
  43. }
  44. input[type=checkbox] {
  45.     -webkit-appearance: button;
  46.     white-space: nowrap;
  47.     overflow: hidden;
  48.     min-width: 20px;
  49.     min-height: 20px;
  50. }
  51. .loader {
  52.     width: 100vw;
  53.     height: 100vh;
  54.     background: rgba(0,0,0,0.7);
  55.     z-index: 999;
  56.     position: absolute;
  57.     top: 0px;
  58.     left: 0px;
  59.     min-width: 100%;
  60.     min-height: 100%;
  61.     display:none;
  62. }
  63. select.form-control:not([size]):not([multiple]) {
  64.     height: calc(2.25rem + 6px);
  65. }
  66. </style>
  67. {% endblock head %}
  68. {% block header %}
  69. {% include 'header.html' %}
  70. {% include 'sidebar.html' with active_menu="PatchExclude" %}
  71. {% endblock header %}
  72. {% block bodyContent %}
  73. <div class="loader"></div>
  74. <div class="content-wrapper" style="min-height: 916px;">
  75.     <!-- Content Header (Page header) -->
  76.     <section class="content-header">
  77.         <h1>
  78.             Patch Exclusions
  79.             <small>Exclusions</small>
  80.         </h1>
  81.         <ol class="breadcrumb">
  82.             <li><a href="/home"><i class="fa fa-dashboard"></i> Home</a></li>
  83.             <li class="active">Patch Exclusions</li>
  84.         </ol>
  85.     </section>
  86.  
  87.     <!-- Main content -->
  88.     <section class="content">
  89.         <div class="row">
  90.             <div class="col-md-12">
  91.                 <div class="box">
  92.                     <div class="box-header hidden">
  93.                         <h3 class="box-title"></h3>
  94.                     </div>
  95.  
  96.                     <!-- /.box-header -->
  97.                     <div class="box-body">
  98.                         <div class="col-md-12 text-center">
  99.                                     <h4 style="text-align:center;position:relative;color:DodgerBlue;"><b><u>Info!</u></b> Here you can exclude servers from Patching</h4>
  100.                             <h5 style="text-align:center;position:relative;color:DodgerBlue;"><b><u>Note:</u></b> Select Checkbox and click Edit to Exclude</h5>
  101.                                 </div>
  102.                         <div class="row">
  103.                             <div class="col-xs-12 col-xs-12 btn-group text-right" role="group">
  104.                                 <button type="button" class="btn btn-primary btn-md pull-right export-csv">
  105.                                     <i class="fa fa-download"></i> Export CSV
  106.                                 </button>
  107.                             </div>
  108.                         </div>
  109.  
  110.                         <div class="row">&nbsp;</div>
  111.  
  112.                         <div class="row bulk-edit-div" style="display:none;">
  113.                             <div class="col-xs-12">
  114.                                 <div class="alert alert-primary p-2 pl-3" role="alert">
  115.                                     <strong>Alert: </strong> Click here to bulk edit &nbsp;
  116.                                     <button type="button" class="btn btn-success btn-sm" id="bulk-edit-form-btn">
  117.                                         <i class="fa fa-pencil"></i>Edit
  118.                                     </button>
  119.                                 </div>
  120.                             </div>
  121.                         </div>
  122.                         <div class="row bulk-edit-success-div" style="display:none;">
  123.                             <div class="col-xs-12">
  124.                                 <div class="alert alert-success p-2 pl-3" role="alert">Data updated successfully.</div>
  125.                             </div>
  126.                         </div>
  127.                         <div class="row single-edit-div" style="display:none;">
  128.                             <div class="col-xs-12">
  129.                                 <div class="alert alert-primary p-2 pl-3" role="alert">
  130.                                     <strong>Alert: </strong> Click here to Save changes &nbsp;
  131.                                     <button type="button" class="btn btn-success btn-sm" id="single-update-btn">
  132.                                         <i class="fa fa-save"></i> Save
  133.                                     </button>
  134.                                 </div>
  135.                             </div>
  136.                         </div>
  137.                         <div class="row single-edit-error-div" style="display:none">
  138.                             <div class="col-xs-12">
  139.                                 <div class="alert alert-danger p-2 pl-3" role="alert">All fields are required</div>
  140.                             </div>
  141.                         </div>
  142.  
  143.                         <div class="row">
  144.                             <div class="col-md-12" style="overflow:auto;">
  145.                                 <table id="patchExclusionsTable" class="table table-striped table-bordered nowrap">
  146.                                     <thead>
  147.                                         <tr class="sort-header paginated btn-primary text-sm">
  148.                                             {% if total_count > 0 %}
  149.                                             <th key="checkbox" class="text-center">
  150.                                                 <input type="checkbox" id="bulk-check-all" />
  151.                                             </th>
  152.                                             {% endif %}
  153.                                             <th key="servername">Hostname</th>
  154.                                             <th key="os">OS</th>
  155.                                             <th key="serverenvironment">Server Environment</th>
  156.                                             <th key="environment">Environment</th>
  157.                                             <th key="operational_status">Operational Status</th>
  158.                                             <th key="appcode">Appcode</th>
  159.                                             <th key="virtual">Virtual</th>
  160.                                             <th key="q1_servicewindow">Q1 Service Window</th>
  161.                                             <th key="q2_servicewindow">Q2 Service Window</th>
  162.                                             <th key="q3_servicewindow">Q3 Service Window</th>
  163.                                             <th key="q4_servicewindow">Q4 Service Window</th>
  164.                                             <th key="servicewindow_exclude_option">Patch Exclude</th>
  165.                                             <th key="exclude_comments">Comments</th>
  166.                                         </tr>
  167.                                         <tr class="filter-header">
  168.                                             {% if total_count > 0 %}
  169.                                             <th class="text-center" id="bulk-check-count">0 Selected</th>
  170.                                             {% endif %}
  171.                                             <th>Hostname</th>
  172.                                             <th>OS</th>
  173.                                             <th>Server Environment</th>
  174.                                             <th class="environment-filter">Environment</th>
  175.                                             <th>Operational Status</th>
  176.                                             <th>Appcode</th>
  177.                                             <th>Virtual</th>
  178.                                             <th>Q1 Service Window</th>
  179.                                             <th>Q2 Service Window</th>
  180.                                             <th>Q3 Service Window</th>
  181.                                             <th>Q4 Service Window</th>
  182.                                             <th>Patch Exclude</th>
  183.                                             <th>Comments</th>
  184.                                         </tr>
  185.                                     </thead>
  186.                                     <tbody>
  187.                                     </tbody>
  188.                                 </table>
  189.                             </div><!-- /col-md-12 -->
  190.                         </div><!-- /.table row -->
  191.  
  192.                     </div><!-- /box-body -->
  193.                 </div><!-- /box -->
  194.             </div><!-- /col-md-12 -->
  195.         </div><!-- /row (content) -->
  196.     </section><!-- /section (body) -->
  197.  
  198.  
  199. </div><!-- /content-wrapper -->
  200.  
  201. <div class="modal fade" id="bulkEditModal" tabindex="-1" role="dialog" aria-labelledby="bulkEditModal" aria-hidden="true">
  202.   <div class="modal-dialog" role="document">
  203.     <div class="modal-content">
  204.       <div class="modal-header">
  205.         <h5 class="modal-title" id="bulkEditModalLabel">Commenting for 0 items</h5>
  206.         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  207.           <span aria-hidden="true">&times;</span>
  208.         </button>
  209.       </div>
  210.       <div class="modal-body">
  211.         <form>
  212.           <div class="form-group">
  213.             <label for="servicewindow_exclude_option" class="col-form-label">Service Window Exclude Option:</label>
  214.             <select name="servicewindow_exclude_option[0]" row="0" class="form-control" style="height: 39px">
  215.                     <option value="None">None</option>
  216.                     <option value="Manual">Manual</option>
  217.                     <option value="Temp-Ex">Temp-Ex</option>
  218.                     <option value="CW-CCT">CW-CCT</option>
  219.                     <option value="CW-HADOOP">CW-HADOOP</option>
  220.                 </select>
  221.           </div>
  222.           <div class="form-group">
  223.             <label for="exclude_comments" class="col-form-label">Comments:</label>
  224.             <textarea class="form-control" name="exclude_comments[0]" row="0" required="required"></textarea>
  225.           </div>
  226.              <div class="form-group">
  227.                 <label class="text-danger" id="bulk-update-error" style="display:none;">All fields are required</label>
  228.             </div>
  229.             <div class="form-group">
  230.                 <label class="text-danger" id="bulk-update-success" style="display:none;">Data updated successfully.</label>
  231.             </div>
  232.         </form>
  233.       </div>
  234.       <div class="modal-footer">
  235.         <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  236.         <button type="button" class="btn btn-primary" id="bulk-update-btn">Update</button>
  237.       </div>
  238.     </div>
  239.   </div>
  240. </div>
  241.  
  242. {% endblock bodyContent %}
  243.  
  244.  
  245. {% block footerScripts %}
  246. <script type="text/javascript">
  247. window.json_data = {};
  248. window.table = {};
  249. window.table_selector = '#patchExclusionsTable';
  250. function log(i) {
  251.     console.log(i);
  252.     return true;
  253. }
  254. function loading(c) {
  255.     $.LoadingOverlay('show');
  256.     $('.loader').show();
  257.     if(typeof(c)!='undefined' && c!='') {
  258.         return c();
  259.     }
  260. }
  261.  
  262. function loaded(c) {
  263.     $.LoadingOverlay('hide');
  264.     $('.loader').hide();
  265.     if(typeof(c)!='undefined' && c!='') {
  266.         return c();
  267.     }
  268. }
  269.  
  270. function convertToCSV(objArray) {
  271.     var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
  272.     var str = '';
  273.     for (var i = 0; i < array.length; i++) {
  274.         var line = '';
  275.         for (var index in array[i]) {
  276.             line += array[i][index];
  277.             line += ','
  278.         }
  279.         line = line.replace(/(,$)/g, "");
  280.         str += line + '\r\n';
  281.     }
  282.     return str;
  283. }
  284.  
  285. function exportCSVFile(headers, items, fileTitle) {
  286.     if (headers) {
  287.         items.unshift(headers);
  288.     }
  289.     var jsonObject = JSON.stringify(items);
  290.     var csv = this.convertToCSV(jsonObject);
  291.     var exportedFilenmae = fileTitle + '.csv' || 'export.csv';
  292.     var blob = new Blob([csv], {
  293.         type: 'text/csv;charset=utf-8;'
  294.     });
  295.     if (navigator.msSaveBlob) { // IE 10+
  296.         navigator.msSaveBlob(blob, exportedFilenmae);
  297.     } else {
  298.         var link = document.createElement("a");
  299.         if (link.download !== undefined) {
  300.             var url = URL.createObjectURL(blob);
  301.             link.setAttribute("href", url);
  302.             link.setAttribute("download", exportedFilenmae);
  303.             link.style.visibility = 'hidden';
  304.             document.body.appendChild(link);
  305.             link.click();
  306.             document.body.removeChild(link);
  307.         }
  308.     }
  309. }
  310.  
  311. $(document).ready(function () {
  312.  
  313.     $('.export-csv').on('click', function (e) {
  314.         e.preventDefault();
  315.         loading();
  316.         // log(window.json_data[0]['id']);
  317.         var table = window.table;
  318.         var items_not_formatted = window.json_data;
  319.         if(typeof(table)!='undefined' && table!='') {
  320.             var nodes = table.rows({search: 'applied'}).nodes();
  321.             if(nodes.length<=items_not_formatted.length) {
  322.                 var items_filtered = [];
  323.                 $.each(nodes, function (index, item) {
  324.                     var row = $(item).find('.row_id').attr('row');
  325.                     var servicewindow_exclude_option = '';
  326.                     var exclude_comments = '';
  327.                     if($(item).find('.bulk-check-item').length>0) {
  328.                         servicewindow_exclude_option = $(item).find('.servicewindow_exclude_option').closest('td').text();
  329.                         exclude_comments = $(item).find('.exclude_comments').closest('td').text();
  330.                     }
  331.                     for (var i=0; i<items_not_formatted.length; i++) {
  332.                         if(row==items_not_formatted[i]['id']) {
  333.                             if(servicewindow_exclude_option!='') {
  334.                                 items_not_formatted[i]['servicewindow_exclude_option'] = servicewindow_exclude_option;
  335.                                 items_not_formatted[i]['exclude_comments'] = exclude_comments;
  336.                             }
  337.                             items_filtered.push(items_not_formatted[i]);
  338.                             break;
  339.                         }
  340.                     }
  341.                 });
  342.             }
  343.         }
  344.         var headers = {
  345.             "environment": 'Environment',
  346.             "operational_status": 'Operational Status',
  347.             "os": 'OS',
  348.             "q1_servicewindow": 'Q1 Service Window',
  349.             "q2_servicewindow": 'Q2 Service Window',
  350.             "q3_servicewindow": 'Q3 Service Window',
  351.             "q4_servicewindow": 'Q4 Service Window',
  352.             "serverenvironment": 'Server Environment',
  353.             "servername": 'Server Name',
  354.             /*"sys_class_name": 'Sys Class Name',*/
  355.             "virtual": 'Virtual',
  356.             "servicewindow_exclude_option": 'Patch Exclude',
  357.             "exclude_comments": 'Excluded Comments',
  358.             "appcode": 'App Code'
  359.         };
  360.  
  361.         var items_formatted = [];
  362.         var considerable_data = (typeof(items_filtered)!='undefined' && items_filtered.length>0)?items_filtered:items_not_formatted;
  363.        
  364.         considerable_data.forEach(function(item){
  365.             var t_object = {};
  366.             for(var key in headers) {
  367.                 t_object[key] = (typeof(item[key])!=='undeinfed' ? item[key] : ' ');
  368.             }
  369.             items_formatted.push(t_object);
  370.         });
  371.         var fileTitle = 'Unix_Patching_' + new Date().toLocaleDateString();
  372.         // exportCSVFile(headers, items_formatted, fileTitle);
  373.         // var json_data = [{}];
  374.         var headers_text = "";
  375.         for(var key in headers) {
  376.             headers_text += '['+key+'] AS ['+headers[key]+']' + ', ';
  377.         }
  378.         try {
  379.             headers_text = headers_text.replace(/,\s*$/, "");
  380.             var options = {
  381.                 headers: true,
  382.                 sheetid:"Report",
  383.                 column: {style:{Font:{Bold:"1",Color: "#3C3741"}}},
  384.                 rows: {1:{style:{Font:{Bold:"1",Color:"#FF0000"}}}}
  385.             };
  386.             var result = alasql('SELECT '+headers_text+' INTO XLSX("'+fileTitle+'.xlsx",?) FROM ?', [options, items_formatted]);
  387.         } catch(e) {
  388.             console.log(e);
  389.         }
  390.         loaded();
  391.     });
  392. });
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418. $(document).ready(function () {
  419.     document.onreadystatechange = function () {
  420.         var state = document.readyState
  421.         if (state == 'complete') {
  422.             setTimeout(function () {
  423.                 document.getElementById('interactive');
  424.                 try {
  425.                     document.getElementById('load').style.visibility = "hidden";
  426.                 } catch (err) {}
  427.             }, 2000);
  428.         }
  429.     }
  430.     /* My Code */
  431.  
  432.     function createTable() {
  433.         var json_data = window.json_data;
  434.         var table_selector = window.table_selector;
  435.         var table_header_count = ($(table_selector).find('.sort-header th').length);
  436.         var table_column_settings = [];
  437.         var table_column_defs = [{ "orderable": false, "targets": 0, "bSearchable": false, "asSorting": false }];
  438.         table_column_settings.push({"orderable": false});
  439.         for(var i=1; i<table_header_count; i++) {
  440.             table_column_settings.push(null);
  441.         }
  442.         var table_settings = {
  443.             'searching': true,
  444.             'orderCellsTop': true,
  445.             'paging': true,
  446.             'pageLength': 100000,
  447.             'dom': 'Bfrtip',
  448.             'order': [[ 1, 'asc' ]],
  449.             'columns': table_column_settings,
  450.             'columnDefs': table_column_defs,
  451.             'initComplete': function (settings, json) {
  452.                 if (typeof (table) != 'undefined') {
  453.                     log('Table initialized!');
  454.                     actionsAfterTableInit(settings, json);
  455.                 }
  456.             },
  457.             'recordsTotal': ((typeof (json_data) != 'undefined') ? json_data.length : 0),
  458.             'deferRender': false,
  459.             'scrollX': true,
  460.             'scrollY': 340,
  461.             'scrollCollapse': false,
  462.             'scroller': {
  463.            loadingIndicator: false
  464.         },
  465.             "oLanguage": {
  466.                 "sInfo": "Displaying _TOTAL_ records",
  467.             },
  468.             'cache': true
  469.         };
  470.         log(table_settings);
  471.         window.table = $(table_selector).DataTable(table_settings);
  472.         actionsAfterTableCreate(window.table);
  473.     }
  474.     createTable();
  475.  
  476.     function actionsAfterTableCreate(table) {
  477.         if(typeof(table)!='undefined') {
  478.             addColumnFilters(table);
  479.             addDataToTable(table);
  480.             $('.dataTables_wrapper').prepend($('.dataTables_info').detach());
  481.         }
  482.     }
  483.  
  484.     function actionsAfterTableInit(settings, json) {
  485.         /*log(settings);
  486.         log(json);*/
  487.     }
  488.  
  489.     function actionsAfterFilter() {
  490.         /* Things need to be done after filter/search */
  491.         // Uncheck all
  492.         // Update checked count
  493.         bulkCheckToggle(false);
  494.         renderBulkCheckCount();
  495.         $('#bulk-check-all').prop('checked',false);
  496.     }
  497.  
  498.  
  499.  
  500.     function addColumnFilters(table) {
  501.         /* Adding by Filter for Column */
  502.         $('.dataTables_scrollHeadInner thead tr.filter-header th').each(function () {
  503.             if ($(this).hasClass('environment-filter')) {
  504.                 $(this).html(
  505.                     '<select class="column_search form-control input-sm">'+
  506.                         '<option value="">Select ENV</option>'+
  507.                         '<option value="Production">Production</option>'+
  508.                         '<option value="Non-Production">Non-Production</option>'+
  509.                     '</select>'
  510.                 );
  511.             } else if($(this).attr('id')!='bulk-check-count') {
  512.                 $(this).html('<input type="text" class="column_search form-control input-sm" placeholder="Search ' + $(this).text() + '" />');
  513.             }
  514.         });
  515.         table.columns().every(function() {
  516.             var column = table.column(this, {
  517.                 search: 'applied'
  518.             });
  519.         });
  520.         /* /Adding by Filter for Column */
  521.  
  522.         /* Seaching by Column */
  523.         $(window.table_selector+'_filter').remove();
  524.  
  525.         var delay = (function() {
  526.             var timer = 0;
  527.             return function(callback, ms) {
  528.                 clearTimeout(timer);
  529.                 timer = setTimeout(callback, ms);
  530.             };
  531.         })();
  532.  
  533.         $('.dataTables_scrollHeadInner thead').on('keyup change', '.column_search', function(e) {
  534.             var index = $(this).parent().index();
  535.             var value = this.value;
  536.             delay_time = 500;
  537.             if(e.type=='change' && e.target.nodeName!='INPUT') {
  538.                 delay_time = 0;
  539.             } else if(e.type=='keyup') {
  540.                 delay_time = 300;
  541.             } else if(e.type=='change' && e.target.nodeName=='INPUT') {
  542.                 return false;
  543.             }
  544.             delay(function() {
  545.                 loading();
  546.                 var table = window.table;
  547.                 try {
  548.                     if (table.column(index).header().getAttribute('key') == 'environment' && value != '') {
  549.                         table.column(index).search("^" + value + "$", true, false, true).draw();
  550.                     } else {
  551.                         table.column(index).search(value).draw();
  552.                     }
  553.                 } catch(e) {
  554.                     log('Error');
  555.                     log(e)
  556.                 }
  557.                 actionsAfterFilter();
  558.                 loaded();
  559.             }, delay_time);
  560.             return true;
  561.         });
  562.         /* /Searching by Column */
  563.     }
  564.  
  565.     function getDataValueByKey(index, key) {
  566.         //if(typeof(key)!='undefined' && typeof(index)!='undefined' && key!='' && index!='') {
  567.             return typeof(window.json_data[index][key])!='undefined'?window.json_data[index][key]:'';
  568.         //} else if (typeof(index)!='undefined' && index!='') {
  569.         //  return typeof(window.json_data[index])!='undefined'?window.json_data[index]:'';
  570.         //} else {
  571.         //  return '';
  572.         //}
  573.     }
  574.  
  575.     function getBulkCheckItem(id) {
  576.         if(typeof(id)!='undefined' && id!='') {
  577.             return '<input type="checkbox" class="bulk-check-item" row="'+id+'" />';
  578.         } else {
  579.             return '';
  580.         }
  581.     }
  582.  
  583.     function getEditLink(id,type) {
  584.         if(typeof(id)!='undefined' && id!='') {
  585.             return '<a href="javascript:void(0);" class="float-right edit-link '+type+'" row="'+id+'"><i class="fa fa-pencil"></i></a>';
  586.         } else {
  587.             return '';
  588.         }
  589.     }
  590.  
  591.     function getCloseLink(id,type) {
  592.         if(typeof(id)!='undefined' && id!='') {
  593.             return '<a href="javascript:void(0);" class="float-right close-link '+type+'" row="'+id+'"><i class="fa fa-times text-danger"></i></a>';
  594.         } else {
  595.             return '';
  596.         }
  597.     }
  598.  
  599.     function addDataToTable(table) {
  600.         loaded();
  601.         var table_header_count = ($(table_selector).find('.sort-header th').length);
  602.         var table_header_keys = [];
  603.         $(table_selector).find('.sort-header th').each(function(){
  604.             table_header_keys.push($(this).attr('key'));
  605.         });
  606.         var row_count = window.json_data.length;
  607.         log(table_header_keys);
  608.         log(table.rows());
  609.         for(var i=0;i<row_count;i++) {
  610.             table_row = [];
  611.             table_row_id = getDataValueByKey(i, 'id');
  612.             table_row.push('');
  613.             for(var j=1; j<table_header_count; j++) {
  614.                 if(table_header_keys[j]!='servicewindow_exclude_option' && table_header_keys[j]!='exclude_comments') {
  615.                     table_row.push(getDataValueByKey(i, table_header_keys[j]));
  616.                 } else if((''+getDataValueByKey(i, 'environment')).toLowerCase()=='production' || (''+getDataValueByKey(i, 'environment')).toLowerCase()=='non-production') {
  617.                     table_row[0] = getBulkCheckItem(table_row_id);
  618.                     if(table_header_keys[j]!='exclude_comments') {
  619.                         table_row.push(getDataValueByKey(i, table_header_keys[j])+' '+getEditLink(table_row_id,table_header_keys[j]));
  620.                     } else {
  621.                         table_row.push('<span row="'+table_row_id+'" class="exclude_comments">'+getDataValueByKey(i, table_header_keys[j])+'</span>');
  622.                     }
  623.                 } else {
  624.                     table_row.push(getDataValueByKey(i, table_header_keys[j]));
  625.                 }
  626.             }
  627.             table_row[0] += '<i class="row_id hidden" row="'+table_row_id+'"></i>';
  628.             table.row.add(table_row);
  629.             if(i%5000==0) {
  630.                 table.draw(false);
  631.                 log('Till: '+i+' loaded');
  632.             }
  633.         }
  634.         table.draw(false);
  635.         log('Data loaded');
  636.     }
  637.  
  638.     function totalCheckboxCount() {
  639.         var table = window.table;
  640.         var counter = 0;
  641.         if (typeof (table) != 'undefined') {
  642.             $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  643.                 if ($(item).find('.bulk-check-item').length > 0) {
  644.                     counter += 1;
  645.                 }
  646.             });
  647.         }
  648.         return counter;
  649.     }
  650.  
  651.     function renderBulkCheckCount() {
  652.         var table = window.table;
  653.         var counter = 0;
  654.         if (typeof (table) != 'undefined') {
  655.             $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  656.                 if ($(item).find('.bulk-check-item').length > 0) {
  657.                     var checkbox = $(item).find('.bulk-check-item')[0];
  658.                     if ($(checkbox).is(':checked')) {
  659.                         counter += 1;
  660.                     }
  661.                 }
  662.             });
  663.             $('#bulk-check-count').html(counter + ' Selected');
  664.             return counter;
  665.         } else {
  666.             return false;
  667.         }
  668.     }
  669.  
  670.     function bulkCheckToggle(flag) {
  671.         var table = window.table;
  672.         flag = typeof(flag)!='undefined'?flag:false;
  673.         if (typeof (table) != 'undefined') {
  674.             $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  675.                 if ($(item).find('.bulk-check-item').length>0) {
  676.                     var checkbox = $(item).find('.bulk-check-item')[0];
  677.                     if(flag==true) {
  678.                         $(checkbox).prop('checked', true);
  679.                     } else {
  680.                         $(checkbox).prop('checked', false);
  681.                     }
  682.                 }
  683.             });
  684.             return flag;
  685.         }
  686.     }
  687.  
  688.     function hideSingleEdits(row) {
  689.         if(typeof(row)!='undefined' && row!='') {
  690.             $('div.servicewindow_exclude_option[row="'+row+'"]').remove();
  691.             $('div.exclude_comments[row="'+row+'"]').remove();
  692.             $('span.servicewindow_exclude_option[row="'+row+'"]').show();
  693.             $('span.exclude_comments[row="'+row+'"]').show();
  694.         } else {
  695.             $('div.servicewindow_exclude_option[row]').remove();
  696.             $('div.exclude_comments[row]').remove();
  697.             $('span.servicewindow_exclude_option[row]').show();
  698.             $('span.exclude_comments[row]').show();
  699.         }
  700.     }
  701.  
  702.     function renderSelectForRow(row) {
  703.         var element = $('.servicewindow_exclude_option[row='+row+']');
  704.         var text = element.closest('td').text().trim();
  705.         var text_l = text.toLowerCase();
  706.         var html = '<span style="display:none;" class="servicewindow_exclude_option" row="'+row+'">'+text+getEditLink(row,'servicewindow_exclude_option')+'</span>'+
  707.                     '<div class="servicewindow_exclude_option" row="'+row+'">'+
  708.                     '<select name="servicewindow_exclude_option['+row+']" row="'+row+'" class="form-control input-sm">'+
  709.                         '<option value="None" '+(text_l=='none'?'selected':'')+'>None</option>'+
  710.                         '<option value="Manual" '+(text_l=='manual'?'selected':'')+'>Manual</option>'+
  711.                         '<option value="Temp-Ex" '+(text_l=='temp-ex'?'selected':'')+'>Temp-Ex</option>'+
  712.                         '<option value="CW-CCT" '+(text_l=='cw-cct'?'selected':'')+'>CW-CCT</option>'+
  713.                         '<option value="CW-HADOOP" '+(text_l=='cw-hadoop'?'selected':'')+'>CW-HADOOP</option>'+
  714.                     '</select>'+
  715.                     '&nbsp;'+getCloseLink(row,'servicewindow_exclude_option')+
  716.                     '</div>';
  717.         element.closest('td').html(html);
  718.     }
  719.  
  720.     function renderCommentsForRow(row) {
  721.         var element = $('.exclude_comments[row='+row+']');
  722.         var text = element.closest('td').text().trim();
  723.         var text_l = text.toLowerCase();
  724.         var html = '<span style="display:none;" class="exclude_comments" row="'+row+'">'+text+'</span>'+
  725.                     '<div class="exclude_comments" row="'+row+'">'+
  726.                         '<textarea name="exclude_comments['+row+']" row="'+row+'" class="form-control input-sm">'+
  727.                         '</textarea>'+
  728.                     '</div>';
  729.         element.closest('td').html(html);
  730.     }
  731.  
  732.     function submitForm(form_data, is_bulk, callback) {
  733.         loading();
  734.         if(typeof(form_data)!='undefined' && form_data!='') {
  735.             var data = {'formData':form_data, 'is_bulk':is_bulk};
  736.             var $post = $.post( "/dashboard/exclude_servicenow_data/", data);
  737.             $post.done(function(data) {
  738.                 actionsAfterSubmitForm(form_data, is_bulk);
  739.                 callback(true);
  740.             });
  741.             $post.always(function(){
  742.                 loaded();
  743.             });
  744.         }
  745.     }
  746.  
  747.     function actionsAfterSubmitForm(form_data, is_bulk) {
  748.         if(!is_bulk) {
  749.             for(var i in form_data) {
  750.                 $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  751.                     var row = form_data[i]['id'];
  752.                     if ($(item).find('.bulk-check-item').length > 0 && $(item).find('span[row="'+row+'"]').length > 0 ) {
  753.                         var element_a = $(item).find('.servicewindow_exclude_option[row="'+row+'"]');
  754.                         var html_a = (form_data[i]['exclude'])+' '+getEditLink(row,'servicewindow_exclude_option');
  755.                         $(element_a).closest('td').html(html_a);
  756.                         var element_b = $(item).find('.exclude_comments[row="'+row+'"]');
  757.                         var html_b = '<span row="'+row+'" class="exclude_comments">'+form_data[i]['comments']+'</span>';
  758.                         $(element_b).closest('td').html(html_b);
  759.                         return false;
  760.                     }
  761.                 });
  762.             }
  763.         } else {
  764.             /*log('In afterSubmit')
  765.             log(form_data);*/
  766.             var id_list = form_data['id_list'];
  767.             var exclude = form_data['exclude'];
  768.             var comments = form_data['comments'];
  769.             if(id_list.length<5000) {
  770.                 for(i in id_list) {
  771.                     var row = id_list[i];
  772.                     $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  773.                         if ($(item).find('.bulk-check-item').length > 0 && $(item).find('span[row="'+row+'"]').length > 0 ) {
  774.                             var element_a = $(item).find('.servicewindow_exclude_option[row="'+row+'"]');
  775.                             var html_a = (exclude)+' '+getEditLink(row,'servicewindow_exclude_option');
  776.                             $(element_a).closest('td').html(html_a);
  777.                             var element_b = $(item).find('.exclude_comments[row="'+row+'"]');
  778.                             var html_b = '<span row="'+row+'" class="exclude_comments">'+comments+'</span>';
  779.                             $(element_b).closest('td').html(html_b);
  780.                             return false;
  781.                         }
  782.                     });
  783.                 }
  784.             } else {
  785.                 window.location.reload();
  786.             }
  787.         }
  788.         $('textarea[name="exclude_comments[0]"]').val('');
  789.     }
  790.  
  791.     $(document).on('click', '#bulk-check-all', function(e){
  792.         loading();
  793.         var flag = bulkCheckToggle($(this).is(':checked'));
  794.         if(flag) {
  795.             $('.bulk-edit-div').show();
  796.             $('.single-edit-div').hide();
  797.         } else {
  798.             $('.bulk-edit-div').hide();
  799.         }
  800.         renderBulkCheckCount();
  801.         hideSingleEdits();
  802.         loaded();
  803.     });
  804.  
  805.     $(document).on('click', '.bulk-check-item', function(e){
  806.         if($(this).is(':checked')) {
  807.             $('.bulk-edit-div').show();
  808.             $('.single-edit-div').hide();
  809.         } else {
  810.             $('#bulk-check-all').prop('checked',false);
  811.         }
  812.         if(renderBulkCheckCount()==totalCheckboxCount()) {
  813.             $('#bulk-check-all').prop('checked', true);
  814.         } else if(renderBulkCheckCount()==0) {
  815.             $('.bulk-edit-div').hide();
  816.         }
  817.         hideSingleEdits();
  818.     });
  819.  
  820.     $(document).on('click', '.edit-link', function(e){
  821.         var row = $(this).attr('row');
  822.         bulkCheckToggle();
  823.         renderBulkCheckCount();
  824.         $('#bulk-check-all').prop('checked', false);
  825.         $('.bulk-edit-div').hide();
  826.         $('.single-edit-div').show();
  827.         renderSelectForRow(row);
  828.         renderCommentsForRow(row);
  829.     });
  830.  
  831.     $(document).on('click', '.close-link', function(e){
  832.         var row = $(this).attr('row');
  833.         hideSingleEdits(row);
  834.     });
  835.  
  836.     $(document).on('click', '#bulk-edit-form-btn', function(e){
  837.         $('#bulkEditModalLabel').html('<h4>Commenting for <b>'+renderBulkCheckCount()+'</b> items</h4>');
  838.         $('#bulk-update-success').hide();
  839.         $('#bulk-update-error').hide();
  840.         $('#bulkEditModal').modal('show');
  841.     });
  842.  
  843.     $(document).on('click', '#bulk-update-btn', function(e){
  844.         var table = window.table;
  845.         var servicewindow_exclude_option = $('select[name="servicewindow_exclude_option[0]"]').val();
  846.         var exclude_comments = $('textarea[name="exclude_comments[0]"]').val();
  847.         if (servicewindow_exclude_option!='' && exclude_comments!='') {
  848.             $('#bulk-update-error').hide();
  849.             var id_list = [];
  850.             $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  851.                 if ($(item).find('.bulk-check-item').length > 0) {
  852.                     var checkbox = $(item).find('.bulk-check-item')[0];
  853.                     if ($(checkbox).is(':checked')) {
  854.                         id_list.push($(checkbox).attr('row'));
  855.                     }
  856.                 }
  857.             });
  858.             var form_data = {'exclude':servicewindow_exclude_option,'comments':exclude_comments,'id_list':id_list};
  859.             submitForm(form_data, true, function(flag){
  860.                 if(flag) {
  861.                     $('#bulk-update-error').hide();
  862.                     $('.bulk-edit-success-div').show();
  863.                     setTimeout(function(){
  864.                         $('.bulk-edit-success-div').hide();
  865.                     }, 3000);
  866.                 }
  867.                 $('#bulkEditModal').modal('hide');
  868.             });
  869.         } else {
  870.             $('#bulk-update-error').show();
  871.         }
  872.     });
  873.  
  874.     $(document).on('click', '#single-update-btn', function(e){
  875.         var table = window.table;
  876.         var form_data = [];
  877.         $('.single-edit-error-div').hide();
  878.         $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
  879.             if($(item).find('a.close-link').length>0) {
  880.                 var servicewindow_exclude_option = $(item).find('select[name^="servicewindow_exclude_option"]').val();
  881.                 var exclude_comments = $(item).find('textarea[name^="exclude_comments"]').val();
  882.                 if(servicewindow_exclude_option=='' || exclude_comments=='') {
  883.                     $('.single-edit-error-div').show();
  884.                     $(item).find('select[name^="servicewindow_exclude_option"]').focus();
  885.                     return false;
  886.                 } else {
  887.                     var row = $(item).find('textarea[name^="exclude_comments"]').attr('row');
  888.                     form_data.push({"comments":exclude_comments, "exclude":servicewindow_exclude_option, "id":row});
  889.                 }
  890.             }
  891.         });
  892.         if(!$('.single-edit-error-div').is(':visible')) {
  893.             submitForm(form_data, false,function(flag){
  894.                 if(flag) {
  895.                     $('.single-edit-div').hide();
  896.                     $('.single-edit-error-div').hide();
  897.                     $('.bulk-edit-success-div').show();
  898.                     setTimeout(function(){
  899.                         $('.bulk-edit-success-div').hide();
  900.                     }, 3000);
  901.                 }
  902.             });
  903.         }
  904.     });
  905.  
  906.  
  907.     /* /My Code */
  908. });
  909.  
  910.  
  911.  
  912. window.json_data = "{{ complete_data | escapejs }}";
  913. window.json_data = JSON.parse(window.json_data);
  914. </script>
  915. {% endblock footerScripts %}
Add Comment
Please, Sign In to add comment