package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
HTML::Mason::Exception::Params->throw
    ( error =>
      "Odd number of parameters passed to component expecting name/value pairs"
    ) if @_ % 2;
my ( $user_id, @programs, @locations, @roles, $odk_service );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }
#line 3 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
     $user_id = exists $pos{'user_id'} ? $_[ $pos{'user_id'} ] :  undef;
#line 4 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
     @programs = exists $pos{'programs'} ? HTML::Mason::Tools::coerce_to_array( $_[ $pos{'programs'} ], '@programs') :  ();
#line 5 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
     @locations = exists $pos{'locations'} ? HTML::Mason::Tools::coerce_to_array( $_[ $pos{'locations'} ], '@locations') :  ();
#line 6 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
     @roles = exists $pos{'roles'} ? HTML::Mason::Tools::coerce_to_array( $_[ $pos{'roles'} ], '@roles') :  ();
#line 7 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
     $odk_service = exists $pos{'odk_service'} ? $_[ $pos{'odk_service'} ] :  undef;
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 1 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 9 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 10 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/util/import_javascript.mas', classes => [ 'jquery.iframe-post-form','CXGN.BreedersToolbox.Crosses', 'jstree.dist.jstree', 'CXGN.TrialTreeFolders']   
); #line 10 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '

' );
#line 12 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/util/import_css.mas', paths => ['/static/documents/inc/jstree_theme/jstree-bstheme-min.css']   
); #line 12 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '

' );
#line 14 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
 if ($odk_service eq 'ONA') {
$m->print( '    ' );
#line 15 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/cross/cross_wishlist.mas'  
); #line 15 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 16 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
}
$m->comp(   '/breeders_toolbox/cross/add_cross_dialogs.mas', programs=>\@programs, locations=>\@locations   
); #line 17 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 18 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/cross/upload_crosses_dialogs.mas', programs=>\@programs, locations=>\@locations   
); #line 18 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 19 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/cross/add_crossing_trial_dialogs.mas', programs=>\@programs, locations=>\@locations   
); #line 19 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 20 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/folder/folder_set.mas', project_type=>'crossing_experiment'   
); #line 20 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 21 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/folder/folder_new.mas', project_type=>'crossing_experiment'   
); #line 21 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 22 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/folder/folder_move.mas', project_type=>'crossing_experiment'   
); #line 22 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '
' );
#line 23 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->comp(   '/breeders_toolbox/folder/folders_edit.mas', folder_tree_type => 'Cross', folder_tree_identifier => 'crosses_list', folder_tree_refresh_name => 'refresh_crosses_jstree_html'   
); #line 23 "/home/production/cxgn/sgn/mason/breeders_toolbox/crossing_experiment_tree.mas"
$m->print( '

<table class="table table-bordered">
    <thead>
        <tr>
            <th>Information</th>
            <th>Breeding Programs -- Folders -- Crossing Experiments&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-default" id="refresh_crosses_jstree_html_trialtree_button" name="refresh_crosses_jstree_html">Refresh</button></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <h4>Search</h4>
                <input type="text" class="form-control input-sm" id="cross_tree_search" placeholder="Search" />
                <hr>

                <h5><i>Double click<br />crossing experiment (&nbsp;<span class="glyphicon glyphicon-grain text-success"></span>&nbsp;) or folder (&nbsp;<span class="glyphicon glyphicon-folder-open text-danger"></span>&nbsp;)<br/>to view detail page.</i></h5>
                <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
                <hr>

                <h4>Folders</h4>
                <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
                <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move crossing experiment(s) to folder</button><br/><br/>
                <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>

                <div id="folder_edit_options" style="display:none">
                    <hr>
                    <h5><i>Select multiple folders by holding \'Ctrl\'.</i></h5>
                    <button class="btn btn-primary" id="edit_folders_button" title="First Select Folder(s) to Edit">Edit Folder(s)</button>
                    <br/>
                </div>

                <!--<button id="delete" disabled="disabled" >Delete</button -->
                <br />
            </td>
            <td>
                <div id="crosses_list" >[loading...]</div>
            </td>
        </tr>
    </tbody>
</table>


<script>

jQuery.noConflict();

jQuery(document).ready(function($) {

    jQuery(\'#crosses_datatable\').DataTable({
        destroy: true,
        scrollY:        \'30vh\',
            scrollCollapse: true,
            paging:         false,
    });

    jQuery.ajax( {
      url: \'/ajax/breeders/get_trials_with_folders_cached?type=cross\',
      success: function(response) {
        var html = \'<ul>\'+response.html+\'</ul>\';

        jQuery(\'#crosses_list\').html(html);
        //console.log(html);
        jQuery(\'#crosses_list\').jstree( {
            "core": { \'themes\': { \'name\': \'proton\', \'responsive\': true}},
            "valid_children" : [ "folder", "trial", "breeding_program" ],
            "types" : {
                "breeding_program" : {
                    "icon": \'glyphicon glyphicon-briefcase text-info\',
                },
                "folder" : {
                    "icon": \'glyphicon glyphicon-folder-open text-danger\',
                },
                "cross" : {
                    "icon": \'glyphicon glyphicon-grain text-success\',
                }
            },
            "search" : {
                 "case_insensitive" : true,
             },
          "plugins" : ["html_data","types","search"],

        });

      },
      error: function(response) {
        alert("An error occurred while loading the trial data.");
      }
  });

    jQuery("#cross_tree_search").keyup(function() {
        var v = jQuery("#cross_tree_search").val();
        jQuery("#crosses_list").jstree(true).search(v);
    });

    jQuery(\'#crosses_list\').on("changed.jstree", function (e, data) {
        //console.log(data);
        if ($(\'#trial_list\').jstree(\'is_leaf\', data.node) && data.node.data.jstree.type == \'folder\') {
            jQuery("#folder_edit_options").show();
        }
        else {
            jQuery("#folder_edit_options").hide();
        }
    });

    jQuery("#crosses_list").delegate("li", "dblclick", function(event){
        var node = $("#crosses_list").jstree("get_node", this);
        //console.log(node);
        if (node.id.substr(0,1) !== \'j\') {
            if (node.type == \'folder\') {
                window.open(\'/folder/\'+node.id);
                event.stopPropagation();
            } else if (node.type == \'cross\') {
                window.open(\'/breeders_toolbox/trial/\'+node.id);
                event.stopPropagation();
            }
        }
    });

});

</script>
' );
;return;
},
'declared_args' => {
  '$odk_service' => { default => ' undef' },
  '$user_id' => { default => ' undef' },
  '@locations' => { default => ' ()' },
  '@programs' => { default => ' ()' },
  '@roles' => { default => ' ()' }
},
'load_time' => 1763180866,

)
;