2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00
This commit is contained in:
Rushabh Mehta 2018-01-10 18:24:27 +05:30
parent 0fa2c70133
commit 3ce79d2027
3 changed files with 29 additions and 23 deletions

View File

@ -1,4 +1,4 @@
# Frappe.JS
# Frappe.js
Frappe.js is a meta-data driven framework that enables rapid application development of Node.js and Electron based applications.
@ -12,7 +12,7 @@ Frappe.js is a meta-data driven framework that enables rapid application develop
## Documentation
[Read the full docs](docs/README.md)
[Read the full docs](frappe/docs/README.md)
## License

View File

@ -12,7 +12,7 @@ Frappe.js is a meta-data driven framework that enables rapid application develop
- [Server](server.md)
- [REST API](rest.md)
- [Client](client.md)
- [Routing](routing.md)
- [Routing](router.md)
- [Page](page.md)
- [Lists](lists.md)
- [Forms](forms.md)

View File

@ -1,21 +1,43 @@
# Controllers
In Frappe.js you can extend the metadata class as well as the document class for a particular DocType. The `meta` class contains actions that are done on a group of objects and a document represents a single object. So properties and actions related to the group will be part of the `meta` class
In Frappe.js you can extend the metadata class as well as the document class for a particular DocType.
You can write event handlers in controllers, by declaring a `.js` file in the `models/doctype/` folder along with the model file.
### Naming
## Naming
1. The name of the controller class must be the slugged name of the DocType (example `todo`)
2. The name of the `meta` class must be the name of the controller class prefixed by `meta_` (example `meta_todo`)
To add a standard handler, you must bind all handlers in `setup` method.
### Example
## Document Controller
You can bind events to the controller that will be called when an action is completed on a document or its property.
The document controller represents a single record and is subclassed from the `frappe.document.Document` class
```js
const frappe = require('frappe-core');
// extend the document and add event handlers
class todo extends frappe.document.Document {
setup() {
this.add_handler('validate');
}
validate() {
if (!this.status) {
this.status = 'Open';
}
}
}
```
## Metadata Controller
The `meta` class contains actions that are done on a group of objects and a document represents a single object. So properties and actions related to the group will be part of the `meta` class.
```js
// extend the meta class
class todo_meta extends frappe.meta.Meta {
setup_meta() {
@ -29,25 +51,9 @@ class todo_meta extends frappe.meta.Meta {
}
}
// extend the document and add event handlers
class todo extends frappe.document.Document {
setup() {
this.add_handler('validate');
}
validate() {
if (!this.status) {
this.status = 'Open';
}
}
}
module.exports = {
todo: todo,
todo_meta: todo_meta
};
```
### Controller Events
Standard events on which you can bind handlers are