<commit_before>/* global dialogFieldRefresh jqplot_bind_events miqBrowserDetect miqExpressionPrefill miqGridCheckAll miqGridGetCheckedRows miqLoadTL miqMenu miqValueStylePrefill performFiltering */

// MIQ specific JS functions

// Things to be done on page loads
function miqOnLoad() {
  // controller to be used in url in miqDropComplete method
  ManageIQ.widget.dashboardUrl = "dashboard/widget_dd_done";

  // Initialize the dashboard column sortables
  if (miqDomElementExists('col1')) {
    miqInitDashboardCols();
  }

  // Track the mouse coordinates for popup menus
  $(document).mousemove(function (e) {
    ManageIQ.mouse.x = e.pageX;
    ManageIQ.mouse.y = e.pageY;
  });

  miqBuildCalendar();
  miqLoadCharts();

  if (typeof miqLoadTL == "function") {
    miqLoadTL();
    if (ManageIQ.timelineFilter) {
      performFiltering(tl, [ 0, 1 ]);
    }
  }

  // Init the toolbars
  if (typeof miqInitToolbars == "function") {
    miqInitToolbars();
  }

  // Initialize the dashboard widget pulldown
  if (miqDomElementExists('widget_select_div')) {
    miqInitWidgetPulldown();
  }

  // Refresh the myCodeMirror editor
  if (ManageIQ.editor !== null) {
    ManageIQ.editor.refresh();
  }

  // Run MIQ after onload code if present
  if (typeof ManageIQ.afterOnload == "string") {
    eval(ManageIQ.afterOnload);
  }

  // Focus on search box, if it's there and allows focus
  if (miqDomElementExists('search_text')) {
    try {
      $('#search_text').focus();
    } catch (_e) {}
  }

  miqInitAccordions();
  miqInitMainContent();
}

function miqPrepRightCellForm(tree) {
  if (miqDomElementExists('adv_searchbox_div')) {
    $('#adv_searchbox_div').hide();
  }
  $('#toolbar').hide();
  miqTreeObject(tree).disableAll({silent: true, keepState: true});
  miqDimDiv(tree + '_div', true);
}

// Initialize the widget pulldown on the dashboard
function miqInitWidgetPulldown() {
  $("#dashboard_dropdown button:not(.dropdown-toggle), #toolbar ul.dropdown-menu > li > a").off('click');
  $("#dashboard_dropdown button:not(.dropdown-toggle), #toolbar ul.dropdown-menu > li > a").on('click', miqWidgetToolbarClick);
}

function miqCalendarDateConversion(server_offset) {
  return moment().utcOffset(Number(server_offset) / 60);
}

// The expressions variable is used only in the following two functions
// TODO: Remove this scope wrapper after the expressions were moved to Ruby
(function () {
  // TODO: This probably should be moved into the Ruby code
  var expressions = {
    'boolean':     __('true/false'),
    'bytes':       __('Number (Bytes)'),
    'date':        __('Date'),
    'datetime':    __('Date/Time'),
    'decimal':     __('Integer'),
    'fixnum':      __('Integer'),
    'float':       __('Number'),
    'gigabytes':   __('Number (GB)'),
    'integer':     __('Integer'),
    'kbps':        __('KBps'),
    'kilobytes':   __('Number (kB)'),
    'megabytes':   __('Number (MB)'),
    'mhz':         __('MHz'),
    'mhz_avg':     __('MHz'),
    'numeric_set': __('Number List'),
    'percent':     __('Percent'),
    'regex':       __('Text (REGEX)'),
    'ruby':        __('Ruby Script'),
    'string':      __('Text'),
    'string_set':  __('String List'),
    'text':        __('Text')
  };

  // Prefill expression value text entry fields when blank
  window.miqExpressionPrefill = function (expEditor, noPrefillCount) {
    var title;


    if ($('#chosen_value[type=text]').length) {
      $('#chosen_value').prop('placeholder', expressions[expEditor.first.type])
      $('#chosen_value').prop('title', expEditor.first.title);
      $('#chosen_value').prop('alt', expEditor.first.title);
    }
    if ($('#chosen_cvalue[type=text]').length) {
      $('#chosen_cvalue').prop('placeholder', expressions[expEditor.second.type])
      $('#chosen_cvalue').prop('title', expEditor.second.title);
      $('#chosen_cvalue').prop('alt', expEditor.second.title);
    }
    if ($('#chosen_regkey[type=text]').length) {
      title = __("Registry Key");
      $('#chosen_regkey').prop('placeholder', expressions['string']);
      $('#chosen_regkey').prop('title', title);
      $('#chosen_regkey').prop('alt', title);
    }
    if ($('#chosen_regval[type=text]').length) {
      title = __("Registry Key Value");
      $('#chosen_regval').prop('placeholder', expressions['string']);
      $('#chosen_regval').prop('title', title);
      $('#chosen_regval').prop('alt', title);
    }
    if ($('#miq_date_1_0[type=text]').length) {
      $('#miq_date_1_0').prop('placeholder', expressions[expEditor.first.type]);
      $('#miq_date_1_0').prop('title', expEditor.first.title);
      $('#miq_date_1_0').prop('alt', expEditor.first.title);
    }
    if ($('#miq_date_1_1[type=text]').length) {
      $('#miq_date_1_1').prop('placeholder', expressions[expEditor.first.type]);
      $('#miq_date_1_1').prop('title', expEditor.first.title);
      $('#miq_date_1_1').prop('alt', expEditor.first.title);
    }
    if ($('#miq_date_2_0[type=text]').length) {
      $('#miq_date_2_0').prop('placeholder', expressions[expEditor.second.type]);
      $('#miq_date_2_0').prop('title', expEditor.second.title);
      $('#miq_date_2_0').prop('alt', expEditor.second.title);
    }
    if ($('#miq_date_2_1[type=text]').length) {
      $('#miq_date_2_1').prop('placeholder', expressions[expEditor.second.type]);
      $('#miq_date_2_1').prop('title', expEditor.second.title);
      $('#miq_date_2_1').prop('alt', expEditor.second.title);
    }
    if (noPrefillCount) {
      expEditor.prefillCount = 0;
      setTimeout(function () {
        miqExpressionPrefill(expEditor, false);
      }, 200);
    } else {
      if (++expEditor.prefillCount > 100) {
        expEditor.prefillCount = 0;
      }
      setTimeout(function () {
        miqExpressionPrefill(expEditor, false);
      }, 200);
    }
  }

  // Prefill report editor style value text entry fields when blank
  // (written more generic for reuse, just have to build
  // the ManageIQ.reportEditor.valueStyles hash)
  window.miqValueStylePrefill = function (count) {
    var found = false;

    for (var field in ManageIQ.reportEditor.valueStyles) {
      if ($(field).length) {
        $(field).prop('placeholder', expressions[ManageIQ.reportEditor.valueStyles[field]]);
        found = true;
      }
    }
    if (found) {
      if (typeof count == 'undefined') {
        ManageIQ.reportEditor.prefillCount = 0;
        setTimeout(function () {
          miqValueStylePrefill(ManageIQ.reportEditor.prefillCount);
        }, 200);
      } else if (count == ManageIQ.reportEditor.prefillCount) {
        if (++ManageIQ.reportEditor.prefillCount > 100) {
          ManageIQ.reportEditor.prefillCount = 0;
        }
        setTimeout(function () {
          miqValueStylePrefill(ManageIQ.reportEditor.prefillCount);
        }, 200);
      }
    }
  }
})();

// Get user's time zone offset
function miqGetTZO() {
  if (miqDomElementExists('user_TZO')) {
    $('#user_TZO').val(moment().utcOffset() / 60);
  }
}

// Get user's browswer info
function miqGetBrowserInfo() {
  var bd = miqBrowserDetect();

  if (miqDomElementExists('browser_name')) {
    $('#browser_name').val(bd.browser);
  }
  if (miqDomElementExists('browser_version')) {
    $('#browser_version').val(bd.version);
  }
  if (miqDomElementExists('browser_os')) {
    $('#browser_os').val(bd.OS);
  }
}

// Turn highlight on or off
function miqHighlight(elem, status) {
  if ($(elem).length) {
    return;
  }

  if (status) {
    $(elem).addClass('active');
  } else {
    $(elem).removeClass('active');
  }
}

// Turn on activity indicator
function miqSparkle(status) {
  if (status) {
    // Make sure an ajax request is active before sparkling
    if ($.active) {
      miqSparkleOn();
    }
  } else {
    // Make sure all but 1 ajax request is done
    if ($.active < 2) {
      miqSparkleOff();
    }
  }
}

function miqSparkleOn() {
  if (miqDomElementExists('advsearchModal') &&
      ($('#advsearchModal').hasClass('modal fade in'))) {
    if (miqDomElementExists('searching_spinner_center')) {
      miqSearchSpinner(true);
    }
    miqSpinner(false);
    if (miqDomElementExists('notification')) {
      $('#notification').hide();
    }
  } else {
    if (miqDomElementExists('notification')) {
      $('#notification').show();
    }
    miqSpinner(true);
  }
}

function miqSparkleOff() {
  miqSpinner(false);
  if (miqDomElementExists('searching_spinner_center')) {
    miqSearchSpinner(false);
  }
  if (miqDomElementExists('notification')) {
    $('#notification').hide();
  }
  if (miqDomElementExists('rep_notification')) {
    $('#rep_notification').hide();
  }
}

// dim/un-dim a div: pass divname and status (true to dim, false to un-dim)
function miqDimDiv(divname, status) {
  if ($(divname).length) {
    if (status) {
      $(divname).addClass('dimmed');
    } else {
      $(divname).removeClass('dimmed');
    }
  }
}

// Check for changes and prompt
function miqCheckForChanges() {
  if (ManageIQ.angular.scope) {
    if (angular.isDefined(ManageIQ.angular.scope.angularForm) && ManageIQ.angular.scope.angularForm.$dirty) {
      var answer = confirm(__("Abandon changes?"));
      if (answer) {
        ManageIQ.angular.scope.angularForm.$setPristine(true);
      }
      return answer;
    }
  } else if (((miqDomElementExists('buttons_on') &&
               $('#buttons_on').is(":visible")) ||
              ManageIQ.changes !== null) &&
             !miqDomElementExists('ignore_form_changes')) {
    return confirm(__("Abandon changes?"));
  }
  // use default browser reaction for onclick
  return true;
}

// Hide/show form buttons
function miqButtons(h_or_s, prefix) {
  $('#flash_msg_div').hide();

  var on = h_or_s == 'show' ? 'on' : 'off';
  var off = h_or_s == 'show' ? 'off' : 'on';

  prefix = (typeof prefix === 'undefined' || prefix === '') ? '' : (prefix + '_');

  $('#' + prefix + 'buttons_' + on).show();
  $('#' + prefix + 'buttons_' + off).hide();
}

// Hide/show form validate buttons
function miqValidateButtons(h_or_s, prefix) {
  prefix = (prefix == null) ? "" : prefix;
  var buttonsOnId = prefix + 'validate_buttons_on';
  var buttonsOffId = prefix + 'validate_buttons_off';

  if (miqDomElementExists('flash_msg_div')) {
    $('flash_msg_div').hide();
  }

  if (h_or_s == "show") {
    if (miqDomElementExists(buttonsOnId)) {
      $('#' + buttonsOnId).show();
    }
    if (miqDomElementExists(buttonsOffId)) {
      $('#' + buttonsOffId).hide();
    }
  } else {
    if (miqDomElementExists(buttonsOffId)) {
      $('#' + buttonsOffId).show();
    }
    if (miqDomElementExists(buttonsOnId)) {
      $('#' + buttonsOnId).hide();
    }
  }
}

// Convert Button image to hyperlink
function toggleConvertButtonToLink(button, url, toggle) {
  if (toggle) {
    button.removeClass('dimmed');
    if (!button.parent().is('a[href]')) {
      button
        .wrap($('<a/>')
          .attr('href', url)
          .attr('title', button.attr('alt')));
    }
  } else {
    button.addClass('dimmed');
    if (button.parent().is('a[href]')) {
      button.unwrap();
    }
  }
}

// update all checkboxes on a form when the masterToggle checkbox is changed
// parms: button_div=<id of div with buttons to update>
function miqUpdateAllCheckboxes(button_div) {
  if (!miqDomElementExists('masterToggle'))
    return;

  var state = $('#masterToggle').prop('checked');

  if (ManageIQ.grids.gtl_list_grid) {
    miqGridCheckAll(state);
    var crows = miqGridGetCheckedRows();

    ManageIQ.gridChecks = crows;
    miqSetButtons(crows.length, button_div);
  } else if ($("input.listcheckbox").length) {
    // No list_grid on the screen
    var cbs = $("input.listcheckbox")
      .prop('checked', state)
      .trigger('change');

    miqUpdateButtons(cbs[0], button_div);
  } else if ($("input[id^='storage_cb']").length) {
    // to handle check/uncheck all for C&U collection
    $("input[id^='storage_cb']")
      .prop('checked', state)
      .trigger('change');
    miqJqueryRequest(miqPassFields(
      "/configuration/form_field_changed",
      {storage_cb_all: state}
    ));
  }
}

// Update buttons based on number of checkboxes that are checked
// parms: obj=<checkbox element>, button_div=<id of div with buttons to update>
function miqUpdateButtons(obj, button_div) {
  var count = 0;

  sendDataWithRx({rowSelect: obj});

  if (typeof obj.id != "undefined") {
    $("input[id^='check_']").each(function () {
      if (this.checked && !this.disabled) {
        count++;
      }
      if (count > 1) {
        return false;
      }
    });
  // Check for number object, as passed from snapshot tree
  } else if (typeof obj == 'number') {
    count = 1;
  }
  miqSetButtons(count, button_div);
}

// Set button enabled or disabled according to the number of selected items
function miqButtonOnWhen(button, onwhen, count) {
  if (typeof onwhen != "undefined") {
    var toggle = true;
    switch(onwhen) {
      case 1:
      case '1':
        toggle = count == 1;
        break;
      case '1+':
        toggle = count >= 1;
        break;
      case '2+':
        toggle = count >= 2;
        break;
    }
    button.toggleClass('disabled', !toggle);
  }
}

// Set the buttons in a div based on the count of checked items passed in
function miqSetButtons(count, button_div) {
  if (!miqDomElementExists(button_div)) {
    return
  }

  if (button_div.match("_tb$")) {
    var toolbar = $('#' + button_div);

    // Non-dropdown master buttons
    toolbar.find('button:not(.dropdown-toggle)').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button, button.data('onwhen'), count);
    });

    // Dropdown master buttons
    toolbar.find('button.dropdown-toggle').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button, button.data('onwhen'), count);
    });

    // Dropdown button items
    toolbar.find('ul.dropdown-menu > li > a').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button.parent(), button.data('onwhen'), count);
    });
  }
}

// go to the specified URL when a table cell is clicked
function DoNav(theUrl) {
  document.location.href = theUrl;
}

// Routines to get the size of the window
function miqResetSizeTimer() {
  var height = window.innerHeight;
  var offset = 427;
  var h = height - offset;
<commit_msg>Added JS code back to handle buttons that are not part of toolbars.<commit_after>/* global dialogFieldRefresh jqplot_bind_events miqBrowserDetect miqExpressionPrefill miqGridCheckAll miqGridGetCheckedRows miqLoadTL miqMenu miqValueStylePrefill performFiltering */

// MIQ specific JS functions

// Things to be done on page loads
function miqOnLoad() {
  // controller to be used in url in miqDropComplete method
  ManageIQ.widget.dashboardUrl = "dashboard/widget_dd_done";

  // Initialize the dashboard column sortables
  if (miqDomElementExists('col1')) {
    miqInitDashboardCols();
  }

  // Track the mouse coordinates for popup menus
  $(document).mousemove(function (e) {
    ManageIQ.mouse.x = e.pageX;
    ManageIQ.mouse.y = e.pageY;
  });

  miqBuildCalendar();
  miqLoadCharts();

  if (typeof miqLoadTL == "function") {
    miqLoadTL();
    if (ManageIQ.timelineFilter) {
      performFiltering(tl, [ 0, 1 ]);
    }
  }

  // Init the toolbars
  if (typeof miqInitToolbars == "function") {
    miqInitToolbars();
  }

  // Initialize the dashboard widget pulldown
  if (miqDomElementExists('widget_select_div')) {
    miqInitWidgetPulldown();
  }

  // Refresh the myCodeMirror editor
  if (ManageIQ.editor !== null) {
    ManageIQ.editor.refresh();
  }

  // Run MIQ after onload code if present
  if (typeof ManageIQ.afterOnload == "string") {
    eval(ManageIQ.afterOnload);
  }

  // Focus on search box, if it's there and allows focus
  if (miqDomElementExists('search_text')) {
    try {
      $('#search_text').focus();
    } catch (_e) {}
  }

  miqInitAccordions();
  miqInitMainContent();
}

function miqPrepRightCellForm(tree) {
  if (miqDomElementExists('adv_searchbox_div')) {
    $('#adv_searchbox_div').hide();
  }
  $('#toolbar').hide();
  miqTreeObject(tree).disableAll({silent: true, keepState: true});
  miqDimDiv(tree + '_div', true);
}

// Initialize the widget pulldown on the dashboard
function miqInitWidgetPulldown() {
  $("#dashboard_dropdown button:not(.dropdown-toggle), #toolbar ul.dropdown-menu > li > a").off('click');
  $("#dashboard_dropdown button:not(.dropdown-toggle), #toolbar ul.dropdown-menu > li > a").on('click', miqWidgetToolbarClick);
}

function miqCalendarDateConversion(server_offset) {
  return moment().utcOffset(Number(server_offset) / 60);
}

// The expressions variable is used only in the following two functions
// TODO: Remove this scope wrapper after the expressions were moved to Ruby
(function () {
  // TODO: This probably should be moved into the Ruby code
  var expressions = {
    'boolean':     __('true/false'),
    'bytes':       __('Number (Bytes)'),
    'date':        __('Date'),
    'datetime':    __('Date/Time'),
    'decimal':     __('Integer'),
    'fixnum':      __('Integer'),
    'float':       __('Number'),
    'gigabytes':   __('Number (GB)'),
    'integer':     __('Integer'),
    'kbps':        __('KBps'),
    'kilobytes':   __('Number (kB)'),
    'megabytes':   __('Number (MB)'),
    'mhz':         __('MHz'),
    'mhz_avg':     __('MHz'),
    'numeric_set': __('Number List'),
    'percent':     __('Percent'),
    'regex':       __('Text (REGEX)'),
    'ruby':        __('Ruby Script'),
    'string':      __('Text'),
    'string_set':  __('String List'),
    'text':        __('Text')
  };

  // Prefill expression value text entry fields when blank
  window.miqExpressionPrefill = function (expEditor, noPrefillCount) {
    var title;


    if ($('#chosen_value[type=text]').length) {
      $('#chosen_value').prop('placeholder', expressions[expEditor.first.type])
      $('#chosen_value').prop('title', expEditor.first.title);
      $('#chosen_value').prop('alt', expEditor.first.title);
    }
    if ($('#chosen_cvalue[type=text]').length) {
      $('#chosen_cvalue').prop('placeholder', expressions[expEditor.second.type])
      $('#chosen_cvalue').prop('title', expEditor.second.title);
      $('#chosen_cvalue').prop('alt', expEditor.second.title);
    }
    if ($('#chosen_regkey[type=text]').length) {
      title = __("Registry Key");
      $('#chosen_regkey').prop('placeholder', expressions['string']);
      $('#chosen_regkey').prop('title', title);
      $('#chosen_regkey').prop('alt', title);
    }
    if ($('#chosen_regval[type=text]').length) {
      title = __("Registry Key Value");
      $('#chosen_regval').prop('placeholder', expressions['string']);
      $('#chosen_regval').prop('title', title);
      $('#chosen_regval').prop('alt', title);
    }
    if ($('#miq_date_1_0[type=text]').length) {
      $('#miq_date_1_0').prop('placeholder', expressions[expEditor.first.type]);
      $('#miq_date_1_0').prop('title', expEditor.first.title);
      $('#miq_date_1_0').prop('alt', expEditor.first.title);
    }
    if ($('#miq_date_1_1[type=text]').length) {
      $('#miq_date_1_1').prop('placeholder', expressions[expEditor.first.type]);
      $('#miq_date_1_1').prop('title', expEditor.first.title);
      $('#miq_date_1_1').prop('alt', expEditor.first.title);
    }
    if ($('#miq_date_2_0[type=text]').length) {
      $('#miq_date_2_0').prop('placeholder', expressions[expEditor.second.type]);
      $('#miq_date_2_0').prop('title', expEditor.second.title);
      $('#miq_date_2_0').prop('alt', expEditor.second.title);
    }
    if ($('#miq_date_2_1[type=text]').length) {
      $('#miq_date_2_1').prop('placeholder', expressions[expEditor.second.type]);
      $('#miq_date_2_1').prop('title', expEditor.second.title);
      $('#miq_date_2_1').prop('alt', expEditor.second.title);
    }
    if (noPrefillCount) {
      expEditor.prefillCount = 0;
      setTimeout(function () {
        miqExpressionPrefill(expEditor, false);
      }, 200);
    } else {
      if (++expEditor.prefillCount > 100) {
        expEditor.prefillCount = 0;
      }
      setTimeout(function () {
        miqExpressionPrefill(expEditor, false);
      }, 200);
    }
  }

  // Prefill report editor style value text entry fields when blank
  // (written more generic for reuse, just have to build
  // the ManageIQ.reportEditor.valueStyles hash)
  window.miqValueStylePrefill = function (count) {
    var found = false;

    for (var field in ManageIQ.reportEditor.valueStyles) {
      if ($(field).length) {
        $(field).prop('placeholder', expressions[ManageIQ.reportEditor.valueStyles[field]]);
        found = true;
      }
    }
    if (found) {
      if (typeof count == 'undefined') {
        ManageIQ.reportEditor.prefillCount = 0;
        setTimeout(function () {
          miqValueStylePrefill(ManageIQ.reportEditor.prefillCount);
        }, 200);
      } else if (count == ManageIQ.reportEditor.prefillCount) {
        if (++ManageIQ.reportEditor.prefillCount > 100) {
          ManageIQ.reportEditor.prefillCount = 0;
        }
        setTimeout(function () {
          miqValueStylePrefill(ManageIQ.reportEditor.prefillCount);
        }, 200);
      }
    }
  }
})();

// Get user's time zone offset
function miqGetTZO() {
  if (miqDomElementExists('user_TZO')) {
    $('#user_TZO').val(moment().utcOffset() / 60);
  }
}

// Get user's browswer info
function miqGetBrowserInfo() {
  var bd = miqBrowserDetect();

  if (miqDomElementExists('browser_name')) {
    $('#browser_name').val(bd.browser);
  }
  if (miqDomElementExists('browser_version')) {
    $('#browser_version').val(bd.version);
  }
  if (miqDomElementExists('browser_os')) {
    $('#browser_os').val(bd.OS);
  }
}

// Turn highlight on or off
function miqHighlight(elem, status) {
  if ($(elem).length) {
    return;
  }

  if (status) {
    $(elem).addClass('active');
  } else {
    $(elem).removeClass('active');
  }
}

// Turn on activity indicator
function miqSparkle(status) {
  if (status) {
    // Make sure an ajax request is active before sparkling
    if ($.active) {
      miqSparkleOn();
    }
  } else {
    // Make sure all but 1 ajax request is done
    if ($.active < 2) {
      miqSparkleOff();
    }
  }
}

function miqSparkleOn() {
  if (miqDomElementExists('advsearchModal') &&
      ($('#advsearchModal').hasClass('modal fade in'))) {
    if (miqDomElementExists('searching_spinner_center')) {
      miqSearchSpinner(true);
    }
    miqSpinner(false);
    if (miqDomElementExists('notification')) {
      $('#notification').hide();
    }
  } else {
    if (miqDomElementExists('notification')) {
      $('#notification').show();
    }
    miqSpinner(true);
  }
}

function miqSparkleOff() {
  miqSpinner(false);
  if (miqDomElementExists('searching_spinner_center')) {
    miqSearchSpinner(false);
  }
  if (miqDomElementExists('notification')) {
    $('#notification').hide();
  }
  if (miqDomElementExists('rep_notification')) {
    $('#rep_notification').hide();
  }
}

// dim/un-dim a div: pass divname and status (true to dim, false to un-dim)
function miqDimDiv(divname, status) {
  if ($(divname).length) {
    if (status) {
      $(divname).addClass('dimmed');
    } else {
      $(divname).removeClass('dimmed');
    }
  }
}

// Check for changes and prompt
function miqCheckForChanges() {
  if (ManageIQ.angular.scope) {
    if (angular.isDefined(ManageIQ.angular.scope.angularForm) && ManageIQ.angular.scope.angularForm.$dirty) {
      var answer = confirm(__("Abandon changes?"));
      if (answer) {
        ManageIQ.angular.scope.angularForm.$setPristine(true);
      }
      return answer;
    }
  } else if (((miqDomElementExists('buttons_on') &&
               $('#buttons_on').is(":visible")) ||
              ManageIQ.changes !== null) &&
             !miqDomElementExists('ignore_form_changes')) {
    return confirm(__("Abandon changes?"));
  }
  // use default browser reaction for onclick
  return true;
}

// Hide/show form buttons
function miqButtons(h_or_s, prefix) {
  $('#flash_msg_div').hide();

  var on = h_or_s == 'show' ? 'on' : 'off';
  var off = h_or_s == 'show' ? 'off' : 'on';

  prefix = (typeof prefix === 'undefined' || prefix === '') ? '' : (prefix + '_');

  $('#' + prefix + 'buttons_' + on).show();
  $('#' + prefix + 'buttons_' + off).hide();
}

// Hide/show form validate buttons
function miqValidateButtons(h_or_s, prefix) {
  prefix = (prefix == null) ? "" : prefix;
  var buttonsOnId = prefix + 'validate_buttons_on';
  var buttonsOffId = prefix + 'validate_buttons_off';

  if (miqDomElementExists('flash_msg_div')) {
    $('flash_msg_div').hide();
  }

  if (h_or_s == "show") {
    if (miqDomElementExists(buttonsOnId)) {
      $('#' + buttonsOnId).show();
    }
    if (miqDomElementExists(buttonsOffId)) {
      $('#' + buttonsOffId).hide();
    }
  } else {
    if (miqDomElementExists(buttonsOffId)) {
      $('#' + buttonsOffId).show();
    }
    if (miqDomElementExists(buttonsOnId)) {
      $('#' + buttonsOnId).hide();
    }
  }
}

// Convert Button image to hyperlink
function toggleConvertButtonToLink(button, url, toggle) {
  if (toggle) {
    button.removeClass('dimmed');
    if (!button.parent().is('a[href]')) {
      button
        .wrap($('<a/>')
          .attr('href', url)
          .attr('title', button.attr('alt')));
    }
  } else {
    button.addClass('dimmed');
    if (button.parent().is('a[href]')) {
      button.unwrap();
    }
  }
}

// update all checkboxes on a form when the masterToggle checkbox is changed
// parms: button_div=<id of div with buttons to update>
function miqUpdateAllCheckboxes(button_div) {
  if (!miqDomElementExists('masterToggle'))
    return;

  var state = $('#masterToggle').prop('checked');

  if (ManageIQ.grids.gtl_list_grid) {
    miqGridCheckAll(state);
    var crows = miqGridGetCheckedRows();

    ManageIQ.gridChecks = crows;
    miqSetButtons(crows.length, button_div);
  } else if ($("input.listcheckbox").length) {
    // No list_grid on the screen
    var cbs = $("input.listcheckbox")
      .prop('checked', state)
      .trigger('change');

    miqUpdateButtons(cbs[0], button_div);
  } else if ($("input[id^='storage_cb']").length) {
    // to handle check/uncheck all for C&U collection
    $("input[id^='storage_cb']")
      .prop('checked', state)
      .trigger('change');
    miqJqueryRequest(miqPassFields(
      "/configuration/form_field_changed",
      {storage_cb_all: state}
    ));
  }
}

// Update buttons based on number of checkboxes that are checked
// parms: obj=<checkbox element>, button_div=<id of div with buttons to update>
function miqUpdateButtons(obj, button_div) {
  var count = 0;

  sendDataWithRx({rowSelect: obj});

  if (typeof obj.id != "undefined") {
    $("input[id^='check_']").each(function () {
      if (this.checked && !this.disabled) {
        count++;
      }
      if (count > 1) {
        return false;
      }
    });
  // Check for number object, as passed from snapshot tree
  } else if (typeof obj == 'number') {
    count = 1;
  }
  miqSetButtons(count, button_div);
}

// Set button enabled or disabled according to the number of selected items
function miqButtonOnWhen(button, onwhen, count) {
  if (typeof onwhen != "undefined") {
    var toggle = true;
    switch(onwhen) {
      case 1:
      case '1':
        toggle = count == 1;
        break;
      case '1+':
        toggle = count >= 1;
        break;
      case '2+':
        toggle = count >= 2;
        break;
    }
    button.toggleClass('disabled', !toggle);
  }
}

// Set the buttons in a div based on the count of checked items passed in
function miqSetButtons(count, button_div) {
  if (!miqDomElementExists(button_div)) {
    return
  }

  if (button_div.match("_tb$")) {
    var toolbar = $('#' + button_div);

    // Non-dropdown master buttons
    toolbar.find('button:not(.dropdown-toggle)').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button, button.data('onwhen'), count);
    });

    // Dropdown master buttons
    toolbar.find('button.dropdown-toggle').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button, button.data('onwhen'), count);
    });

    // Dropdown button items
    toolbar.find('ul.dropdown-menu > li > a').each(function (_k, v) {
      var button = $(v);
      miqButtonOnWhen(button.parent(), button.data('onwhen'), count);
    });
  } else if (button_div.match("_buttons$")) { // Handle buttons that are not part of miq toolbars
    if (count === 0) {
      $("#" + button_div + " button[id$=on_1]").prop('disabled', true);
    } else if (count == 1) {
      $("#" + button_div + " button[id$=on_1]").prop('disabled', false);
    } else {
      $("#" + button_div + " button[id$=on_1]").prop('disabled', false);
    }
  }
}

// go to the specified URL when a table cell is clicked
function DoNav(theUrl) {
  document.location.href = theUrl;
}

// Routines to get the size of the window
function miqResetSizeTimer() {
  var height = window.innerHeight;
  var offset = 427;
  var h = height - offset;

{'fraction_non_alphanumeric': 0.16682173748233917, 'fraction_numerical': 0.005479168820427995, 'mean_word_length': 3.287825059101655, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 33, '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': '7647091', 'n_tokens_mistral': 9663, 'n_tokens_neox': 9522, 'n_words': 1955}