<commit_before><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

    <h:head>
    </h:head>

    <h:body> 
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{DatasetPage.editMode == 'CREATE' ? 'Add New Dataset' : DatasetPage.displayVersion.title} - #{DatasetPage.dataset.owner.name}"/>
            <ui:param name="dataverse" value="#{DatasetPage.dataset.owner}"/>
            <ui:param name="dataset" value="#{DatasetPage.dataset}"/>
            <ui:param name="version" value="#{DatasetPage.displayVersion}"/>
            <ui:param name="showBreadcrumbs" value="#{empty DatasetPage.editMode}"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:define name="body">
                <script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="<KEY>"/>
                <script type="text/javascript">                    
                    function openDropboxChooser() {
                        options = {
                            // Required. Called when a user selects an item in the Chooser.
                            success: function(files) {
                                // Pass the JSON-ized output of the Chooser to the backing bean,
                                // via a hidden input field: 
                                $('input[id$="dropBoxSelectionInput"]').val(JSON.stringify(files));
                                //alert(JSON.stringify(files));
                                // Trigger the upload processing method in the backing
                                // bean, via an invisible commandButton: 
                                $('button[id$="dropBoxButton"]').trigger('click');
                                
                            },
                            linkType: "direct",
                            multiselect: true,

                        };
                        Dropbox.choose(options);
                    }
                </script>
                
                <f:metadata>
                    <f:viewParam name="id" value="#{DatasetPage.dataset.id}"/>
                    <f:viewParam name="ownerId" value="#{DatasetPage.ownerId}"/>
                    <f:viewParam name="versionId" value="#{DatasetPage.versionId}"/>
                    <f:viewAction action="#{DatasetPage.init}" />
                </f:metadata>

                <h:form id="datasetForm">

                    <!-- Header / Button Panel -->
                    <ui:fragment>

                        <!-- View mode -->
                        <ui:fragment rendered="#{empty DatasetPage.editMode}">
                            <div id="topDatasetBlock">
                                <div id="actionButtonBlock" class="clearfix" style="margin-bottom:.55em;">
                                   <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                            and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                            and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <div class="btn-group">
                                                <button type="button" id="editDataSet" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span class="glyphicon glyphicon-pencil" style="margin-right:.3em;"/> Edit Dataset <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu pull-right" role="menu" style="text-align:left;">
                                                    <li>
                                                        <p:commandLink id="editFiles" actionListener="#{DatasetPage.edit('FILE')}" update="@form" oncomplete="javascript:post_edit_files()">
                                                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                            <h:outputText value="Files (Upload + Edit)" />
                                                        </p:commandLink>   
                                                    </li>
                                                    <li>
                                                        <p:commandLink id="editMetadata" actionListener="#{DatasetPage.edit('METADATA')}" update="@form" oncomplete="javascript:post_edit_metadata()">
                                                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                            <h:outputText value="Metadata" />
                                                        </p:commandLink>   
                                                    </li>
                                                    <!--<li><a href="#" class="ui-commandlink ui-widget" style="pointer-events: none; color: grey;">Permissions</a></li>-->
                                                </ul>
                                            </div>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('ReleaseDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <ui:fragment rendered="#{!DatasetPage.dataset.released and DatasetPage.dataset.latestVersion.versionState=='DRAFT' and DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="confirmation.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>                                            
                                            <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.dataset.latestVersion.versionState=='DRAFT' and DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="releaseDraft.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.versionState=='DRAFT' and !DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="mayNotRelease.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>
                                        </div>
                                        <p:confirmDialog message="Are you sure you want to publish your dataset? Once you do so it must remain 'Published'." header="Publish Dataset" widgetVar="confirmation">  
                                            <p:commandButton value="Continue" onclick="confirmation.hide()" action="#{DatasetPage.releaseDataset}">
                                            </p:commandButton>  
                                            <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />   
                                        </p:confirmDialog>
                                        <p:confirmDialog message="Are you sure you want to republish your dataset?" header="Publish Dataset" widgetVar="releaseDraft">  
                                            <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.minorUpdate}">
                                                Select version number:
                                                <p:selectOneRadio id="options" value="#{DatasetPage.releaseRadio}">  
                                                    <f:selectItem itemLabel="Major Release (#{DatasetPage.datasetNextMajorVersion})" itemValue="1" />  
                                                    <f:selectItem itemLabel="Minor Release (#{DatasetPage.datasetNextMinorVersion})" itemValue="2" />   
                                                </p:selectOneRadio>  
                                            </ui:fragment> 
                                            <ui:fragment rendered="#{!DatasetPage.dataset.latestVersion.minorUpdate}">
                                                Due to the nature of changes to the current draft this will be a major release (#{DatasetPage.datasetNextMajorVersion})
                                            </ui:fragment> 
                                            <p:commandButton value="Continue" onclick="releaseDraft.hide()" action="#{DatasetPage.releaseDraft}">
                                            </p:commandButton>  
                                            <p:commandButton value="Cancel" onclick="releaseDraft.hide()" type="button" />   
                                        </p:confirmDialog>
                                        <p:confirmDialog message="This dataset may not be published because its host dataverse has not been published." header="May not publish" widgetVar="mayNotRelease">
                                        </p:confirmDialog>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.draft and DatasetPage.displayVersion != DatasetPage.dataset.latestVersion
                                                       and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <h:outputLink styleClass="btn btn-warning" value="/dataset.xhtml?id=#{DatasetPage.dataset.id}&#38;versionId=#{DatasetPage.dataset.latestVersion.id}">
                                                <h:outputText value="View Unpublished Version"/>
                                            </h:outputLink>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.displayVersion != DatasetPage.dataset.releasedVersion}">
                                        <div style="float:right; margin-left:1em;">
                                            <h:outputLink styleClass="btn btn-primary" value="/dataset.xhtml?id=#{DatasetPage.dataset.id}">
                                                <h:outputText value="View Published Version"/>
                                            </h:outputLink>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{empty DatasetPage.editMode}">
                                        <div style="float:right;">
                                            <button type="button" class="btn btn-default" onclick="contact_confirmation.show()">
                                                <span class="glyphicon glyphicon-envelope" style="margin-right:.3em;"/> Email Dataset Contact
                                            </button>
                                        </div>
                                    </ui:fragment>
                                    <p:confirmDialog message="Dataverse 4.0 Beta cannot email dataset contacts. Look for this feature in Dataverse 4.0!" header="Email Dataset Contact" widgetVar="contact_confirmation">                                           
                                    </p:confirmDialog>
                                </div>
                                <div id="datasetVersionBlock">
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.title.value}">
                                        <span id="title">#{DatasetPage.datasetVersionUI.title.value}</span>
                                        <h:outputText value="Draft" styleClass="label label-warning" style="margin-left:1em;vertical-align:text-top;" rendered="#{DatasetPage.displayVersion.draft}"/>
                                        <h:outputText value="Unpublished" styleClass="label label-danger" style="margin-left:1em;vertical-align:text-top;" rendered="#{!DatasetPage.dataset.released}"/>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.displayCitation}">
                                        <div id="citation">
                                            <span>#{DatasetPage.displayCitation}</span> 
                                            <ui:fragment rendered="#{!DatasetPage.dataset.released}">
                                                <span class="glyphicon glyphicon-question-sign text-primary" style="cursor:pointer; cursor:hand;" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-original-title="DRAFT VERSION will be replaced in the citation with V1 once the dataset has been published."></span>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.displayVersion.draft}">
                                                <span class="glyphicon glyphicon-question-sign text-primary" style="cursor:pointer; cursor:hand;" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-original-title="DRAFT VERSION will be replaced in the citation with the selected version once the dataset has been published."></span>
                                            </ui:fragment>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.description.value}">
                                        <span id="description">#{DatasetPage.datasetVersionUI.description.value}</span>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.keyword.value or !empty DatasetPage.datasetVersionUI.subject.value or !empty DatasetPage.datasetVersionUI.relPublicationCitation or !empty DatasetPage.datasetVersionUI.notes.value}">
                                        <div class="panel panel-default" style="margin-top:1em;">
                                            <div class="panel-body">
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.keyword.value}">
                                                    <span id="keywords">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.keyword.datasetFieldType.description}" title="" style="margin-right:1em;">Keyword(s)</a>
                                                        #{DatasetPage.datasetVersionUI.keyword.displayValue}
                                                    </span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.subject.value}">
                                                    <span id="subject">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.subject.datasetFieldType.description}" title="" style="margin-right:1em;">Subject(s)</a>
                                                        #{DatasetPage.datasetVersionUI.subject.displayValue}
                                                    </span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.relPublicationCitation}">
                                                    <span id="publication">Related Publication: #{DatasetPage.datasetVersionUI.relPublicationCitation} #{DatasetPage.datasetVersionUI.relPublicationId}  <a href="#{DatasetPage.datasetVersionUI.relPublicationUrl}" target="_blank">#{DatasetPage.datasetVersionUI.relPublicationUrl}</a></span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.notes.value}">
                                                    <span id="note">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.notes.datasetFieldType.description}" title="" style="margin-right:1em;">Notes</a>
                                                        <div>
                                                            #{DatasetPage.datasetVersionUI.notes.value}
                                                        </div>
                                                    </span>
                                                </ui:fragment>
                                            </div>
                                        </div>
                                    </ui:fragment>
                                </div>
                            </div>
                        </ui:fragment>

                        <!-- Create mode -->
                        <ui:fragment rendered="#{DatasetPage.editMode == 'METADATA' or DatasetPage.editMode == 'CREATE'}">
                            <div class="form-group">
                                <label for="select_HostDataverse" class="col-sm-2 control-label">
                                    <a href="#" data-toggle="tooltip" data-placement="auto right" class="tooltiplabel right" data-original-title="The Dataverse which contains this data.">Host Dataverse</a>
                                </label>
                                <div class="col-sm-10">
                                   
                                    <h:outputText value="#{ DatasetPage.dataset.owner.name }" style="font-weight:bold;"/>
                                    <h:inputHidden value="#{DatasetPage.ownerId}" id="select_HostDataverse" />
                                     
                                     <ui:remove><!-- removed for beta -->
                                    <p:selectOneMenu id="select_HostDataverse" value="#{DatasetPage.ownerId}" filter="true" filterMatchMode="startsWith" effect="none">
                                        <f:selectItems value="#{dataverseServiceBean.findAll()}" var="dv" itemLabel="#{dv.name}" itemValue="#{dv.id}"/>
                                    </p:selectOneMenu>
                                     </ui:remove>
                                </div>
                            </div>
                        </ui:fragment>
                        <ui:fragment rendered="#{DatasetPage.editMode == 'CREATE'}">
                            <ui:include src="metadataFragment.xhtml"/>
                        </ui:fragment>
                    </ui:fragment>

                    <!-- Tabs -->
                    <ui:fragment rendered="#{DatasetPage.editMode != 'INFO'}">
                        <div id="contentTabs">
                            <ui:fragment rendered="#{empty DatasetPage.editMode}">
                                <p:commandButton id="refreshButton" widgetVar="refreshButton" actionListener="#{DatasetPage.refresh}" update="@all" style="display:none"/>
                                <script type="text/javascript">
                                    function updateFilesTable(facesmessage) {
                                        $('button[id$="refreshButton"]').trigger('click');
                                    }
                                </script>
                                <p:socket channel="/ingest#{dataset.id}" onMessage="updateFilesTable" autoConnect="true">
                                    <p:ajax event="message" update="@all" />
                                </p:socket>
                            </ui:fragment>
                            <p:tabView id="tabView" widgetVar="content" activeIndex="#{DatasetPage.selectedTabIndex}">
                                <p:tab id="dataFilesTab" title="Files" rendered="#{(empty DatasetPage.editMode or DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}" >
                                    <!-- Upload -->
                                    <!--<p:message for="fileUpload" showDetail="true"/>-->
                                    <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                        <ui:fragment rendered="#{DatasetPage.editMode == 'CREATE'}">
                                            <div class="alert alert-info">
                                                Tip: You can drag and drop your files from your desktop, directly into the upload widget.
                                            </div>
                                        </ui:fragment>
                                        <p:fileUpload id="fileUpload" dragDropSupport="true" auto="true" multiple="true" rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}"
                                                  fileUploadListener="#{DatasetPage.handleFileUpload}" process="filesTable" update="filesTable" label="Select Files to Add"/> 
                                                                   
                                        <h:inputText id="dropBoxSelectionInput" style="display:none" value="#{DatasetPage.dropBoxSelection}"/>
                                        <p:commandButton id="dropBoxButton" actionListener="#{DatasetPage.handleDropBoxUpload}" update="@all" style="display:none">
                                        </p:commandButton>
                                        <div style="margin:1em 0;">
                                            <p:commandButton value="Upload from Dropbox" onclick="openDropboxChooser();" icon="dropin-btn-status" />
                                            <p class="help-block">You can also upload your files directly from your Dropbox.</p>
                                        </div>
                                    </ui:fragment>
                                    <!-- View -->
                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div class="containder" style="text-align:right; margin-bottom:.5em;">
                                            <p:commandLink style="color:black;" styleClass="btn btn-default" title="Upload + Edit Files" actionListener="#{DatasetPage.edit('FILE')}" update="@form" oncomplete="javascript:post_edit_files()">
                                                <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                <span class="glyphicon glyphicon-plus" style="margin-right:.3em;"/> Upload + Edit Files
                                            </p:commandLink>
                                        </div>
                                        <!--<p class="bg-info" style="padding:1em; margin-right:200px;">
                                            <h:outputText value="Use the Edit Dataverse button to edit or add metadata to this dataset." />
                                        </p>-->
                                    </ui:fragment>
                                    <p:dataTable id="filesTable" value="#{empty DatasetPage.editMode ? DatasetPage.displayVersion.fileMetadatas : DatasetPage.dataset.latestVersion.fileMetadatas}" var="fileMetadata">
                                        <p:column styleClass="col-xs-1" style="text-align:center;">

                                            <ui:fragment rendered="#{!empty fileMetadata.dataFile.id and fileMetadata.dataFile.image}">
                                                <a class="imageThumbPreview" data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-html="true" data-content="&lt;img src=&#34;/api/access/datafile/#{fileMetadata.dataFile.id}?imageThumb=400&#34; alt=&#34;Preview: #{fileMetadata.label}&#34; /&gt;">
                                                    <p:graphicImage value="/api/access/datafile/#{fileMetadata.dataFile.id}?imageThumb=true"/>
                                                </a>
                                            </ui:fragment>

                                            <p:graphicImage value="/resources/images/icon_file.png" rendered="#{!fileMetadata.dataFile.image}"/>

                                            <ui:fragment rendered="#{empty fileMetadata.dataFile.id and !empty fileMetadata.dataFile.fileSystemName and fileMetadata.dataFile.image}">
                                                <p:graphicImage value="/api/access/imagethumb/#{fileMetadata.dataFile.fileSystemName}?mimetype=#{fileMetadata.dataFile.contentType}"/>
                                                <h:outputText id="imgPreview" value="Preview" styleClass="bg-info text-info" style="display:block;text-align:center;"/>
                                            </ui:fragment>
                                        </p:column>
                                        <p:column styleClass="col-sm-7">
                                            <h:outputText id="fileNameOutput" value="#{fileMetadata.label}" style="display:block;font-weight:bold;" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}"/>

                                            <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                                <label class="control-label" for="fileName" style="margin-right:1em;margin-bottom:.5em;">
                                                    File Name
                                                </label>
                                                <p:inputText id="fileName" value="#{fileMetadata.label}" style="margin-bottom:.5em;"/>
                                                <p:message for="fileName"/>
                                            </ui:fragment>

                                            <h:outputText id="fileTypeOutputRegular" value="#{fileMetadata.dataFile.friendlyType}#{!empty fileMetadata.dataFile.md5 ? ', ' : ''}" rendered="#{!(fileMetadata.dataFile.tabularData)}"/>
                                            <h:outputText id="fileMD5" value="MD5: #{fileMetadata.dataFile.md5}" rendered="#{!(empty fileMetadata.dataFile.md5) and !(fileMetadata.dataFile.tabularData)}"/>

                                            <h:outputText id="fileTypeOutputTabular" value="Tabular Data#{!empty fileMetadata.dataFile.unf ? ', ' : ''}" rendered="#{fileMetadata.dataFile.tabularData}"/>
                                            <h:outputText id="fileUNF" value="#{fileMetadata.dataFile.unf}" rendered="#{!empty fileMetadata.dataFile.unf}"/>

                                            <div class="fileDescription">
                                                <h:outputText id="fileDescNonEmpty" value="#{fileMetadata.description}" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE') and !(empty fileMetadata.description)}"/>
                                                <!--<h:outputText id="fileDescEmpty" value="NO DESCRIPTION AVAILABLE" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE') and (empty fileMetadata.description)}"/>-->
                                                
                                                <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                                    <label class="control-label" for="fileDescription" style="margin-right:1em; margin-top:.5em; vertical-align:top;">
                                                        Description
                                                    </label>
                                                    <p:inputTextarea  id="fileDescription" immediate="true" rows="2" cols="40" value="#{fileMetadata.description}" style="margin-top:.5em;"/>
                                                    <p:watermark for="fileDescription" value="Add file description..."/>
                                                    <p:message for="fileDescription"/>
                                                </ui:fragment>
                                            </div>
                                        </p:column>

                                        <p:column styleClass="col-sm-4" style="overflow: visible;text-align:right;" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}">
                                            <ui:fragment rendered="#{fileMetadata.dataFile.tabularData or fileMetadata.dataFile.ingestInProgress}">
                                                <h:outputLink style="margin-right:1em;color:black;font-size:1em;" class="btn btn-default #{fileMetadata.dataFile.ingestInProgress ? 'disabled' : ''}" disabled="#{fileMetadata.dataFile.ingestInProgress ? 'disabled' : ''}" title="Explore" value="/dataexplore/gui.html?dfId=#{fileMetadata.dataFile.id}" target="_blank">
                                                    <span class="glyphicon glyphicon-stats" style="margin-right:.3em;"/> <span class="ladda-label">Explore</span>
                                                </h:outputLink>
                                            </ui:fragment>

                                            <!--<ui:fragment rendered="#{fileMetadata.dataFile.ingestInProgress}">
                                                <p:graphicImage value="/resources/images/icon_inprogress.gif"/>
                                            </ui:fragment>-->

                                            <ui:fragment rendered="#{!(fileMetadata.dataFile.tabularData)}">
                                                <a class="btn btn-default" href="/api/access/datafile/#{fileMetadata.dataFile.id}" role="button" style="color:#333333;">
                                                    <span class="glyphicon glyphicon-download-alt" style="margin-right:.3em;"/> Download
                                                </a>
                                            </ui:fragment>

<!--<p:button value="Download" disabled="#{empty fileMetadata.dataFile.id}" rendered="#{empty fileMetadata.dataFile.id}"/>-->

                                            <ui:fragment rendered="#{fileMetadata.dataFile.tabularData}">
                                                <div class="btn-group">
                                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                        <span class="glyphicon glyphicon-download-alt" style="margin-right:.3em;"/> Download <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu" role="menu" style="text-align:left;">
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="As Tab-Delimited"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}?format=RData"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="As RData"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}?format=original"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="Saved Original (#{fileMetadata.dataFile.originalFormatLabel})"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/meta/datafile/#{fileMetadata.dataFile.id}"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="Variable Metadata"/>
                                                            </h:outputLink>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </ui:fragment>

                                            <ui:fragment rendered="#{fileMetadata.dataFile.ingestInProgress}">
                                                <h:outputText id="txtInprogess" value="Ingest in progress..." styleClass="bg-info text-info" style="display:block;text-align:center;"/>
                                            </ui:fragment>

                                        </p:column>
                                    </p:dataTable>
                                </p:tab>

                                <p:tab id="metadataMapTab" title="Metadata" rendered="#{empty DatasetPage.editMode or DatasetPage.editMode == 'METADATA'}">

                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div class="containder" style="text-align:right; margin-bottom:.5em;">
                                            <p:commandLink style="color:black;" styleClass="btn btn-default" title="Add + Edit Metadata" actionListener="#{DatasetPage.edit('METADATA')}" update="@form" oncomplete="javascript:post_edit_metadata()">
                                                <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                <span class="glyphicon glyphicon-pencil" style="margin-right:.3em;"/> Add + Edit Metadata
                                            </p:commandLink>
                                        </div>
                                        <!--<p class="bg-info" style="padding:1em; margin-right:200px;">
                                            <h:outputText value="Use the Edit Dataverse button to edit or add metadata to this dataset." />
                                        </p>-->
                                    </ui:fragment>
                                    <div style="clear:left;">
                                        <ui:include src="metadataFragment.xhtml"/>
                                    </div>

                                </p:tab>

                                <p:tab id="versionsTab" title="Versions" rendered="#{empty DatasetPage.editMode}">                                       
                                    <p:dataTable id="versionsTable" value="#{DatasetPage.versionTabList}" var="versionTab">                                        
                                        <p:column >
                                            <f:facet name="header">
                                                Title
                                            </f:facet>
                                            <h:link id="versionLink" styleClass="ui-commandlink ui-widget" outcome="dataset">
                                                <h:outputText value="#{versionTab.title}" />
                                                <f:param name="id" value="#{versionTab.dataset.id}" />
                                                <f:param name="versionId" value="#{versionTab.id}" />
                                            </h:link>
                                        </p:column>
                                        <p:column >
                                            <f:facet name="header">
                                                Version
                                            </f:facet>
                                            <h:outputText rendered="#{!versionTab.released}" id="versionStatusOutput" value="#{versionTab.versionState}" />
                                            <h:outputText rendered="#{versionTab.released}" id="versionNumberOutput" value="#{versionTab.versionNumber}.#{versionTab.minorVersionNumber}" />
                                        </p:column>
                                        <p:column  > 
                                            <f:facet name="header">
                                                Version Date
                                            </f:facet>
                                            <h:outputText rendered="#{versionTab.released}" id="versionDate" value="#{versionTab.versionDate}" />
                                        </p:column>
                                    </p:dataTable>
                                </p:tab>
                            </p:tabView>
                        </div>
                    </ui:fragment>

                    <!-- Create/Save Dataset Button Panel -->
                    <p:panel styleClass="panelLayoutButtonBlock" rendered="#{!empty DatasetPage.editMode}">
                        <p:commandButton id="save"  value="#{DatasetPage.editMode == 'CREATE' ? 'Add Dataset' : 'Save Changes'}" action="#{DatasetPage.save}" update="@all">
                        </p:commandButton>
                        <p:commandButton id="cancel" value="Cancel" action="#{DatasetPage.cancel}" process="@this" update="@form"  rendered="#{DatasetPage.editMode != 'CREATE'}" oncomplete="javascript:post_cancel_edit_files_or_metadata()">
                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="#{DatasetPage.editMode == 'METADATA' ? 1 : DatasetPage.selectedTabIndex}"/>
                        </p:commandButton>
                        <p:button id="cancelCreate" value="Cancel" outcome="/dataverse.xhtml?id=#{DatasetPage.ownerId}"  rendered="#{DatasetPage.editMode == 'CREATE'}" />
                    </p:panel>

                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</html>
<commit_msg>Add javascript rebinding for file upload and then cancel.  Bug #3942<commit_after><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

    <h:head>
    </h:head>

    <h:body> 
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{DatasetPage.editMode == 'CREATE' ? 'Add New Dataset' : DatasetPage.displayVersion.title} - #{DatasetPage.dataset.owner.name}"/>
            <ui:param name="dataverse" value="#{DatasetPage.dataset.owner}"/>
            <ui:param name="dataset" value="#{DatasetPage.dataset}"/>
            <ui:param name="version" value="#{DatasetPage.displayVersion}"/>
            <ui:param name="showBreadcrumbs" value="#{empty DatasetPage.editMode}"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:define name="body">
                <script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="<KEY>"/>
                <script type="text/javascript">                    
                    function openDropboxChooser() {
                        options = {
                            // Required. Called when a user selects an item in the Chooser.
                            success: function(files) {
                                // Pass the JSON-ized output of the Chooser to the backing bean,
                                // via a hidden input field: 
                                $('input[id$="dropBoxSelectionInput"]').val(JSON.stringify(files));
                                //alert(JSON.stringify(files));
                                // Trigger the upload processing method in the backing
                                // bean, via an invisible commandButton: 
                                $('button[id$="dropBoxButton"]').trigger('click');
                                
                            },
                            linkType: "direct",
                            multiselect: true,

                        };
                        Dropbox.choose(options);
                    }
                </script>
                
                <f:metadata>
                    <f:viewParam name="id" value="#{DatasetPage.dataset.id}"/>
                    <f:viewParam name="ownerId" value="#{DatasetPage.ownerId}"/>
                    <f:viewParam name="versionId" value="#{DatasetPage.versionId}"/>
                    <f:viewAction action="#{DatasetPage.init}" />
                </f:metadata>

                <h:form id="datasetForm">

                    <!-- Header / Button Panel -->
                    <ui:fragment>

                        <!-- View mode -->
                        <ui:fragment rendered="#{empty DatasetPage.editMode}">
                            <div id="topDatasetBlock">
                                <div id="actionButtonBlock" class="clearfix" style="margin-bottom:.55em;">
                                   <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                            and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                            and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <div class="btn-group">
                                                <button type="button" id="editDataSet" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span class="glyphicon glyphicon-pencil" style="margin-right:.3em;"/> Edit Dataset <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu pull-right" role="menu" style="text-align:left;">
                                                    <li>
                                                        <p:commandLink id="editFiles" actionListener="#{DatasetPage.edit('FILE')}" update="@form" oncomplete="javascript:post_edit_files()">
                                                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                            <h:outputText value="Files (Upload + Edit)" />
                                                        </p:commandLink>   
                                                    </li>
                                                    <li>
                                                        <p:commandLink id="editMetadata" actionListener="#{DatasetPage.edit('METADATA')}" update="@form" oncomplete="javascript:post_edit_metadata()">
                                                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                            <h:outputText value="Metadata" />
                                                        </p:commandLink>   
                                                    </li>
                                                    <!--<li><a href="#" class="ui-commandlink ui-widget" style="pointer-events: none; color: grey;">Permissions</a></li>-->
                                                </ul>
                                            </div>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('ReleaseDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <ui:fragment rendered="#{!DatasetPage.dataset.released and DatasetPage.dataset.latestVersion.versionState=='DRAFT' and DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="confirmation.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>                                            
                                            <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.dataset.latestVersion.versionState=='DRAFT' and DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="releaseDraft.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.versionState=='DRAFT' and !DatasetPage.dataset.owner.released }">
                                                <button type="button" class="btn btn-default" onclick="mayNotRelease.show()">
                                                    <span class="glyphicon glyphicon-globe" style="margin-right:.3em;"/> Publish Dataset
                                                </button>
                                            </ui:fragment>
                                        </div>
                                        <p:confirmDialog message="Are you sure you want to publish your dataset? Once you do so it must remain 'Published'." header="Publish Dataset" widgetVar="confirmation">  
                                            <p:commandButton value="Continue" onclick="confirmation.hide()" action="#{DatasetPage.releaseDataset}">
                                            </p:commandButton>  
                                            <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />   
                                        </p:confirmDialog>
                                        <p:confirmDialog message="Are you sure you want to republish your dataset?" header="Publish Dataset" widgetVar="releaseDraft">  
                                            <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.minorUpdate}">
                                                Select version number:
                                                <p:selectOneRadio id="options" value="#{DatasetPage.releaseRadio}">  
                                                    <f:selectItem itemLabel="Major Release (#{DatasetPage.datasetNextMajorVersion})" itemValue="1" />  
                                                    <f:selectItem itemLabel="Minor Release (#{DatasetPage.datasetNextMinorVersion})" itemValue="2" />   
                                                </p:selectOneRadio>  
                                            </ui:fragment> 
                                            <ui:fragment rendered="#{!DatasetPage.dataset.latestVersion.minorUpdate}">
                                                Due to the nature of changes to the current draft this will be a major release (#{DatasetPage.datasetNextMajorVersion})
                                            </ui:fragment> 
                                            <p:commandButton value="Continue" onclick="releaseDraft.hide()" action="#{DatasetPage.releaseDraft}">
                                            </p:commandButton>  
                                            <p:commandButton value="Cancel" onclick="releaseDraft.hide()" type="button" />   
                                        </p:confirmDialog>
                                        <p:confirmDialog message="This dataset may not be published because its host dataverse has not been published." header="May not publish" widgetVar="mayNotRelease">
                                        </p:confirmDialog>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{DatasetPage.dataset.latestVersion.draft and DatasetPage.displayVersion != DatasetPage.dataset.latestVersion
                                                       and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div style="float:right; margin-left:1em;">
                                            <h:outputLink styleClass="btn btn-warning" value="/dataset.xhtml?id=#{DatasetPage.dataset.id}&#38;versionId=#{DatasetPage.dataset.latestVersion.id}">
                                                <h:outputText value="View Unpublished Version"/>
                                            </h:outputLink>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.displayVersion != DatasetPage.dataset.releasedVersion}">
                                        <div style="float:right; margin-left:1em;">
                                            <h:outputLink styleClass="btn btn-primary" value="/dataset.xhtml?id=#{DatasetPage.dataset.id}">
                                                <h:outputText value="View Published Version"/>
                                            </h:outputLink>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{empty DatasetPage.editMode}">
                                        <div style="float:right;">
                                            <button type="button" class="btn btn-default" onclick="contact_confirmation.show()">
                                                <span class="glyphicon glyphicon-envelope" style="margin-right:.3em;"/> Email Dataset Contact
                                            </button>
                                        </div>
                                    </ui:fragment>
                                    <p:confirmDialog message="Dataverse 4.0 Beta cannot email dataset contacts. Look for this feature in Dataverse 4.0!" header="Email Dataset Contact" widgetVar="contact_confirmation">                                           
                                    </p:confirmDialog>
                                </div>
                                <div id="datasetVersionBlock">
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.title.value}">
                                        <span id="title">#{DatasetPage.datasetVersionUI.title.value}</span>
                                        <h:outputText value="Draft" styleClass="label label-warning" style="margin-left:1em;vertical-align:text-top;" rendered="#{DatasetPage.displayVersion.draft}"/>
                                        <h:outputText value="Unpublished" styleClass="label label-danger" style="margin-left:1em;vertical-align:text-top;" rendered="#{!DatasetPage.dataset.released}"/>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.displayCitation}">
                                        <div id="citation">
                                            <span>#{DatasetPage.displayCitation}</span> 
                                            <ui:fragment rendered="#{!DatasetPage.dataset.released}">
                                                <span class="glyphicon glyphicon-question-sign text-primary" style="cursor:pointer; cursor:hand;" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-original-title="DRAFT VERSION will be replaced in the citation with V1 once the dataset has been published."></span>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{DatasetPage.dataset.released and DatasetPage.displayVersion.draft}">
                                                <span class="glyphicon glyphicon-question-sign text-primary" style="cursor:pointer; cursor:hand;" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-original-title="DRAFT VERSION will be replaced in the citation with the selected version once the dataset has been published."></span>
                                            </ui:fragment>
                                        </div>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.description.value}">
                                        <span id="description">#{DatasetPage.datasetVersionUI.description.value}</span>
                                    </ui:fragment>
                                    <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.keyword.value or !empty DatasetPage.datasetVersionUI.subject.value or !empty DatasetPage.datasetVersionUI.relPublicationCitation or !empty DatasetPage.datasetVersionUI.notes.value}">
                                        <div class="panel panel-default" style="margin-top:1em;">
                                            <div class="panel-body">
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.keyword.value}">
                                                    <span id="keywords">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.keyword.datasetFieldType.description}" title="" style="margin-right:1em;">Keyword(s)</a>
                                                        #{DatasetPage.datasetVersionUI.keyword.displayValue}
                                                    </span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.subject.value}">
                                                    <span id="subject">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.subject.datasetFieldType.description}" title="" style="margin-right:1em;">Subject(s)</a>
                                                        #{DatasetPage.datasetVersionUI.subject.displayValue}
                                                    </span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.relPublicationCitation}">
                                                    <span id="publication">Related Publication: #{DatasetPage.datasetVersionUI.relPublicationCitation} #{DatasetPage.datasetVersionUI.relPublicationId}  <a href="#{DatasetPage.datasetVersionUI.relPublicationUrl}" target="_blank">#{DatasetPage.datasetVersionUI.relPublicationUrl}</a></span>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!empty DatasetPage.datasetVersionUI.notes.value}">
                                                    <span id="note">
                                                        <a href="#" data-toggle="tooltip" data-placement="auto top" class="tooltiplabel right" data-original-title="#{DatasetPage.datasetVersionUI.notes.datasetFieldType.description}" title="" style="margin-right:1em;">Notes</a>
                                                        <div>
                                                            #{DatasetPage.datasetVersionUI.notes.value}
                                                        </div>
                                                    </span>
                                                </ui:fragment>
                                            </div>
                                        </div>
                                    </ui:fragment>
                                </div>
                            </div>
                        </ui:fragment>

                        <!-- Create mode -->
                        <ui:fragment rendered="#{DatasetPage.editMode == 'METADATA' or DatasetPage.editMode == 'CREATE'}">
                            <div class="form-group">
                                <label for="select_HostDataverse" class="col-sm-2 control-label">
                                    <a href="#" data-toggle="tooltip" data-placement="auto right" class="tooltiplabel right" data-original-title="The Dataverse which contains this data.">Host Dataverse</a>
                                </label>
                                <div class="col-sm-10">
                                   
                                    <h:outputText value="#{ DatasetPage.dataset.owner.name }" style="font-weight:bold;"/>
                                    <h:inputHidden value="#{DatasetPage.ownerId}" id="select_HostDataverse" />
                                     
                                     <ui:remove><!-- removed for beta -->
                                    <p:selectOneMenu id="select_HostDataverse" value="#{DatasetPage.ownerId}" filter="true" filterMatchMode="startsWith" effect="none">
                                        <f:selectItems value="#{dataverseServiceBean.findAll()}" var="dv" itemLabel="#{dv.name}" itemValue="#{dv.id}"/>
                                    </p:selectOneMenu>
                                     </ui:remove>
                                </div>
                            </div>
                        </ui:fragment>
                        <ui:fragment rendered="#{DatasetPage.editMode == 'CREATE'}">
                            <ui:include src="metadataFragment.xhtml"/>
                        </ui:fragment>
                    </ui:fragment>

                    <!-- Tabs -->
                    <ui:fragment rendered="#{DatasetPage.editMode != 'INFO'}">
                        <div id="contentTabs">
                            <ui:fragment rendered="#{empty DatasetPage.editMode}">
                                <p:commandButton id="refreshButton" widgetVar="refreshButton" actionListener="#{DatasetPage.refresh}" update="@all" style="display:none"/>
                                <script type="text/javascript">
                                    function updateFilesTable(facesmessage) {
                                        $('button[id$="refreshButton"]').trigger('click');
                                    }
                                </script>
                                <p:socket channel="/ingest#{dataset.id}" onMessage="updateFilesTable" autoConnect="true">
                                    <p:ajax event="message" update="@all" />
                                </p:socket>
                            </ui:fragment>
                            <p:tabView id="tabView" widgetVar="content" activeIndex="#{DatasetPage.selectedTabIndex}">
                                <p:tab id="dataFilesTab" title="Files" rendered="#{(empty DatasetPage.editMode or DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}" >
                                    <!-- Upload -->
                                    <!--<p:message for="fileUpload" showDetail="true"/>-->
                                    <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                        <ui:fragment rendered="#{DatasetPage.editMode == 'CREATE'}">
                                            <div class="alert alert-info">
                                                Tip: You can drag and drop your files from your desktop, directly into the upload widget.
                                            </div>
                                        </ui:fragment>
                                        <p:fileUpload id="fileUpload" dragDropSupport="true" auto="true" multiple="true" rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}"
                                                  fileUploadListener="#{DatasetPage.handleFileUpload}" process="filesTable" update="filesTable" label="Select Files to Add" oncomplete="javascript:bind_bsui_components();"/> 
                                                                   
                                        <h:inputText id="dropBoxSelectionInput" style="display:none" value="#{DatasetPage.dropBoxSelection}"/>
                                        <p:commandButton id="dropBoxButton" actionListener="#{DatasetPage.handleDropBoxUpload}" update="@all" style="display:none">
                                        </p:commandButton>
                                        <div style="margin:1em 0;">
                                            <p:commandButton value="Upload from Dropbox" onclick="openDropboxChooser();" icon="dropin-btn-status" />
                                            <p class="help-block">You can also upload your files directly from your Dropbox.</p>
                                        </div>
                                    </ui:fragment>
                                    <!-- View -->
                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div class="containder" style="text-align:right; margin-bottom:.5em;">
                                            <p:commandLink style="color:black;" styleClass="btn btn-default" title="Upload + Edit Files" actionListener="#{DatasetPage.edit('FILE')}" update="@form" oncomplete="javascript:post_edit_files()">
                                                <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                <span class="glyphicon glyphicon-plus" style="margin-right:.3em;"/> Upload + Edit Files
                                            </p:commandLink>
                                        </div>
                                        <!--<p class="bg-info" style="padding:1em; margin-right:200px;">
                                            <h:outputText value="Use the Edit Dataverse button to edit or add metadata to this dataset." />
                                        </p>-->
                                    </ui:fragment>
                                    <p:dataTable id="filesTable" value="#{empty DatasetPage.editMode ? DatasetPage.displayVersion.fileMetadatas : DatasetPage.dataset.latestVersion.fileMetadatas}" var="fileMetadata">
                                        <p:column styleClass="col-xs-1" style="text-align:center;">

                                            <ui:fragment rendered="#{!empty fileMetadata.dataFile.id and fileMetadata.dataFile.image}">
                                                <a class="imageThumbPreview" data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-html="true" data-content="&lt;img src=&#34;/api/access/datafile/#{fileMetadata.dataFile.id}?imageThumb=400&#34; alt=&#34;Preview: #{fileMetadata.label}&#34; /&gt;">
                                                    <p:graphicImage value="/api/access/datafile/#{fileMetadata.dataFile.id}?imageThumb=true"/>
                                                </a>
                                            </ui:fragment>

                                            <p:graphicImage value="/resources/images/icon_file.png" rendered="#{!fileMetadata.dataFile.image}"/>

                                            <ui:fragment rendered="#{empty fileMetadata.dataFile.id and !empty fileMetadata.dataFile.fileSystemName and fileMetadata.dataFile.image}">
                                                <p:graphicImage value="/api/access/imagethumb/#{fileMetadata.dataFile.fileSystemName}?mimetype=#{fileMetadata.dataFile.contentType}"/>
                                                <h:outputText id="imgPreview" value="Preview" styleClass="bg-info text-info" style="display:block;text-align:center;"/>
                                            </ui:fragment>
                                        </p:column>
                                        <p:column styleClass="col-sm-7">
                                            <h:outputText id="fileNameOutput" value="#{fileMetadata.label}" style="display:block;font-weight:bold;" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}"/>

                                            <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                                <label class="control-label" for="fileName" style="margin-right:1em;margin-bottom:.5em;">
                                                    File Name
                                                </label>
                                                <p:inputText id="fileName" value="#{fileMetadata.label}" style="margin-bottom:.5em;"/>
                                                <p:message for="fileName"/>
                                            </ui:fragment>

                                            <h:outputText id="fileTypeOutputRegular" value="#{fileMetadata.dataFile.friendlyType}#{!empty fileMetadata.dataFile.md5 ? ', ' : ''}" rendered="#{!(fileMetadata.dataFile.tabularData)}"/>
                                            <h:outputText id="fileMD5" value="MD5: #{fileMetadata.dataFile.md5}" rendered="#{!(empty fileMetadata.dataFile.md5) and !(fileMetadata.dataFile.tabularData)}"/>

                                            <h:outputText id="fileTypeOutputTabular" value="Tabular Data#{!empty fileMetadata.dataFile.unf ? ', ' : ''}" rendered="#{fileMetadata.dataFile.tabularData}"/>
                                            <h:outputText id="fileUNF" value="#{fileMetadata.dataFile.unf}" rendered="#{!empty fileMetadata.dataFile.unf}"/>

                                            <div class="fileDescription">
                                                <h:outputText id="fileDescNonEmpty" value="#{fileMetadata.description}" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE') and !(empty fileMetadata.description)}"/>
                                                <!--<h:outputText id="fileDescEmpty" value="NO DESCRIPTION AVAILABLE" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE') and (empty fileMetadata.description)}"/>-->
                                                
                                                <ui:fragment rendered="#{DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE'}">
                                                    <label class="control-label" for="fileDescription" style="margin-right:1em; margin-top:.5em; vertical-align:top;">
                                                        Description
                                                    </label>
                                                    <p:inputTextarea  id="fileDescription" immediate="true" rows="2" cols="40" value="#{fileMetadata.description}" style="margin-top:.5em;"/>
                                                    <p:watermark for="fileDescription" value="Add file description..."/>
                                                    <p:message for="fileDescription"/>
                                                </ui:fragment>
                                            </div>
                                        </p:column>

                                        <p:column styleClass="col-sm-4" style="overflow: visible;text-align:right;" rendered="#{!(DatasetPage.editMode == 'FILE' or DatasetPage.editMode == 'CREATE')}">
                                            <ui:fragment rendered="#{fileMetadata.dataFile.tabularData or fileMetadata.dataFile.ingestInProgress}">
                                                <h:outputLink style="margin-right:1em;color:black;font-size:1em;" class="btn btn-default #{fileMetadata.dataFile.ingestInProgress ? 'disabled' : ''}" disabled="#{fileMetadata.dataFile.ingestInProgress ? 'disabled' : ''}" title="Explore" value="/dataexplore/gui.html?dfId=#{fileMetadata.dataFile.id}" target="_blank">
                                                    <span class="glyphicon glyphicon-stats" style="margin-right:.3em;"/> <span class="ladda-label">Explore</span>
                                                </h:outputLink>
                                            </ui:fragment>

                                            <!--<ui:fragment rendered="#{fileMetadata.dataFile.ingestInProgress}">
                                                <p:graphicImage value="/resources/images/icon_inprogress.gif"/>
                                            </ui:fragment>-->

                                            <ui:fragment rendered="#{!(fileMetadata.dataFile.tabularData)}">
                                                <a class="btn btn-default" href="/api/access/datafile/#{fileMetadata.dataFile.id}" role="button" style="color:#333333;">
                                                    <span class="glyphicon glyphicon-download-alt" style="margin-right:.3em;"/> Download
                                                </a>
                                            </ui:fragment>

<!--<p:button value="Download" disabled="#{empty fileMetadata.dataFile.id}" rendered="#{empty fileMetadata.dataFile.id}"/>-->

                                            <ui:fragment rendered="#{fileMetadata.dataFile.tabularData}">
                                                <div class="btn-group">
                                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                        <span class="glyphicon glyphicon-download-alt" style="margin-right:.3em;"/> Download <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu" role="menu" style="text-align:left;">
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="As Tab-Delimited"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}?format=RData"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="As RData"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/access/datafile/#{fileMetadata.dataFile.id}?format=original"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="Saved Original (#{fileMetadata.dataFile.originalFormatLabel})"/>
                                                            </h:outputLink>
                                                        </li>
                                                        <li>
                                                            <h:outputLink value="/api/meta/datafile/#{fileMetadata.dataFile.id}"  disabled="#{empty fileMetadata.dataFile.id}">
                                                                <h:outputText value="Variable Metadata"/>
                                                            </h:outputLink>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </ui:fragment>

                                            <ui:fragment rendered="#{fileMetadata.dataFile.ingestInProgress}">
                                                <h:outputText id="txtInprogess" value="Ingest in progress..." styleClass="bg-info text-info" style="display:block;text-align:center;"/>
                                            </ui:fragment>

                                        </p:column>
                                    </p:dataTable>
                                </p:tab>

                                <p:tab id="metadataMapTab" title="Metadata" rendered="#{empty DatasetPage.editMode or DatasetPage.editMode == 'METADATA'}">

                                    <ui:fragment rendered="#{!dataverseSession.user.guest and empty DatasetPage.editMode 
                                                             and DatasetPage.displayVersion == DatasetPage.dataset.latestVersion
                                                             and permissionServiceBean.on(DatasetPage.dataset).canIssueCommand('UpdateDatasetCommand')}">
                                        <div class="containder" style="text-align:right; margin-bottom:.5em;">
                                            <p:commandLink style="color:black;" styleClass="btn btn-default" title="Add + Edit Metadata" actionListener="#{DatasetPage.edit('METADATA')}" update="@form" oncomplete="javascript:post_edit_metadata()">
                                                <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="0" />
                                                <span class="glyphicon glyphicon-pencil" style="margin-right:.3em;"/> Add + Edit Metadata
                                            </p:commandLink>
                                        </div>
                                        <!--<p class="bg-info" style="padding:1em; margin-right:200px;">
                                            <h:outputText value="Use the Edit Dataverse button to edit or add metadata to this dataset." />
                                        </p>-->
                                    </ui:fragment>
                                    <div style="clear:left;">
                                        <ui:include src="metadataFragment.xhtml"/>
                                    </div>

                                </p:tab>

                                <p:tab id="versionsTab" title="Versions" rendered="#{empty DatasetPage.editMode}">                                       
                                    <p:dataTable id="versionsTable" value="#{DatasetPage.versionTabList}" var="versionTab">                                        
                                        <p:column >
                                            <f:facet name="header">
                                                Title
                                            </f:facet>
                                            <h:link id="versionLink" styleClass="ui-commandlink ui-widget" outcome="dataset">
                                                <h:outputText value="#{versionTab.title}" />
                                                <f:param name="id" value="#{versionTab.dataset.id}" />
                                                <f:param name="versionId" value="#{versionTab.id}" />
                                            </h:link>
                                        </p:column>
                                        <p:column >
                                            <f:facet name="header">
                                                Version
                                            </f:facet>
                                            <h:outputText rendered="#{!versionTab.released}" id="versionStatusOutput" value="#{versionTab.versionState}" />
                                            <h:outputText rendered="#{versionTab.released}" id="versionNumberOutput" value="#{versionTab.versionNumber}.#{versionTab.minorVersionNumber}" />
                                        </p:column>
                                        <p:column  > 
                                            <f:facet name="header">
                                                Version Date
                                            </f:facet>
                                            <h:outputText rendered="#{versionTab.released}" id="versionDate" value="#{versionTab.versionDate}" />
                                        </p:column>
                                    </p:dataTable>
                                </p:tab>
                            </p:tabView>
                        </div>
                    </ui:fragment>

                    <!-- Create/Save Dataset Button Panel -->
                    <p:panel styleClass="panelLayoutButtonBlock" rendered="#{!empty DatasetPage.editMode}">
                        <p:commandButton id="save"  value="#{DatasetPage.editMode == 'CREATE' ? 'Add Dataset' : 'Save Changes'}" action="#{DatasetPage.save}" update="@all">
                        </p:commandButton>
                        <p:commandButton id="cancel" value="Cancel" action="#{DatasetPage.cancel}" process="@this" update="@form"  rendered="#{DatasetPage.editMode != 'CREATE'}" oncomplete="javascript:post_cancel_edit_files_or_metadata()">
                            <f:setPropertyActionListener target="#{DatasetPage.selectedTabIndex}" value="#{DatasetPage.editMode == 'METADATA' ? 1 : DatasetPage.selectedTabIndex}"/>
                        </p:commandButton>
                        <p:button id="cancelCreate" value="Cancel" outcome="/dataverse.xhtml?id=#{DatasetPage.ownerId}"  rendered="#{DatasetPage.editMode == 'CREATE'}" />
                    </p:panel>

                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</html>

{'fraction_non_alphanumeric': 0.11023745492697869, 'fraction_numerical': 0.0022913375381387103, 'mean_word_length': 1.1138472519628837, 'pattern_counts': {'":': 0, '<': 807, '<?xml version=': 0, '>': 807, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1114, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1438731', 'n_tokens_mistral': 16299, 'n_tokens_neox': 15844, 'n_words': 2787}