171171 })
172172
173173 function appload (appvalue ) {
174+ const itemId = $ (' input[name="item_id"]' ).val ();
174175 if (appvalue == ' null' ) {
175176 $ (' #sapconfig' ).html (' ' ).hide ();
176177 $ (' #tile-preview .app-icon' ).attr (' src' , ' /img/heimdall-icon-small.png' );
177178 $ (' #appimage' ).html (" <img src='/img/heimdall-icon-small.png' />" );
178179 $ (' #sapconfig' ).html (' ' ).hide ();
179180 } else {
180- $ .post (' {{ route (' appload' ) } }' , { app: appvalue }, function (data ) {
181+ $ .post (' {{ route (' appload' ) } }' , { app: appvalue, item_id : itemId }, function (data ) {
181182 // Main details
182183 $ (' #appimage' ).html (" <img src='" + data .iconview + " ' /><input type='hidden' name='icon' value='" + data .iconview + " ' />" );
183184 $ (' input[name=colour]' ).val (data .colour );
@@ -194,6 +195,21 @@ function appload(appvalue) {
194195 if (data .custom != null ) {
195196 $ .get (base+ ' view/' + data .custom , function (getdata ) {
196197 $ (' #sapconfig' ).html (getdata).show ();
198+ // Populate fields in the loaded form with description data
199+ if (data .description ) {
200+ const description = JSON .parse (data .appvalue );
201+ Object .keys (description).forEach (function (key ) {
202+ const value = description[key];
203+ const field = $ (` #sapconfig [name="config[${ key} ]"]` );
204+ if (field .length ) {
205+ if (field .is (' :checkbox' )) {
206+ field .prop (' checked' , value);
207+ } else {
208+ field .val (value);
209+ }
210+ }
211+ });
212+ }
197213 });
198214 } else {
199215 $ (' #sapconfig' ).html (' ' ).hide ();
0 commit comments