<commit_before>/*!
    Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
    Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
    Created By: <EMAIL>
    Maintained By: <EMAIL>
*/

//= require bootstrap-modal
//= require can.jquery-all
//= require jquery-migrate
//= require jquery-ui

!function($) {

  "use strict"; // jshint ;_;

  function preload_content() {
    var template =
      [ '<div class="modal-header">'
      , '  <a class="btn btn-mini pull-right" href="#" data-dismiss="modal">'
      , '    <i class="grcicon-x-grey"></i>'
      , '  </a>'
      , '  <h2>Loading...</h2>'
      , '</div>'
      , '<div class="modal-body" style="padding-top:150px;"></div>'
      , '<div class="modal-footer">'
      , '</div>'
      ];
    return $(template.join('\n'))
      .filter('.modal-body')
        .html(
          $(new Spinner().spin().el)
            .css({
              width: '100px', height: '100px',
              left: '50%', top: '50%',
              zIndex : calculate_spinner_z_index
            })
        ).end();
  }

  function emit_loaded(responseText, textStatus, xhr) {
    if (xhr.status == 403) {
      // For now, only inject the response HTML in the case
      // of an authorization error
      $(this).html(responseText)
    }
    $(this).trigger('loaded');
  }

  function refresh_page() {
    setTimeout(can.proxy(window.location.reload, window.location), 10);
  }

  var handlers = {
    'modal': function($target, $trigger, option) {
      $target.modal(option).draggable({ handle: '.modal-header' });
    },

    'listselect': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_single_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('modal:select', function(e, data) {
        $target.modal_single_selector('hide');
        $trigger.trigger('modal:select', data);
      });
    },

    'relationshipsform': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_relationship_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          $trigger.trigger('modal:success', [data]);
          if (list_target == 'refresh') {
            refresh_page();
          } else if (list_target) {
            $(list_target).tmpl_setitems(data);
            $target.modal_relationship_selector('hide');
          }
        }

      });
    },

    'listform': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_relationship_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else if (list_target == 'refresh') {
          refresh_page();
        } else if (list_target) {
          $(list_target).tmpl_setitems(data);
          $target.modal_relationship_selector('hide');
        }
      });
    },

    'listnewform': function($target, $trigger, option) {
      $target.modal_form(option, $trigger);
      var list_target = $trigger.data('list-target')
        , selector_target = $trigger.data('selector-target')
        ;

      // Close the modal and append to the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          if (list_target) {
            $(list_target).tmpl_additem(data)
          }
          if (selector_target) {
            $(selector_target).trigger('list-add-item', data);
          }
          //$(tablist_target).trigger('list-add-item', data);
          $target.modal_form('hide');
        }
      });
    },

    'listeditform': function($target, $trigger, option) {
      $target.modal_form(option, $trigger);
      var list_target = $trigger.data('list-target')
        , selector_target = $trigger.data('selector-target')
        ;

      // Close the modal and append to the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          if (list_target) {
            $(list_target).tmpl_mergeitems([data]);
          }
          if (selector_target) {
            $(selector_target).trigger('list-update-item', data);
          }
          $target.modal_form('hide');
          $trigger.trigger('modal:success', data);
        }
      });
    },

    'deleteform': function($target, $trigger, option) {
      var form_target = $trigger.data('form-target')
      , model = CMS.Models[$trigger.attr("data-object-singular")]
      , instance;
      if($trigger.attr('data-object-id') === "page") {
        instance = GGRC.page_instance();
      } else {
        instance = model.findInCacheById($trigger.attr('data-object-id'));
      }

      $target
      .modal_form(option, $trigger)
      .ggrc_controllers_delete({
          $trigger : $trigger
        , new_object_form : false
        , button_view : GGRC.mustache_path + "/modals/delete_cancel_buttons.mustache"
        , model : model
        , instance : instance
        , modal_title : "Delete " + $trigger.attr("data-object-singular")
        , content_view : GGRC.mustache_path + "/base_objects/confirm_delete.mustache" 
      });

      $target.on('modal:success', function(e, data) {
        var model_name = $trigger.attr("data-object-singular");
        if($trigger.attr('data-object-id') === "page" || (instance === GGRC.page_instance())) {
          window.location.assign('/dashboard');
        } else if (model_name  == 'Person' || model_name  == 'Role') { //FIXME: Kludge
          window.location.assign('/admin');
        } else {
          $trigger.trigger('modal:success', data);
          $target.modal_form('hide');
        }
      });
    },

    'form': function($target, $trigger, option) {
      var form_target = $trigger.data('form-target')
      , object_params = $trigger.attr('data-object-params')
      , model = CMS.Models[$trigger.attr("data-object-singular")]
      , instance;
      if($trigger.attr('data-object-id') === "page") {
        instance = GGRC.page_instance();
      } else {
        instance = model.findInCacheById($trigger.attr('data-object-id'));<commit_msg>Fixed delete redirect on admin dashboard<commit_after>/*!
    Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
    Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
    Created By: <EMAIL>
    Maintained By: <EMAIL>
*/

//= require bootstrap-modal
//= require can.jquery-all
//= require jquery-migrate
//= require jquery-ui

!function($) {

  "use strict"; // jshint ;_;

  function preload_content() {
    var template =
      [ '<div class="modal-header">'
      , '  <a class="btn btn-mini pull-right" href="#" data-dismiss="modal">'
      , '    <i class="grcicon-x-grey"></i>'
      , '  </a>'
      , '  <h2>Loading...</h2>'
      , '</div>'
      , '<div class="modal-body" style="padding-top:150px;"></div>'
      , '<div class="modal-footer">'
      , '</div>'
      ];
    return $(template.join('\n'))
      .filter('.modal-body')
        .html(
          $(new Spinner().spin().el)
            .css({
              width: '100px', height: '100px',
              left: '50%', top: '50%',
              zIndex : calculate_spinner_z_index
            })
        ).end();
  }

  function emit_loaded(responseText, textStatus, xhr) {
    if (xhr.status == 403) {
      // For now, only inject the response HTML in the case
      // of an authorization error
      $(this).html(responseText)
    }
    $(this).trigger('loaded');
  }

  function refresh_page() {
    setTimeout(can.proxy(window.location.reload, window.location), 10);
  }

  var handlers = {
    'modal': function($target, $trigger, option) {
      $target.modal(option).draggable({ handle: '.modal-header' });
    },

    'listselect': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_single_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('modal:select', function(e, data) {
        $target.modal_single_selector('hide');
        $trigger.trigger('modal:select', data);
      });
    },

    'relationshipsform': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_relationship_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          $trigger.trigger('modal:success', [data]);
          if (list_target == 'refresh') {
            refresh_page();
          } else if (list_target) {
            $(list_target).tmpl_setitems(data);
            $target.modal_relationship_selector('hide');
          }
        }

      });
    },

    'listform': function($target, $trigger, option) {
      var list_target = $trigger.data('list-target');
      $target.modal_relationship_selector(option, $trigger);

      // Close the modal and rewrite the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else if (list_target == 'refresh') {
          refresh_page();
        } else if (list_target) {
          $(list_target).tmpl_setitems(data);
          $target.modal_relationship_selector('hide');
        }
      });
    },

    'listnewform': function($target, $trigger, option) {
      $target.modal_form(option, $trigger);
      var list_target = $trigger.data('list-target')
        , selector_target = $trigger.data('selector-target')
        ;

      // Close the modal and append to the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          if (list_target) {
            $(list_target).tmpl_additem(data)
          }
          if (selector_target) {
            $(selector_target).trigger('list-add-item', data);
          }
          //$(tablist_target).trigger('list-add-item', data);
          $target.modal_form('hide');
        }
      });
    },

    'listeditform': function($target, $trigger, option) {
      $target.modal_form(option, $trigger);
      var list_target = $trigger.data('list-target')
        , selector_target = $trigger.data('selector-target')
        ;

      // Close the modal and append to the target list
      $target.on('ajax:json', function(e, data, xhr) {
        if (data.errors) {
        } else {
          if (list_target) {
            $(list_target).tmpl_mergeitems([data]);
          }
          if (selector_target) {
            $(selector_target).trigger('list-update-item', data);
          }
          $target.modal_form('hide');
          $trigger.trigger('modal:success', data);
        }
      });
    },

    'deleteform': function($target, $trigger, option) {
      var form_target = $trigger.data('form-target')
      , model = CMS.Models[$trigger.attr("data-object-singular")]
      , instance;
      if($trigger.attr('data-object-id') === "page") {
        instance = GGRC.page_instance();
      } else {
        instance = model.findInCacheById($trigger.attr('data-object-id'));
      }

      $target
      .modal_form(option, $trigger)
      .ggrc_controllers_delete({
          $trigger : $trigger
        , new_object_form : false
        , button_view : GGRC.mustache_path + "/modals/delete_cancel_buttons.mustache"
        , model : model
        , instance : instance
        , modal_title : "Delete " + $trigger.attr("data-object-singular")
        , content_view : GGRC.mustache_path + "/base_objects/confirm_delete.mustache" 
      });

      $target.on('modal:success', function(e, data) {
        var model_name = $trigger.attr("data-object-plural").toLowerCase();
        if($trigger.attr('data-object-id') === "page" || (instance === GGRC.page_instance())) {
          window.location.assign('/dashboard');
        } else if (model_name  == 'people' || model_name  == 'roles') {
          window.location.assign('/admin#' + model_name + "_list_widget");
          window.location.reload();
        } else {
          $trigger.trigger('modal:success', data);
          $target.modal_form('hide');
        }
      });
    },

    'form': function($target, $trigger, option) {
      var form_target = $trigger.data('form-target')
      , object_params = $trigger.attr('data-object-params')
      , model = CMS.Models[$trigger.attr("data-object-singular")]
      , instance;
      if($trigger.attr('data-object-id') === "page") {
        instance = GGRC.page_instance();
      } else {
        instance = model.findInCacheById($trigger.attr('data-object-id'));
{'fraction_non_alphanumeric': 0.16341747572815535, 'fraction_numerical': 0.00403883495145631, 'mean_word_length': 2.3671548117154813, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '5406042', 'n_tokens_mistral': 3957, 'n_tokens_neox': 3855, 'n_words': 725}