// (C) Copyright 2020 Hewlett-Packard Enterprise Company, L.P.
/**
 * @type (GroupReportsView)
 * This is a view class for Group Reports menu option.
 */

define(['hpsum/presenter/group/GroupPresenter',
	'hpsum/presenter/node/NodePresenter',
    'hp/core/Router',
    'hp/core/UrlFragment',
    'hp/view/FormStateView',
    'hp/core/HelpMenu',
	'hp/core/Localizer',
	'hp/core/Notifications',
	'hp/view/DialogView',
	'hp/model/Session',
	'text!hpPages/core/header_help.html',
    'jquery',
    'hp/lib/jquery.hpStackedPanels',
	'hpsum/common/jquery.hpsumBrowse',
    'lib/jquery.selectBox'],
function(groupPresenter, presenter, router,urlFragment, FormStateView, helpMenu, localizer, notifications, DialogView,session, headerHelpHtml) {"use strict";
	var report_output_path = '';
	var GroupReportsShowView = ( function() {
			var FORM = '#hpsum-groups-reports-form',
			    RESET = '#hpsum-groups-reset',
			    CANCEL = '#hpsum-groups-reports-close',
			    GENERATE = '#hpsum-groups-reports-generate',
			    PANEL_SELECTOR = '#hpsum-group-reports-panel-selector',
			    PANELS = '#hpsum-group-reports-panels',
			    TYPE = '#hpsum-group-reports-type',
			    ROUTE_PREFIX = '/group/reports',
				INFO_DIALOG = '#hpsum-info-dialog',
				BROWSE_LOCATION_ERROR = '#hpsum-invalid-location-error',
			    FIRMWARECHECKBOX = '#hpsum-group-reports-firmware',
			    INSTALLABLECHECKBOX = '#hpsum-group-reports-installable',
			    FAILEDDEPCHECKBOX = '#hpsum-group-reports-faileddep',
			    INSTALLEDCHECKBOX = '#hpsum-group-reports-installed',
			    COMBINEDCHECKBOX = '#hpsum-group-reports-combined',
			    REPORTFORMATHTML = '#hpsum-group-reports-html',
			    REPORTFORMATXML = '#hpsum-group-reports-xml',
			    REPORTFORMATCSV = '#hpsum-group-reports-csv',
			    RUNBACKCHECKBOX = '#chkbox-runbackReport',
			    TITLE = '#hpsum-group-reports-title',
			    SPLASH_DIALOG = '#hpsum-report-wait-dialog',
			    SPLASH_SPINNER = '#hpsum-report-spinner',
			    REPORTS_TABLE = '#hpsum-reports-table',
			    REPORTS_LOCATION_BROWSE = '#hpsum-group-report-location-browse';

			function GroupReportsShowView() {
				var groupItem = null,
				    timer = null,
				    inProgressTimer = null,
				    inProgressReportId = null,
				    reportWaitDialog,
				    allReportsDialog,
				    deleteInfoDialog,
				    deleteReportId,
					infoDialog,
					instReportLocBrowse,
					rept_path,
				    generateInProgress = false;
				    
				function reset() {
					$(FIRMWARECHECKBOX).attr('checked', true);
					$(FIRMWARECHECKBOX).attr('disabled', false);
					$(FIRMWARECHECKBOX).trigger('change');
					
					$(INSTALLABLECHECKBOX).attr('checked', true);
					$(INSTALLABLECHECKBOX).attr('disabled', false);
					$(INSTALLABLECHECKBOX).trigger('change');
					
					$(FAILEDDEPCHECKBOX).attr('checked', true);
					$(FAILEDDEPCHECKBOX).attr('disabled', false);
					$(FAILEDDEPCHECKBOX).trigger('change');
					
					$(COMBINEDCHECKBOX).attr('checked', true);
                    $(COMBINEDCHECKBOX).attr('disabled', false);
                    $(COMBINEDCHECKBOX).trigger('change');
					
					if (groupItem && groupItem.hasOwnProperty("group_state")) {
						var arr = ["STAGE_ONLY_DONE", "INSTALLDONE"];
						if($.inArray(groupItem.group_state, arr) > -1){
							$(INSTALLEDCHECKBOX).attr('checked', true);
							$(INSTALLEDCHECKBOX).attr('disabled', false);
							$(INSTALLEDCHECKBOX).trigger('change');
						} else {
							$(INSTALLEDCHECKBOX).attr('checked', false);
							$(INSTALLEDCHECKBOX).attr('disabled', true);
							$(INSTALLEDCHECKBOX).trigger('change');
						}
					}
					
					$(RUNBACKCHECKBOX).attr('checked', false);
					$(RUNBACKCHECKBOX).attr('disabled', false);
					$(RUNBACKCHECKBOX).trigger('change');
					$(REPORTFORMATHTML).attr('checked', true);
					instReportLocBrowse.setPanelText(report_output_path);
				}
				
				function onHandleInvalidPath(hapi) {
				if (hapi.hcode == 5) {
					$(BROWSE_LOCATION_ERROR).html(localizer.getString('hpsum.baseline.add.inValidLocation'));
					instReportLocBrowse.addInputClass("hp-error");
					$(BROWSE_LOCATION_ERROR).show();
						$(GENERATE).attr("disabled", true);
				} else {
				    $(BROWSE_LOCATION_ERROR).hide();
				    instReportLocBrowse.removeInputClass("hp-error");
				}
			}

				function onItemChange(item) {
					if (timer) {
						clearInterval(timer);
						timer = null;
					}
					groupItem = item.hapi;
					if (groupItem && groupItem.hasOwnProperty("group_id")) {
						$(TITLE).text(groupItem.group_name);	
						var arr = ["STAGE_ONLY_DONE", "INSTALLDONE"];
						if($.inArray(groupItem.group_state, arr) > -1){
						    $(INSTALLEDCHECKBOX).attr('checked', true);
						    $(INSTALLEDCHECKBOX).attr('disabled', false);
						    $(INSTALLEDCHECKBOX).trigger('change');
						} else {
							if(groupItem.group_flag == true){
							$(INSTALLEDCHECKBOX).attr('checked', true);
						    $(INSTALLEDCHECKBOX).attr('disabled', false);
						    $(INSTALLEDCHECKBOX).trigger('change');
							}
							else {
							$(INSTALLEDCHECKBOX).attr('checked', false);
						    $(INSTALLEDCHECKBOX).attr('disabled', true);
						    $(INSTALLEDCHECKBOX).trigger('change');
							}
						}
					} else {
						$(CANCEL).trigger('click');
					}
				}

				function showReportGenerationWait() {
					var reportButtons = {};
					reportButtons[localizer.getString('hpsum.node.runbackReport')] = function() {
						notifications.show(localizer.getString("hpsum.node.runningReportInBack", new Array(groupItem.group_name)) + ' '+
									 localizer.getString("hpsum.node.referForReportStatus"), 'ok');
						closesReportGenerationWait();
					};
	
					reportWaitDialog = $(SPLASH_DIALOG);
					reportWaitDialog.dialog({
						modal : true,
						dialogClass : 'hp-simple-dialog',
						position : "center",
						draggable : false,
						resizable : false,
						buttons : reportButtons,
						width : 300,
						height : 180
					}); 
					
					$(SPLASH_SPINNER).show();
					reportWaitDialog.dialog('open');
				}

				function closesReportGenerationWait() {
					$(SPLASH_SPINNER).hide();
					if (reportWaitDialog) {
					   reportWaitDialog.dialog('close');
					}
				}

				function populateReportsTable(isItemOnChange) {	
					var reports = [],
					    firmware_report,
					    deploy_preview_report,
					    installed_report,
					    dependency_report,
					    combined_report,
					    nodes = [];

					presenter.getAllReports({
						success : function(data) {
							reports = data.hapi.reports.report;
							var tableReports = [],
							    reportTypes = [],
							    reportStatus,
							    inProgress = false;
								rept_path=data.hapi.reports.report_location;
								report_output_path = rept_path
								instReportLocBrowse.setPanelText(rept_path);
							    							    
							for (var idx = 0; idx < reports.length; ++idx) {
								    reportStatus = reports[idx].report_state;
								    
								if (reportStatus == "report_generation_completed") {
									reportStatus = localizer.getString("hpsum.node.completed");
								} else if (reportStatus == "in_progress" || reportStatus == "not_started" || reportStatus == "partially_generated") {
									reportStatus = localizer.getString("hpsum.node.inProgress");
									inProgress = true;
									generateInProgress = true;
									if (isItemOnChange) {
										inProgressReportId = reports[idx].report_id;

										$(GENERATE).attr("disabled", true);
										inProgressTimer = setInterval(function() {
											presenter.getReportStatus(inProgressReportId, {
												success : function(data) {
													if (data.hapi.report_state.match(/in_progress|not_started|partially_generated/i)) {
													} else if (data.hapi.report_state.match(/report_generation_completed/i)) {

														clearInterval(inProgressTimer);

														$(GENERATE).attr("disabled", false);
														populateReportsTable(false);
														generateInProgress = false;

													} else {

														clearInterval(inProgressTimer);

													}
												},
												error : function(errorInfo) {

													clearInterval(inProgressTimer);
												}
											});

										}, 10000);
									}
								} else {
									reportStatus = localizer.getString("hpsum.node.failed");
								}

								    
								    reportTypes = reports[idx].report_type;
								    firmware_report = deploy_preview_report = 	installed_report = dependency_report = combined_report = "";					    
								    for (var i=0; i < reportTypes.length; i++) {
								    	
								    	if (reportTypes[i] == "firmware_report") {
								    		reportTypes[i] = "Firmware";
								    		if (inProgress) {
												firmware_report = '<img src="/img/hp-piano/throbber-small.png" class="hpsum-status-change-med">';
											} else { 	
								    		    firmware_report =  '<a href="' + reports[idx].report_id + '/' + reportTypes[i] + '-' + reports[idx].report_format+ '.rpt"' + 'class="company-a" target ="_blank">' + 
								    		                   '<img src="/img/hp-piano/status-ok.png" ></br>' +
								    		                   localizer.getString("hpsum.node.viewDetails") + '</a>';
								    		}
								    	}
								    	else if (reportTypes[i] == "deploy_preview_report") {
								    		reportTypes[i] = "deploy_preview";
								    		if (inProgress) {
												deploy_preview_report = '<img src="/img/hp-piano/throbber-small.png" class="hpsum-status-change-med">';
											} else { 
								    		    deploy_preview_report =  '<a href="' + reports[idx].report_id + '/' + reportTypes[i] + '-' + reports[idx].report_format+ '.rpt"' + 'class="company-a" target ="_blank">' +
								    		                      '<img src="/img/hp-piano/status-ok.png" ></br>' +
								    		                      localizer.getString("hpsum.node.viewDetails") + '</a>';
								    		}
								    	}
								    	else if (reportTypes[i] == "installed_report") {
								    		reportTypes[i] = "Installed";
								    		if (inProgress) {
												installed_report = '<img src="/img/hp-piano/throbber-small.png" class="hpsum-status-change-med">';
											} else { 
								    		    installed_report =  '<a href="' + reports[idx].report_id + '/' + reportTypes[i] + '-' + reports[idx].report_format+ '.rpt"' + 'class="company-a" target ="_blank">' +
								    		                    '<img src="/img/hp-piano/status-ok.png" ></br>' +
								    		                     localizer.getString("hpsum.node.viewDetails") + '</a>';
								    		}
								    	}
								    	else if (reportTypes[i] == "dependency_report") {
								    		reportTypes[i] = "FailedDependency";
								    		if (inProgress) {
												dependency_report = '<img src="/img/hp-piano/throbber-small.png" class="hpsum-status-change-med">';
											} else { 
								    		    dependency_report =  '<a href="' + reports[idx].report_id + '/' + reportTypes[i] + '-' + reports[idx].report_format+ '.rpt"' + 'class="company-a" target ="_blank">' +
								    		                     '<img src="/img/hp-piano/status-ok.png" ></br>' +
								    		                   localizer.getString("hpsum.node.viewDetails") + '</a>';
								    		}
								    	}
								    	else if (reportTypes[i] == "combined_report") {
                                            reportTypes[i] = "Combined";
                                            if (inProgress) {
                                                combined_report = '<img src="/img/hp-piano/throbber-small.png" class="hpsum-status-change-med">';
                                            } else { 
                                                combined_report =  '<a href="' + reports[idx].report_id + '/' + reportTypes[i] + '-' + reports[idx].report_format + '.rpt"' + 'class="company-a" target ="_blank">' +
                                                                 '<img src="/img/hp-piano/status-ok.png" ></br>' +
                                                               localizer.getString("hpsum.node.viewDetails") + '</a>';
                                            }
                                        }
								    }
								    
								    inProgress = false;
								
								var deleteReport = '<a id="hpsum-groups-delete-report" data-custom-value="' + reports[idx].report_id + '-' + reports[idx].report_format + '">' +
								'<img src="/img/hp-piano/close.png" >' + '</a>';
								
								tableReports.push({
									time_stamp : reports[idx].date_and_time,
									report_path:reports[idx].report_path,
									report_format : reports[idx].report_format,
									firmware_type : firmware_report,
									deploy_preview_type : deploy_preview_report,
									installed_type : installed_report,
									dependency_type : dependency_report,
									combined_report : combined_report,
									report_status : reportStatus,
									node_name : reports[idx].node_id,
									delete_report : deleteReport
								});
							}
									    
							$(REPORTS_TABLE).dataTable().fnClearTable();
							$(REPORTS_TABLE).dataTable().fnAddData(tableReports);
						},
						error : function(data) {
							notifications.show(data.hapi.hmessage, 'error');
							$(CANCEL).trigger('click');
						}
					});
				};

					
				function onGenerate() {	
					generateInProgress = true;
					$(GENERATE).attr("disabled", true);
					if (!$(RUNBACKCHECKBOX).is(':checked')) {
						showReportGenerationWait();
					}

					var request, reportformat = "false";
					if ($(REPORTFORMATHTML).is(':checked')) {
						reportformat = $(REPORTFORMATHTML).val();
					} else if ($(REPORTFORMATXML).is(':checked')) {
						reportformat = $(REPORTFORMATXML).val();
					} else if ($(REPORTFORMATCSV).is(':checked')) {
						reportformat = $(REPORTFORMATCSV).val();
					}

					var firmwaretype = $(FIRMWARECHECKBOX).is(':checked');
					var deploy_previewtype = $(INSTALLABLECHECKBOX).is(':checked');
					var faileddeptype = $(FAILEDDEPCHECKBOX).is(':checked');
					var installedtype = $(INSTALLEDCHECKBOX).is(':checked');
					var combinedtype = $(COMBINEDCHECKBOX).is(':checked');

					var requestNodeArray = [],
						reportNodes = groupItem.group_nodes.group_node;
						
					for (var i=0; i<reportNodes.length; i++){
						requestNodeArray.push({
									node_id : reportNodes[i],
									firmware_report : firmwaretype,
									deploy_preview_report : deploy_previewtype,
									dependency_report : faileddeptype,
									installed_report : installedtype,
									combined_report : combinedtype
						});
					}
                    
					var request = {
						hapi : {
							report_format : reportformat,
							baseline_report: "false",
							nodes : {
								node : requestNodeArray
							}
						}
					};

					var requestSetSessionAttribute = {
						hapi : {
							report_dir : instReportLocBrowse.getLocation()
							}
					};
					
					if ( rept_path.toLowerCase() != instReportLocBrowse.getLocation().toLowerCase() ) {
					presenter.setSessionAttribute(requestSetSessionAttribute, {
						success : function(data) {
							createRepPresenter(request)	;
					
						},
						error : function(errorInfo) {
							closesReportGenerationWait();
							$(BROWSE_LOCATION_ERROR).show();
							$(BROWSE_LOCATION_ERROR).html(localizer.getString('hpsum.baseline.add.errorReportText'));
							instReportLocBrowse.addInputClass("hp-error");
							$(GENERATE).attr("disabled", true);
							}
						});
					}
					else
					{
						createRepPresenter(request)	;
					}

				}
				function createRepPresenter(request)
				{
					presenter.createReport(request, {
						success : function(data) {
							onSuccessReportCreation(data.hapi.report_id);
						},
						error : function(errorInfo) {
							notifications.show(errorInfo, 'error');
							closesReportGenerationWait();
							$(CANCEL).trigger('click');
						}
					});
				}
			
			function onNoSelection() {
				showInfoDialog();
			}
			
			function showInfoDialog()
            {
            	if (!infoDialog) {
                    infoDialog =  $(INFO_DIALOG);
                    infoDialog.dialog({
                        modal : true,
                        dialogClass: 'hp-simple-dialog',
                        position : "center",
                        draggable : false,
                        resizable : false
                    });
                    $('button', infoDialog).on('click', function () {
                        infoDialog.dialog('close');
                    });
                }
                infoDialog.dialog('open');
            }
            
            	function getReportStatus(reportId) {
					if (timer) {
						clearInterval(timer);
						timer = null;
					}
					timer = setInterval(function() {
						presenter.getReportStatus(reportId, {
							success : function(data) {
								if (data.hapi.report_state.match(/in_progress|not_started/i)) {
								} else if (data.hapi.report_state.match(/report_generation_completed/i)) {
									closesReportGenerationWait();
									if (timer) {
										clearInterval(timer);
										timer = null;
									}
									$(GENERATE).attr("disabled", false);
									populateReportsTable(false);
									generateInProgress = false;
								} else if (data.hapi.report_state.match(/partially_generated/i)) {
									
								} else {
									notifications.show(data.hapi.hmessage, 'error');
									closesReportGenerationWait();
									
									if (timer) {
										clearInterval(timer);
										timer = null;
									}

									$(CANCEL).trigger('click');
								}
							},
							error : function(errorInfo) {
								notifications.show(errorInfo, 'error');
								closesReportGenerationWait();
								
								if (timer) {
									clearInterval(timer);
									timer = null;
								}

								$(CANCEL).trigger('click');
							}
						});

					}, 10000);
				}

				function onSuccessReportCreation(reportId) {
					populateReportsTable(false);
					presenter.generateReport(reportId, {
						success : function(data) {
							if (!$(RUNBACKCHECKBOX).is(':checked')) {
								populateReportsTable(false);
								getReportStatus(reportId);
							} else {
								notifications.show(localizer.getString("hpsum.node.runningReportInBack", new Array(groupItem.group_name)) + ' '+
											localizer.getString("hpsum.node.referForReportStatus"), 'ok');
							    populateReportsTable(false);
								getReportStatus(reportId);
							}
						},
						error : function(errorInfo) {
							notifications.show(errorInfo, 'error');
							closesReportGenerationWait();
							$(CANCEL).trigger('click');
						}
					});
				}

				function onDeleteReport() {
					var deleteConfirmButtons = {};

					deleteConfirmButtons[localizer.getString('core.delete.delete_button')] = function() {
						presenter.deleteReport({report_id : deleteReportId},
							{
							success : function(data) {
								notifications.show(data.hapi.hmessage, 'ok');
								populateReportsTable(false);
							},
							error : function(message) {
								notifications.show(message, 'error');
							}
						});
						deleteInfoDialog.dialog('close');
					};

					deleteConfirmButtons[localizer.getString('core.delete.cancel_button')] = function() {
						deleteInfoDialog.dialog('close');
					};
					
					if (!deleteInfoDialog) {
						deleteInfoDialog = $('#hpsum-delete-report-dialog');
						deleteInfoDialog.dialog({
							modal : true,
							dialogClass : 'hp-simple-dialog',
							position : "center",
							draggable : false,
							resizable : false,
							buttons : deleteConfirmButtons,
							open: function() {
										$('.ui-dialog-buttonpane').find('button:contains("delete")').addClass('hp-primary');
									}
						});
					}
					
					deleteInfoDialog.dialog('open');	
				}
				
				function changeLocation(location) {
					if (location.length > ROUTE_PREFIX.length) {
						$(PANELS).hpStackedPanels('setPanelByLocation', '#' + location);
					} else {
						$(PANELS).hpStackedPanels('setFirstPanel');
					}
				}
				
				function checkNoneReportTypeChecked(){
						onReportLocationChange();
				}	
				
				function onReportLocationChange(){
					$(GENERATE).attr("disabled", true);
					if(generateInProgress){
						return;
					}
					
					var path= instReportLocBrowse.getLocation();
					if( path=="" ){
						$(BROWSE_LOCATION_ERROR).show();
						$(BROWSE_LOCATION_ERROR).html(localizer.getString('hpsum.baseline.add.emptyReportText'));
						instReportLocBrowse.addInputClass("hp-error");
					}
					else
					{
						$(BROWSE_LOCATION_ERROR).hide();
						instReportLocBrowse.removeInputClass("hp-error");
						if ( $(INSTALLABLECHECKBOX).is(':checked') || 
							 $(FAILEDDEPCHECKBOX).is(':checked') || $(INSTALLEDCHECKBOX).is(':checked') ||
							 $(COMBINEDCHECKBOX).is(':checked') || $(FIRMWARECHECKBOX).is(':checked') )
						{
							$(GENERATE).attr("disabled", false);
						}
					}
				}
				
				this.init = function() {
				
					var options = 	{
									command : 'init',
									panelLabel: "hpsum.baseline.add.enterDirectory",
									panelLabelStyle: "padding-left: 33px;",
						            panelHelp: "",
						            panelBrowseText: "hpsum.common.browse",
									bShowEmptyFolder: false,
						            onHandleInvalidPath: onHandleInvalidPath,
						            onNoSelection: onNoSelection
						        };
					$(REPORTS_LOCATION_BROWSE).hpsumBrowse(options);
					
					instReportLocBrowse = $(REPORTS_LOCATION_BROWSE).data('plugin_hpsumBrowse');
					
					instReportLocBrowse.setInputEvent("onkeyup", onReportLocationChange);
					instReportLocBrowse.setInputEvent("onchange", onReportLocationChange);
					instReportLocBrowse.setInputEvent('onfocusout', onReportLocationChange);
					instReportLocBrowse.setInputEvent('onfocus', onReportLocationChange);
				
					var resource = router.location().split('/');
                	resource = resource[1];
              	$('a[data-panel-id]').each(function(index) {
                		var currentLink = $(this).attr('href');
                		if(currentLink  == undefined)
                			return;
                		var current = currentLink.split('/');
                		current[1] = resource;
                		currentLink =current.join('/');
                		$(this).attr('href',currentLink);
  					});
  					ROUTE_PREFIX = '/'+ resource +'/reports';

					$(PANELS).hpStackedPanels({
						panelSelector : PANEL_SELECTOR
					});

					$(RESET).live('click', function() {
						reset.call();
						onReportLocationChange();
					});

					$(GENERATE).live('click', function(ev) {
						var path= instReportLocBrowse.getLocation();
						if (!generateInProgress && path != "") {
						 onGenerate.call();
						}
						else
						$(GENERATE).attr("disabled", true);
						ev.preventDefault();
					});
					
					$(FIRMWARECHECKBOX).on('click', function(ev) {
						checkNoneReportTypeChecked.call();
					});
					$(INSTALLABLECHECKBOX).on('click', function(ev) {
						checkNoneReportTypeChecked.call();
					});
					$(FAILEDDEPCHECKBOX).on('click', function(ev) {
						checkNoneReportTypeChecked.call();
					});
					$(INSTALLEDCHECKBOX).on('click', function(ev) {
						checkNoneReportTypeChecked.call();
					});
					$(COMBINEDCHECKBOX).on('click', function(ev) {
						checkNoneReportTypeChecked.call();
					});
					
					$('#hpsum-groups-delete-report').live('click', function(ev) {
						deleteReportId = $(this).data("custom-value");
						onDeleteReport.call();
						ev.preventDefault();
					});
					
					// put help in header
					if ($('.hp-details-header-controls', $(FORM).parent()).length === 0) {
						var headerHelp = $(headerHelpHtml);
						localizer.localizeDom(headerHelp);
						$('.hp-details-header', $(FORM).parent()).append(headerHelp);
					}
					
					$(CANCEL).click(function () {
					if (timer) {
						clearInterval(timer);
						timer = null;
					}
					if (inProgressTimer) {
						clearInterval(inProgressTimer);
						inProgressTimer = null;
					}
					
                    router.go(urlFragment.replaceView(router.location(), 'show'));
                });
					router.watch('node report section', ROUTE_PREFIX + '.*', {
						parent : ROUTE_PREFIX,
						change : changeLocation
					});
					
					this.resume();
				};

				this.resume = function() {
					
					var dummyReportsData = [];
					$(REPORTS_TABLE).dataTable({
						oLanguage : {
						    sEmptyTable: localizer.getString("hpsum.node.noReports"),
						    sSearch: localizer.getString('hpsum.common.search')
						},
						bPaginate : false,
						bFilter : false,
						bInfo : false,
						bAutoWidth : false,
						bRetrieve : true,
						bDestroy : true,
						aaData : dummyReportsData,
						aoColumns : [{
							mDataProp : 'time_stamp'
						},{
							mDataProp : 'report_path'
						},{
							sWidth: 75, mDataProp : 'firmware_type'
						},{
							sWidth: 75, mDataProp : 'deploy_preview_type'
						},{
							sWidth: 75, mDataProp : 'dependency_type'
						},{
							sWidth: 75, mDataProp : 'installed_type'
						},{
                            sWidth: 75, mDataProp : 'combined_report'
                        },{
							mDataProp : 'report_format'
						},{
							mDataProp : 'report_status'
						},{
							mDataProp : 'delete_report'
						}],
						aaSorting: [[ 0, "desc" ]]
					});
					
					generateInProgress = false;
					if (timer) {
						clearInterval(timer);
						timer = null;
					}
					if (inProgressTimer) {
						clearInterval(inProgressTimer);
						inProgressTimer = null;
					}
					$(RESET).trigger('click');	    
					groupPresenter.on("itemChange", onItemChange);
					$(PANELS).hpStackedPanels('resume');
					$(GENERATE).attr("disabled", false);
					$(BROWSE_LOCATION_ERROR).hide();
					instReportLocBrowse.removeInputClass('hp-error');
					populateReportsTable(true);
				};

				this.pause = function() {
					
					if (timer) {
						clearInterval(timer);
						timer = null;
					}
					groupPresenter.off("itemChange", onItemChange);
					$(PANELS).hpStackedPanels('pause');
				};

			}

			return GroupReportsShowView;
		}());

	return new GroupReportsShowView();

});



