From 3ce79d2027a098dca0e2f20becc7ed2312df91bd Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 10 Jan 2018 18:24:27 +0530 Subject: [PATCH] docs --- README.md | 4 ++-- frappe/docs/README.md | 2 +- frappe/docs/controllers.md | 46 +++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8faf6745..3b8fd65c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/frappe/docs/README.md b/frappe/docs/README.md index 65eafe15..9cd9cc99 100644 --- a/frappe/docs/README.md +++ b/frappe/docs/README.md @@ -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) diff --git a/frappe/docs/controllers.md b/frappe/docs/controllers.md index 71f59efd..d51e4390 100644 --- a/frappe/docs/controllers.md +++ b/frappe/docs/controllers.md @@ -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