Solution →

CiTi · Computer Coding · Year Two · Unit 1

Roster Admin: An Inline Edit Form

Build the page an administrator uses to add, edit, and remove every student in the program

The Goal

Every student in this program has a record in a database called roster.db. It holds names, logins, class session, level, computer number, district, and more. Right now the only way to change a record is to open the file and edit it by hand. One wrong tab and the whole file breaks.

Your job is to build the admin page that fixes that: one page where an administrator can see every student, open any one of them, change anything, and press Save. The same page adds new students and removes old ones.

You will build it in three parts
  1. UI: what the admin sees. A clean, readable page with a short list of students. Click a student to open that student's full edit form. Plus an "Add a new student" form. No database yet, just the look. Go →
  2. DNA / Data: make it real. Connect the page to roster.db with WebDNA so the list is real and Add, Save, and Delete actually change the data, safely. Go →
  3. JavaScript: make it friendly. Small helpers in the browser: open or close every student at once, warn about unsaved changes, and ask "Are you sure?" before a delete. Go →

What it looks like when it's done

Use these as a reference point. Your colors and layout can be your own; the page has to do the same jobs.

The finished admin page. A toolbar with Show, Sort, and Expand all sits above a count of 10 students and a list of summary rows. The first student, Jordan Avery, is open: the first name was just changed, so the row is highlighted and marked unsaved. Below it, labeled boxes group Name, Login, Class, Account, and Folder fields, with Delete, Undo changes, and Save buttons and the record's Key.
A student opened for editing. The first name was just changed, so the row is marked (unsaved) until Save is pressed.
The Add a new student area, opened. The same five labeled boxes, empty, with defaults filled in: AM, this year, 1st Year, Active, chat Yes, Student, and Choose a district. Clear and Add student buttons at the bottom right.
The “Add a new student” area, opened. Same fields, empty, with sensible defaults.

Finish each part and show your teacher before you start the next one. Each part should still work on its own: the page has to do its real job (Part 2) even if JavaScript is turned off.

0Start Here

  1. Go to your assignments folder: /citi/coding/2027/2/YOURINTS/lessons/assignments/. Make a new file there called week2.html. This one file is your whole project.
  2. In the same assignments folder, make a folder called databases.
  3. Download roster.zip and unzip it. It holds two files: roster.db and district.db. Upload both into assignments/databases/. Your page will find them at databases/roster.db and databases/district.db. Do not open them in your editor and save them. If your editor changes their line endings or tabs, WebDNA can stop reading them. Messed one up? Download the zip again for fresh copies.
  4. Open your live URL in Chrome and keep it open the whole time. WebDNA only runs on the server, so always test the live page.
About apps This assignment names the job, not the app. “Upload” means sending files to the server over SFTP (the secure file transfer protocol). “Your editor” means any plain-text editor. In class we use Fetch for SFTP and BBEdit as the editor, but any SFTP app and any plain-text editor do the same job.
Treat it like real data The 12 students in the file are made up, but treat them like a real admin would. Do your testing on test students you add yourself (name them something like "Test Student"). Never delete or rename the records that came in the file.

Know Your Data

Before you design a single box, you need to know what is in the table. Here is every field in roster.db. Field names are the exact spelling in the file (WebDNA does not care about capital letters, but spelling must match).

FieldWhat it holdsStored asBest form control
SKURecord number. WebDNA makes it.numberShow it, never edit it
FNAMEFirst nametextText box (required)
LNAMELast nametextText box (required)
KEYA long unique ID made when the record is addednumberShow it, never edit it
UNAMELogin username. No two students may share one.textText box (required)
PWORDLogin passwordtextText box (required)
SESSIONClass session1 = AM, 0 = PMDropdown
SCHOOLYEARSchool year, like 20264-digit yearDropdown: 5 years back to 5 years ahead of this year
STATUSStill in the program?1 = Active, 0 = InactiveDropdown
STUDENTDIRThe student's web foldertext pathText box
LEVELWho this person is1 = 1st Year, 2 = 2nd Year, 3 = Teacher, 4 = Admin, 5 = OperatorDropdown
COMPUTERNUMAssigned computernumberText box
CHATALLOWEDCan use chat?1 = Yes, 0 = NoDropdown
EMAILSchool emailtextText box
ADMINACCESSCan use admin pages?1 = Admin, 0 = StudentDropdown
r_districtHome school district. It holds the sku of a row in district.db, not the name.number (a district sku)Dropdown built from district.db

The second table: district.db

The district names live in their own small table. Each district is stored once.

FieldWhat it holds
skuThe district's record number (1 to 9)
districtThe district's name, like Oswego

The two tables are linked. In district.db, sku is the primary key: it names exactly one district. In roster.db, r_district is a foreign key: it points at that sku. (The r_ means “related to.”) If a student's r_district is 6, look up sku 6 in district.db and you get Oswego. Rename a district once in district.db and every student shows the new name.

Notice Most fields store a number that stands for a word. The database says 1; the admin should see "AM." Your page translates in both directions: show the word, save the number. For most fields, the meaning is in the table above. For the district, the meaning is in district.db.

1UI: What the Admin Sees

Goal: a finished-looking page built with hand-typed sample students. When Part 1 is done, a stranger should be able to look at it and know exactly how to add, edit, and delete a student, even though nothing saves yet.

Steps

  1. Sketch it first. On paper, draw the page: a header, an "Add a new student" area, a toolbar, and a list of students. Decide which 6 to 8 fields are worth seeing in the closed list row (hint: the ones an admin scans for). Everything else lives in the open form.
  2. Build the page shell. Header with a title and one line telling the admin how the page works. Put your CSS in a style block at the top of the page.
  3. Build one student row that opens and closes. Use the HTML element that is made for "click to show more" (look up the pair of tags that do this with no JavaScript). The always-visible part is the summary row. The hidden part is that student's edit form.
  4. Give each student their own form. One form per student, with a field for every editable column in the table above. Use the right control for each field: a text box or a dropdown.
  5. Label every field. Every box gets a visible label. An admin should never have to guess what a box is for.
  6. Group the fields. 15 fields in one long line is unreadable. Group them in boxes with titles, for example Name, Login, Class, Account, and Folder.
  7. Add the buttons. Each student form needs Save, Delete, and Undo changes. Make Delete look different from Save (it should look dangerous). Show the record number and KEY, but as text, not as boxes.
  8. Build the "Add a new student" form. Same fields, empty, inside its own open-and-close area at the top. One button: Add student. Add sensible defaults: this year selected, Active, Student.
  9. Add a toolbar. Two dropdowns above the list: Show (Active, Inactive, All) and Sort (First name, Last name, Record #, Computer #). They don't need to work yet.
  10. Make inactive students look inactive. Pick one of your sample rows to be inactive and style it so an admin can tell at a glance (faded, crossed out, a gray badge, your call).
  11. Copy the row 3 or 4 times with different sample people, so you can judge how a full list looks.
  12. Check a phone-width window. Make your browser narrow. The page must not scroll sideways. Hide the less important summary columns on small screens.
Done with Part 1 when
  • Each student is a closed summary row that opens to a full, labeled, grouped edit form.
  • Every editable field from Know Your Data has the right kind of control.
  • Save, Delete, and Undo changes are on every student; Delete looks different.
  • The Add form, toolbar, and an inactive row are all there.
  • No sideways scrolling at phone width.
  • Show your teacher before Part 2.

2DNA / Data: Make It Real

Goal: the sample rows are gone. The list comes from roster.db, and Add, Save, and Delete really change the data. Bad input can't break the file, and refreshing the page never saves anything twice.

How the page is laid out

Top of the fileSettings: the database path and any default values.
→
ThenThe action section: if a form was sent, do the add, save, or delete, then send the browser back to the page.
→
ThenThe HTML you built in Part 1, now filled from a database search.
→
Very endClose the database so changes are written to the file.

The page sends its forms to itself. One hidden piece of information (an "action") tells the top of the page which job to do. Hint: the Save and Delete buttons can each carry their own action value, so one form can do two jobs.

Steps

  1. Settings. At the top, store each database path (roster and district) in its own text variable. Use the variables everywhere after that, never the typed paths.
  2. List the real students. Replace your sample rows with a database search that finds every record, and put your Part 1 row inside the found-items loop. Every value in the row and the form comes from the record.
  3. Translate numbers to words. In the summary row, show "PM" and "2nd Year," not 0 and 2. For the district, don't type the names into your page: look up the name in district.db using the student's r_district. If no district matches, show "Unknown."
  4. Build the district dropdown from district.db. Replace your hand-typed district options with a search of district.db, sorted by name. Each option's value is the district's sku; its text is the name. Do this in the Add form and in every student's form. The form field is named r_district, to match the database. Careful: inside this search, sku means the district's sku, not the student's. Save the student's district in a text variable before the search starts, then compare to that.
  5. Pre-select every dropdown. Each student's dropdowns must open on that student's saved value. Check the school year carefully: it must show the year in the record, not this year. (Last year's student version got this wrong, and every Save quietly changed students' years.)
  6. Show a count. Above the list, show how many students were found, with the right word: "1 student," "10 students."
  7. Make Show and Sort work. The toolbar sends its choice to the page. Use it to change the search: Active only, Inactive only, or All, and the sort order. Number fields (Record #, Computer #) must sort as numbers, or 10 lands before 2. If no students match, show a friendly "No students match this view" message.
  8. Add. When the Add form is sent, append a new record with every field. Let WebDNA number the record. Give the KEY a unique value made by WebDNA.
  9. Save. When a student's form is sent, replace that one record, found by its record number. Every student form needs to send its record number in a hidden field.
  10. Delete. When Delete is pressed, delete that one record, found by its record number. Only test this on your own test students. The "Are you sure?" comes in Part 3.
  11. Protect the data from special characters. Try adding a last name like O'Brien & Sons and a password with an equals sign in it. If the saved value gets cut off, you forgot to encode the values you write to the database. Every value you save must be encoded.
  12. Block duplicate usernames. Before you add, search for the username. If it's taken, don't add. Show a clear red message, and keep the Add form open with what the admin typed. On Save, the username may match this student, but not anyone else.
  13. Send the browser back after every change. After a successful add, save, or delete, redirect to the page. Then pressing Refresh can never send the form again. Keep the admin's Show and Sort choices in that redirect.
  14. Confirm what happened. After the redirect, show a short green message: "Student added," "Changes saved," "Student deleted." Pass a short code word in the address, not the message itself. The page decides what each code word says. (Why? If the page prints whatever text is in the address, anyone can send an admin a link that puts their own words, or worse, on your page.)
  15. Handle fields that were never sent. Open your page with no form sent. Do any square-bracket names show up in your messages or boxes? A form field that wasn't sent prints its own name. Find each one and make it blank.
  16. Close both databases at the very end of the page.
  17. View Source. On your live page, you should find no square brackets anywhere.
Done with Part 2 when
  • The list, count, Show, and Sort all come from roster.db.
  • District names and both district dropdowns come from district.db; nothing about districts is typed into the page.
  • Add, Save, and Delete work, and every dropdown opens on the saved value.
  • O'Brien & Sons saves and comes back exactly as typed.
  • A duplicate username is refused on Add and on Save, with a clear message.
  • Refreshing after any change does nothing.
  • The page works with JavaScript turned off.
  • Show your teacher before Part 3.

3JavaScript: Make It Friendly

Goal: small browser helpers that make the page safer and faster to use. JavaScript never saves data here. WebDNA already does that. JavaScript only helps the admin in the browser.

Watch out WebDNA reads your whole page before the browser does, JavaScript included. Anything in square brackets inside your script can be read as a WebDNA tag. Write your JavaScript so it needs no square brackets.

Steps

  1. "Are you sure?" before Delete. When Delete is pressed, ask "Delete First Last? This cannot be undone." If the admin cancels, nothing is sent. Get the student's name from a data attribute on the form, not by pasting it into the script. Test it on a name with an apostrophe in it.
  2. Expand all / Collapse all. One toolbar button opens every student. Pressing it again closes them all. The button's words change to match.
  3. Mark unsaved changes. The moment the admin types or changes anything in a student's form, that student's row changes color and says "(unsaved)." Undo changes and Save both clear it.
  4. Warn before leaving. If any row is still marked unsaved and the admin tries to leave or refresh, the browser asks first.
  5. Turn JavaScript off and test again. Everything from Part 2 must still work. (Delete just won't ask first.)
Done with Part 3 when
  • Delete always asks first, and Cancel really cancels, even for O'Brien.
  • Expand all and Collapse all work, and the button's words change.
  • An edited row is marked unsaved; Save and Undo clear it.
  • Leaving with unsaved edits asks first.
  • The browser console shows no red errors.

Test Plan: prove it works

Real developers write down their tests and the results. Copy this table into a document, run every test on your live page, and fill in what happened. Hand it in with your page.

#Do thisIt should
1Add "Test O'Brien & Sons" with password a&b=cShow "Student added"; name and password come back exactly as typed
2Add another student with the same usernameRefuse, red message, Add form still filled in
3Change your test student's school year and district and saveReopen shows the new year and district; the summary row shows the new district name
4Give your test student a real student's username and saveRefuse with a message; nothing changes
5Set your test student to Inactive and saveLeaves the Active view; shows in Inactive, styled as inactive
6Press Refresh right after a saveNothing is saved again
7Sort by Computer #2 comes before 10 and 19
8Edit a field, then try to leave the pageRow shows unsaved; browser asks before leaving
9Press Delete, then CancelNothing deleted
10Delete your test student for real"Student deleted"; count goes down by one
11View SourceNo square brackets anywhere
12Narrow the window to phone widthNo sideways scrolling

Grading

PartPointsWhat earns them
1 · UI30Clear layout, open-and-close rows, labeled and grouped fields, right controls, Add form, toolbar, inactive style
2 · DNA / Data50Real list and count, Show and Sort, district lookup and dropdown from district.db, Add, Save, Delete, saved values pre-selected, duplicate check, redirect, code-word messages
3 · JavaScript15Delete confirm, Expand all, unsaved marker, leave warning, no console errors
Test Plan5All 12 tests run on the live page, with results written down

Am I done? Check before you tell your teacher

  • My page is assignments/week2.html and reads assignments/databases/roster.db and district.db.
  • Every student opens to a full, labeled edit form with Save, Delete, and Undo changes.
  • Add, Save, and Delete really change the database, and Refresh never repeats them.
  • Every dropdown opens on the student's saved value, school year and district included.
  • Special characters save correctly, and duplicate usernames are refused.
  • Show, Sort, and the student count work.
  • Delete asks first; unsaved edits are marked and warned about.
  • The page works with JavaScript off.
  • View Source shows no square brackets.
  • I deleted my test students, and the original records are untouched.
  • My test plan is filled in.