<commit_before>// ------------------------------------------------------------------------------------------------------
//
//   Copyright (c) 2008, Southpaw Technology Inc., All Rights Reserved
//   
//   PROPRIETARY INFORMATION.  This software is proprietary to Southpaw Technology Inc., and is not to be
//   reproduced, transmitted, or disclosed in any way without written permission.
//   
// ------------------------------------------------------------------------------------------------------


spt.dg_table_action = {};


spt.dg_table_action.get_popup_wdg = function( evt, bvr )
{
    var popup = $("popup");

    var args = bvr.args;
    if (typeof(args) == "undefined") {
        args = {};
    }

    var server = TacticServerStub.get();
    values = {}
    if (bvr.values)
    {
        for (i in bvr.values)
            values[i] = eval(bvr.values[i]);
    }
    var kwargs = {'args': args, 'values': values};
    var widget_html = server.get_widget(bvr.class_name, kwargs);

    // replace the popup html
    spt.behavior.replace_inner_html( popup, widget_html );
    spt.popup.open( bvr.args.popup_id );
    return popup;
}


spt.dg_table_action.set_actionbar_aux_content = function( evt, bvr )
{
    //var aux_div = $("ActionBar_Aux");
    //var aux_content = $("ActionBar_Aux_Content");
    //var aux_title = $("ActionBar_Aux_Title");
    //
    var table_id = bvr.args['table_id'];
    var table = $(table_id);
    var table_top = table.getParent(".spt_table_top")

    var aux_div = table_top.getElement(".spt_table_aux")
    var aux_title = table_top.getElement(".spt_table_aux_title")
    var aux_content = table_top.getElement(".spt_table_aux_content")
    
    arg_dict = {};
    for ( i in bvr.args )
    {
        // insert some table related args into the dict
        if (i=='table_id')
        {
            var table_id = bvr.args['table_id'];
            var table = $(table_id);
            if (table)
            {
                var view = table.getProperty("spt_view");
                var search_type = table.getProperty("spt_search_type");
                arg_dict['search_type'] = search_type;
                arg_dict['view'] = view;
                arg_dict['selected_search_keys'] = spt.dg_table.get_selected_search_keys(table_id).join(',');
            }
        }
        arg_dict[i] = bvr.args[i];
    }
 
    spt.panel.load(aux_content, bvr.class_name, arg_dict, [], true);
    arg_dict['is_aux_title'] ='true';
    spt.panel.load(aux_title, bvr.class_name, arg_dict, [], false);
    aux_div.setStyle("display", "block");
    aux_div.setStyle("visibility", "visible");
    
    
    spt.ctx_menu.clear();
}


spt.dg_table_action.get_popup_wdg2 = function( evt, bvr )
{
    // get the common popup, clone it and fill it in
    var container = $("popup_container");
    var popup = $("popup_template");
    var clone = spt.behavior.clone(popup);

    clone.setAttribute("id", "whatever");
    container.appendChild(clone);


    // get the title
    var title = bvr.title;
    var width = bvr.width;
    var height = bvr.height;
    var class_name = bvr.class_name;

    // use a dst el to put this under
    var dst_el = bvr.dst_el;


    var server = TacticServerStub.get();
    var kwargs = {'args': bvr.args};
    var widget_html = server.get_widget(bvr.class_name, kwargs);

    // get the content container
    var content_wdg = clone.getElement(".spt_popup_content");
    var width_wdg = clone.getElement(".spt_popup_width");
    if (width != null) {
        width_wdg.setStyle("width", width);
    }
    if (height != null) {
        width_wdg.setStyle("height", height);
    }

    // replace the title
    if (title != null) {
        var title_wdg = clone.getElement(".spt_popup_title");
        spt.behavior.replace_inner_html( title_wdg, title );
    }
 
    // replace the popup html
    spt.behavior.replace_inner_html( content_wdg, widget_html );

    // display the clone
    clone.setStyle("display", '');
}



spt.dg_table_action.csv_export = function( evt, bvr )
{

    var project = spt.Environment.get().get_project();
    var site = spt.Environment.get().get_site();
    var my_search_type = bvr.search_type;
    var my_is_export_all = bvr.is_export_all;
    var filename = my_search_type.replace(/[\/\?\=]/g,"_") + "_" + bvr.view + ".csv";
    var class_name = "pyasm.widget.CsvDownloadWdg";
    var column_name_vals = spt.api.Utility.get_input_values('csv_export_table', 'input[name=' + bvr.column_names+']');
    var selected_search_keys = '';
    if (my_is_export_all != 'true')
        selected_search_keys = bvr.search_keys;
    
    var column_names = column_name_vals[bvr.column_names];
    var no_column_name = true;
    
    for (var k=0;  k<column_names.length; k++){
        if(column_names[k] != '') {
            no_column_name = false;
            break;
        }
    }
    var my_include_id = spt.api.Utility.get_input('csv_export_action', 
        'include_id').checked;
     
    if ( no_column_name && !my_include_id) {
        alert('Please select at least 1 column or just the "Include ID" checkbox')
        return;
    }
   
    
    var options = {
        search_type: my_search_type,
        view: bvr.view,
        filename: filename,
        column_names: column_names,
        search_keys: selected_search_keys,
        include_id: my_include_id 
    };
    var popup = bvr.src_el.getParent('.spt_popup');
    // this is assgined in spt.dg_table.gear_smenu_export_cbk 
    var values = popup.values_dict;
    
    var server = TacticServerStub.get();
   
   
    var kwargs = {'args': options, 'values': values};
    var rtn_file_name = '';
    try {
        rtn_file_name = server.get_widget(class_name, kwargs);
    } catch(e) {
        spt.error(spt.exception.handler(e));
        return;
    }
    if (rtn_file_name.length > 200 ) {
        spt.alert("Error exporting one of the widgets:\n" + rtn_file_name, {type: 'html'} );
        return;
    }
        
    var csv_file_name = encodeURIComponent(rtn_file_name);
    var param_dict = {};
    class_name = "pyasm.widget.CsvGenerator";
    param_dict['dynamic_file'] = "true";
    param_dict['widget'] = class_name;
    param_dict['filepath'] = csv_file_name;
    var url = spt.Environment.get_widget_server_url(project, param_dict);

    if (site != "default")
    {
        // If site != default, the project is access from Portal.
        // Split the csv download URL, and insert site at url[4]. 
        // The final url should look something like this: 
        // http://192.168.2.234/tactic/hello11/default/WidgetServer/...
        url = url.split('/')
        url.splice(4, 0, site);
        url = url.join('/');
    }
    
    document.location = url;

}






// This is a convenience method which sets the row to be commitable
//
spt.dg_table_action.set_commitable = function(top_el, value_wdg) {
    // Utilize edit cell keyboard handler call-back mechanism to do all the modified field goodness
    // (e.g. turning row green) ... TODO: refactor this mechanism to pull out common functionality<commit_msg>Update dg_table_action.js<commit_after>// ------------------------------------------------------------------------------------------------------
//
//   Copyright (c) 2008, Southpaw Technology Inc., All Rights Reserved
//   
//   PROPRIETARY INFORMATION.  This software is proprietary to Southpaw Technology Inc., and is not to be
//   reproduced, transmitted, or disclosed in any way without written permission.
//   
// ------------------------------------------------------------------------------------------------------


spt.dg_table_action = {};


spt.dg_table_action.get_popup_wdg = function( evt, bvr )
{
    var popup = $("popup");

    var args = bvr.args;
    if (typeof(args) == "undefined") {
        args = {};
    }

    var server = TacticServerStub.get();
    values = {}
    if (bvr.values)
    {
        for (i in bvr.values)
            values[i] = eval(bvr.values[i]);
    }
    var kwargs = {'args': args, 'values': values};
    var widget_html = server.get_widget(bvr.class_name, kwargs);

    // replace the popup html
    spt.behavior.replace_inner_html( popup, widget_html );
    spt.popup.open( bvr.args.popup_id );
    return popup;
}


spt.dg_table_action.set_actionbar_aux_content = function( evt, bvr )
{
    //var aux_div = $("ActionBar_Aux");
    //var aux_content = $("ActionBar_Aux_Content");
    //var aux_title = $("ActionBar_Aux_Title");
    //
    var table_id = bvr.args['table_id'];
    var table = $(table_id);
    var table_top = table.getParent(".spt_table_top")

    var aux_div = table_top.getElement(".spt_table_aux")
    var aux_title = table_top.getElement(".spt_table_aux_title")
    var aux_content = table_top.getElement(".spt_table_aux_content")
    
    arg_dict = {};
    for ( i in bvr.args )
    {
        // insert some table related args into the dict
        if (i=='table_id')
        {
            var table_id = bvr.args['table_id'];
            var table = $(table_id);
            if (table)
            {
                var view = table.getProperty("spt_view");
                var search_type = table.getProperty("spt_search_type");
                arg_dict['search_type'] = search_type;
                arg_dict['view'] = view;
                arg_dict['selected_search_keys'] = spt.dg_table.get_selected_search_keys(table_id).join(',');
            }
        }
        arg_dict[i] = bvr.args[i];
    }
 
    spt.panel.load(aux_content, bvr.class_name, arg_dict, [], true);
    arg_dict['is_aux_title'] ='true';
    spt.panel.load(aux_title, bvr.class_name, arg_dict, [], false);
    aux_div.setStyle("display", "block");
    aux_div.setStyle("visibility", "visible");
    
    
    spt.ctx_menu.clear();
}


spt.dg_table_action.get_popup_wdg2 = function( evt, bvr )
{
    // get the common popup, clone it and fill it in
    var container = $("popup_container");
    var popup = $("popup_template");
    var clone = spt.behavior.clone(popup);

    clone.setAttribute("id", "whatever");
    container.appendChild(clone);


    // get the title
    var title = bvr.title;
    var width = bvr.width;
    var height = bvr.height;
    var class_name = bvr.class_name;

    // use a dst el to put this under
    var dst_el = bvr.dst_el;


    var server = TacticServerStub.get();
    var kwargs = {'args': bvr.args};
    var widget_html = server.get_widget(bvr.class_name, kwargs);

    // get the content container
    var content_wdg = clone.getElement(".spt_popup_content");
    var width_wdg = clone.getElement(".spt_popup_width");
    if (width != null) {
        width_wdg.setStyle("width", width);
    }
    if (height != null) {
        width_wdg.setStyle("height", height);
    }

    // replace the title
    if (title != null) {
        var title_wdg = clone.getElement(".spt_popup_title");
        spt.behavior.replace_inner_html( title_wdg, title );
    }
 
    // replace the popup html
    spt.behavior.replace_inner_html( content_wdg, widget_html );

    // display the clone
    clone.setStyle("display", '');
}



spt.dg_table_action.csv_export = function( evt, bvr )
{

    var project = spt.Environment.get().get_project();
    var site = spt.Environment.get().get_site();
    var my_search_type = bvr.search_type;
    var my_is_export_all = bvr.is_export_all;
    var filename = my_search_type.replace(/[\/\?\=]/g,"_") + "_" + bvr.view + ".csv";
    var class_name = "pyasm.widget.CsvDownloadWdg";
    var column_name_vals = spt.api.Utility.get_input_values('csv_export_table', 'input[name=' + bvr.column_names+']');
    var selected_search_keys = '';
    if (my_is_export_all != 'true')
        selected_search_keys = bvr.search_keys;
    
    var column_names = column_name_vals[bvr.column_names];
    var no_column_name = true;
    
    for (var k=0;  k<column_names.length; k++){
        if(column_names[k] != '') {
            no_column_name = false;
            break;
        }
    }
    var my_include_id = spt.api.Utility.get_input('csv_export_action', 
        'include_id').checked;
     
    if ( no_column_name && !my_include_id) {
        alert('Please select at least 1 column or just the "Include ID" checkbox')
        return;
    }
   
    
    var options = {
        search_type: my_search_type,
        view: bvr.view,
        filename: filename,
        column_names: column_names,
        search_keys: selected_search_keys,
        include_id: my_include_id 
    };
    var popup = bvr.src_el.getParent('.spt_popup');
    // this is assgined in spt.dg_table.gear_smenu_export_cbk 
    var values = popup.values_dict;
    
    var server = TacticServerStub.get();
   
   
    var kwargs = {'args': options, 'values': values};
    var rtn_file_name = '';
    try {
        rtn_file_name = server.get_widget(class_name, kwargs);
    } catch(e) {
        spt.error(spt.exception.handler(e));
        return;
    }
    if (rtn_file_name.length > 200 ) {
        spt.alert("Error exporting one of the widgets:\n" + rtn_file_name, {type: 'html'} );
        return;
    }
        
    var csv_file_name = encodeURIComponent(rtn_file_name);
    var param_dict = {};
    class_name = "pyasm.widget.CsvGenerator";
    param_dict['dynamic_file'] = "true";
    param_dict['widget'] = class_name;
    param_dict['filepath'] = csv_file_name;
    var url = spt.Environment.get_widget_server_url(project, param_dict);

    if (site != "default")
    {
        url = url.split('/')
        url.splice(4, 0, site);
        url = url.join('/');
    }
    
    document.location = url;

}






// This is a convenience method which sets the row to be commitable
//
spt.dg_table_action.set_commitable = function(top_el, value_wdg) {
    // Utilize edit cell keyboard handler call-back mechanism to do all the modified field goodness
    // (e.g. turning row green) ... TODO: refactor this mechanism to pull out common functionality
{'fraction_non_alphanumeric': 0.15521958243340533, 'fraction_numerical': 0.002663786897048236, 'mean_word_length': 2.3609968545850473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6121053', 'n_tokens_mistral': 4615, 'n_tokens_neox': 4487, 'n_words': 968}