Skip to content

Commit cab8e28

Browse files
committed
done
1 parent 6455ae5 commit cab8e28

File tree

10 files changed

+373
-117
lines changed

10 files changed

+373
-117
lines changed

app/Demo.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Demo extends Model
8+
{
9+
protected $table = 'demo';
10+
public $timestamps = false;
11+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Demo;
6+
use Validator;
7+
use Response;
8+
use Illuminate\Support\Facades\Input;
9+
use Illuminate\Http\Request;
10+
11+
class DemoController extends Controller
12+
{
13+
public function addItem(Request $request)
14+
{
15+
$rules = array(
16+
'name' => 'required|alpha_num',
17+
);
18+
$validator = Validator::make(Input::all(), $rules);
19+
if ($validator->fails()) {
20+
return Response::json(array(
21+
'errors' => $validator->getMessage()->toArray(),
22+
));
23+
} else {
24+
$data = new Demo();
25+
$data->name = $request->name;
26+
$data->save();
27+
return response()->json($data);
28+
}
29+
}
30+
31+
32+
public function readItems(Request $req)
33+
{
34+
$data = Demo::all();
35+
return view('welcome')->withData($data);
36+
}
37+
38+
39+
public function editItem(Request $req)
40+
{
41+
$data = Demo::find($req->id);
42+
$data->name = $req->name;
43+
$data->save();
44+
return response()->json($data);
45+
}
46+
47+
48+
public function deleteItem(Request $req)
49+
{
50+
Demo::find($req->id)->delete();
51+
return response()->json();
52+
}
53+
54+
55+
}

app/Providers/AppServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
namespace App\Providers;
4-
4+
use Illuminate\Support\Facades\Schema;
55
use Illuminate\Support\ServiceProvider;
66

77
class AppServiceProvider extends ServiceProvider
@@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider
1313
*/
1414
public function boot()
1515
{
16-
//
16+
Schema::defaultStringLength(191);
1717
}
1818

1919
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateDemoTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('demo', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::dropIfExists('demo');
31+
}
32+
}

public/css/app.css

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/master.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.table-borderless tbody tr td, .table-borderless tbody tr th, .table-borderless thead tr th {
2+
border: none;
3+
}

public/js/app.js

+28-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/script.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Created by MDABUTALHA on 6/10/2017.
3+
*/
4+
$(document).ready(function() {
5+
6+
7+
$(document).on('click', '.edit-modal', function() {
8+
$('#footer_action_button').text("Update");
9+
$('#footer_action_button').addClass('glyphicon-check');
10+
$('#footer_action_button').removeClass('glyphicon-trash');
11+
$('.actionBtn').addClass('btn-success');
12+
$('.actionBtn').removeClass('btn-danger');
13+
$('.actionBtn').addClass('edit');
14+
$('.modal-title').text('Edit');
15+
$('.deleteContent').hide();
16+
$('.form-horizontal').show();
17+
$('#fid').val($(this).data('id'));
18+
$('#n').val($(this).data('name'));
19+
$('#myModal').modal('show');
20+
});
21+
22+
23+
24+
25+
$(document).on('click', '.delete-modal', function() {
26+
$('#footer_action_button').text(" Delete");
27+
$('#footer_action_button').removeClass('glyphicon-check');
28+
$('#footer_action_button').addClass('glyphicon-trash');
29+
$('.actionBtn').removeClass('btn-success');
30+
$('.actionBtn').addClass('btn-danger');
31+
$('.actionBtn').addClass('delete');
32+
$('.modal-title').text('Delete');
33+
$('.did').text($(this).data('id'));
34+
$('.deleteContent').show();
35+
$('.form-horizontal').hide();
36+
$('.dname').html($(this).data('name'));
37+
$('#myModal').modal('show');
38+
});
39+
40+
41+
42+
43+
$('.modal-footer').on('click', '.edit', function() {
44+
45+
$.ajax({
46+
type: 'post',
47+
url: '/editItem',
48+
data: {
49+
'_token': $('input[name=_token]').val(),
50+
'id': $("#fid").val(),
51+
'name': $('#n').val()
52+
},
53+
success: function(data) {
54+
$('.item' + data.id).replaceWith("<tr class='item" + data.id + "'><td>" + data.id + "</td><td>" + data.name + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.name + "' ><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
55+
}
56+
});
57+
});
58+
59+
60+
$("#add").click(function() {
61+
62+
$.ajax({
63+
type: 'post',
64+
url: '/addItem',
65+
data: {
66+
'_token': $('input[name=_token]').val(),
67+
'name': $('input[name=name]').val()
68+
},
69+
success: function(data) {
70+
if ((data.errors)){
71+
$('.error').removeClass('hidden');
72+
$('.error').text(data.errors.name);
73+
// console.log('sss')
74+
}
75+
else {
76+
$('.error').addClass('hidden');
77+
$('#table').append("<tr class='item" + data.id + "'><td>" + data.id + "</td><td>" + data.name + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
78+
}
79+
},
80+
81+
});
82+
$('#name').val('');
83+
});
84+
85+
86+
$('.modal-footer').on('click', '.delete', function() {
87+
$.ajax({
88+
type: 'post',
89+
url: '/deleteItem',
90+
data: {
91+
'_token': $('input[name=_token]').val(),
92+
'id': $('.did').text()
93+
},
94+
success: function(data) {
95+
$('.item' + $('.did').text()).remove();
96+
}
97+
});
98+
});
99+
100+
101+
102+
});

0 commit comments

Comments
 (0)