<commit_before>/**
 * Copyright (C) 2011 Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

$(document).ready(function() {
  $("#add_collaboration_form").submit(function(event) {
    var data = $(this).getFormData();
    if(!data['collaboration[title]']) {
      event.preventDefault();
      event.stopPropagation();
      $(this).find("#collaboration_title").errorBox('Please enter a name for this document');
      $("html,body").scrollTo($(this));
      return false;
    }
    setTimeout(function() {
      //reload the page but get rid of anything in the hash so that it doesnt automatically
      //open the Start a New Collaboration section when it reloads
      window.location = window.location.href.replace(window.location.hash, "");
    }, 2500);
  });
  $(".toggle_collaborators_link").live('click', function() {
    $(this).parents(".collaboration").find(".collaborators").slideToggle();
  });
  $(".add_collaboration_link").click(function(event) {
    event.preventDefault();
    $(this).hide();
    $("#add_collaboration_form").slideToggle(function() {
      $("html,body").scrollTo($(this));
      $(this).find(":text:visible:first").focus().select();
    });
  });
  $("#add_collaboration_form .cancel_button").click(function(event) {
    $(".add_collaboration_link").show();
    $("#add_collaboration_form").slideToggle();
  });
  $("#delete_collaboration_dialog .cancel_button").click(function() {
    $("#delete_collaboration_dialog").dialog('close');
  });
  $("#delete_collaboration_dialog .delete_button").click(function() {
    var delete_document = $(this).hasClass('delete_document_button'),
        data = {delete_doc: delete_document},
        $collaboration = $("#delete_collaboration_dialog").data('collaboration'),
        url = $collaboration.find(".delete_collaboration_link").attr('href');
    $collaboration.dim();
    $("#delete_collaboration_dialog").dialog('close');
    $.ajaxJSON(url, 'DELETE', function(data) {
      $collaboration.slideUp(function() {
        $(this).remove();
      });
    }, function(data) {
    });
  });
  $(".delete_collaboration_link").click(function(event) {
    event.preventDefault();
    var $collaboration = $(this).parents(".collaboration");
    if($(this).parents(".collaboration").hasClass('google_docs')) {
      $("#delete_collaboration_dialog").data('collaboration', $collaboration);
      $("#delete_collaboration_dialog").dialog('close').dialog({
        autoOpen: false,
        title: "Delete Collaboration?",
        width: 350
      }).dialog('open');
    } else {
      $collaboration.confirmDelete({
        message: "Are you sure you want to delete this collaboration?",
        url: $(this).attr('href'),
        success: function(data) {
          if($("#collaborations .collaboration:visible").length <= 1) {
            $("#no_collaborations_message").slideDown();
          }
          $(this).slideUp(function() {
            $(this).remove();
          });
        }
      });
    }
  });
  $(".edit_collaboration_link").click(function(event) {
    event.preventDefault();
    var $form = $("#edit_collaboration_form").clone(true);
    $form.attr('action', $(this).attr('href'));
    var $collaboration = $(this).parents(".collaboration");
    $form.attr('class', $collaboration.attr('class'));
    var ids = [];
    var data = $collaboration.getTemplateData({textValues: ['title', 'description']});
    $form.fillFormData(data, {object_name: 'collaboration'});
    var collaborators = $collaboration.find(".collaborators li").each(function() {
      var id = $(this).getTemplateData({textValues: ['id']}).id;
      if(id) {
        ids.push(id);
      }
    });
    $form.find(":checkbox").each(function() {
      $(this).attr('checked', false);
    });
    for(var idx in ids) {
      var id = ids[idx];
      $form.find(".collaborator_" + id + " :checkbox").attr('checked', true);
    }
    $collaboration.hide().after($form.show());
  });
  $("#edit_collaboration_form .cancel_button").click(function() {
    var $form = $(this).parents("form");
    $form.hide().prev(".collaboration").show();
    $form.remove();
  });
  $(document).fragmentChange(function(event, hash) {
    if(hash == "#add_collaboration") {
      $(".add_collaboration_link").click();
    }
  });
  $(".collaboration .show_participants_link.verbose_footer_link").click(function(event) {
    event.preventDefault();
    $(this).parents(".collaboration").find(".collaborators").slideToggle();
  });
  $("#collaboration_collaboration_type").change(function(event) {
    var name = $(this).val();
    var type = name;
    if(INST.collaboration_types) {
      for(var idx in INST.collaboration_types) {
        var collab = INST.collaboration_types[idx];
        if(collab.name == name) {
          type = collab.type;
        }
      }
    }
    $("#add_collaboration_form .collaboration_type").hide();
    var $description = $("#add_collaboration_form #" + type + "_description");
    $description.show();
    $(".collaborate_data").showIf(!$description.hasClass('unauthorized'));
    $(".collaboration_authorization").hide();
    $("#collaborate_authorize_" + type).showIf($description.hasClass('unauthorized'));
  }).change();
  $(".collaborate_data").find(".select_all_link,.deselect_all_link").click(function(event) {
    event.preventDefault();
    var checked = $(this).hasClass('select_all_link');
    $(this).parents(".collaborate_data").find(".collaborator_list :checkbox").each(function() {
      $(this).attr('checked', checked);<commit_msg>select/deselect all links not working on collaborations page<commit_after>/**
 * Copyright (C) 2011 Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

$(document).ready(function() {
  $("#add_collaboration_form").submit(function(event) {
    var data = $(this).getFormData();
    if(!data['collaboration[title]']) {
      event.preventDefault();
      event.stopPropagation();
      $(this).find("#collaboration_title").errorBox('Please enter a name for this document');
      $("html,body").scrollTo($(this));
      return false;
    }
    setTimeout(function() {
      //reload the page but get rid of anything in the hash so that it doesnt automatically
      //open the Start a New Collaboration section when it reloads
      window.location = window.location.href.replace(window.location.hash, "");
    }, 2500);
  });
  $(".toggle_collaborators_link").live('click', function() {
    $(this).parents(".collaboration").find(".collaborators").slideToggle();
  });
  $(".add_collaboration_link").click(function(event) {
    event.preventDefault();
    $(this).hide();
    $("#add_collaboration_form").slideToggle(function() {
      $("html,body").scrollTo($(this));
      $(this).find(":text:visible:first").focus().select();
    });
  });
  $("#add_collaboration_form .cancel_button").click(function(event) {
    $(".add_collaboration_link").show();
    $("#add_collaboration_form").slideToggle();
  });
  $("#delete_collaboration_dialog .cancel_button").click(function() {
    $("#delete_collaboration_dialog").dialog('close');
  });
  $("#delete_collaboration_dialog .delete_button").click(function() {
    var delete_document = $(this).hasClass('delete_document_button'),
        data = {delete_doc: delete_document},
        $collaboration = $("#delete_collaboration_dialog").data('collaboration'),
        url = $collaboration.find(".delete_collaboration_link").attr('href');
    $collaboration.dim();
    $("#delete_collaboration_dialog").dialog('close');
    $.ajaxJSON(url, 'DELETE', function(data) {
      $collaboration.slideUp(function() {
        $(this).remove();
      });
    }, function(data) {
    });
  });
  $(".delete_collaboration_link").click(function(event) {
    event.preventDefault();
    var $collaboration = $(this).parents(".collaboration");
    if($(this).parents(".collaboration").hasClass('google_docs')) {
      $("#delete_collaboration_dialog").data('collaboration', $collaboration);
      $("#delete_collaboration_dialog").dialog('close').dialog({
        autoOpen: false,
        title: "Delete Collaboration?",
        width: 350
      }).dialog('open');
    } else {
      $collaboration.confirmDelete({
        message: "Are you sure you want to delete this collaboration?",
        url: $(this).attr('href'),
        success: function(data) {
          if($("#collaborations .collaboration:visible").length <= 1) {
            $("#no_collaborations_message").slideDown();
          }
          $(this).slideUp(function() {
            $(this).remove();
          });
        }
      });
    }
  });
  $(".edit_collaboration_link").click(function(event) {
    event.preventDefault();
    var $form = $("#edit_collaboration_form").clone(true);
    $form.attr('action', $(this).attr('href'));
    var $collaboration = $(this).parents(".collaboration");
    $form.attr('class', $collaboration.attr('class'));
    var ids = [];
    var data = $collaboration.getTemplateData({textValues: ['title', 'description']});
    $form.fillFormData(data, {object_name: 'collaboration'});
    var collaborators = $collaboration.find(".collaborators li").each(function() {
      var id = $(this).getTemplateData({textValues: ['id']}).id;
      if(id) {
        ids.push(id);
      }
    });
    $form.find(":checkbox").each(function() {
      $(this).attr('checked', false);
    });
    for(var idx in ids) {
      var id = ids[idx];
      $form.find(".collaborator_" + id + " :checkbox").attr('checked', true);
    }
    $collaboration.hide().after($form.show());
  });
  $("#edit_collaboration_form .cancel_button").click(function() {
    var $form = $(this).parents("form");
    $form.hide().prev(".collaboration").show();
    $form.remove();
  });
  $(document).fragmentChange(function(event, hash) {
    if(hash == "#add_collaboration") {
      $(".add_collaboration_link").click();
    }
  });
  $(".collaboration .show_participants_link.verbose_footer_link").click(function(event) {
    event.preventDefault();
    $(this).parents(".collaboration").find(".collaborators").slideToggle();
  });
  $("#collaboration_collaboration_type").change(function(event) {
    var name = $(this).val();
    var type = name;
    if(INST.collaboration_types) {
      for(var idx in INST.collaboration_types) {
        var collab = INST.collaboration_types[idx];
        if(collab.name == name) {
          type = collab.type;
        }
      }
    }
    $("#add_collaboration_form .collaboration_type").hide();
    var $description = $("#add_collaboration_form #" + type + "_description");
    $description.show();
    $(".collaborate_data").showIf(!$description.hasClass('unauthorized'));
    $(".collaboration_authorization").hide();
    $("#collaborate_authorize_" + type).showIf($description.hasClass('unauthorized'));
  }).change();
  $(".collaborate_data").find(".select_all_link,.deselect_all_link").click(function(event) {
    event.preventDefault();
    var checked = $(this).hasClass('select_all_link');
    $("#collaborator_list :checkbox").each(function() {
      $(this).attr('checked', checked);
{'fraction_non_alphanumeric': 0.1792844918914514, 'fraction_numerical': 0.0021188167223535163, 'mean_word_length': 3.818217510797016, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2120976', 'n_tokens_mistral': 3632, 'n_tokens_neox': 3628, 'n_words': 668}