Editing Data

At this point we have a working SMS service. However, to modify replies or add new keywords, we must modify our script. This is not really all that user friendly. It would be much better to have a graphical user interface allowing us to edit the database. We would like to be able to modify replies for existing keywords, and to add new keywords and replies.

In m, it is fairly easy to construct such a user interface using the functions from module module ui:

First, the user should be able to choose one of the existing keywords to modify it, or pick an item <New> if she wants to add a new keyword/reply pair:

use ui, array

list=keys(db);
array.sort(list);
array.insert(list, 0, "<New>");
i=ui.list(list);

This code fragment, if executed on our database variable db, shows the following dialog:

   
Series 60 sample screen
UIQ sample screen

Comments:

Once the user has made her choice, we can add a new key-value pair, or edit an existing one.

i=i[0];
if i=0 then // <New> was selected: add
  f=ui.form(["Key":"","Text":"\n"]);
  if f#null then
    k=f["Key"];
    if db[k]=null then db[k]=f["Text"]
    else ui.error(k + " already exists") end
  end
else // an existing keyword was selected: edit
  k=list[i];
  f=ui.form([k,"Text":db[k]+"\n"]);
  if f#null then db[k]=f["Text"] end
end

A few explanations:


© 2004-2010 airbit AG, CH-8008 Zürich
Document AB-M-TUT-869