<commit_before>﻿// Script to handle saving photos to a user defined collection

// Dependencies:
// ** visibleItems, a global variable containing a comma-separated list of photo Ids
// ** #userCollectionModal, a bootstrap modal that presents the existing user collections
//          and allows users to create a new collection      


/*
 * Handles user selection on the list of existing user defined collections.
 */
var collectionIds = [];
function registerCollectionSelection(collectionId) {
    if (jQuery.inArray(collectionId, collectionIds) == -1) {
        collectionIds.push(collectionId);
    }
    else {
        var index = collectionIds.indexOf(collectionId);
        collectionIds.splice(index, 1);
    }
}

/*
 * Hides the SilverLight viewer, if applicable, and presents the user with a modal
 * to create a new collection add/or add photos to existing collections.
 */
function saveCollectionPrompt() {
    $("#silverlightControlHost").hide();

    $('#userCollectionModal').modal({
        show: true,
        backdrop: 'static',
        closeOnEscape: true
    });
}

/*
 * Handles Cancel modal button click
 * The modal is dismissed and, if applicable, the SilverLight viewer is shown.
 */
function cancelCollectionModalButton() {
    $("#silverlightControlHost").show();
}

/*
 * Handles Save modal button click
 * If a New Collection name is provided, saveCollection() is called to create this new collection.
 * If existing collections are selected, addToCollection() is called to add photos to those collections.
 * The modal is dismissed and, if applicable, the SilverLight view is shown.
 */
function saveCollectionModalButton() {
    var newName = $('#newCollectionName').val();
    if (newName != "") {
        saveCollection(newName);
    }

    if (collectionIds.length > 0) {
        addToCollection(collectionIds);
    }

    $("#silverlightControlHost").show();
}

/*
 * POST the collection Ids and photo Ids to the User Collection API contoller.
 */
function addToCollection(collectionIds) {
    // Make the call to add the given photos to the collection
    $.ajax({
        url: '/api/usercollection/AddToCollection?collectionIds=' + collectionIds.join(',') + '&photoIds=' + visibleItems,
        type: 'POST'
    });

    // Update the documents on the page to reflect the changes

    // Number of photos added
    var photoCount = visibleItems.split(',').length;

    // Loop over the collections and update photo counts and removed .list-group-item-success
    for (var i = 0; i < collectionIds.length; i++) {
        var currentCount = $('li#' + collectionIds[i] + ' span').text();
        $('li#' + collectionIds[i] + ' span').text((parseInt(currentCount) + photoCount));
        $('li#' + collectionIds[i]).removeClass('list-group-item-success');
    }

    // Removed the selected collections from the array
    collectionIds = [];
}

/*
 * POST the photo Ids and New Collection Name to the User Collection API controller.
 */
function saveCollection(collectionName) {
    $.ajax({
        url: '/api/usercollection/SaveUserCollection?photoIds=' + visibleItems + '&collectionName=' + collectionName,
        type: "POST"
    });
}

/*
 * Register a click listener on the modal <li> elements to toggle selection.
 */
$(document).ready(function () {
    $('.list-group-item').click(function () {
        $(this).toggleClass("list-group-item-success");

        registerCollectionSelection($(this).attr('id'));
    });
});<commit_msg>Switched back to single quotes for consistency.<commit_after>﻿// Script to handle saving photos to a user defined collection

// Dependencies:
// ** visibleItems, a global variable containing a comma-separated list of photo Ids
// ** #userCollectionModal, a bootstrap modal that presents the existing user collections
//          and allows users to create a new collection      


/*
 * Handles user selection on the list of existing user defined collections.
 */
var collectionIds = [];
function registerCollectionSelection(collectionId) {
    if (jQuery.inArray(collectionId, collectionIds) == -1) {
        collectionIds.push(collectionId);
    }
    else {
        var index = collectionIds.indexOf(collectionId);
        collectionIds.splice(index, 1);
    }
}

/*
 * Hides the SilverLight viewer, if applicable, and presents the user with a modal
 * to create a new collection add/or add photos to existing collections.
 */
function saveCollectionPrompt() {
    $("#silverlightControlHost").hide();

    $('#userCollectionModal').modal({
        show: true,
        backdrop: 'static',
        closeOnEscape: true
    });
}

/*
 * Handles Cancel modal button click
 * The modal is dismissed and, if applicable, the SilverLight viewer is shown.
 */
function cancelCollectionModalButton() {
    $("#silverlightControlHost").show();
}

/*
 * Handles Save modal button click
 * If a New Collection name is provided, saveCollection() is called to create this new collection.
 * If existing collections are selected, addToCollection() is called to add photos to those collections.
 * The modal is dismissed and, if applicable, the SilverLight view is shown.
 */
function saveCollectionModalButton() {
    var newName = $('#newCollectionName').val();
    if (newName != "") {
        saveCollection(newName);
    }

    if (collectionIds.length > 0) {
        addToCollection(collectionIds);
    }

    $("#silverlightControlHost").show();
}

/*
 * POST the collection Ids and photo Ids to the User Collection API contoller.
 */
function addToCollection(collectionIds) {
    // Make the call to add the given photos to the collection
    $.ajax({
        url: '/api/usercollection/AddToCollection?collectionIds=' + collectionIds.join(',') + '&photoIds=' + visibleItems,
        type: 'POST'
    });

    // Update the documents on the page to reflect the changes

    // Number of photos added
    var photoCount = visibleItems.split(',').length;

    // Loop over the collections and update photo counts and removed .list-group-item-success
    for (var i = 0; i < collectionIds.length; i++) {
        var currentCount = $('li#' + collectionIds[i] + ' span').text();
        $('li#' + collectionIds[i] + ' span').text((parseInt(currentCount) + photoCount));
        $('li#' + collectionIds[i]).removeClass('list-group-item-success');
    }

    // Removed the selected collections from the array
    collectionIds = [];
}

/*
 * POST the photo Ids and New Collection Name to the User Collection API controller.
 */
function saveCollection(collectionName) {
    $.ajax({
        url: '/api/usercollection/SaveUserCollection?photoIds=' + visibleItems + '&collectionName=' + collectionName,
        type: "POST"
    });
}

/*
 * Register a click listener on the modal <li> elements to toggle selection.
 */
$(document).ready(function () {
    $('.list-group-item').click(function () {
        $(this).toggleClass('list-group-item-success');

        registerCollectionSelection($(this).attr('id'));
    });
});
{'fraction_non_alphanumeric': 0.12159839587510742, 'fraction_numerical': 0.0011458034947006588, 'mean_word_length': 3.37531328320802, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491934', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1821, 'n_words': 622}