@@ -111,8 +111,10 @@ public function store(ImageUploadRequest $request) : RedirectResponse
111111
112112 $ settings = Setting::getSettings ();
113113
114- $ success = false ;
114+ $ successes = [];
115+ $ failures = [];
115116 $ serials = $ request ->input ('serials ' );
117+ $ asset = null ;
116118
117119 for ($ a = 1 ; $ a <= count ($ asset_tags ); $ a ++) {
118120 $ asset = new Asset ();
@@ -199,20 +201,35 @@ public function store(ImageUploadRequest $request) : RedirectResponse
199201 $ asset ->checkOut ($ target , auth ()->user (), date ('Y-m-d H:i:s ' ), $ request ->input ('expected_checkin ' , null ), 'Checked out on asset creation ' , $ request ->get ('name ' ), $ location );
200202 }
201203
202- $ success = true ;
203-
204+ $ successes [] = "<a href=' " . route ('hardware.show ' , ['hardware ' => $ asset ->id ]) . "' style='color: white;'> " . e ($ asset ->asset_tag ) . "</a> " ;
205+
206+ } else {
207+ $ failures [] = join (", " , $ asset ->getErrors ()->all ());
204208 }
205209 }
206210
207211 session ()->put (['redirect_option ' => $ request ->get ('redirect_option ' ), 'checkout_to_type ' => $ request ->get ('checkout_to_type ' )]);
208212
209213
210- if ($ success ) {
214+ if ($ successes ) {
215+ if ($ failures ) {
216+ //some succeeded, some failed
217+ return redirect ()->to (Helper::getRedirectOption ($ request , $ asset ->id , 'Assets ' )) //FIXME - not tested
218+ ->with ('success-unescaped ' , trans_choice ('admin/hardware/message.create.multi_success_linked ' , $ successes , ['links ' => join (", " , $ successes )]))
219+ ->with ('warning ' , trans_choice ('admin/hardware/message.create.partial_failure ' , $ failures , ['failures ' => join ("; " , $ failures )]));
220+ } else {
221+ if (count ($ successes ) == 1 ) {
222+ //the most common case, keeping it so we don't have to make every use of that translation string be trans_choice'ed
223+ //and re-translated
224+ return redirect ()->to (Helper::getRedirectOption ($ request , $ asset ->id , 'Assets ' ))
225+ ->with ('success-unescaped ' , trans ('admin/hardware/message.create.success_linked ' , ['link ' => route ('hardware.show ' , ['hardware ' => $ asset ->id ]), 'id ' , 'tag ' => e ($ asset ->asset_tag )]));
226+ } else {
227+ //multi-success
228+ return redirect ()->to (Helper::getRedirectOption ($ request , $ asset ->id , 'Assets ' ))
229+ ->with ('success-unescaped ' , trans_choice ('admin/hardware/message.create.multi_success_linked ' , $ successes , ['links ' => join (", " , $ successes )]));
230+ }
231+ }
211232
212- return redirect ()->to (Helper::getRedirectOption ($ request , $ asset ->id , 'Assets ' ))
213- ->with ('success-unescaped ' , trans ('admin/hardware/message.create.success_linked ' , ['link ' => route ('hardware.show ' , ['hardware ' => $ asset ->id ]), 'id ' , 'tag ' => e ($ asset ->asset_tag )]));
214-
215-
216233 }
217234
218235 return redirect ()->back ()->withInput ()->withErrors ($ asset ->getErrors ());
0 commit comments