<commit_before><%@taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="laf" tagdir="/WEB-INF/tags/laf"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="commons" uri="http://bioinformatics.northwestern.edu/taglibs/commons" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<tags:javascriptLink name="psc-tools/misc"/>

<tags:stylesheetLink name="yui-sam/2.7.0/datatable"/>
<%-- TODO: move common YUI parts to a tag if they are re-used --%>
<c:forEach items="${fn:split('yahoo-dom-event element-min datasource-min logger-min json-min connection-min get-min datatable-min', ' ')}" var="script">
   <tags:javascriptLink name="yui/2.7.0/${script}"/>
</c:forEach>

<html>
  <head>
      <title>Study Manipulations</title>
      <tags:includeScriptaculous/>

    <style type="text/css">
      div.submit {
          text-align: center;
      }

      .bundle-list {
          padding-top:5em;
          padding-left:1em;
      }

      .selectedInfo {
          padding: 1em;
      }

      .myLi {
          list-style-type: none;
          padding: 0 0 5px 0;
      }

      .myUl {
          margin: 0 0 0 9em;
          padding: 0;
      }

    </style>
    <script type="text/javascript">
        var studyAutocompleter;
        var bundleList;


        function createStudyAutocompleter() {
            studyAutocompleter = new SC.FunctionalAutocompleter(
                'study-autocompleter-input', 'study-autocompleter-div', studyAutocompleterChoices, {
                select: "subjects-name",
                afterUpdateElement: function(input, selected) {
                    input.value = ""
                    input.focus()
                }
            });
        }


        function studyAutocompleterChoices(str, callback) {
            var searchString = $F("study-autocompleter-input")
            if (searchString == "Search for study") {
                searchString = ""
            }

            var uri = SC.relativeUri("/api/v1/provided-studies")
            if (searchString.blank()) {
                return;
            }

            var params = {};
            if (!searchString.blank()) {
                params.q = searchString;
            }

            SC.asyncRequest(uri+".json", {
                method: "GET", parameters: params,
                onSuccess: function(response) {
                    var bundleListColumns = [
                        { key: "long_title", label: "Long Title", sortable: true , formatter:longTitleFormatter},
                        { key: "assigned_identifier", label: "Assigned Identifier", sortable: true },
                        { key: "provider", label:"Provider", sortable:true},
                        { key: "secondary_identifiers", label: "Secondary Identifier", sortable: true, formatter: secondaryIdentifierFormatter},
                        { key: "button", label:"Show record data", formatter:myButtonFormatter}
                    ];

                    var myDataSource = new YAHOO.util.DataSource(response.responseJSON);
                    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;

                    myDataSource.responseSchema = {
                        resultsList : "studies",
                        fields : [
                            { key: "long_title", formatter:longTitleFormatter},
                            { key: "assigned_identifier"},
                            { key: "provider"},
                            { key: "secondary_identifiers", formatter: secondaryIdentifierFormatter},
                            { key: "button", label:"Show record data", formatter:myButtonFormatter}
                        ]
                    };

                    bundleList = new YAHOO.widget.DataTable("bundle-list", bundleListColumns, myDataSource);
                }
            })
        }

        var myButtonFormatter = function (elCell, oRecord, oCollumn, oData) {
            var container = jQuery('<div class="row" />')
            var divSubmit = jQuery('<div class="submit" />')
            var submitButton = jQuery('<input type="submit" value="Assign" />')

            divSubmit.append(submitButton);
            container.append(divSubmit);


            jQuery(elCell).append(container);
            YAHOO.util.Event.addListener( submitButton, "click", myClickHandler, oRecord);
        }

        var myClickHandler = function(event, oRecord){
            var assignedId = oRecord.getData('assigned_identifier');
            var provider = oRecord.getData('provider');
            var secondaryIds = oRecord.getData('secondary_identifiers');
            var studyIdentifier = "${study.assignedIdentifier}";

            var text1 = "<p class='selectedInfo'> You picked '" + assignedId + "' from '" + provider + "'. <br> Pick the identifier to use with this study in PSC: <br>";
            var container = jQuery('#edit-notes-lightbox');

            container.empty();

            container.append(jQuery('<h1> Assigning new study identifier </h1> '))

            var input1 = jQuery('<input class="radio" type="radio" name="group" checked value="' + studyIdentifier +'" >' )
            var input2 = jQuery('<input class="radio" type="radio" name="group" value="' + assignedId + '">')

            YAHOO.util.Event.addListener( input1, "click", function(e){
                input1.checked = true;
            });

            YAHOO.util.Event.addListener( input2, "click", function(e){
                input2.checked = true;
            });

            var keepStudyId = "Keep <b>" + studyIdentifier + "</b>"
            var keepAssignedId = "Use <b>" + assignedId + "</b> (suggested by provider)"

            var divRow1 = jQuery('<div class="row"/>')
            var divLabel1 = jQuery('<div class="label"/>')
            var divValue1 = jQuery('<div class="value"/>')

            divLabel1.append(input1);<commit_msg>Commit for #811 - Added UI corrections for the lightbox and datatable.<commit_after><%@taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="laf" tagdir="/WEB-INF/tags/laf"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="commons" uri="http://bioinformatics.northwestern.edu/taglibs/commons" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<tags:javascriptLink name="psc-tools/misc"/>

<tags:stylesheetLink name="yui-sam/2.7.0/datatable"/>
<%-- TODO: move common YUI parts to a tag if they are re-used --%>
<c:forEach items="${fn:split('yahoo-dom-event element-min datasource-min logger-min json-min connection-min get-min datatable-min', ' ')}" var="script">
   <tags:javascriptLink name="yui/2.7.0/${script}"/>
</c:forEach>

<html>
  <head>
      <title>Study Manipulations</title>
      <tags:includeScriptaculous/>

    <style type="text/css">
      div.submit {
          text-align: center;
      }

      .bundle-list {
          padding-top:5em;
          padding-left:1em;
      }

      .selectedInfo {
          padding: 1em;
      }

      .myLi {
          list-style-type: none;
          padding: 0 0 5px 0;
      }

      .myUl {
          margin: 0 0 0 9em;
          padding: 0;
      }

      .lightBoxContentRow {
          padding:1em;
      }

    </style>
    <script type="text/javascript">
        var studyAutocompleter;
        var bundleList;


        function createStudyAutocompleter() {
            studyAutocompleter = new SC.FunctionalAutocompleter(
                'study-autocompleter-input', 'study-autocompleter-div', studyAutocompleterChoices, {
                select: "subjects-name",
                afterUpdateElement: function(input, selected) {
                    input.value = ""
                    input.focus()
                }
            });
        }


        function studyAutocompleterChoices(str, callback) {
            var searchString = $F("study-autocompleter-input")
            if (searchString == "Search for study") {
                searchString = ""
            }

            var uri = SC.relativeUri("/api/v1/provided-studies")
            if (searchString.blank()) {
                return;
            }

            var params = {};
            if (!searchString.blank()) {
                params.q = searchString;
            }

            SC.asyncRequest(uri+".json", {
                method: "GET", parameters: params,
                onSuccess: function(response) {
                    var bundleListColumns = [
                        { key: "long_title", label: "Long Title", sortable: true , formatter:longTitleFormatter},
                        { key: "assigned_identifier", label: "Assigned Identifier", sortable: true },
                        { key: "provider", label:"Provider", sortable:true},
                        { key: "secondary_identifiers", label: "Secondary Identifier", sortable: true, formatter: secondaryIdentifierFormatter},
                        { key: "button", label: "", formatter:myButtonFormatter}
                    ];

                    var myDataSource = new YAHOO.util.DataSource(response.responseJSON);
                    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;

                    myDataSource.responseSchema = {
                        resultsList : "studies",
                        fields : [
                            { key: "long_title", formatter:longTitleFormatter},
                            { key: "assigned_identifier"},
                            { key: "provider"},
                            { key: "secondary_identifiers", formatter: secondaryIdentifierFormatter},
                            { key: "button", label: "", formatter:myButtonFormatter}
                        ]
                    };

                    bundleList = new YAHOO.widget.DataTable("bundle-list", bundleListColumns, myDataSource);
                }
            })
        }

        var myButtonFormatter = function (elCell, oRecord, oCollumn, oData) {
            var container = jQuery('<div class="row" />')
            var divSubmit = jQuery('<div class="submit" />')
            var submitButton = jQuery('<input type="submit" value="Associate" />')

            divSubmit.append(submitButton);
            container.append(divSubmit);


            jQuery(elCell).append(container);
            YAHOO.util.Event.addListener( submitButton, "click", myClickHandler, oRecord);
        }

        var myClickHandler = function(event, oRecord){
            var assignedId = oRecord.getData('assigned_identifier');
            var provider = oRecord.getData('provider');
            var secondaryIds = oRecord.getData('secondary_identifiers');
            var studyIdentifier = "${study.assignedIdentifier}";
            var longTitle = oRecord.getData('long_title');

            var text1 = "<p class='selectedInfo'> You picked '" + assignedId + "' from '" + provider + "'. <br> Pick the identifier to use with this study in PSC: <br>";
            var container = jQuery('#edit-notes-lightbox');

            container.empty();

            container.append(jQuery('<h1>Associate with ' + assignedId + '</h1> '))

            var divRow = jQuery('<div class="lightBoxContentRow" />')
            divRow.append('You are associating this template with ' + assignedId +' using provider ' + provider+ '. That study\'s title is: \"' + longTitle +
                                 '\".<p>Do you want to change the visible identifier for the template at the same time?')
            container. append(divRow);

            
            var input1 = jQuery('<input class="radio" type="radio" name="group" checked value="' + studyIdentifier +'" >' )
            var input2 = jQuery('<input class="radio" type="radio" name="group" value="' + assignedId + '">')

            YAHOO.util.Event.addListener( input1, "click", function(e){
                input1.checked = true;
            });

            YAHOO.util.Event.addListener( input2, "click", function(e){
                input2.checked = true;
            });

            var keepStudyId = "Keep <b>" + studyIdentifier + "</b>"
            var keepAssignedId = "Use <b>" + assignedId + "</b> (suggested by provider)"

            var divRow1 = jQuery('<div class="row"/>')
            var divLabel1 = jQuery('<div class="label"/>')
            var divValue1 = jQuery('<div class="value"/>')

            divLabel1.append(input1);
{'fraction_non_alphanumeric': 0.13479525269197518, 'fraction_numerical': 0.0055018470486520475, 'mean_word_length': 1.950834879406308, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1562789', 'n_tokens_mistral': 3568, 'n_tokens_neox': 3363, 'n_words': 714}