<commit_before><%--
/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2002-2014 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) 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, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <<EMAIL>>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

--%>

<%@page language="java"
	contentType="text/html"
	session="true"
	import="
		java.io.*,
		java.util.*,
		org.opennms.web.admin.notification.noticeWizard.*,
		org.opennms.netmgt.config.*,
		org.opennms.netmgt.config.notifications.*,
		org.opennms.core.utils.BundleLists,
		org.opennms.core.utils.ConfigFileConstants,
		org.opennms.netmgt.xml.eventconf.Event,
		org.springframework.core.io.FileSystemResource
	"
%>

<%!
	private DefaultEventConfDao m_eventConfDao;

	public void init() throws ServletException {
		try {
			m_eventConfDao = new DefaultEventConfDao();
			m_eventConfDao.setConfigResource(new FileSystemResource(ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME)));
			m_eventConfDao.afterPropertiesSet();
		} catch (Throwable e) {
			throw new ServletException("Cannot load configuration file", e);
		}
	}
%>

<%
    HttpSession user = request.getSession(true);
    Notification newNotice = (Notification)user.getAttribute("newNotice");
%>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
  <jsp:param name="title" value="Choose Event" />
  <jsp:param name="headTitle" value="Choose Event" />
  <jsp:param name="headTitle" value="Admin" />
  <jsp:param name="breadcrumb" value="<a href='admin/index.jsp'>Admin</a>" />
  <jsp:param name="breadcrumb" value="<a href='admin/notification/index.jsp'>Configure Notifications</a>" />
  <jsp:param name="breadcrumb" value="<a href='admin/notification/noticeWizard/eventNotices.jsp'>Event Notifications</a>" />
  <jsp:param name="breadcrumb" value="Choose Event" />
</jsp:include>

<script type="text/javascript" src="js/jquery/jquery.js"></script>

<script type="text/javascript" >

    function next()
    {
        if (document.events.uei.selectedIndex==-1)
        {
            alert("Please select a uei to associate with this notification.");
        }
        else
        {
            document.events.submit();
        }
    }

$(document).ready(function() {

  $("select#uei").change(function(e) {
    var label = $(e.target.options[e.target.selectedIndex]).text();
    $('#regexp').prop('disabled', label !== 'REGEX_FIELD');
  });

  $('#regexp').change(function(e) {
    var value = e.target.value;
    if (!value.match("^~")) {
      alert("Invalid regex field: [" + value + "], value does not start with ~\n" +
        "Resetting value back to default.\n"
      );
      e.target.value = e.target.defaultValue;
      return false;
    }
    var uei = $('#uei')[0];
    $(uei.options[uei.selectedIndex]).val(value);
    uei.selectmenu('refresh');
  });
  if ($('#regexp').val() === '~^$') {
    $('#regexp').prop('disabled', true);
  }

});

</script>

<h2><%=(newNotice.getName()!=null ? "Editing notice: " + newNotice.getName() + "<br/>" : "")%></h2>

<form method="post" name="events"
      action="admin/notification/noticeWizard/notificationWizard" >
<input type="hidden" name="sourcePage" value="<%=NotificationWizardServlet.SOURCE_PAGE_UEIS%>"/>

<div class="row">
  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">Choose the event uei that will trigger this notification.</h3>
      </div>
      <table class="table table-condensed">
        <tr>
          <td valign="top" align="left">
            <div class="form-group">
              <label for="uei" class="control-label">Events</label>
              <select id="uei" name="uei" class="form-control" size="20" >
              <%=buildEventSelect(newNotice)%>
              </select>
            </div>
            <div class="form-group">
              <label for="regexp" class="control-label">Regular Expression Field</label>
              <input id="regexp" name="regexp" type="text" class="form-control" size="96" value="<%=(newNotice.getUei()!=null ? newNotice.getUei() : "")%>" />
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <input type="reset" class="btn btn-default"/><commit_msg>NMS-7507: Notification wizard client-side filtering of event list  (in foundation)<commit_after><%--
/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2002-2015 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2015 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) 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, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <<EMAIL>>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

--%>

<%@page language="java"
	contentType="text/html"
	session="true"
	import="
		java.io.*,
		java.util.*,
		org.opennms.web.admin.notification.noticeWizard.*,
		org.opennms.netmgt.config.*,
		org.opennms.netmgt.config.notifications.*,
		org.opennms.core.utils.BundleLists,
		org.opennms.core.utils.ConfigFileConstants,
		org.opennms.netmgt.xml.eventconf.Event,
		org.springframework.core.io.FileSystemResource
	"
%>

<%!
	private DefaultEventConfDao m_eventConfDao;

	public void init() throws ServletException {
		try {
			m_eventConfDao = new DefaultEventConfDao();
			m_eventConfDao.setConfigResource(new FileSystemResource(ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME)));
			m_eventConfDao.afterPropertiesSet();
		} catch (Throwable e) {
			throw new ServletException("Cannot load configuration file", e);
		}
	}
%>

<%
    HttpSession user = request.getSession(true);
    Notification newNotice = (Notification)user.getAttribute("newNotice");
%>

<jsp:include page="/includes/bootstrap.jsp" flush="false" >
  <jsp:param name="title" value="Choose Event" />
  <jsp:param name="headTitle" value="Choose Event" />
  <jsp:param name="headTitle" value="Admin" />
  <jsp:param name="breadcrumb" value="<a href='admin/index.jsp'>Admin</a>" />
  <jsp:param name="breadcrumb" value="<a href='admin/notification/index.jsp'>Configure Notifications</a>" />
  <jsp:param name="breadcrumb" value="<a href='admin/notification/noticeWizard/eventNotices.jsp'>Event Notifications</a>" />
  <jsp:param name="breadcrumb" value="Choose Event" />
</jsp:include>

<script type="text/javascript" src="js/jquery/jquery.js"></script>

<script type="text/javascript" >

    function next()
    {
        if (document.events.uei.selectedIndex==-1)
        {
            alert("Please select a uei to associate with this notification.");
        }
        else
        {
            document.events.submit();
        }
    }

$(document).ready(function() {

  var allUeiOptions = $("#uei > option");
  var unavailableUeiOptGroup = $("#uei > optgroup");

  function filterUeiList() {
    var filterText = $("#uei-list-filter").val().toLowerCase();
    $("#uei").empty();
    if (filterText.length == 0) {
      $("#uei").append(allUeiOptions);
      $("#uei").append(unavailableUeiOptGroup);
    } else {
      allUeiOptions.each(function ( index, element ) {
        if ( $(this).text().toLowerCase().indexOf(filterText) != -1) {
          $("#uei").append( $(this) );
        }
      });
    }
    $('#filteringModal').modal('hide');
    $('#uei-list-filter').focus();
  }

  $("#uei-list-filter").keydown(function(event) {
    if (event.which == 27) {
      event.preventDefault();
      if ($("#uei-list-filter").val().length > 0) {
        $('#uei-list-filter').val("");
        $('#filteringModal').modal('show');
      }
    }
  });

  $("#uei").keydown(function(event) {
    if (event.which == 27) {
      event.preventDefault();
      if ($("#uei-list-filter").val().length > 0) {
        $('#uei-list-filter').val("");
        $('#filteringModal').modal('show');
      }
    }
  });

  $("#uei-list-filter").keypress(function(event) {
    if (event.which == 13) {
      event.preventDefault();
      $('#filteringModal').modal('show');
    }
  });

  $("#filteringModal").on( "shown.bs.modal", function() { filterUeiList(); } );

  $("select#uei").change(function(e) {
    var label = $(e.target.options[e.target.selectedIndex]).text();
    $('#regexp').prop('disabled', label !== 'REGEX_FIELD');
  });

  $('#regexp').change(function(e) {
    var value = e.target.value;
    if (!value.match("^~")) {
      alert("Invalid regex field: [" + value + "], value does not start with ~\n" +
        "Resetting value back to default.\n"
      );
      e.target.value = e.target.defaultValue;
      return false;
    }
    var uei = $('#uei')[0];
    $(uei.options[uei.selectedIndex]).val(value);
    uei.selectmenu('refresh');
  });
  if ($('#regexp').val() === '~^$') {
    $('#regexp').prop('disabled', true);
  }

});

</script>

<div id="filteringModal" class="modal fade" tabindex="-1">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-body">
        <i class="fa fa-spinner"></i> Filtering
      </div>
    </div>
  </div>
</div>

<h2><%=(newNotice.getName()!=null ? "Editing notice: " + newNotice.getName() + "<br/>" : "")%></h2>

<form method="post" name="events"
      action="admin/notification/noticeWizard/notificationWizard" >
<input type="hidden" name="sourcePage" value="<%=NotificationWizardServlet.SOURCE_PAGE_UEIS%>"/>

<div class="row">
  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">Choose the event UEI that will trigger this notification.</h3>
      </div>
      <table class="table table-condensed">
        <tr>
          <td valign="top" align="left">
            <div class="form-group">
              <label for="uei" class="control-label">Events</label>
              <input id="uei-list-filter" name="uei-list-filter" type="text" class="form-control" size="96" value="" placeholder="Filter displayed events..." />
              <select id="uei" name="uei" class="form-control" size="20" >
              <%=buildEventSelect(newNotice)%>
              </select>
            </div>
            <div class="form-group">
              <label for="regexp" class="control-label">Regular Expression Field</label>
              <input id="regexp" name="regexp" type="text" class="form-control" size="96" value="<%=(newNotice.getUei()!=null ? newNotice.getUei() : "")%>" />
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <input type="reset" class="btn btn-default"/>
{'fraction_non_alphanumeric': 0.19485174323884003, 'fraction_numerical': 0.006109481915933529, 'mean_word_length': 3.411426518145886, 'pattern_counts': {'":': 0, '<': 134, '<?xml version=': 0, '>': 138, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, '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': '2373300', 'n_tokens_mistral': 3952, 'n_tokens_neox': 3820, 'n_words': 820}