UNPKG

3.01 kBJavaScriptView Raw
1'use strict'
2
3var Base = require('ribcage-view')
4 , _ = require('lodash')
5 , rt = require('../../../lib/rt.js')
6 , cache = require('../../../app/cache/')
7 , Button = require('../../pieces/button')
8 , {{PascalName}}Step = require('./step')
9 , State = require('ampersand-state').extend({
10 // forces you define all properties on the state model
11 // this helps catch bugs and makes code more readable
12 extraProperties: 'reject'
13 // output the derived properties and the props in toJSON
14 , toJSON: function toJSON(){
15 return _.extend(this.serialize(), this.getAttributes({derived: true}))
16 }
17 })
18 , {{PascalName}}Pane
19
20{{PascalName}}Pane = Base.extend({
21
22 className: '{{camelName}}Pane'
23
24, stackBranchStart: false
25
26, navBarTitle: '{{titleName}}'
27
28// back buttons are the default, you don't need to define one
29// , navBarLeftButton: new Button({icon: 'chevron-left'})
30
31// You may want to define a right button though.
32// Set it to false otherwise.
33// Don't forget to set a listener in BindEvents.
34, navBarRightButton: new Button({label: 'Next'})
35
36, State: State.extend({
37 props: {
38
39 }
40 })
41
42// Backbone Events
43, bindEvents: function bindEvents(){
44 // always stopListening so we don't reattach multiple listeners
45 if (this.state){
46 this.stopListening(this.state)
47 // listen to state, model, etc… events
48 // this.listenTo(this.state, 'change:text', this.onStateChangeText)
49 }
50 }
51
52// e.g.
53// , onStateChangeText: function onStateChangeText(state, value){
54// console.log(value)
55// }
56
57// helper methods
58// e.g.
59// , findModelIndex: function findModelIndex(model){
60// this.collection.findIndex(model)
61// }
62
63// public methods
64// e.g.
65// , getLabel: function getLabel(){
66// return this.state.label
67// }
68//
69// , setLabel: function setLabel(label){
70// this.state.label = label
71// }
72
73// Create Subviews
74, create{{PascalName}}Step: function create{{PascalName}}Step(){
75 return new {{PascalName}}Step({})
76 }
77
78// Lifecycle Methods
79, beforeInit: function beforeInit(options){
80 // check for required props
81 var requiredProps = this.State.prototype._definition
82
83 _.each(requiredProps, function eachRequiredProp(setting, prop){
84 if (setting.required && _.isUndefined(options[prop]))
85 throw new Error(this.className + ' requires ' + prop)
86 }, this)
87
88 this.state = new this.State(options)
89 }
90
91, afterInit: function afterInit(){
92 this.{{camelName}}Step = this.create{{PascalName}}Step()
93 }
94
95// load in all necessary data here
96// if you don't need this method, you should delete it
97// NOTE: you might need to create subviews here after you've loaded the necessary
98// models and/or collections
99// loadData docs: https://github.com/Techwraith/ribcage-view#loaddatafunction-done
100, loadData: function loadData(done){
101 done()
102 }
103
104// , beforeRender: function beforeRender(){
105// }
106
107, afterRender: function afterRender(){
108 this.appendSubview(this.{{camelName}}Step)
109 }
110
111})
112
113module.exports = {{PascalName}}Pane