5050 </div >
5151 </div >
5252
53- <hr />
53+ <hr />
5454
5555 <h3 >Add fields</h3 >
5656
5757 <table class =" table" >
5858 <tbody id =" generator" >
59+ <tr >
60+ <td >Show in list</td >
61+ <td ></td >
62+ <td ></td >
63+ <td ></td >
64+ <td ></td >
65+ <td ></td >
66+ </tr >
5967 @if (old (' f_type' ) )
6068 @foreach (old (' f_type' ) as $index => $fieldName )
6169 @include (' tpl::crud_field_line' , [' index' => $index ] )
6876
6977 <div class =" form-group" >
7078 <div class =" col-md-12" >
71- <button type =" button" id =" addField" class =" btn btn-success" ><i class =" fa fa-plus" ></i > Add one more field</button >
79+ <button type =" button" id =" addField" class =" btn btn-success" ><i class =" fa fa-plus" ></i > Add one more field
80+ </button >
7281 </div >
7382 </div >
7483
75- <hr />
84+ <hr />
7685
7786 <div class =" form-group" >
7887 <div class =" col-md-12" >
8897 @include (' tpl::crud_field_line' , [' index' => ' ' ] )
8998 </tbody >
9099 </table >
100+
101+ <!-- Select for relationship column-->
102+ @foreach ($models as $key => $model )
103+ <select name =" f_relationship_field[{{ $key } } ]" class =" form-control relationship-field rf-{{ $key } }" >
104+ <option value =" " >Select display field</option >
105+ @foreach ($model as $key2 => $option )
106+ <option value =" {{ $option } }"
107+ @if ($option == old (' f_relationship_field.' . $key ) ) selected @endif >{{ $option } } </option >
108+ @endforeach
109+ </select >
110+ @endforeach
111+ <!-- /Select for relationship column-->
91112 </div >
92113
93114@endsection
94115
95116@section (' javascript' )
96117 <script >
118+ function typeChange (e ) {
119+ var val = $ (e).val ();
120+ // Hide all possible outputs
121+ $ (e).parent ().parent ().find (' .value' ).hide ();
122+ $ (e).parent ().parent ().find (' .default_c' ).hide ();
123+ $ (e).parent ().parent ().find (' .relationship' ).hide ();
124+ $ (e).parent ().parent ().find (' .title' ).show ().val (' ' );
125+ $ (e).parent ().parent ().find (' .texteditor' ).hide ();
126+ $ (e).parent ().parent ().find (' .size' ).hide ();
127+
128+ // Show a checbox which enables/disables showing in list
129+ $ (e).parent ().parent ().parent ().find (' .show2' ).show ();
130+ $ (e).parent ().parent ().parent ().find (' .show_hid' ).val (1 );
131+ switch (val) {
132+ case ' radio' :
133+ $ (e).parent ().parent ().find (' .value' ).show ();
134+ break ;
135+ case ' checkbox' :
136+ $ (e).parent ().parent ().find (' .default_c' ).show ();
137+ break ;
138+ case ' relationship' :
139+ $ (e).parent ().parent ().find (' .relationship' ).show ();
140+ $ (e).parent ().parent ().find (' .title' ).hide ().val (' -' );
141+ break ;
142+ case ' textarea' :
143+ $ (e).parent ().parent ().find (' .show2' ).hide ();
144+ $ (e).parent ().parent ().find (' .show_hid' ).val (0 );
145+ $ (e).parent ().parent ().find (' .texteditor' ).show ();
146+ break ;
147+ case ' file' :
148+ $ (e).parent ().parent ().find (' .size' ).show ();
149+ break ;
150+ }
151+ }
152+
153+ function relationshipChange (e ) {
154+ var val = $ (e).val ();
155+ $ (e).parent ().parent ().find (' .relationship-field' ).remove ();
156+ var select = $ (' .rf-' + val).clone ();
157+ $ (e).parent ().parent ().find (' .relationship-holder' ).html (select);
158+ }
159+
97160 $ (document ).ready (function () {
161+ $ (' .type' ).each (function () {
162+ typeChange ($ (this ))
163+ });
164+ $ (' .relationship' ).each (function () {
165+ relationshipChange ($ (this ))
166+ });
167+
168+ $ (' .show2' ).change (function () {
169+ var checked = $ (this ).is (" :checked" );
170+ if (checked) {
171+ $ (this ).parent ().find (' .show_hid' ).val (1 );
172+ } else {
173+ $ (this ).parent ().find (' .show_hid' ).val (0 );
174+ }
175+ });
176+
98177 // Add new row to the table of fields
99178 $ (' #addField' ).click (function () {
100179 var line = $ (' #line' ).html ();
101180 var table = $ (' #generator' );
102181 table .append (line);
103182 });
183+
104184 // Remove row from the table of fields
105185 $ (document ).on (' click' , ' .rem' , function () {
106186 $ (this ).parent ().parent ().remove ();
107187 });
108188
109189 $ (document ).on (' change' , ' .type' , function () {
110- var val = $ (this ).val ();
111- if (val == ' radio' || val == ' checkbox' ) {
112- $ (this ).parent ().parent ().find (' .value' ).show ();
113- }else {
114- $ (this ).parent ().parent ().find (' .value' ).hide ();
115- }
190+ typeChange ($ (this ))
191+ });
192+ $ (document ).on (' change' , ' .relationship' , function () {
193+ relationshipChange ($ (this ))
116194 });
117195 });
196+
118197 </script >
119198@stop
0 commit comments