|
| 1 | +# Getting started |
| 2 | + |
| 3 | +In this guide you'll learn how to create a mini bookstore. |
| 4 | + |
| 5 | +## The model |
| 6 | + |
| 7 | +To keep things simple our model `Book` only contains three properties: |
| 8 | +- an auto-generated `id` |
| 9 | +- `name` |
| 10 | +- `author` |
| 11 | + |
| 12 | +## Server |
| 13 | + |
| 14 | +TODO |
| 15 | + |
| 16 | +## Client |
| 17 | +### Templates |
| 18 | + |
| 19 | +To get a basic CRUD (Create, Read, Update and Delete), you need three templates: |
| 20 | +- `list.tpl.html` (shows an overview of all your models, with optional searching/filtering and sorting) |
| 21 | +- `details-view.tpl.html` (detail page of a specific object) |
| 22 | +- `details-edit.tpl.html` (create and edit page of an object) |
| 23 | + |
| 24 | +#### list template |
| 25 | + |
| 26 | +``` |
| 27 | +<table class="table"> |
| 28 | + <thead> |
| 29 | + <tr> |
| 30 | + <th cat-sortable="name">Name</th> |
| 31 | + <th cat-sortable="author">Author</th> |
| 32 | + </tr> |
| 33 | + </thead> |
| 34 | + <tbody> |
| 35 | + <tr ng-repeat="data in listData.collection"> |
| 36 | + <td><a ui-sref="Book.detail({id: data.id})">{{::data.name}}</a></td> |
| 37 | + <td>{{::data.author}}</td> |
| 38 | + </tr> |
| 39 | + </tbody> |
| 40 | +</table> |
| 41 | +``` |
| 42 | + |
| 43 | +Save this file as `book-list.tpl.html` in the `src/main/resources/static/book` directory. |
| 44 | +This template generates a table with two columns, Name and Author. The attribute `cat-sortable` marks the column sortable |
| 45 | +(the attribute value is the model attribute name). All model objects are in the `listData.collection` array. |
| 46 | + |
| 47 | +#### detail view template |
| 48 | + |
| 49 | +``` |
| 50 | +<form class="form-horizontal"> |
| 51 | + <div class="form-group"> |
| 52 | + <label class="col-sm-2 control-label">Name</label> |
| 53 | + <div class="col-sm-10"> |
| 54 | + <p class="form-control-static">{{::detail.name}}</p> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + <div class="form-group"> |
| 58 | + <label class="col-sm-2 control-label">Author</label> |
| 59 | + <div class="col-sm-10"> |
| 60 | + <p class="form-control-static">{{::detail.author}}</p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | +</form> |
| 64 | +``` |
| 65 | + |
| 66 | +Save this file as `book-details-view.tpl.html` in the `src/main/resources/static/book` directory. |
| 67 | +In this template the model is named `detail`. You can access the model attributes of the `Book` model with `detail.name` and `detail.author`. |
| 68 | + |
| 69 | +#### detail edit template |
| 70 | + |
| 71 | +``` |
| 72 | +<div class="form-horizontal"> |
| 73 | + <div cat-input-group label="Name" name="name"> |
| 74 | + <input id="name" ng-model="editDetail.name" class="form-control" /> |
| 75 | + </div> |
| 76 | +
|
| 77 | + <div cat-input-group label="Author" name="author"> |
| 78 | + <input id="author" ng-model="editDetail.author" class="form-control" /> |
| 79 | + </div> |
| 80 | +</div> |
| 81 | +``` |
| 82 | + |
| 83 | +Save this file as `book-details-edit.tpl.html` in the `src/main/resources/static/book` directory. |
| 84 | +This template is the form for creating and editing models. The angular model is called `editDetail`. |
0 commit comments