<commit_before> /**
 *  Copyright (C) 2010 Cloud.com, Inc.  All rights reserved.
 * 
 * This software is licensed under the GNU General Public License v3 or later.
 * 
 * It is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

//***** actions for details tab in right panel (begin) ************************************************************************
function buildActionLinkForDetailsTab(label, actionMap, $actionMenu, $midmenuItem1, $detailsTab) { 
    var apiInfo = actionMap[label];
    var $listItem = $("#action_list_item").clone();
    $actionMenu.find("#action_list").append($listItem.show());
    var $link = $listItem.find("#link").text(label);
    $link.data("label", label);	  
    $link.data("inProcessText", apiInfo.inProcessText);	 
    $link.data("api", apiInfo.api);				                 
    $link.data("isAsyncJob", apiInfo.isAsyncJob);
    $link.data("asyncJobResponse", apiInfo.asyncJobResponse);		     
    $link.data("afterActionSeccessFn", apiInfo.afterActionSeccessFn);
    $link.data("dialogBeforeActionFn", apiInfo.dialogBeforeActionFn);     
     
    var id = $detailsTab.data("jsonObj").id;
    
    $link.bind("click", function(event) {   
        $actionMenu.hide();    	 
        var $actionLink = $(this);   
        
        var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn"); 
        if(dialogBeforeActionFn == null) {	 
            var apiCommand = "command="+$actionLink.data("api")+"&id="+id;                      
            doActionToDetailsTab(id, $actionLink, apiCommand, $midmenuItem1, $detailsTab); 
        }
        else {
            dialogBeforeActionFn($actionLink, $detailsTab, $midmenuItem1);	
        }               
        return false;
    });  
} 

function doActionToDetailsTab(id, $actionLink, apiCommand, $midmenuItem1, $detailsTab) {  
    var label = $actionLink.data("label");	
    var inProcessText = $actionLink.data("inProcessText");		           
    var isAsyncJob = $actionLink.data("isAsyncJob");
    var asyncJobResponse = $actionLink.data("asyncJobResponse");	
    var afterActionSeccessFn = $actionLink.data("afterActionSeccessFn");	    
            
    var $spinningWheel = $detailsTab.find("#spinning_wheel");
    $spinningWheel.find("#description").text(inProcessText);  
    $spinningWheel.show();  
    
    var $afterActionInfoContainer = $("#right_panel_content #after_action_info_container_on_top");   
    $afterActionInfoContainer.removeClass("errorbox").hide();       
    
	//Async job (begin) *****
	if(isAsyncJob == true) {	                     
        $.ajax({
            data: createURL(apiCommand),
            dataType: "json",           
            success: function(json) {	                       	                        
                var jobId = json[asyncJobResponse].jobid;                  			                        
                var timerKey = "<KEY> + jobId;					                       
                $("body").everyTime(
                    10000,
                    timerKey,
                    function() {
                        $.ajax({
                            data: createURL("command=queryAsyncJobResult&jobId="+jobId),
	                        dataType: "json",									                    					                    
	                        success: function(json) {		                                                     							                       
		                        var result = json.queryasyncjobresultresponse;										                   
		                        if (result.jobstatus == 0) {
			                        return; //Job has not completed
		                        } else {											                    
			                        $("body").stopTime(timerKey);				                        
			                        $spinningWheel.hide();   			                                             
			                        if (result.jobstatus == 1) { // Succeeded 	
			                            $afterActionInfoContainer.find("#after_action_info").text(label + " action succeeded.");
                                        $afterActionInfoContainer.removeClass("errorbox").show();  
                                        
                                        $midmenuItem1.data("afterActionInfo", (label + " action succeeded.")); 	
                                        $midmenuItem1.find("#info_icon").removeClass("error").show();                                        
                                                                               
                                        afterActionSeccessFn(json, $midmenuItem1, id);     
			                        } else if (result.jobstatus == 2) { // Failed		
			                            $afterActionInfoContainer.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult));
                                        $afterActionInfoContainer.addClass("errorbox").show();                                        
                                        
                                        $midmenuItem1.data("afterActionInfo", (label + " action failed. Reason: " + fromdb(result.jobresult))); 
                                        $midmenuItem1.find("#info_icon").addClass("error").show();                                        
			                        }											                    
		                        }
	                        },
	                        error: function(XMLHttpResponse) {	                            
		                        $("body").stopTime(timerKey);		                       		                        
		                        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer); 	
		                        handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);    	                        
	                        }
                        });
                    },
                    0
                );
            },
            error: function(XMLHttpResponse) {	                 
		        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer);  
		        handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);      
            }
        });     
    }     
    //Async job (end) *****
    
    //Sync job (begin) *****
    else { 	    
        $.ajax({
            data: createURL(apiCommand),
	        dataType: "json",
	        async: false,
	        success: function(json) {	 	                  
	            $spinningWheel.hide(); 	        
	            $afterActionInfoContainer.find("#after_action_info").text(label + " action succeeded.");
                $afterActionInfoContainer.removeClass("errorbox").show(); 
                
                $midmenuItem1.data("afterActionInfo", (label + " action succeeded.")); 	
                $midmenuItem1.find("#info_icon").removeClass("error").show();     
                 				
				afterActionSeccessFn(json, $midmenuItem1, id);				
	        },
            error: function(XMLHttpResponse) {	                
		        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer); 
		        handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);       
            }        
        });
    }
    //Sync job (end) *****
}

function handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer) { 
    $detailsTab.find("#spinning_wheel").hide();      
		                        
    var errorMsg = "";
    if(XMLHttpResponse.responseText != null & XMLHttpResponse.responseText.length > 0) {
        var start = XMLHttpResponse.responseText.indexOf("h1") + 3;
        var end = XMLHttpResponse.responseText.indexOf("</h1");
        errorMsg = XMLHttpResponse.responseText.substring(start, end);		
    }        
   
    if(errorMsg.length > 0) 
        $afterActionInfoContainer.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(errorMsg));
    else
        $afterActionInfoContainer.find("#after_action_info").text(label + " action failed.");        
    $afterActionInfoContainer.addClass("errorbox").show();
}    	                
//***** actions for details tab in right panel (end) **************************************************************************

//***** actions for a subgrid item in right panel (begin) ************************************************************************
function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, $subgridItem) {
    var apiInfo = actionMap[label];
    var $listItem = $("#action_list_item").clone();
    $actionMenu.find("#action_list").append($listItem.show());
    var $link = $listItem.find("#link").text(label);
    $link.data("label", label);	  
    $link.data("inProcessText", apiInfo.inProcessText);	 
    $link.data("api", apiInfo.api);				                 
    $link.data("isAsyncJob", apiInfo.isAsyncJob);
    $link.data("asyncJobResponse", apiInfo.asyncJobResponse);		     
    $link.data("afterActionSeccessFn", apiInfo.afterActionSeccessFn);
    $link.data("dialogBeforeActionFn", apiInfo.dialogBeforeActionFn);      
    
    var id = $subgridItem.data("jsonObj").id;
    
    $link.bind("click", function(event) {   
        $actionMenu.hide();    	 
        var $actionLink = $(this);   
        var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn"); <commit_msg>new UI - after details action is finished, action info will be recorded in middle menu. So, when a user move between different middle menu items, right panel will show corresponding action info for each item.<commit_after> /**
 *  Copyright (C) 2010 Cloud.com, Inc.  All rights reserved.
 * 
 * This software is licensed under the GNU General Public License v3 or later.
 * 
 * It is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

//***** actions for details tab in right panel (begin) ************************************************************************
function buildActionLinkForDetailsTab(label, actionMap, $actionMenu, $midmenuItem1, $detailsTab) { 
    var apiInfo = actionMap[label];
    var $listItem = $("#action_list_item").clone();
    $actionMenu.find("#action_list").append($listItem.show());
    var $link = $listItem.find("#link").text(label);
    $link.data("label", label);	  
    $link.data("inProcessText", apiInfo.inProcessText);	 
    $link.data("api", apiInfo.api);				                 
    $link.data("isAsyncJob", apiInfo.isAsyncJob);
    $link.data("asyncJobResponse", apiInfo.asyncJobResponse);		     
    $link.data("afterActionSeccessFn", apiInfo.afterActionSeccessFn);
    $link.data("dialogBeforeActionFn", apiInfo.dialogBeforeActionFn);     
     
    var id = $detailsTab.data("jsonObj").id;
    
    $link.bind("click", function(event) {   
        $actionMenu.hide();    	 
        var $actionLink = $(this);   
        
        var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn"); 
        if(dialogBeforeActionFn == null) {	 
            var apiCommand = "command="+$actionLink.data("api")+"&id="+id;                      
            doActionToDetailsTab(id, $actionLink, apiCommand, $midmenuItem1, $detailsTab); 
        }
        else {
            dialogBeforeActionFn($actionLink, $detailsTab, $midmenuItem1);	
        }               
        return false;
    });  
} 

function doActionToDetailsTab(id, $actionLink, apiCommand, $midmenuItem1, $detailsTab) {  
    var label = $actionLink.data("label");	
    var inProcessText = $actionLink.data("inProcessText");		           
    var isAsyncJob = $actionLink.data("isAsyncJob");
    var asyncJobResponse = $actionLink.data("asyncJobResponse");	
    var afterActionSeccessFn = $actionLink.data("afterActionSeccessFn");	    
            
    var $spinningWheel = $detailsTab.find("#spinning_wheel");
    $spinningWheel.find("#description").text(inProcessText);  
    $spinningWheel.show();  
    
    var $afterActionInfoContainer = $("#right_panel_content #after_action_info_container_on_top");   
    $afterActionInfoContainer.removeClass("errorbox").hide();       
    
	//Async job (begin) *****
	if(isAsyncJob == true) {	                     
        $.ajax({
            data: createURL(apiCommand),
            dataType: "json",           
            success: function(json) {	                       	                        
                var jobId = json[asyncJobResponse].jobid;                  			                        
                var timerKey = "asyncJob_" + jobId;					                       
                $("body").everyTime(
                    10000,
                    timerKey,
                    function() {
                        $.ajax({
                            data: createURL("command=queryAsyncJobResult&jobId="+jobId),
	                        dataType: "json",									                    					                    
	                        success: function(json) {		                                                     							                       
		                        var result = json.queryasyncjobresultresponse;										                   
		                        if (result.jobstatus == 0) {
			                        return; //Job has not completed
		                        } else {											                    
			                        $("body").stopTime(timerKey);				                        
			                        $spinningWheel.hide();   			                                             
			                        if (result.jobstatus == 1) { // Succeeded 	
			                            $afterActionInfoContainer.find("#after_action_info").text(label + " action succeeded.");
                                        $afterActionInfoContainer.removeClass("errorbox").show();  
                                        
                                        $midmenuItem1.data("afterActionInfo", (label + " action succeeded.")); 	
                                        $midmenuItem1.find("#info_icon").removeClass("error").show();                                        
                                                                               
                                        afterActionSeccessFn(json, $midmenuItem1, id);     
			                        } else if (result.jobstatus == 2) { // Failed		
			                            $afterActionInfoContainer.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult));
                                        $afterActionInfoContainer.addClass("errorbox").show();                                        
                                        
                                        $midmenuItem1.data("afterActionInfo", (label + " action failed. Reason: " + fromdb(result.jobresult))); 
                                        $midmenuItem1.find("#info_icon").addClass("error").show();                                        
			                        }											                    
		                        }
	                        },
	                        error: function(XMLHttpResponse) {	                            
		                        $("body").stopTime(timerKey);		                       		                        
		                        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer, $midmenuItem1); 		                                             
	                        }
                        });
                    },
                    0
                );
            },
            error: function(XMLHttpResponse) {	                 
		        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer, $midmenuItem1);  		        
            }
        });     
    }     
    //Async job (end) *****
    
    //Sync job (begin) *****
    else { 	    
        $.ajax({
            data: createURL(apiCommand),
	        dataType: "json",
	        async: false,
	        success: function(json) {	 	                  
	            $spinningWheel.hide(); 	        
	            $afterActionInfoContainer.find("#after_action_info").text(label + " action succeeded.");
                $afterActionInfoContainer.removeClass("errorbox").show(); 
                
                $midmenuItem1.data("afterActionInfo", (label + " action succeeded.")); 	
                $midmenuItem1.find("#info_icon").removeClass("error").show();     
                 				
				afterActionSeccessFn(json, $midmenuItem1, id);				
	        },
            error: function(XMLHttpResponse) {	                
		        handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer, $midmenuItem1); 		       
            }        
        });
    }
    //Sync job (end) *****
}

function handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label, $afterActionInfoContainer, $midmenuItem1) { 
    //details tab
    $detailsTab.find("#spinning_wheel").hide();      
		                        
    var errorMsg = "";
    if(XMLHttpResponse.responseText != null & XMLHttpResponse.responseText.length > 0) {
        var start = XMLHttpResponse.responseText.indexOf("h1") + 3;
        var end = XMLHttpResponse.responseText.indexOf("</h1");
        errorMsg = XMLHttpResponse.responseText.substring(start, end);		
    }        
   
    var afterActionInfo;
    if(errorMsg.length > 0) 
        afterActionInfo = label + " action failed. Reason: " + fromdb(errorMsg);
    else
        afterActionInfo = label + " action failed.";
    
    $afterActionInfoContainer.find("#after_action_info").text(afterActionInfo);         
    $afterActionInfoContainer.addClass("errorbox").show();
    
    //middle menu
    $midmenuItem1.data("afterActionInfo", afterActionInfo); 	
    $midmenuItem1.find("#info_icon").addClass("error").show();		
}    	                
//***** actions for details tab in right panel (end) **************************************************************************

//***** actions for a subgrid item in right panel (begin) ************************************************************************
function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, $subgridItem) {
    var apiInfo = actionMap[label];
    var $listItem = $("#action_list_item").clone();
    $actionMenu.find("#action_list").append($listItem.show());
    var $link = $listItem.find("#link").text(label);
    $link.data("label", label);	  
    $link.data("inProcessText", apiInfo.inProcessText);	 
    $link.data("api", apiInfo.api);				                 
    $link.data("isAsyncJob", apiInfo.isAsyncJob);
    $link.data("asyncJobResponse", apiInfo.asyncJobResponse);		     
    $link.data("afterActionSeccessFn", apiInfo.afterActionSeccessFn);
    $link.data("dialogBeforeActionFn", apiInfo.dialogBeforeActionFn);      
    
    var id = $subgridItem.data("jsonObj").id;
    
    $link.bind("click", function(event) {   
        $actionMenu.hide();    	 
        var $actionLink = $(this);   
        var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn"); 
{'fraction_non_alphanumeric': 0.12956547560130655, 'fraction_numerical': 0.0036127882807087002, 'mean_word_length': 1.6144391253719756, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 50, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5083512', 'n_tokens_mistral': 5232, 'n_tokens_neox': 4722, 'n_words': 928}