4848 < button id ="create-book-async " class ="btn btn-primary " type ="button " name ="button ">
4949 < span class ="fa fa-plus mr-2 "> </ span > Create book - Asynchronous
5050 </ button >
51- < button id ="filter-book " class ="bs-modal btn btn-primary " type ="button " name ="button " data-form-url ="{% url 'filter_book' %} ">
51+ < button id ="filter-book " class ="filter-book btn btn-primary " type ="button " name ="button " data-form-url ="{% url 'filter_book' %} ">
5252 < span class ="fa fa-filter mr-2 "> </ span > Filter books
5353 </ button >
5454 </ div >
5555 < div class ="col-12 mb-3 ">
56+ {% if 'type' in request.GET %}
57+ < p class ="filtered-books "> Filtered books.</ p >
58+ {% endif %}
5659 {% if books %}
5760 {% include "_books_table.html" %}
5861 {% else %}
6972{% block extrascripts %}
7073 < script type ="text/javascript ">
7174 $ ( function ( ) {
72- // Log in & Sign up buttons
73- // The formURL is given explicitly
75+ // Login
7476 $ ( "#login-btn" ) . modalForm ( {
7577 formURL : "{% url 'login' %}"
7678 } ) ;
7779
80+ // Signup
7881 $ ( "#signup-btn" ) . modalForm ( {
7982 formURL : "{% url 'signup' %}"
8083 } ) ;
8184
82- // Create book button opens modal with id="create-modal"
83- /*
84- $("#create-book").modalForm({
85- formURL: "{% url 'create_book' %}",
86- modalID: "#create-modal"
87- });
88- */
89-
85+ // Create book synchronous
9086 function createBookSyncModalForm ( ) {
9187 $ ( "#create-book-sync" ) . modalForm ( {
9288 formURL : "{% url 'create_book' %}" ,
9591 }
9692 createBookSyncModalForm ( ) ;
9793
94+ // Create book asynchronous button
95+ // message
9896 var asyncSuccessMessageCreate = [
9997 "<div " ,
10098 "style='position:fixed;top:0;z-index:10000;width:100%;border-radius:0;' " ,
@@ -109,6 +107,26 @@ <h4>
109107 "<\/script>"
110108 ] . join ( "" ) ;
111109
110+ // modal form
111+ function createBookAsyncModalForm ( ) {
112+ $ ( "#create-book-async" ) . modalForm ( {
113+ formURL : "{% url 'create_book' %}" ,
114+ modalID : "#create-modal" ,
115+ asyncUpdate : true ,
116+ asyncSettings : {
117+ closeOnSubmit : true ,
118+ successMessage : asyncSuccessMessageCreate ,
119+ dataUrl : "books/" ,
120+ dataElementId : "#books-table" ,
121+ dataKey : "table" ,
122+ addModalFormFunction : updateBookModalForm
123+ }
124+ } ) ;
125+ }
126+ createBookAsyncModalForm ( ) ;
127+
128+ // Update book asynchronous button
129+ // message
112130 var asyncSuccessMessageUpdate = [
113131 "<div " ,
114132 "style='position:fixed;top:0;z-index:10000;width:100%;border-radius:0;' " ,
123141 "<\/script>"
124142 ] . join ( "" ) ;
125143
144+ // modal form
126145 function updateBookModalForm ( ) {
127146 $ ( ".update-book" ) . each ( function ( ) {
128147 $ ( this ) . modalForm ( {
@@ -141,26 +160,18 @@ <h4>
141160 }
142161 updateBookModalForm ( ) ;
143162
144- function createBookAsyncModalForm ( ) {
145- $ ( "#create-book-async" ) . modalForm ( {
146- formURL : "{% url 'create_book' %}" ,
147- modalID : "#create-modal" ,
148- asyncUpdate : true ,
149- asyncSettings : {
150- closeOnSubmit : true ,
151- successMessage : asyncSuccessMessageCreate ,
152- dataUrl : "books/" ,
153- dataElementId : "#books-table" ,
154- dataKey : "table" ,
155- addModalFormFunction : updateBookModalForm
156- }
157- } ) ;
158- }
159- createBookAsyncModalForm ( ) ;
163+ // Delete book buttons - formURL is retrieved from the data of the element
164+ $ ( ".delete-book" ) . each ( function ( ) {
165+ $ ( this ) . modalForm ( { formURL : $ ( this ) . data ( "form-url" ) , isDeleteForm : true } ) ;
166+ } ) ;
167+
168+ // Read book buttons
169+ $ ( ".read-book" ) . each ( function ( ) {
170+ $ ( this ) . modalForm ( { formURL : $ ( this ) . data ( "form-url" ) } ) ;
171+ } ) ;
160172
161- // Read and Delete book buttons open modal with id="modal"
162- // The formURL is retrieved from the data of the element
163- $ ( ".bs-modal" ) . each ( function ( ) {
173+ // Filter books button
174+ $ ( "#filter-book" ) . each ( function ( ) {
164175 $ ( this ) . modalForm ( { formURL : $ ( this ) . data ( "form-url" ) } ) ;
165176 } ) ;
166177
0 commit comments