Commit 636d814c5300f2fd514fcd45315c913ef282ff09

Authored by Андрей Ларионов
1 parent b1a7d3c76c

Редактор табов образования

Showing 3 changed files with 32 additions and 3 deletions Side-by-side Diff

app/Http/Controllers/Admin/EducationController.php
... ... @@ -8,6 +8,7 @@ use App\Http\Requests\ProgramEducationRequest;
8 8 use App\Models\Education;
9 9 use App\Models\ProgramEducation;
10 10 use Illuminate\Http\Request;
  11 +use Illuminate\Support\Facades\DB;
11 12 use Illuminate\Support\Facades\Storage;
12 13  
13 14 class EducationController extends Controller
... ... @@ -108,6 +109,22 @@ class EducationController extends Controller
108 109 return redirect()->route('admin.education.index');
109 110 }
110 111  
  112 + public function rename_program(Request $request) {
  113 + if ($request->ajax()) {
  114 + $oldnamelevel = $request->oldname;
  115 + $newnamelevel = $request->newname;
  116 + $id_education = $request->id_education;
  117 +
  118 + $result = DB::table('program_education')
  119 + ->where('education_id', '=', $id_education)
  120 + ->where('level', '=', $oldnamelevel)
  121 + ->update(['level' => $newnamelevel]);
  122 +
  123 + return $result;
  124 + } else return "";
  125 +
  126 + }
  127 +
111 128 public function add_program(Request $request) {
112 129 $id_education = $request->id;
113 130 $level = $request->level;
resources/views/admin/education/form.blade.php
... ... @@ -246,10 +246,21 @@
246 246 e.preventDefault();
247 247 }
248 248  
249   - /*if (tabsInput.dataset.edit) {
  249 + if (tabsInput.dataset.edit) {
250 250  
251 251 tabsBtns.forEach(btn => {
252 252 if (tabsInput.dataset.edit === btn.dataset.id) {
  253 + console.log('oldname: '+btn.textContent+' newname: '+tabsInputValue+' id_education: '+<?=$education->id?>+'');
  254 + $.ajax({
  255 + url: '{{ route('admin.rename-program-education') }}',
  256 + method: 'get', /* Метод запроса (post или get) */
  257 + dataType: 'html', /* Тип данных в ответе (xml, json, script, html). */
  258 + data: {oldname: btn.textContent, newname:tabsInputValue, id_education: <?=$education->id?>}, /* Данные передаваемые в массиве */
  259 + success: function(data){ /* функция которая будет выполнена после успешного запроса. */
  260 + console.log(data); /* В переменной data содержится ответ от index.php. */
  261 + }
  262 + });
  263 +
253 264 btn.textContent = tabsInputValue;
254 265 btn.dataset.btn = tabsInputValue;
255 266 }
... ... @@ -261,7 +272,7 @@
261 272  
262 273 if (!tabsBtns.length) {
263 274 tabsButtons.innerHTML += getTabsBtnTemplate(tabsInputValue, id);
264   - tabsContent.innerHTML += getTabsItemTemplate(id);
  275 + //tabsContent.innerHTML += getTabsItemTemplate(id);
265 276 }
266 277  
267 278 if (tabsBtns.length && tabsBtns.length < qty) {
... ... @@ -280,7 +291,7 @@
280 291 tabsContent.innerHTML += getTabsItemTemplate(id, 'hidden');
281 292 }
282 293 }
283   - }*/
  294 + }
284 295  
285 296 //tabsInput.value = '';
286 297 addDisabledBtnStatus(tabsSubmitBtn);
... ... @@ -226,6 +226,7 @@ Route::group([
226 226 // CRUD-операции над справочником Образование
227 227 Route::resource('education', EducationController::class, ['except' => ['show']]);
228 228  
  229 + Route::get('rename-program-education', [EducationController::class, 'rename_program'])->name('rename-program-education');
229 230 Route::get('program-education', [EducationController::class, 'add_program'])->name('add-program-education');
230 231 Route::post('program-education', [EducationController::class, 'store_program'])->name('store-program-education');
231 232