44$ ( document ) . ready ( function ( ) {
55
66
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+
725 $ ( 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' ) ;
1733 $ ( '#fid' ) . val ( $ ( this ) . data ( 'id' ) ) ;
1834 $ ( '#n' ) . val ( $ ( this ) . data ( 'name' ) ) ;
19- $ ( '#myModal ' ) . modal ( 'show' ) ;
35+ $ ( '#myModalEdit ' ) . modal ( 'show' ) ;
2036 } ) ;
2137
2238
2339
2440
41+
2542 $ ( 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' ) ;
3350 $ ( '.did' ) . text ( $ ( this ) . data ( 'id' ) ) ;
34- $ ( '.deleteContent' ) . show ( ) ;
35- $ ( '.form-horizontal' ) . hide ( ) ;
3651 $ ( '.dname' ) . html ( $ ( this ) . data ( 'name' ) ) ;
37- $ ( '#myModal ' ) . modal ( 'show' ) ;
52+ $ ( '#myModalDelete ' ) . modal ( 'show' ) ;
3853 } ) ;
3954
4055
4156
4257
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 ( ) {
6159
6260 $ . ajax ( {
6361 type : 'post' ,
@@ -70,19 +68,41 @@ $(document).ready(function() {
7068 if ( ( data . errors ) ) {
7169 $ ( '.error' ) . removeClass ( 'hidden' ) ;
7270 $ ( '.error' ) . text ( data . errors . name ) ;
73- // console.log('sss')
71+ // console.log('sss')
7472 }
7573 else {
7674 $ ( '.error' ) . addClass ( 'hidden' ) ;
7775 $ ( '#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>" ) ;
7876 }
7977 } ,
78+ } ) ;
79+
80+ } ) ;
81+
82+
83+
8084
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+ }
8199 } ) ;
82- $ ( '#name' ) . val ( '' ) ;
83100 } ) ;
84101
85102
103+
104+
105+
86106 $ ( '.modal-footer' ) . on ( 'click' , '.delete' , function ( ) {
87107 $ . ajax ( {
88108 type : 'post' ,
@@ -99,4 +119,9 @@ $(document).ready(function() {
99119
100120
101121
122+
123+
124+
125+
126+
102127} ) ;
0 commit comments