Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {% extends "index.html" %}
- {% block pageTitleBlock %}
- {% with pageTitle='UNIX Data :: Patch Exclusions' %}
- {{ block.super }}
- {% endwith %}
- {% endblock pageTitleBlock %}
- {% load static %}
- {% block head %}
- <link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css" />
- <link rel="stylesheet" href="//cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css" />
- <link rel="stylesheet" href="//cdn.datatables.net/fixedheader/3.1.6/css/fixedHeader.bootstrap.min.css" />
- <link rel="stylesheet" href="//cdn.datatables.net/scroller/2.0.1/css/scroller.dataTables.min.css" />
- <script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
- <script src="//cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
- <script src="//cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>
- <script src="//cdn.datatables.net/fixedheader/3.1.6/js/fixedHeader.bootstrap.min.js"></script>
- <script src="//cdn.datatables.net/scroller/2.0.1/js/dataTables.scroller.min.js"></script>
- <script src="{% static 'js/xlsx.js' %}"></script>
- <style type="text/css">
- th, .table-striped>tbody>tr td:first-child {
- vertical-align: middle !important;
- text-transform: capitalize !important;
- }
- .table-striped>tbody>tr td:first-child {
- text-align: center;
- }
- tr.sort-header th {
- font-size: 12px;
- }
- tr.filter-header th{
- font-size: 10px;
- padding: 0px;
- }
- thead .sorting:after {
- }
- table.table-bordered.dataTable tbody th, table.table-bordered.dataTable tbody td {
- vertical-align: middle;
- }
- div.dts div.dataTables_scrollBody {
- background: #fff !important;
- }
- input[type=checkbox] {
- -webkit-appearance: button;
- white-space: nowrap;
- overflow: hidden;
- min-width: 20px;
- min-height: 20px;
- }
- .loader {
- width: 100vw;
- height: 100vh;
- background: rgba(0,0,0,0.7);
- z-index: 999;
- position: absolute;
- top: 0px;
- left: 0px;
- min-width: 100%;
- min-height: 100%;
- display:none;
- }
- select.form-control:not([size]):not([multiple]) {
- height: calc(2.25rem + 6px);
- }
- </style>
- {% endblock head %}
- {% block header %}
- {% include 'header.html' %}
- {% include 'sidebar.html' with active_menu="PatchExclude" %}
- {% endblock header %}
- {% block bodyContent %}
- <div class="loader"></div>
- <div class="content-wrapper" style="min-height: 916px;">
- <!-- Content Header (Page header) -->
- <section class="content-header">
- <h1>
- Patch Exclusions
- <small>Exclusions</small>
- </h1>
- <ol class="breadcrumb">
- <li><a href="/home"><i class="fa fa-dashboard"></i> Home</a></li>
- <li class="active">Patch Exclusions</li>
- </ol>
- </section>
- <!-- Main content -->
- <section class="content">
- <div class="row">
- <div class="col-md-12">
- <div class="box">
- <div class="box-header hidden">
- <h3 class="box-title"></h3>
- </div>
- <!-- /.box-header -->
- <div class="box-body">
- <div class="col-md-12 text-center">
- <h4 style="text-align:center;position:relative;color:DodgerBlue;"><b><u>Info!</u></b> Here you can exclude servers from Patching</h4>
- <h5 style="text-align:center;position:relative;color:DodgerBlue;"><b><u>Note:</u></b> Select Checkbox and click Edit to Exclude</h5>
- </div>
- <div class="row">
- <div class="col-xs-12 col-xs-12 btn-group text-right" role="group">
- <button type="button" class="btn btn-primary btn-md pull-right export-csv">
- <i class="fa fa-download"></i> Export CSV
- </button>
- </div>
- </div>
- <div class="row"> </div>
- <div class="row bulk-edit-div" style="display:none;">
- <div class="col-xs-12">
- <div class="alert alert-primary p-2 pl-3" role="alert">
- <strong>Alert: </strong> Click here to bulk edit
- <button type="button" class="btn btn-success btn-sm" id="bulk-edit-form-btn">
- <i class="fa fa-pencil"></i>Edit
- </button>
- </div>
- </div>
- </div>
- <div class="row bulk-edit-success-div" style="display:none;">
- <div class="col-xs-12">
- <div class="alert alert-success p-2 pl-3" role="alert">Data updated successfully.</div>
- </div>
- </div>
- <div class="row single-edit-div" style="display:none;">
- <div class="col-xs-12">
- <div class="alert alert-primary p-2 pl-3" role="alert">
- <strong>Alert: </strong> Click here to Save changes
- <button type="button" class="btn btn-success btn-sm" id="single-update-btn">
- <i class="fa fa-save"></i> Save
- </button>
- </div>
- </div>
- </div>
- <div class="row single-edit-error-div" style="display:none">
- <div class="col-xs-12">
- <div class="alert alert-danger p-2 pl-3" role="alert">All fields are required</div>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12" style="overflow:auto;">
- <table id="patchExclusionsTable" class="table table-striped table-bordered nowrap">
- <thead>
- <tr class="sort-header paginated btn-primary text-sm">
- {% if total_count > 0 %}
- <th key="checkbox" class="text-center">
- <input type="checkbox" id="bulk-check-all" />
- </th>
- {% endif %}
- <th key="servername">Hostname</th>
- <th key="os">OS</th>
- <th key="serverenvironment">Server Environment</th>
- <th key="environment">Environment</th>
- <th key="operational_status">Operational Status</th>
- <th key="appcode">Appcode</th>
- <th key="virtual">Virtual</th>
- <th key="q1_servicewindow">Q1 Service Window</th>
- <th key="q2_servicewindow">Q2 Service Window</th>
- <th key="q3_servicewindow">Q3 Service Window</th>
- <th key="q4_servicewindow">Q4 Service Window</th>
- <th key="servicewindow_exclude_option">Patch Exclude</th>
- <th key="exclude_comments">Comments</th>
- </tr>
- <tr class="filter-header">
- {% if total_count > 0 %}
- <th class="text-center" id="bulk-check-count">0 Selected</th>
- {% endif %}
- <th>Hostname</th>
- <th>OS</th>
- <th>Server Environment</th>
- <th class="environment-filter">Environment</th>
- <th>Operational Status</th>
- <th>Appcode</th>
- <th>Virtual</th>
- <th>Q1 Service Window</th>
- <th>Q2 Service Window</th>
- <th>Q3 Service Window</th>
- <th>Q4 Service Window</th>
- <th>Patch Exclude</th>
- <th>Comments</th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </div><!-- /col-md-12 -->
- </div><!-- /.table row -->
- </div><!-- /box-body -->
- </div><!-- /box -->
- </div><!-- /col-md-12 -->
- </div><!-- /row (content) -->
- </section><!-- /section (body) -->
- </div><!-- /content-wrapper -->
- <div class="modal fade" id="bulkEditModal" tabindex="-1" role="dialog" aria-labelledby="bulkEditModal" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="bulkEditModalLabel">Commenting for 0 items</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">
- <form>
- <div class="form-group">
- <label for="servicewindow_exclude_option" class="col-form-label">Service Window Exclude Option:</label>
- <select name="servicewindow_exclude_option[0]" row="0" class="form-control" style="height: 39px">
- <option value="None">None</option>
- <option value="Manual">Manual</option>
- <option value="Temp-Ex">Temp-Ex</option>
- <option value="CW-CCT">CW-CCT</option>
- <option value="CW-HADOOP">CW-HADOOP</option>
- </select>
- </div>
- <div class="form-group">
- <label for="exclude_comments" class="col-form-label">Comments:</label>
- <textarea class="form-control" name="exclude_comments[0]" row="0" required="required"></textarea>
- </div>
- <div class="form-group">
- <label class="text-danger" id="bulk-update-error" style="display:none;">All fields are required</label>
- </div>
- <div class="form-group">
- <label class="text-danger" id="bulk-update-success" style="display:none;">Data updated successfully.</label>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
- <button type="button" class="btn btn-primary" id="bulk-update-btn">Update</button>
- </div>
- </div>
- </div>
- </div>
- {% endblock bodyContent %}
- {% block footerScripts %}
- <script type="text/javascript">
- window.json_data = {};
- window.table = {};
- window.table_selector = '#patchExclusionsTable';
- function log(i) {
- console.log(i);
- return true;
- }
- function loading(c) {
- $.LoadingOverlay('show');
- $('.loader').show();
- if(typeof(c)!='undefined' && c!='') {
- return c();
- }
- }
- function loaded(c) {
- $.LoadingOverlay('hide');
- $('.loader').hide();
- if(typeof(c)!='undefined' && c!='') {
- return c();
- }
- }
- function convertToCSV(objArray) {
- var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
- var str = '';
- for (var i = 0; i < array.length; i++) {
- var line = '';
- for (var index in array[i]) {
- line += array[i][index];
- line += ','
- }
- line = line.replace(/(,$)/g, "");
- str += line + '\r\n';
- }
- return str;
- }
- function exportCSVFile(headers, items, fileTitle) {
- if (headers) {
- items.unshift(headers);
- }
- var jsonObject = JSON.stringify(items);
- var csv = this.convertToCSV(jsonObject);
- var exportedFilenmae = fileTitle + '.csv' || 'export.csv';
- var blob = new Blob([csv], {
- type: 'text/csv;charset=utf-8;'
- });
- if (navigator.msSaveBlob) { // IE 10+
- navigator.msSaveBlob(blob, exportedFilenmae);
- } else {
- var link = document.createElement("a");
- if (link.download !== undefined) {
- var url = URL.createObjectURL(blob);
- link.setAttribute("href", url);
- link.setAttribute("download", exportedFilenmae);
- link.style.visibility = 'hidden';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
- }
- }
- $(document).ready(function () {
- $('.export-csv').on('click', function (e) {
- e.preventDefault();
- loading();
- // log(window.json_data[0]['id']);
- var table = window.table;
- var items_not_formatted = window.json_data;
- if(typeof(table)!='undefined' && table!='') {
- var nodes = table.rows({search: 'applied'}).nodes();
- if(nodes.length<=items_not_formatted.length) {
- var items_filtered = [];
- $.each(nodes, function (index, item) {
- var row = $(item).find('.row_id').attr('row');
- var servicewindow_exclude_option = '';
- var exclude_comments = '';
- if($(item).find('.bulk-check-item').length>0) {
- servicewindow_exclude_option = $(item).find('.servicewindow_exclude_option').closest('td').text();
- exclude_comments = $(item).find('.exclude_comments').closest('td').text();
- }
- for (var i=0; i<items_not_formatted.length; i++) {
- if(row==items_not_formatted[i]['id']) {
- if(servicewindow_exclude_option!='') {
- items_not_formatted[i]['servicewindow_exclude_option'] = servicewindow_exclude_option;
- items_not_formatted[i]['exclude_comments'] = exclude_comments;
- }
- items_filtered.push(items_not_formatted[i]);
- break;
- }
- }
- });
- }
- }
- var headers = {
- "environment": 'Environment',
- "operational_status": 'Operational Status',
- "os": 'OS',
- "q1_servicewindow": 'Q1 Service Window',
- "q2_servicewindow": 'Q2 Service Window',
- "q3_servicewindow": 'Q3 Service Window',
- "q4_servicewindow": 'Q4 Service Window',
- "serverenvironment": 'Server Environment',
- "servername": 'Server Name',
- /*"sys_class_name": 'Sys Class Name',*/
- "virtual": 'Virtual',
- "servicewindow_exclude_option": 'Patch Exclude',
- "exclude_comments": 'Excluded Comments',
- "appcode": 'App Code'
- };
- var items_formatted = [];
- var considerable_data = (typeof(items_filtered)!='undefined' && items_filtered.length>0)?items_filtered:items_not_formatted;
- considerable_data.forEach(function(item){
- var t_object = {};
- for(var key in headers) {
- t_object[key] = (typeof(item[key])!=='undeinfed' ? item[key] : ' ');
- }
- items_formatted.push(t_object);
- });
- var fileTitle = 'Unix_Patching_' + new Date().toLocaleDateString();
- // exportCSVFile(headers, items_formatted, fileTitle);
- // var json_data = [{}];
- var headers_text = "";
- for(var key in headers) {
- headers_text += '['+key+'] AS ['+headers[key]+']' + ', ';
- }
- try {
- headers_text = headers_text.replace(/,\s*$/, "");
- var options = {
- headers: true,
- sheetid:"Report",
- column: {style:{Font:{Bold:"1",Color: "#3C3741"}}},
- rows: {1:{style:{Font:{Bold:"1",Color:"#FF0000"}}}}
- };
- var result = alasql('SELECT '+headers_text+' INTO XLSX("'+fileTitle+'.xlsx",?) FROM ?', [options, items_formatted]);
- } catch(e) {
- console.log(e);
- }
- loaded();
- });
- });
- $(document).ready(function () {
- document.onreadystatechange = function () {
- var state = document.readyState
- if (state == 'complete') {
- setTimeout(function () {
- document.getElementById('interactive');
- try {
- document.getElementById('load').style.visibility = "hidden";
- } catch (err) {}
- }, 2000);
- }
- }
- /* My Code */
- function createTable() {
- var json_data = window.json_data;
- var table_selector = window.table_selector;
- var table_header_count = ($(table_selector).find('.sort-header th').length);
- var table_column_settings = [];
- var table_column_defs = [{ "orderable": false, "targets": 0, "bSearchable": false, "asSorting": false }];
- table_column_settings.push({"orderable": false});
- for(var i=1; i<table_header_count; i++) {
- table_column_settings.push(null);
- }
- var table_settings = {
- 'searching': true,
- 'orderCellsTop': true,
- 'paging': true,
- 'pageLength': 100000,
- 'dom': 'Bfrtip',
- 'order': [[ 1, 'asc' ]],
- 'columns': table_column_settings,
- 'columnDefs': table_column_defs,
- 'initComplete': function (settings, json) {
- if (typeof (table) != 'undefined') {
- log('Table initialized!');
- actionsAfterTableInit(settings, json);
- }
- },
- 'recordsTotal': ((typeof (json_data) != 'undefined') ? json_data.length : 0),
- 'deferRender': false,
- 'scrollX': true,
- 'scrollY': 340,
- 'scrollCollapse': false,
- 'scroller': {
- loadingIndicator: false
- },
- "oLanguage": {
- "sInfo": "Displaying _TOTAL_ records",
- },
- 'cache': true
- };
- log(table_settings);
- window.table = $(table_selector).DataTable(table_settings);
- actionsAfterTableCreate(window.table);
- }
- createTable();
- function actionsAfterTableCreate(table) {
- if(typeof(table)!='undefined') {
- addColumnFilters(table);
- addDataToTable(table);
- $('.dataTables_wrapper').prepend($('.dataTables_info').detach());
- }
- }
- function actionsAfterTableInit(settings, json) {
- /*log(settings);
- log(json);*/
- }
- function actionsAfterFilter() {
- /* Things need to be done after filter/search */
- // Uncheck all
- // Update checked count
- bulkCheckToggle(false);
- renderBulkCheckCount();
- $('#bulk-check-all').prop('checked',false);
- }
- function addColumnFilters(table) {
- /* Adding by Filter for Column */
- $('.dataTables_scrollHeadInner thead tr.filter-header th').each(function () {
- if ($(this).hasClass('environment-filter')) {
- $(this).html(
- '<select class="column_search form-control input-sm">'+
- '<option value="">Select ENV</option>'+
- '<option value="Production">Production</option>'+
- '<option value="Non-Production">Non-Production</option>'+
- '</select>'
- );
- } else if($(this).attr('id')!='bulk-check-count') {
- $(this).html('<input type="text" class="column_search form-control input-sm" placeholder="Search ' + $(this).text() + '" />');
- }
- });
- table.columns().every(function() {
- var column = table.column(this, {
- search: 'applied'
- });
- });
- /* /Adding by Filter for Column */
- /* Seaching by Column */
- $(window.table_selector+'_filter').remove();
- var delay = (function() {
- var timer = 0;
- return function(callback, ms) {
- clearTimeout(timer);
- timer = setTimeout(callback, ms);
- };
- })();
- $('.dataTables_scrollHeadInner thead').on('keyup change', '.column_search', function(e) {
- var index = $(this).parent().index();
- var value = this.value;
- delay_time = 500;
- if(e.type=='change' && e.target.nodeName!='INPUT') {
- delay_time = 0;
- } else if(e.type=='keyup') {
- delay_time = 300;
- } else if(e.type=='change' && e.target.nodeName=='INPUT') {
- return false;
- }
- delay(function() {
- loading();
- var table = window.table;
- try {
- if (table.column(index).header().getAttribute('key') == 'environment' && value != '') {
- table.column(index).search("^" + value + "$", true, false, true).draw();
- } else {
- table.column(index).search(value).draw();
- }
- } catch(e) {
- log('Error');
- log(e)
- }
- actionsAfterFilter();
- loaded();
- }, delay_time);
- return true;
- });
- /* /Searching by Column */
- }
- function getDataValueByKey(index, key) {
- //if(typeof(key)!='undefined' && typeof(index)!='undefined' && key!='' && index!='') {
- return typeof(window.json_data[index][key])!='undefined'?window.json_data[index][key]:'';
- //} else if (typeof(index)!='undefined' && index!='') {
- // return typeof(window.json_data[index])!='undefined'?window.json_data[index]:'';
- //} else {
- // return '';
- //}
- }
- function getBulkCheckItem(id) {
- if(typeof(id)!='undefined' && id!='') {
- return '<input type="checkbox" class="bulk-check-item" row="'+id+'" />';
- } else {
- return '';
- }
- }
- function getEditLink(id,type) {
- if(typeof(id)!='undefined' && id!='') {
- return '<a href="javascript:void(0);" class="float-right edit-link '+type+'" row="'+id+'"><i class="fa fa-pencil"></i></a>';
- } else {
- return '';
- }
- }
- function getCloseLink(id,type) {
- if(typeof(id)!='undefined' && id!='') {
- return '<a href="javascript:void(0);" class="float-right close-link '+type+'" row="'+id+'"><i class="fa fa-times text-danger"></i></a>';
- } else {
- return '';
- }
- }
- function addDataToTable(table) {
- loaded();
- var table_header_count = ($(table_selector).find('.sort-header th').length);
- var table_header_keys = [];
- $(table_selector).find('.sort-header th').each(function(){
- table_header_keys.push($(this).attr('key'));
- });
- var row_count = window.json_data.length;
- log(table_header_keys);
- log(table.rows());
- for(var i=0;i<row_count;i++) {
- table_row = [];
- table_row_id = getDataValueByKey(i, 'id');
- table_row.push('');
- for(var j=1; j<table_header_count; j++) {
- if(table_header_keys[j]!='servicewindow_exclude_option' && table_header_keys[j]!='exclude_comments') {
- table_row.push(getDataValueByKey(i, table_header_keys[j]));
- } else if((''+getDataValueByKey(i, 'environment')).toLowerCase()=='production' || (''+getDataValueByKey(i, 'environment')).toLowerCase()=='non-production') {
- table_row[0] = getBulkCheckItem(table_row_id);
- if(table_header_keys[j]!='exclude_comments') {
- table_row.push(getDataValueByKey(i, table_header_keys[j])+' '+getEditLink(table_row_id,table_header_keys[j]));
- } else {
- table_row.push('<span row="'+table_row_id+'" class="exclude_comments">'+getDataValueByKey(i, table_header_keys[j])+'</span>');
- }
- } else {
- table_row.push(getDataValueByKey(i, table_header_keys[j]));
- }
- }
- table_row[0] += '<i class="row_id hidden" row="'+table_row_id+'"></i>';
- table.row.add(table_row);
- if(i%5000==0) {
- table.draw(false);
- log('Till: '+i+' loaded');
- }
- }
- table.draw(false);
- log('Data loaded');
- }
- function totalCheckboxCount() {
- var table = window.table;
- var counter = 0;
- if (typeof (table) != 'undefined') {
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if ($(item).find('.bulk-check-item').length > 0) {
- counter += 1;
- }
- });
- }
- return counter;
- }
- function renderBulkCheckCount() {
- var table = window.table;
- var counter = 0;
- if (typeof (table) != 'undefined') {
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if ($(item).find('.bulk-check-item').length > 0) {
- var checkbox = $(item).find('.bulk-check-item')[0];
- if ($(checkbox).is(':checked')) {
- counter += 1;
- }
- }
- });
- $('#bulk-check-count').html(counter + ' Selected');
- return counter;
- } else {
- return false;
- }
- }
- function bulkCheckToggle(flag) {
- var table = window.table;
- flag = typeof(flag)!='undefined'?flag:false;
- if (typeof (table) != 'undefined') {
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if ($(item).find('.bulk-check-item').length>0) {
- var checkbox = $(item).find('.bulk-check-item')[0];
- if(flag==true) {
- $(checkbox).prop('checked', true);
- } else {
- $(checkbox).prop('checked', false);
- }
- }
- });
- return flag;
- }
- }
- function hideSingleEdits(row) {
- if(typeof(row)!='undefined' && row!='') {
- $('div.servicewindow_exclude_option[row="'+row+'"]').remove();
- $('div.exclude_comments[row="'+row+'"]').remove();
- $('span.servicewindow_exclude_option[row="'+row+'"]').show();
- $('span.exclude_comments[row="'+row+'"]').show();
- } else {
- $('div.servicewindow_exclude_option[row]').remove();
- $('div.exclude_comments[row]').remove();
- $('span.servicewindow_exclude_option[row]').show();
- $('span.exclude_comments[row]').show();
- }
- }
- function renderSelectForRow(row) {
- var element = $('.servicewindow_exclude_option[row='+row+']');
- var text = element.closest('td').text().trim();
- var text_l = text.toLowerCase();
- var html = '<span style="display:none;" class="servicewindow_exclude_option" row="'+row+'">'+text+getEditLink(row,'servicewindow_exclude_option')+'</span>'+
- '<div class="servicewindow_exclude_option" row="'+row+'">'+
- '<select name="servicewindow_exclude_option['+row+']" row="'+row+'" class="form-control input-sm">'+
- '<option value="None" '+(text_l=='none'?'selected':'')+'>None</option>'+
- '<option value="Manual" '+(text_l=='manual'?'selected':'')+'>Manual</option>'+
- '<option value="Temp-Ex" '+(text_l=='temp-ex'?'selected':'')+'>Temp-Ex</option>'+
- '<option value="CW-CCT" '+(text_l=='cw-cct'?'selected':'')+'>CW-CCT</option>'+
- '<option value="CW-HADOOP" '+(text_l=='cw-hadoop'?'selected':'')+'>CW-HADOOP</option>'+
- '</select>'+
- ' '+getCloseLink(row,'servicewindow_exclude_option')+
- '</div>';
- element.closest('td').html(html);
- }
- function renderCommentsForRow(row) {
- var element = $('.exclude_comments[row='+row+']');
- var text = element.closest('td').text().trim();
- var text_l = text.toLowerCase();
- var html = '<span style="display:none;" class="exclude_comments" row="'+row+'">'+text+'</span>'+
- '<div class="exclude_comments" row="'+row+'">'+
- '<textarea name="exclude_comments['+row+']" row="'+row+'" class="form-control input-sm">'+
- '</textarea>'+
- '</div>';
- element.closest('td').html(html);
- }
- function submitForm(form_data, is_bulk, callback) {
- loading();
- if(typeof(form_data)!='undefined' && form_data!='') {
- var data = {'formData':form_data, 'is_bulk':is_bulk};
- var $post = $.post( "/dashboard/exclude_servicenow_data/", data);
- $post.done(function(data) {
- actionsAfterSubmitForm(form_data, is_bulk);
- callback(true);
- });
- $post.always(function(){
- loaded();
- });
- }
- }
- function actionsAfterSubmitForm(form_data, is_bulk) {
- if(!is_bulk) {
- for(var i in form_data) {
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- var row = form_data[i]['id'];
- if ($(item).find('.bulk-check-item').length > 0 && $(item).find('span[row="'+row+'"]').length > 0 ) {
- var element_a = $(item).find('.servicewindow_exclude_option[row="'+row+'"]');
- var html_a = (form_data[i]['exclude'])+' '+getEditLink(row,'servicewindow_exclude_option');
- $(element_a).closest('td').html(html_a);
- var element_b = $(item).find('.exclude_comments[row="'+row+'"]');
- var html_b = '<span row="'+row+'" class="exclude_comments">'+form_data[i]['comments']+'</span>';
- $(element_b).closest('td').html(html_b);
- return false;
- }
- });
- }
- } else {
- /*log('In afterSubmit')
- log(form_data);*/
- var id_list = form_data['id_list'];
- var exclude = form_data['exclude'];
- var comments = form_data['comments'];
- if(id_list.length<5000) {
- for(i in id_list) {
- var row = id_list[i];
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if ($(item).find('.bulk-check-item').length > 0 && $(item).find('span[row="'+row+'"]').length > 0 ) {
- var element_a = $(item).find('.servicewindow_exclude_option[row="'+row+'"]');
- var html_a = (exclude)+' '+getEditLink(row,'servicewindow_exclude_option');
- $(element_a).closest('td').html(html_a);
- var element_b = $(item).find('.exclude_comments[row="'+row+'"]');
- var html_b = '<span row="'+row+'" class="exclude_comments">'+comments+'</span>';
- $(element_b).closest('td').html(html_b);
- return false;
- }
- });
- }
- } else {
- window.location.reload();
- }
- }
- $('textarea[name="exclude_comments[0]"]').val('');
- }
- $(document).on('click', '#bulk-check-all', function(e){
- loading();
- var flag = bulkCheckToggle($(this).is(':checked'));
- if(flag) {
- $('.bulk-edit-div').show();
- $('.single-edit-div').hide();
- } else {
- $('.bulk-edit-div').hide();
- }
- renderBulkCheckCount();
- hideSingleEdits();
- loaded();
- });
- $(document).on('click', '.bulk-check-item', function(e){
- if($(this).is(':checked')) {
- $('.bulk-edit-div').show();
- $('.single-edit-div').hide();
- } else {
- $('#bulk-check-all').prop('checked',false);
- }
- if(renderBulkCheckCount()==totalCheckboxCount()) {
- $('#bulk-check-all').prop('checked', true);
- } else if(renderBulkCheckCount()==0) {
- $('.bulk-edit-div').hide();
- }
- hideSingleEdits();
- });
- $(document).on('click', '.edit-link', function(e){
- var row = $(this).attr('row');
- bulkCheckToggle();
- renderBulkCheckCount();
- $('#bulk-check-all').prop('checked', false);
- $('.bulk-edit-div').hide();
- $('.single-edit-div').show();
- renderSelectForRow(row);
- renderCommentsForRow(row);
- });
- $(document).on('click', '.close-link', function(e){
- var row = $(this).attr('row');
- hideSingleEdits(row);
- });
- $(document).on('click', '#bulk-edit-form-btn', function(e){
- $('#bulkEditModalLabel').html('<h4>Commenting for <b>'+renderBulkCheckCount()+'</b> items</h4>');
- $('#bulk-update-success').hide();
- $('#bulk-update-error').hide();
- $('#bulkEditModal').modal('show');
- });
- $(document).on('click', '#bulk-update-btn', function(e){
- var table = window.table;
- var servicewindow_exclude_option = $('select[name="servicewindow_exclude_option[0]"]').val();
- var exclude_comments = $('textarea[name="exclude_comments[0]"]').val();
- if (servicewindow_exclude_option!='' && exclude_comments!='') {
- $('#bulk-update-error').hide();
- var id_list = [];
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if ($(item).find('.bulk-check-item').length > 0) {
- var checkbox = $(item).find('.bulk-check-item')[0];
- if ($(checkbox).is(':checked')) {
- id_list.push($(checkbox).attr('row'));
- }
- }
- });
- var form_data = {'exclude':servicewindow_exclude_option,'comments':exclude_comments,'id_list':id_list};
- submitForm(form_data, true, function(flag){
- if(flag) {
- $('#bulk-update-error').hide();
- $('.bulk-edit-success-div').show();
- setTimeout(function(){
- $('.bulk-edit-success-div').hide();
- }, 3000);
- }
- $('#bulkEditModal').modal('hide');
- });
- } else {
- $('#bulk-update-error').show();
- }
- });
- $(document).on('click', '#single-update-btn', function(e){
- var table = window.table;
- var form_data = [];
- $('.single-edit-error-div').hide();
- $.each(table.rows({search: 'applied'}).nodes(), function (index, item) {
- if($(item).find('a.close-link').length>0) {
- var servicewindow_exclude_option = $(item).find('select[name^="servicewindow_exclude_option"]').val();
- var exclude_comments = $(item).find('textarea[name^="exclude_comments"]').val();
- if(servicewindow_exclude_option=='' || exclude_comments=='') {
- $('.single-edit-error-div').show();
- $(item).find('select[name^="servicewindow_exclude_option"]').focus();
- return false;
- } else {
- var row = $(item).find('textarea[name^="exclude_comments"]').attr('row');
- form_data.push({"comments":exclude_comments, "exclude":servicewindow_exclude_option, "id":row});
- }
- }
- });
- if(!$('.single-edit-error-div').is(':visible')) {
- submitForm(form_data, false,function(flag){
- if(flag) {
- $('.single-edit-div').hide();
- $('.single-edit-error-div').hide();
- $('.bulk-edit-success-div').show();
- setTimeout(function(){
- $('.bulk-edit-success-div').hide();
- }, 3000);
- }
- });
- }
- });
- /* /My Code */
- });
- window.json_data = "{{ complete_data | escapejs }}";
- window.json_data = JSON.parse(window.json_data);
- </script>
- {% endblock footerScripts %}
Add Comment
Please, Sign In to add comment