@@ -20,14 +20,18 @@ public function handleAjaxRequest(Request $request, $mode = null)
2020 return $ this ->ajaxCreate ();
2121 }
2222
23- /* if ($mode == 'edit') {
23+ if ($ mode == 'edit ' ) {
2424 return $ this ->ajaxEdit ();
25- }*/
25+ }
2626
2727 if (strtolower ($ request ->method ()) == 'put ' ) {
2828 return $ this ->ajaxStore ($ request );
2929 }
3030
31+ if (strtolower ($ request ->method ()) == 'patch ' ) {
32+ return $ this ->ajaxUpdate ($ request );
33+ }
34+
3135 return $ this ->ajaxIndex ($ request );
3236 }
3337
@@ -65,7 +69,6 @@ public function ajaxCreate()
6569 ->with ('action ' , 'create ' )
6670 ->with ('entity ' , $ this ->getAjaxEntity ())
6771 ->with ('crud ' , $ this ->crud )
68- ->with ('saveAction ' , $ this ->getSaveAction ())
6972 ->with ('fields ' , $ this ->crud ->getCreateFields ())
7073 ->with ('title ' , trans ('backpack::crud.add ' ) . ' ' . $ this ->crud ->entity_name )
7174 ->with ('field_name ' , request ()->input ('field_name ' ))
@@ -79,9 +82,19 @@ public function ajaxCreate()
7982 */
8083 public function ajaxEdit ()
8184 {
82- $ this ->crud ->hasAccessOrFail ('edit ' );
85+ $ this ->crud ->hasAccessOrFail ('update ' );
8386
84- //
87+ return \View::make ('webfactor::modal.edit ' )
88+ ->with ('action ' , 'edit ' )
89+ ->with ('id ' , request ()->input ('id ' ))
90+ ->with ('entity ' , $ this ->getAjaxEntity ())
91+ ->with ('crud ' , $ this ->crud )
92+ ->with ('saveAction ' , $ this ->getSaveAction ())
93+ ->with ('fields ' , $ this ->crud ->getUpdateFields (request ()->input ('id ' )))
94+ ->with ('title ' , trans ('backpack::crud.add ' ) . ' ' . $ this ->crud ->entity_name )
95+ ->with ('field_name ' , request ()->input ('field_name ' ))
96+ ->with ('attribute ' , request ()->input ('attribute ' ))
97+ ->render ();
8598 }
8699
87100 /**
@@ -110,6 +123,32 @@ public function ajaxStore(Request $request)
110123 return $ this ->ajaxRespondError ();
111124 }
112125
126+ /**
127+ * Checks permission and tries to update on-the-fly entity. If you want to enable request validation,
128+ * please set your StoreRequest class by using setAjaxStoreRequest() in your EntityCrudController
129+ *
130+ * @param StoreRequest $request
131+ * @return \Illuminate\Http\JsonResponse
132+ */
133+ public function ajaxUpdate (Request $ request )
134+ {
135+ if (!$ this ->crud ->hasAccess ('update ' )) {
136+ return $ this ->ajaxRespondNoPermission ();
137+ }
138+
139+ if ($ updateRequest = $ this ->getAjaxUpdateRequest ()) {
140+ if ($ errors = $ this ->ajaxValidationFails ($ request , $ updateRequest ->rules ())) {
141+ return response ()->json ($ this ->ajaxFormatMessage ($ errors ), 422 );
142+ }
143+ }
144+
145+ if (parent ::updateCrud ($ request )) {
146+ return $ this ->ajaxRespondUpdated ();
147+ }
148+
149+ return $ this ->ajaxRespondError ();
150+ }
151+
113152 /**
114153 * Validates the request and returns an error bag if it fails
115154 *
@@ -146,6 +185,16 @@ private function ajaxRespondCreated()
146185 return response ()->json ([], 201 );
147186 }
148187
188+ /**
189+ * Responses 204 No Content
190+ *
191+ * @return \Illuminate\Http\JsonResponse
192+ */
193+ private function ajaxRespondUpdated ()
194+ {
195+ return response ()->json ([], 204 );
196+ }
197+
149198 /**
150199 * Responses 422 Error
151200 *
0 commit comments