4
4
$ ( document ) . ready ( function ( ) {
5
5
6
6
7
+ $ ( document ) . on ( 'click' , '.new-modal' , function ( ) {
8
+ $ ( '#footer_action_button_new' ) . text ( "New" ) ;
9
+ $ ( '#footer_action_button_new' ) . addClass ( 'glyphicon-check' ) ;
10
+ $ ( '#footer_action_button_new' ) . removeClass ( 'glyphicon-trash' ) ;
11
+ $ ( '.actionBtnNew' ) . addClass ( 'btn-success' ) ;
12
+ $ ( '.actionBtnNew' ) . removeClass ( 'btn-danger' ) ;
13
+ $ ( '.actionBtnNew' ) . addClass ( 'new' ) ;
14
+ $ ( '.modal-title-new' ) . text ( 'New' ) ;
15
+
16
+ $ ( '#name' ) . val ( $ ( this ) . data ( 'name' ) ) ;
17
+
18
+ $ ( '#myModalNew' ) . modal ( 'show' ) ;
19
+ } ) ;
20
+
21
+
22
+
23
+
24
+
7
25
$ ( 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 ( ) ;
26
+ $ ( '#footer_action_button_edit' ) . text ( "Update" ) ;
27
+ $ ( '#footer_action_button_edit' ) . addClass ( 'glyphicon-check' ) ;
28
+ $ ( '#footer_action_button_edit' ) . removeClass ( 'glyphicon-trash' ) ;
29
+ $ ( '.actionBtnEdit' ) . addClass ( 'btn-success' ) ;
30
+ $ ( '.actionBtnEdit' ) . removeClass ( 'btn-danger' ) ;
31
+ $ ( '.actionBtnEdit' ) . addClass ( 'edit' ) ;
32
+ $ ( '.modal-title-edit' ) . text ( 'Edit' ) ;
17
33
$ ( '#fid' ) . val ( $ ( this ) . data ( 'id' ) ) ;
18
34
$ ( '#n' ) . val ( $ ( this ) . data ( 'name' ) ) ;
19
- $ ( '#myModal ' ) . modal ( 'show' ) ;
35
+ $ ( '#myModalEdit ' ) . modal ( 'show' ) ;
20
36
} ) ;
21
37
22
38
23
39
24
40
41
+
25
42
$ ( 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' ) ;
43
+ $ ( '#footer_action_button_delete ' ) . text ( " Delete" ) ;
44
+ $ ( '#footer_action_button_delete ' ) . removeClass ( 'glyphicon-check' ) ;
45
+ $ ( '#footer_action_button_delete ' ) . addClass ( 'glyphicon-trash' ) ;
46
+ $ ( '.actionBtnDelete ' ) . removeClass ( 'btn-success' ) ;
47
+ $ ( '.actionBtnDelete ' ) . addClass ( 'btn-danger' ) ;
48
+ $ ( '.actionBtnDelete ' ) . addClass ( 'delete' ) ;
49
+ $ ( '.modal-title-delete ' ) . text ( 'Delete' ) ;
33
50
$ ( '.did' ) . text ( $ ( this ) . data ( 'id' ) ) ;
34
- $ ( '.deleteContent' ) . show ( ) ;
35
- $ ( '.form-horizontal' ) . hide ( ) ;
36
51
$ ( '.dname' ) . html ( $ ( this ) . data ( 'name' ) ) ;
37
- $ ( '#myModal ' ) . modal ( 'show' ) ;
52
+ $ ( '#myModalDelete ' ) . modal ( 'show' ) ;
38
53
} ) ;
39
54
40
55
41
56
42
57
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 ( ) {
58
+ $ ( '.modal-footer-new' ) . on ( 'click' , '.new' , function ( ) {
61
59
62
60
$ . ajax ( {
63
61
type : 'post' ,
@@ -70,19 +68,41 @@ $(document).ready(function() {
70
68
if ( ( data . errors ) ) {
71
69
$ ( '.error' ) . removeClass ( 'hidden' ) ;
72
70
$ ( '.error' ) . text ( data . errors . name ) ;
73
- // console.log('sss')
71
+ // console.log('sss')
74
72
}
75
73
else {
76
74
$ ( '.error' ) . addClass ( 'hidden' ) ;
77
75
$ ( '#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
76
}
79
77
} ,
78
+ } ) ;
79
+
80
+ } ) ;
81
+
82
+
83
+
80
84
85
+
86
+
87
+ $ ( '.modal-footer-edit' ) . on ( 'click' , '.edit' , function ( ) {
88
+ $ . ajax ( {
89
+ type : 'post' ,
90
+ url : '/editItem' ,
91
+ data : {
92
+ '_token' : $ ( 'input[name=_token]' ) . val ( ) ,
93
+ 'id' : $ ( "#fid" ) . val ( ) ,
94
+ 'name' : $ ( '#n' ) . val ( )
95
+ } ,
96
+ success : function ( data ) {
97
+ $ ( '.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>" ) ;
98
+ }
81
99
} ) ;
82
- $ ( '#name' ) . val ( '' ) ;
83
100
} ) ;
84
101
85
102
103
+
104
+
105
+
86
106
$ ( '.modal-footer' ) . on ( 'click' , '.delete' , function ( ) {
87
107
$ . ajax ( {
88
108
type : 'post' ,
@@ -99,4 +119,9 @@ $(document).ready(function() {
99
119
100
120
101
121
122
+
123
+
124
+
125
+
126
+
102
127
} ) ;
0 commit comments