Since we're using Dart, the first step is writing the pubspec.yaml file. This file configures the app's dependencies on third-party packages. For the sake of sanity, we will specify exactly which versions to use. We only need two external packages, objectory for database access and forcemvc for a web architecture. What we need is something like
/pubspec.yaml
name: ForceMVC_Objectory2
version: 0.0.1
description: A simple console application.
dependencies:
objectory: 0.3.21
forcemvc: 0.8.5
/bin/main.dart
import 'package:forcemvc/force_mvc.dart'; import '../lib/controllers.dart'; main(List<String> args) { print('Opening localhost:8080'); WebApplication application = new WebApplication(); application.start(); }
We will be using the default settings. That means that the views will go in a /views directory. We put two files there: index.html and verify.html. index.html has the form, and verify.html shows the results.
/views/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Force Objectory 2</title>
</head>
<body>
<form action="/verify" method="post">
<fieldset>
<label for="first_name">First name: </label>
<input id="first_name" name="first_name" type="text" required>
</fieldset>
<fieldset>
<label for="last_name">Last name: </label>
<input id="last_name" name="last_name" type="text" required>
</fieldset>
<input id="btn" type="submit" value="Continue">
</form>
</body>
</html>
/views/verify.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Name List</title>
</head>
<body>
<p>{{message}}</p>
<p>Tried to add {{person}}</p>
<ul>
{{# people}}
<li>{{firstName}} {{lastName}}</li>
{{/ people}}
</ul>
{{^ people}}
<h3>Empty List</h3>
{{/ people}}
</body>
</html>
{{person}} echoes the name the user entered. {{people}} is an updated list of all the names on file. "#" generates a list, and "^" means "if the list is empty". In the interest of space, the controllers and model code will be in the next post.
No comments:
Post a Comment