@@ -25,7 +25,9 @@ module.exports = Mn.View.extend({
25
25
form : 'form' ,
26
26
buttons : '.modal-footer button' ,
27
27
cancel : 'button.cancel' ,
28
- save : 'button.save'
28
+ save : 'button.save' ,
29
+ access_add : 'button.access_add' ,
30
+ auth_add : 'button.auth_add'
29
31
} ,
30
32
31
33
regions : {
@@ -105,27 +107,34 @@ module.exports = Mn.View.extend({
105
107
alert ( err . message ) ;
106
108
this . ui . buttons . prop ( 'disabled' , false ) . removeClass ( 'btn-disabled' ) ;
107
109
} ) ;
110
+ } ,
111
+ 'click @ui.access_add' : function ( e ) {
112
+ e . preventDefault ( ) ;
113
+
114
+ let clients = this . model . get ( 'clients' ) ;
115
+ clients . push ( { } ) ;
116
+ this . showChildView ( 'clients_region' , new ClientsView ( {
117
+ collection : new Backbone . Collection ( clients )
118
+ } ) ) ;
119
+ } ,
120
+ 'click @ui.auth_add' : function ( e ) {
121
+ e . preventDefault ( ) ;
122
+
123
+ let items = this . model . get ( 'items' ) ;
124
+ items . push ( { } ) ;
125
+ this . showChildView ( 'items_region' , new ItemsView ( {
126
+ collection : new Backbone . Collection ( items )
127
+ } ) ) ;
108
128
}
109
129
} ,
110
130
111
131
onRender : function ( ) {
112
132
let items = this . model . get ( 'items' ) ;
113
133
let clients = this . model . get ( 'clients' ) ;
114
134
115
- // Add empty items to the end of the list. This is cheating but hey I don't have the time to do it right
116
- let items_to_add = 5 - items . length ;
117
- if ( items_to_add ) {
118
- for ( let i = 0 ; i < items_to_add ; i ++ ) {
119
- items . push ( { } ) ;
120
- }
121
- }
122
-
123
- let clients_to_add = 4 - clients . length ;
124
- if ( clients_to_add ) {
125
- for ( let i = 0 ; i < clients_to_add ; i ++ ) {
126
- clients . push ( { } ) ;
127
- }
128
- }
135
+ // Ensure at least one field is shown initally
136
+ if ( ! items . length ) items . push ( { } ) ;
137
+ if ( ! clients . length ) clients . push ( { } ) ;
129
138
130
139
this . showChildView ( 'items_region' , new ItemsView ( {
131
140
collection : new Backbone . Collection ( items )
0 commit comments