Crescent Credit Union League Richard Coates is the IT manager at the Crescent Credit Union League (CCUL), an advocacy group for credit unions providing a political voice for credit unions and offering education and training for CCUL members. Richard wants you to work on the CCUL’s staff directory page for its website. He wants users to be able to search the directory, retrieving contact information for specific employees at CCUL. The staff directory is stored in an object literal named "staff" that contains a single object named "directory". The directory object contains an array of objects that displays each employee's id, first and last name, position, department, e-mail address, phone number, and image file. Your job is to create a search tool that searches the staff object directory array for employees whose last name, position, and/or department matches the user's search conditions. A preview of the page you will create is shown in Figure 14-48. Setup Use your editor to open the cc_staff.html and cc_staff.js files. Enter your name and the date in the comment section of each file. Linking JS File Go to the cc_staff.html file in your editor. Within the document head add script elements for the cc_data.js and cc_staff.js files in that order. Load the files asynchronously. Take some time to study the contents of the file. Use your editor to open the cc_data.js file and study the data stored in the staff object to become familiar with its contents and structure. Close the file, but do not make any changes to the document. Go to the cc_staff.js file in your editor. Richard has already created a constructor function for the class of employee objects storing each employee's id, name, department, position, e-mail, phone, and photo. He has also already created an object literal named searchResult that will be used to store the search results in an employees array. Event Listeners Go to the event listener for the click event. This event listener will run the code that displays the search results in a staff table. Within this event listener, add the code specified in the remainder of this lab. Richard has added the removeChildren() method to the prototype of the HTMLElement object which removes all children from a DOM element. Apply this method to the tableBody variable to remove all table rows that might still be present in the staff table from previous searches. Erase previous search results by setting the employees array of the searchResult object to the empty array []. Next, you will write the code that returns the employee records that match search conditions set by the user. Apply the forEach() array method to loop through the contents of the directory array in the staff object. For each employee object in the directory array, run an anonymous function with the parameter, record, that represents each record in the array. Add the commands specified in the JavaScript Commands section of the next step to the anonymous function within the forEach() array method. JavaScript Commands Create the nameSearch variable equal to the value entered in the nameSearch input box. Users can search for names in three ways: Matching an employee's last name if it contains the text string specified in nameSearch Matching an employee's last name if it begins with the nameSearch text string Matching an employee's last name only if it exactly matches the nameSearch text string. Richard has supplied you with code to add the selectedValue() method to the prototype of the HTMLSelectElement object class in order to return the value of the selected option in any selection list. Apply the selectedValue() method to the nameSearchType selection list to return the option selected by the user, storing the value in the nameSearchType variable. Create a switch-case structure for the following possible values of the nameSearchType variable: If nameSearchType equals "contains", use the new RegExp() constructor to create a regular expression object named nameRegExp containing the regular expression nameSearch where nameSearch is the value of the nameSearch variable. Include the "i" flag with the regular expression object so that the regular expression matches lower or uppercase characters. If nameSearchType equals "beginsWith", set nameRegExp object to the regular expression ^nameSearch, once again with the "i" flag. If nameSearchType equals "exact", set nameRegExp object to the regular expression ^nameSearch$ with the "i" flag to allow for upper- and lower-case matches. (There is a second part to this that I sent in a separately.)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Crescent Credit Union League Richard Coates is the IT manager at the Crescent Credit Union League (CCUL), an advocacy group for credit unions providing a political voice for credit unions and offering education and training for CCUL members. Richard wants you to work on the CCUL’s staff directory page for its website. He wants users to be able to search the directory, retrieving contact information for specific employees at CCUL.

The staff directory is stored in an object literal named "staff" that contains a single object named "directory". The directory object contains an array of objects that displays each employee's id, first and last name, position, department, e-mail address, phone number, and image file.

Your job is to create a search tool that searches the staff object directory array for employees whose last name, position, and/or department matches the user's search conditions. A preview of the page you will create is shown in Figure 14-48.

Setup

Use your editor to open the cc_staff.html and cc_staff.js files. Enter your name and the date in the comment section of each file.

Linking JS File

Go to the cc_staff.html file in your editor. Within the document head add script elements for the cc_data.js and cc_staff.js files in that order. Load the files asynchronously. Take some time to study the contents of the file.

Use your editor to open the cc_data.js file and study the data stored in the staff object to become familiar with its contents and structure. Close the file, but do not make any changes to the document.

 

Go to the cc_staff.js file in your editor. Richard has already created a constructor function for the class of employee objects storing each employee's id, name, department, position, e-mail, phone, and photo. He has also already created an object literal named searchResult that will be used to store the search results in an employees array.

Event Listeners

Go to the event listener for the click event. This event listener will run the code that displays the search results in a staff table. Within this event listener, add the code specified in the remainder of this lab.

Richard has added the removeChildren() method to the prototype of the HTMLElement object which removes all children from a DOM element. Apply this method to the tableBody variable to remove all table rows that might still be present in the staff table from previous searches.

Erase previous search results by setting the employees array of the searchResult object to the empty array [].

Next, you will write the code that returns the employee records that match search conditions set by the user. Apply the forEach() array method to loop through the contents of the directory array in the staff object. For each employee object in the directory array, run an anonymous function with the parameter, record, that represents each record in the array. Add the commands specified in the JavaScript Commands section of the next step to the anonymous function within the forEach() array method.

 

JavaScript Commands

Create the nameSearch variable equal to the value entered in the nameSearch input box.

Users can search for names in three ways:

  1. Matching an employee's last name if it contains the text string specified in nameSearch
  2. Matching an employee's last name if it begins with the nameSearch text string
  3. Matching an employee's last name only if it exactly matches the nameSearch text string.

Richard has supplied you with code to add the selectedValue() method to the prototype of the HTMLSelectElement object class in order to return the value of the selected option in any selection list. Apply the selectedValue() method to the nameSearchType selection list to return the option selected by the user, storing the value in the nameSearchType variable.

Create a switch-case structure for the following possible values of the nameSearchType variable:

  1. If nameSearchType equals "contains", use the new RegExp() constructor to create a regular expression object named nameRegExp containing the regular expression nameSearch where nameSearch is the value of the nameSearch variable. Include the "i" flag with the regular expression object so that the regular expression matches lower or uppercase characters.
  2. If nameSearchType equals "beginsWith", set nameRegExp object to the regular expression ^nameSearch, once again with the "i" flag.

If nameSearchType equals "exact", set nameRegExp object to the regular expression ^nameSearch$ with the "i" flag to allow for upper- and lower-case matches.

 

 

(There is a second part to this that I sent in a separately.) 

ADVOCACY
COMPLIANCE DEVELOPMENT
COMMUNITY
NEWS
SUPPORT
NEWSLETTER
CRESCENT CREDIT UNION LEAGUE
Staff Directory
Last Name
M
Begins With
Department
Position
director
Contains
search
3 records found
PHOTO
NAME
DEPARTMENT
PO SITION
E-MAIL
PHONE
Betty Moran
Professional Development
Director of Meetings & Conferences
betty.moran@ccul.example.com
B0D-555-6506
Douglas Moorman
Audit Services
Director of Comprehensive Audits
douglaz.moorman@ccul.example.com
B00-555-9019
Steven Miller
PR and Communications
Director of Communications
steven-millen@ccul.example.com
B0D-555-5505
ADVOCACY
COMPLIANCE
DEVELOPMENT
COMMUNITY
Deadlines & Policies
Regulatory Deadlines
Compliance FAQ
Fraud & Risk Resources
Annual Meeting
Leadership Institute
Webinars
Grass Roots Action
Chapters
Asset Groups
CCUL History
Membership Info
Social Media
Federal Issues
Research & Resources
Regulatory Report
Training
Compliance Group
Certification
CCUL Magazine
Call Center
Events
Advocacy Team
Board of Directors
Crescent Credit Union League © 2018 All Rights Reserved
Transcribed Image Text:ADVOCACY COMPLIANCE DEVELOPMENT COMMUNITY NEWS SUPPORT NEWSLETTER CRESCENT CREDIT UNION LEAGUE Staff Directory Last Name M Begins With Department Position director Contains search 3 records found PHOTO NAME DEPARTMENT PO SITION E-MAIL PHONE Betty Moran Professional Development Director of Meetings & Conferences betty.moran@ccul.example.com B0D-555-6506 Douglas Moorman Audit Services Director of Comprehensive Audits douglaz.moorman@ccul.example.com B00-555-9019 Steven Miller PR and Communications Director of Communications steven-millen@ccul.example.com B0D-555-5505 ADVOCACY COMPLIANCE DEVELOPMENT COMMUNITY Deadlines & Policies Regulatory Deadlines Compliance FAQ Fraud & Risk Resources Annual Meeting Leadership Institute Webinars Grass Roots Action Chapters Asset Groups CCUL History Membership Info Social Media Federal Issues Research & Resources Regulatory Report Training Compliance Group Certification CCUL Magazine Call Center Events Advocacy Team Board of Directors Crescent Credit Union League © 2018 All Rights Reserved
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY