<commit_before>@import play.i18n._
@import be.objectify.deadbolt.java.views.html.subjectPresent

@templates = {
<script type="text/template" id="item-template">
    <td>
        <a href="download/<%- id %>"><span class="glyphicon glyphicon-file" aria-hidden="true"></span> <%- name %></a>
    </td>
    <td>
        <ul class="list-inline list-unstyled tags-container">
            <% for(var tag in tags) { %>
            <li><span class="label label-info tag"><%= tags[tag].name %></span></li>
            <% } %>
        </ul>
    </td>
    @subjectPresent() {
    <td>
        <button type="button" class="btn btn-danger btn-xs delete-btn"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> <span class="hidden-xs">@Messages.get("delete")</span></button>
    </td>
    }
</script>
<script type="text/template" id="tag-template">
    <span class="label label-info tag"><%- name %> <a role="button" href="#" class="delete-btn"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span>
</script>
<script type="text/template" id="alert-template">
    <div class="alert alert-<%- type %> alert-dismissible fade in" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
        <p><%- message %></p>
    </div>
</script>
}

@scripts = {
<script src="@routes.WebJarAssets.at(WebJarAssets.locate("underscore-min.js"))"></script>
<script src="@routes.WebJarAssets.at(WebJarAssets.locate("backbone-min.js"))"></script>
<script src="@routes.Assets.versioned("javascripts/models/item.js")"></script>
<script src="@routes.Assets.versioned("javascripts/models/tag.js")"></script>
<script src="@routes.Assets.versioned("javascripts/collections/items.js")"></script>
<script src="@routes.Assets.versioned("javascripts/collections/tags.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/item-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/tag-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/app-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/app.js")"></script>

<script type="text/javascript">
// Prepares upload modal to a new download
function resetUploadModal () {
    $('.upload-file-modal .upload-btn').button('reset');
    $('.upload-file-modal .cancel-btn').show();
    $('.upload-progress').hide();
    updateUploadProgressBarValue(0);
    app.uploadTags.reset();
}

// Updates the progress value of the upload progress bar
function updateUploadProgressBarValue (percent) {
    $('.upload-progress .progress-bar').css('width', percent + '%');
    $('.upload-progress .progress-bar .sr-only').html(percent + "% @Messages.get("completed")");
}

function addTagToSearchBox () {
    var tagsInput = $('.search-box .tags-input');
    if (tagsInput.val() != null && tagsInput.val() != "" && app.searchTags.findWhere({name: tagsInput.val()}) == null) {
        app.searchTags.add({name: tagsInput.val()});
        tagsInput.val('');
    }
    tagsInput.focus();
}

function applySearchFilter () {
    var tags = [];
    app.searchTags.each(function(tag) {
        tags.push(tag.get("name"));
    });
    app.items.fetch({data: {tags: tags.join(",")}, reset: true});
}

$(document).ready(function(){
    resetUploadModal();

    $('.upload-file-modal .upload-btn').click(function(){
        // Get the data from the upload form
        var formData = new FormData($('.upload-form')[0]);
        app.uploadTags.each(function(tag) {
            formData.append('tags', tag.get("name"));
        });

        // Send upload form data trough Ajax (http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously)
        $.ajax({
            url: '@routes.Storage.upload',  //Server script to process data
            type: 'POST',

            // Custom XMLHttpRequest
            xhr: function() {
                var myXhr = $.ajaxSettings.xhr();
                // Check if upload property exists
                if(myXhr.upload){
                    // For handling the progress of the upload
                    myXhr.upload.addEventListener('progress',progressHandler, false);
                }
                return myXhr;
            },

            //Ajax events
            success: completeHandler,
            error: errorHandler,

            // Form data
            data: formData,

            //Options to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: false,
            processData: false
        });

        $('.upload-file-modal .cancel-btn').hide();
        $('.upload-progress').show();
        $('.upload-file-modal .upload-btn').button('uploading');

        function progressHandler(e){
            if(e.lengthComputable){
                updateUploadProgressBarValue (e.loaded / e.total * 100);
            }
        }

        function completeHandler(){
            var searchTags = app.searchTags.pluck("name");
            var uploadTags = app.uploadTags.pluck("name");

            if (_.every(searchTags, function (value) { return _.contains(uploadTags, value) })) {
                applySearchFilter();
            }

            $('.upload-file-modal').modal('hide');
            resetUploadModal();
        }

        function errorHandler(data){
            $('.upload-file-modal .alert').remove();
            var template = _.template($('#alert-template').html());
            $('.upload-file-modal .modal-body').prepend(template({type: "danger", message: "@Messages.get("uploadError")"}));
            resetUploadModal();
        }
    });

    $('.upload-file-modal .add-tag-btn').click(function(){
        var tagsInput = $('.upload-file-modal .tags-input');
        if (tagsInput.val() != null && tagsInput.val() != "" && app.uploadTags.findWhere({name: tagsInput.val()}) == null) {
            app.uploadTags.add({name: tagsInput.val()});
            tagsInput.val('');
        }
        tagsInput.focus();
    });

    $('.search-box .add-tag-btn').click(addTagToSearchBox);
    $('.search-box .tags-input').keyup(function(event) {
        if (event.which == 13) {
            addTagToSearchBox();
        }
    }).focus();

    $('.upload-file-modal').on('hidden.bs.modal', function (e) {
        resetUploadModal();
    });
});
</script>
}

@main(Messages.get("welcome"), null, scripts, templates) {
<div class="container thunderbit-app">
    <div class="row">
        <div class="col-xs-12 search-box">
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-tags" aria-hidden="true"></span></span>
                    <input type="text" class="form-control input-lg tags-input" placeholder="@Messages.get("searchBoxText")">
                    <span class="input-group-btn">
                        <button class="btn btn-default btn-lg add-tag-btn" type="button"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                    </span>
                </div>
            </div>
            <ul class="list-unstyled list-inline tags-container"></ul>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <table class="table">
                <thead>
                    <tr>
                        <th></th>
                        @subjectPresent() {
                            <th></th>
                        }
                    </tr>
                </thead>
                <tbody class="table items-container">
                </tbody>
            </table>
        </div>
    </div>
</div>

@subjectPresent() {
<div class="modal fade upload-file-modal" tabindex="-1" role="dialog" aria-labelledby="uploadFileModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <form enctype="multipart/form-data" class="form-horizontal upload-form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="@Messages.get("close")"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="uploadFileModalLabel">@Messages.get("uploadFile")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="file" class="col-sm-2 control-label">Fichero</label>
                        <div class="col-sm-10">
                            <input type="file" name="file" id="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tags" class="col-sm-2 control-label">@Messages.get("tags")</label>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" class="form-control tags-input" id="tags">
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-default add-tag-btn"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                                </span>
                            </div>
                        </div>
                        <div class="col-sm-7">
                            <ul class="list-inline list-unstyled tags-container"></ul>
                        </div>
                    </div>
                    <div class="progress upload-progress">
                        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                            <span class="sr-only">0% Complete</span>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary upload-btn" data-uploading-text="@Messages.get("uploading")" autocomplete="off"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> @Messages.get("upload")</button>
                    <button type="button" class="btn btn-default cancel-btn" data-dismiss="modal"><span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span> @Messages.get("cancel")</button>
                </div>
            </form>
        </div>
    </div>
</div>
}

}
<commit_msg>Moved messages on index js to an array<commit_after>@import play.i18n._
@import be.objectify.deadbolt.java.views.html.subjectPresent

@templates = {
<script type="text/template" id="item-template">
    <td>
        <a href="download/<%- id %>"><span class="glyphicon glyphicon-file" aria-hidden="true"></span> <%- name %></a>
    </td>
    <td>
        <ul class="list-inline list-unstyled tags-container">
            <% for(var tag in tags) { %>
            <li><span class="label label-info tag"><%= tags[tag].name %></span></li>
            <% } %>
        </ul>
    </td>
    @subjectPresent() {
    <td>
        <button type="button" class="btn btn-danger btn-xs delete-btn"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> <span class="hidden-xs">@Messages.get("delete")</span></button>
    </td>
    }
</script>
<script type="text/template" id="tag-template">
    <span class="label label-info tag"><%- name %> <a role="button" href="#" class="delete-btn"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span>
</script>
<script type="text/template" id="alert-template">
    <div class="alert alert-<%- type %> alert-dismissible fade in" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
        <p><%- message %></p>
    </div>
</script>
}

@scripts = {
<script src="@routes.WebJarAssets.at(WebJarAssets.locate("underscore-min.js"))"></script>
<script src="@routes.WebJarAssets.at(WebJarAssets.locate("backbone-min.js"))"></script>
<script src="@routes.Assets.versioned("javascripts/models/item.js")"></script>
<script src="@routes.Assets.versioned("javascripts/models/tag.js")"></script>
<script src="@routes.Assets.versioned("javascripts/collections/items.js")"></script>
<script src="@routes.Assets.versioned("javascripts/collections/tags.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/item-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/tag-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/views/app-view.js")"></script>
<script src="@routes.Assets.versioned("javascripts/app.js")"></script>

<script type="text/javascript">
// Messages
var messages = {};
messages['completed'] = "@Messages.get("completed")";
messages['uploadError'] = "@Messages.get("uploadError")";

// Prepares upload modal to a new download
function resetUploadModal () {
    $('.upload-file-modal .upload-btn').button('reset');
    $('.upload-file-modal .cancel-btn').show();
    $('.upload-progress').hide();
    updateUploadProgressBarValue(0);
    app.uploadTags.reset();
}

// Updates the progress value of the upload progress bar
function updateUploadProgressBarValue (percent) {
    $('.upload-progress .progress-bar').css('width', percent + '%');
    $('.upload-progress .progress-bar .sr-only').html(percent + "% " + messages['completed']);
}

function addTagToSearchBox () {
    var tagsInput = $('.search-box .tags-input');
    if (tagsInput.val() != null && tagsInput.val() != "" && app.searchTags.findWhere({name: tagsInput.val()}) == null) {
        app.searchTags.add({name: tagsInput.val()});
        tagsInput.val('');
    }
    tagsInput.focus();
}

function applySearchFilter () {
    var tags = [];
    app.searchTags.each(function(tag) {
        tags.push(tag.get("name"));
    });
    app.items.fetch({data: {tags: tags.join(",")}, reset: true});
}

$(document).ready(function(){
    resetUploadModal();

    $('.upload-file-modal .upload-btn').click(function(){
        // Get the data from the upload form
        var formData = new FormData($('.upload-form')[0]);
        app.uploadTags.each(function(tag) {
            formData.append('tags', tag.get("name"));
        });

        // Send upload form data trough Ajax (http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously)
        $.ajax({
            url: '@routes.Storage.upload',  //Server script to process data
            type: 'POST',

            // Custom XMLHttpRequest
            xhr: function() {
                var myXhr = $.ajaxSettings.xhr();
                // Check if upload property exists
                if(myXhr.upload){
                    // For handling the progress of the upload
                    myXhr.upload.addEventListener('progress',progressHandler, false);
                }
                return myXhr;
            },

            //Ajax events
            success: completeHandler,
            error: errorHandler,

            // Form data
            data: formData,

            //Options to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: false,
            processData: false
        });

        $('.upload-file-modal .cancel-btn').hide();
        $('.upload-progress').show();
        $('.upload-file-modal .upload-btn').button('uploading');

        function progressHandler(e){
            if(e.lengthComputable){
                updateUploadProgressBarValue (e.loaded / e.total * 100);
            }
        }

        function completeHandler(){
            var searchTags = app.searchTags.pluck("name");
            var uploadTags = app.uploadTags.pluck("name");

            if (_.every(searchTags, function (value) { return _.contains(uploadTags, value) })) {
                applySearchFilter();
            }

            $('.upload-file-modal').modal('hide');
            resetUploadModal();
        }

        function errorHandler(data){
            $('.upload-file-modal .alert').remove();
            var template = _.template($('#alert-template').html());
            $('.upload-file-modal .modal-body').prepend(template({type: "danger", message: messages['uploadError']}));
            resetUploadModal();
        }
    });

    $('.upload-file-modal .add-tag-btn').click(function(){
        var tagsInput = $('.upload-file-modal .tags-input');
        if (tagsInput.val() != null && tagsInput.val() != "" && app.uploadTags.findWhere({name: tagsInput.val()}) == null) {
            app.uploadTags.add({name: tagsInput.val()});
            tagsInput.val('');
        }
        tagsInput.focus();
    });

    $('.search-box .add-tag-btn').click(addTagToSearchBox);
    $('.search-box .tags-input').keyup(function(event) {
        if (event.which == 13) {
            addTagToSearchBox();
        }
    }).focus();

    $('.upload-file-modal').on('hidden.bs.modal', function (e) {
        resetUploadModal();
    });
});
</script>
}

@main(Messages.get("welcome"), null, scripts, templates) {
<div class="container thunderbit-app">
    <div class="row">
        <div class="col-xs-12 search-box">
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-tags" aria-hidden="true"></span></span>
                    <input type="text" class="form-control input-lg tags-input" placeholder="@Messages.get("searchBoxText")">
                    <span class="input-group-btn">
                        <button class="btn btn-default btn-lg add-tag-btn" type="button"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                    </span>
                </div>
            </div>
            <ul class="list-unstyled list-inline tags-container"></ul>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <table class="table">
                <thead>
                    <tr>
                        <th></th>
                        @subjectPresent() {
                            <th></th>
                        }
                    </tr>
                </thead>
                <tbody class="table items-container">
                </tbody>
            </table>
        </div>
    </div>
</div>

@subjectPresent() {
<div class="modal fade upload-file-modal" tabindex="-1" role="dialog" aria-labelledby="uploadFileModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <form enctype="multipart/form-data" class="form-horizontal upload-form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="@Messages.get("close")"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="uploadFileModalLabel">@Messages.get("uploadFile")</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="file" class="col-sm-2 control-label">Fichero</label>
                        <div class="col-sm-10">
                            <input type="file" name="file" id="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tags" class="col-sm-2 control-label">@Messages.get("tags")</label>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" class="form-control tags-input" id="tags">
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-default add-tag-btn"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                                </span>
                            </div>
                        </div>
                        <div class="col-sm-7">
                            <ul class="list-inline list-unstyled tags-container"></ul>
                        </div>
                    </div>
                    <div class="progress upload-progress">
                        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                            <span class="sr-only">0% Complete</span>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary upload-btn" data-uploading-text="@Messages.get("uploading")" autocomplete="off"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> @Messages.get("upload")</button>
                    <button type="button" class="btn btn-default cancel-btn" data-dismiss="modal"><span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span> @Messages.get("cancel")</button>
                </div>
            </form>
        </div>
    </div>
</div>
}

}

{'fraction_non_alphanumeric': 0.17589007460572292, 'fraction_numerical': 0.00330531683822835, 'mean_word_length': 2.128822573496824, 'pattern_counts': {'":': 0, '<': 345, '<?xml version=': 0, '>': 345, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1848410', 'n_tokens_mistral': 6160, 'n_tokens_neox': 5883, 'n_words': 1074}