Photo Album Example
def module default {
  def entity User {
    id: Id,
    username: String,
    password: String,
    email: String
  }
  read username, password, email where true
  write username, password, email where true
  
  def entity Photos {
    id: Id,
    user: String,
    title: String,
    url: String
  }
 read user, title, url where true
  write user, title, url where true
  
  def screen userList {
    div title {
      label "User List"
    };
    iterator ( row in (from (u in User) select {uname = u.username})) {
      link {
        label row.uname
      } to viewUser(row.uname); br
    }; br;

    div title {
      label "Register"
    };
    label "Username: "; textfield username; br;
    label "Password: "; textfield password; br;
    label "E-mail: "; textfield email; br;
    button "Register" to register(username, password, email)
  }

  def action register(uname: String, pwd: String, em: String) : Block {
    insert {
      username = uname,
      password = pwd,
      email = em
    } in User;
    userList()
  }

  def screen viewUser(uname: String) {
    div title {
      label uname + "'s Photos"
    };
    iterator (photo in (from (p in Photos)
        where p.user == uname
        select {title = p.title, url = p.url})) {
      label photo.title; br;
      image photo.url; br; br
    }; br; br;

    div title {
      label "Add Photo"
    };
    label "Password: "; textfield password; br;
    label "Photo Title: "; textfield title; br;
    label "Photo URL: "; textfield photo; br;
    button "Add" to addPhoto(uname, password, title, photo); br; br;

    link {
      label "Back to User List"
    } to userList()
  }
 
  def action addPhoto(uname: String, pwd: String, title: String, url: String): Block {
    let q = from (u in User)
          where u.username == uname and u.password == pwd
          select u in
      (if (count(q) == 1) then {
            insert {
          user = uname,
          title = title,
              url = url
            } in Photos
      } else {
        false
      });
    viewUser(uname)
  }
}

Back