@@ -25,7 +25,9 @@ module.exports = Mn.View.extend({
2525 form : 'form' ,
2626 buttons : '.modal-footer button' ,
2727 cancel : 'button.cancel' ,
28- save : 'button.save'
28+ save : 'button.save' ,
29+ access_add : 'button.access_add' ,
30+ auth_add : 'button.auth_add'
2931 } ,
3032
3133 regions : {
@@ -105,27 +107,34 @@ module.exports = Mn.View.extend({
105107 alert ( err . message ) ;
106108 this . ui . buttons . prop ( 'disabled' , false ) . removeClass ( 'btn-disabled' ) ;
107109 } ) ;
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+ } ) ) ;
108128 }
109129 } ,
110130
111131 onRender : function ( ) {
112132 let items = this . model . get ( 'items' ) ;
113133 let clients = this . model . get ( 'clients' ) ;
114134
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 ( { } ) ;
129138
130139 this . showChildView ( 'items_region' , new ItemsView ( {
131140 collection : new Backbone . Collection ( items )
0 commit comments