cleaned up key handling; added delete entry panel
This commit is contained in:
parent
beb22585a2
commit
c4d8ea9c08
205
app/appui.cls
205
app/appui.cls
@ -71,6 +71,12 @@
|
|||||||
when clrset = 5 then panel~init_pair(6, panel~COLOR_BLACK, panel~COLOR_GREEN)
|
when clrset = 5 then panel~init_pair(6, panel~COLOR_BLACK, panel~COLOR_GREEN)
|
||||||
/* black text on cyan background */
|
/* black text on cyan background */
|
||||||
when clrset = 6 then panel~init_pair(7, panel~COLOR_BLACK, panel~COLOR_CYAN)
|
when clrset = 6 then panel~init_pair(7, panel~COLOR_BLACK, panel~COLOR_CYAN)
|
||||||
|
/* Yellow text on blue background */
|
||||||
|
when clrset = 7 then panel~init_pair(8, panel~COLOR_YELLOW, panel~COLOR_BLUE)
|
||||||
|
/* Cyan text on black background */
|
||||||
|
when clrset = 8 then panel~init_pair(9, panel~COLOR_CYAN, panel~COLOR_BLACK)
|
||||||
|
/* blacken everything to give the appearance of disappearance */
|
||||||
|
when clrset = 9 then panel~init_pair(10, panel~COLOR_BLACK, panel~COLOR_BLACK)
|
||||||
/* Default to white text on black background */
|
/* Default to white text on black background */
|
||||||
OTHERWISE DO
|
OTHERWISE DO
|
||||||
clrset=0
|
clrset=0
|
||||||
@ -97,8 +103,8 @@
|
|||||||
with_box = .true
|
with_box = .true
|
||||||
|
|
||||||
menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box)
|
menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box)
|
||||||
menu_items = .array~of("[A]dd Contact", "[R]emove Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit")
|
menu_items = .array~of("[A]dd Contact", "[D]elete Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit")
|
||||||
menu_keys = .array~of("a", "r", "e", "s", "l", "q")
|
menu_keys = .array~of("a", "d", "e", "s", "l", "q")
|
||||||
|
|
||||||
/* Display menu items */
|
/* Display menu items */
|
||||||
.environment~selected = 1
|
.environment~selected = 1
|
||||||
@ -125,8 +131,23 @@
|
|||||||
menuwin~refresh
|
menuwin~refresh
|
||||||
return
|
return
|
||||||
|
|
||||||
|
::method dropWindow
|
||||||
|
expose win menuwin
|
||||||
|
use arg window
|
||||||
|
self~SetPanelColor(window, 9)
|
||||||
|
window~erase()
|
||||||
|
window~refresh()
|
||||||
|
window~delwin()
|
||||||
|
win~refresh
|
||||||
|
self~setupMainMenu(win)
|
||||||
|
menuwin~refresh()
|
||||||
|
RETURN
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* Add new contact *
|
||||||
|
**********************/
|
||||||
::method addContactPanel
|
::method addContactPanel
|
||||||
expose win db menuwin menu_items formwin
|
expose win db menuwin formwin
|
||||||
|
|
||||||
/* Create a form panel */
|
/* Create a form panel */
|
||||||
max_y = win~lines
|
max_y = win~lines
|
||||||
@ -147,58 +168,112 @@
|
|||||||
|
|
||||||
/* Input fields */
|
/* Input fields */
|
||||||
firstName = self~getInputField(formwin, 3, 14, 30)
|
firstName = self~getInputField(formwin, 3, 14, 30)
|
||||||
if firstName = .nil then RETURN
|
if firstName = .nil then do
|
||||||
|
self~dropWindow(formwin)
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
lastName = self~getInputField(formwin, 4, 14, 30)
|
lastName = self~getInputField(formwin, 4, 14, 30)
|
||||||
if lastName = .nil then return
|
if lastName = .nil then do
|
||||||
|
self~dropWindow(formwin)
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
phone = self~getInputField(formwin, 5, 14, 15)
|
phone = self~getInputField(formwin, 5, 14, 15)
|
||||||
if phone = .nil then return
|
if phone = .nil then do
|
||||||
|
self~dropWindow(formwin)
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
email = self~getInputField(formwin, 6, 14, 30)
|
email = self~getInputField(formwin, 6, 14, 30)
|
||||||
if email = .nil then return
|
if email = .nil then do
|
||||||
|
self~dropWindow(formwin)
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
|
|
||||||
/* Add to database */
|
if firstname = "" | lastname = "" then do
|
||||||
contactDict = .Directory~new()
|
formwin~mvaddstr(8, 2, "First and Last names are required.")
|
||||||
contactDict["FIRST_NAME"] = firstName
|
formwin~refresh()
|
||||||
contactDict["LAST_NAME"] = lastName
|
call SysWait 1.5
|
||||||
contactDict["PHONE"] = phone
|
END /* don't add contact */
|
||||||
contactDict["EMAIL"] = email
|
else DO
|
||||||
result = db~addContact(contactDict)
|
/* Add to database */
|
||||||
|
contactDict = .Directory~new()
|
||||||
|
contactDict["FIRST_NAME"] = firstName
|
||||||
|
contactDict["LAST_NAME"] = lastName
|
||||||
|
contactDict["PHONE"] = phone
|
||||||
|
contactDict["EMAIL"] = email
|
||||||
|
result = db~addContact(contactDict)
|
||||||
|
|
||||||
/* Display result message */
|
/* Display result message */
|
||||||
if result > 0 then do
|
if result > 0 then do /* should be a result id number */
|
||||||
formwin~mvaddstr(8, 2, "Contact ID ["result"] added successfully!")
|
formwin~mvaddstr(8, 2, "Contact ID ["result"] added successfully!")
|
||||||
end
|
formwin~refresh()
|
||||||
else do
|
call SysWait 1.5
|
||||||
formwin~mvaddstr(8, 2, "Failed to add contact.")
|
end
|
||||||
end
|
else do
|
||||||
|
formwin~mvaddstr(8, 2, "Failed to add contact.")
|
||||||
formwin~refresh()
|
formwin~refresh()
|
||||||
call SysWait 1
|
call SysWait 1.5
|
||||||
self~dropAddWindow
|
end
|
||||||
|
end /* add contact */
|
||||||
|
self~dropWindow(formwin)
|
||||||
return
|
return
|
||||||
|
|
||||||
::method dropAddWindow
|
/****************************
|
||||||
expose win menuwin formwin
|
* Delete Contact Panel *
|
||||||
formwin~erase()
|
****************************/
|
||||||
formwin~refresh()
|
::METHOD deleteContactPanel
|
||||||
self~setupMainMenu(win)
|
expose win db menuwin delwin
|
||||||
menuwin~refresh()
|
|
||||||
|
/* Create a form panel */
|
||||||
|
max_y = win~lines
|
||||||
|
max_x = win~cols
|
||||||
|
form_height = 14
|
||||||
|
form_width = 35
|
||||||
|
start_y = (max_y - form_height) % 2
|
||||||
|
start_x = (max_x - form_width) % 2
|
||||||
|
delwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 0, "Delete A Contact", .true)
|
||||||
|
|
||||||
|
delwin~mvaddstr(3, 2, "Contact ID: ")
|
||||||
|
delwin~mvaddstr(form_height-2, 2, "[Enter] to save, [Esc] to cancel")
|
||||||
|
delwin~refresh()
|
||||||
|
|
||||||
|
contactId = self~getInputField(delwin, 3, 14, 10)
|
||||||
|
if contactId = .nil then do
|
||||||
|
self~dropWindow(delwin)
|
||||||
|
RETURN
|
||||||
|
END
|
||||||
|
|
||||||
|
result = db~deleteContact(contactId)
|
||||||
|
|
||||||
|
if result = 0 then do /* should be a result id number */
|
||||||
|
delwin~mvaddstr(8, 2, "Contact deleted successfully!")
|
||||||
|
delwin~refresh()
|
||||||
|
call SysWait 1.5
|
||||||
|
end
|
||||||
|
else do
|
||||||
|
delwin~mvaddstr(8, 2, "Failed to add contact.")
|
||||||
|
delwin~refresh()
|
||||||
|
call SysWait 1.5
|
||||||
|
end
|
||||||
|
self~dropWindow(delwin)
|
||||||
RETURN
|
RETURN
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
* List all contacts *
|
||||||
|
****************************/
|
||||||
::method listAllContactsPanel
|
::method listAllContactsPanel
|
||||||
expose win db menuwin
|
expose win db menuwin
|
||||||
|
|
||||||
/* Create a list panel */
|
/* Create a list panel */
|
||||||
max_y = win~lines
|
max_y = win~lines
|
||||||
max_x = win~cols
|
max_x = win~cols
|
||||||
list_height = 20
|
list_height = max_y - 5
|
||||||
list_width = 70
|
list_width = 70
|
||||||
start_y = (max_y - list_height) % 2
|
start_y = (max_y - list_height) % 2
|
||||||
start_x = (max_x - list_width) % 2
|
start_x = (max_x - list_width) % 2
|
||||||
listwin = self~DrawSubPanel(list_height, list_width, start_y, start_x, 0, "All Contacts", .true)
|
|
||||||
|
listwin = self~DrawSubPanel(list_height, list_width, start_y, start_x, 1, "All Contacts", .true)
|
||||||
|
listwin~scrollok(.true)
|
||||||
|
listwin~Setscrreg(4,18)
|
||||||
|
|
||||||
/* Display column headers */
|
/* Display column headers */
|
||||||
listwin~attron(listwin~A_BOLD)
|
listwin~attron(listwin~A_BOLD)
|
||||||
@ -224,27 +299,26 @@
|
|||||||
listwin~mvaddstr(i+3, 54, contact['email']) */
|
listwin~mvaddstr(i+3, 54, contact['email']) */
|
||||||
|
|
||||||
/* Break if we run out of screen space */
|
/* Break if we run out of screen space */
|
||||||
if i > list_height-6 then leave
|
if i > list_height-7 then LEAVE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else do
|
else do
|
||||||
listwin~mvaddstr(5, 5, "No contacts found.")
|
listwin~mvaddstr(5, 5, "No contacts found.")
|
||||||
end
|
end
|
||||||
|
/*
|
||||||
listwin~mvaddstr(list_height-2, 2, "Press any key to return to main menu")
|
listwin~mvaddstr(list_height-1, 2, "Press any key to return to main menu")
|
||||||
listwin~refresh()
|
listwin~refresh()
|
||||||
|
*/
|
||||||
|
|
||||||
/* Wait for any key */
|
/* Wait for any key */
|
||||||
listwin~getch()
|
listwin~getch()
|
||||||
|
self~dropWindow(listwin)
|
||||||
|
RETURN
|
||||||
|
Return
|
||||||
|
|
||||||
listwin~erase()
|
/****************************
|
||||||
listwin~refresh()
|
* Search for contact *
|
||||||
|
****************************/
|
||||||
/* Redraw the main menu */
|
|
||||||
win~refresh
|
|
||||||
self~setupMainMenu(win)
|
|
||||||
return
|
|
||||||
|
|
||||||
::method searchContactPanel
|
::method searchContactPanel
|
||||||
expose win db menuwin menu_items
|
expose win db menuwin menu_items
|
||||||
|
|
||||||
@ -255,7 +329,7 @@
|
|||||||
search_width = 50
|
search_width = 50
|
||||||
start_y = (max_y - search_height) % 2
|
start_y = (max_y - search_height) % 2
|
||||||
start_x = (max_x - search_width) % 2
|
start_x = (max_x - search_width) % 2
|
||||||
searchwin = self~DrawSubPanel(search_height, search_width, start_y, start_x, 3, "Search Contacts", .true)
|
searchwin = self~DrawSubPanel(search_height, search_width, start_y, start_x, 7, "Search Contacts", .true)
|
||||||
|
|
||||||
searchwin~mvaddstr(3, 2, "Search term: ")
|
searchwin~mvaddstr(3, 2, "Search term: ")
|
||||||
searchwin~refresh()
|
searchwin~refresh()
|
||||||
@ -265,10 +339,7 @@
|
|||||||
|
|
||||||
/* If canceled, return to main menu */
|
/* If canceled, return to main menu */
|
||||||
if term = .nil then do
|
if term = .nil then do
|
||||||
searchwin~erase()
|
self~DropWindow(searchwin)
|
||||||
searchwin~refresh()
|
|
||||||
self~setupMainMenu(win)
|
|
||||||
menuwin~refresh()
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -277,6 +348,7 @@
|
|||||||
searchwin~refresh()
|
searchwin~refresh()
|
||||||
|
|
||||||
/* Display results in a new window */
|
/* Display results in a new window */
|
||||||
|
self~dropWindow(searchwin)
|
||||||
self~displaySearchResults(term)
|
self~displaySearchResults(term)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -290,6 +362,9 @@
|
|||||||
|
|
||||||
RETURN
|
RETURN
|
||||||
|
|
||||||
|
/************************
|
||||||
|
* Get Input From Field *
|
||||||
|
************************/
|
||||||
::method getInputField
|
::method getInputField
|
||||||
use arg win, y, x, maxlen
|
use arg win, y, x, maxlen
|
||||||
|
|
||||||
@ -297,16 +372,17 @@
|
|||||||
win~curs_set(1) /* Show cursor */
|
win~curs_set(1) /* Show cursor */
|
||||||
win~keypad(1) /* Enable function keys and arrow keys */
|
win~keypad(1) /* Enable function keys and arrow keys */
|
||||||
win~echo() /* Show typed characters */
|
win~echo() /* Show typed characters */
|
||||||
win~raw
|
/* win~raw */
|
||||||
|
|
||||||
buffer = ""
|
buffer = ""
|
||||||
|
|
||||||
do forever
|
do forever
|
||||||
key = win~getch()
|
key = win~getch()
|
||||||
select
|
select
|
||||||
when key = 27 then do /* ESC key */
|
when key = D2C(27) then do /* ESC key */
|
||||||
win~noecho() /* Stop showing typed characters */
|
|
||||||
win~curs_set(0) /* Hide cursor */
|
win~curs_set(0) /* Hide cursor */
|
||||||
|
win~noecho() /* Stop showing typed characters */
|
||||||
|
win~mvaddstr(8, 2, "Decimal: "C2D(key) )
|
||||||
return .nil /* Return nil to indicate cancellation */
|
return .nil /* Return nil to indicate cancellation */
|
||||||
end
|
end
|
||||||
when key = D2C(10) | key = D2C(13) then do /* Enter key */
|
when key = D2C(10) | key = D2C(13) then do /* Enter key */
|
||||||
@ -392,31 +468,20 @@
|
|||||||
use arg menuwin, key_char
|
use arg menuwin, key_char
|
||||||
select
|
select
|
||||||
when key_char = 'a' then do
|
when key_char = 'a' then do
|
||||||
menuwin~mvaddstr(19 - 3, 5, "I would launch the ADD panel ");
|
|
||||||
menuwin~refresh
|
|
||||||
call SysWait 0.25
|
|
||||||
self~addContactPanel()
|
self~addContactPanel()
|
||||||
END
|
END
|
||||||
when key_char = 'r' then do
|
when key_char = 'd' then do
|
||||||
menuwin~mvaddstr(19 - 3, 5, "I would launch the REMOVE panel ");
|
self~deleteContactPanel()
|
||||||
menuwin~refresh
|
|
||||||
call SysWait 0.25
|
|
||||||
END
|
END
|
||||||
when key_char = 'e' then do
|
when key_char = 'e' then do
|
||||||
menuwin~mvaddstr(19 - 3, 5, "I would launch the EDIT panel ");
|
menuwin~mvaddstr(19 - 3, 5, "TODO: Create an Edit Panel ");
|
||||||
menuwin~refresh
|
menuwin~refresh
|
||||||
call SysWait 0.25
|
call SysWait 0.25
|
||||||
END
|
END
|
||||||
when key_char = 's' then do
|
when key_char = 's' then do
|
||||||
menuwin~mvaddstr(19 - 3, 5, "I would launch the SEARCH panel ");
|
|
||||||
menuwin~refresh
|
|
||||||
call SysWait 0.25
|
|
||||||
self~searchContactPanel()
|
self~searchContactPanel()
|
||||||
END
|
END
|
||||||
when key_char = 'l' then do
|
when key_char = 'l' then do
|
||||||
menuwin~mvaddstr(19 - 3, 5, "I would launch the LIST panel ")
|
|
||||||
menuwin~refresh
|
|
||||||
call SysWait 0.25
|
|
||||||
self~listAllContactsPanel()
|
self~listAllContactsPanel()
|
||||||
END
|
END
|
||||||
when key_char = 'q' then do
|
when key_char = 'q' then do
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user