diff --git a/www/patterns/click-to-edit.md b/www/patterns/click-to-edit.md index 990d9510..883f909c 100644 --- a/www/patterns/click-to-edit.md +++ b/www/patterns/click-to-edit.md @@ -1,157 +1,90 @@ --- -layout: layout.njk -title: kutty - UX Patterns +layout: demo_layout.njk --- - -## Implementing A Click To Edit UI - -This pattern shows an inline click-to-edit UI for a contact. When you click the button below the current UI will - be replaced with an editing UI, without a full browser refresh. You can then update the user information - or cancel the edit. - -### Demo - - +## Kutty Pattern: Click To Edit +The click to edit pattern provides a way to offer inline editing of all or part of a record without a page refresh. -
+* It starts with a div that shows the details of a contact. The div has a button that will get the editing UI for the contact from `/contacts/1/edit` +* This returns a form that can be used to edit the contact +* The form issues a `PUT` back to `/contacts/1`, following the usual REST-ful pattern. + +## Activity +
+
+
+
+
+
+ +## Demo Canvas +
+
+
+
-### Code + //========================================================================= + // Fake Server Side Code + //========================================================================= -#### Display HTML + // data + var contact = { + "firstName" : "Joe", + "lastName" : "Blow", + "email" : "joe@blow.com" + }; -```html -
-
First Name: Joe
-
Last Name: Smith
-
Email: joesmith@example.com
- + // routes + init("/contact/1", function(request){ + return displayTemplate(contact); + }); + + onGet("/contact/1/edit", function(request){ + return formTemplate(contact); + }); + + onPut("/contact/1", function (req, params) { + contact.firstName = params['firstName']; + contact.lastName = params['lastName']; + contact.email = params['email']; + return displayTemplate(contact); + }); + + // templates + function formTemplate(contact) { +return `
+
+ +
-``` - -#### Edit HTML - -```html - -
- - -
-
- - -
-
- - -
- - -
-``` - -### Explanation - -The 'Click To Edit' button uses [kt-get](/attributes/kt-get) to issue a `GET` to `/contact/1/edit`, and targets the div -surrounding the entire Contact UI using [kt-target](/attributes/kt-target). - -The server returns a form that replaces the content of the div. The form uses the [kt-put](/attributes/kt-put) to issue a -`PUT` to `/contact/1` and targets the same enclosing div. - -The 'Cancel' button uses [kt-get](/attributes/kt-get) to issue a `GET` to `/contact/1` and targets the same div. - +
+ + +
+
+ + +
+ + +` + } + function displayTemplate(contact) { + return `
+
: ${contact.firstName}
+
: ${contact.lastName}
+
: ${contact.email}
+ +
`; + } +