Lines 1-3
Link Here
|
|
|
1 |
[% BLOCK city_form %] |
2 |
<input type="hidden" name="op" value="add_validate" /> |
3 |
<input type="hidden" name="cityid" id="cityid" value="[% city.cityid %]" /> |
4 |
|
5 |
<fieldset class="rows"> |
6 |
<ol> |
7 |
[% IF city %] |
8 |
<li><span class="label">City ID: </span>[% city.cityid %]</li> |
9 |
[% END %] |
10 |
<li> |
11 |
<label for="city_name" class="required">City: </label> |
12 |
<input type="text" name="city_name" id="city_name" size="40" maxlength="100" value="[% city.city_name |html %]" required="required" class="required" /> <span class="required">Required</span> |
13 |
</li> |
14 |
<li> |
15 |
<label for="city_state">State: </label> |
16 |
<input type="text" name="city_state" id="city_state" size="40" maxlength="100" value="[% city.city_state |html %]" /> |
17 |
</li> |
18 |
<li> |
19 |
<label for="city_zipcode" class="required">ZIP/Postal code: </label> |
20 |
<input type="text" name="city_zipcode" id="city_zipcode" size="20" maxlength="20" value="[% city.city_zipcode %]" required="required" class="required" /> <span class="required">Required</span> |
21 |
</li> |
22 |
<li> |
23 |
<label for="city_country">Country: </label> |
24 |
<input type="text" name="city_country" id="city_country" size="40" maxlength="100" value="[% city.city_country |html %]" /> |
25 |
</li> |
26 |
</ol> |
27 |
</fieldset> |
28 |
[% END %] |
29 |
|
1 |
[% INCLUDE 'doc-head-open.inc' %] |
30 |
[% INCLUDE 'doc-head-open.inc' %] |
2 |
<title>Koha › Administration › [% IF op =='add_form' %]Cities › [% IF city.cityid %] Modify city[% ELSE %] New city[% END %][% ELSE %][% IF op == 'delete_confirm' %]Cities › Confirm deletion of city[% ELSE %] Cities[% END %][% END %]</title> |
31 |
<title>Koha › Administration › [% IF op =='add_form' %]Cities › [% IF city.cityid %] Modify city[% ELSE %] New city[% END %][% ELSE %][% IF op == 'delete_confirm' %]Cities › Confirm deletion of city[% ELSE %] Cities[% END %][% END %]</title> |
3 |
[% INCLUDE 'doc-head-close.inc' %] |
32 |
[% INCLUDE 'doc-head-close.inc' %] |
Lines 28-35
Link Here
|
28 |
this.city_state, |
57 |
this.city_state, |
29 |
this.city_zipcode, |
58 |
this.city_zipcode, |
30 |
this.city_country, |
59 |
this.city_country, |
31 |
"<a href='/cgi-bin/koha/admin/cities.pl?op=add_form&cityid=" + this.cityid + "'>" + _("Edit") + "</a>", |
60 |
"<a href='/cgi-bin/koha/admin/cities.pl?op=add_form&cityid=" + this.cityid + "' class='edit'>" + _("Edit") + "</a>", |
32 |
"<a data-cityid='" + this.cityid + "' href='#'>" + _("Delete") + "</a>" |
61 |
"<a data-cityid='" + this.cityid + "' href='#' class='delete'>" + _("Delete") + "</a>" |
33 |
]); |
62 |
]); |
34 |
}); |
63 |
}); |
35 |
json.iTotalRecords = data.length; |
64 |
json.iTotalRecords = data.length; |
Lines 40-50
Link Here
|
40 |
} |
69 |
} |
41 |
}); |
70 |
}); |
42 |
}, |
71 |
}, |
43 |
'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { |
|
|
44 |
$("td:eq(6)", nRow).find('a').on('click', function() { |
45 |
return delete_city($(this).attr('data-cityid')); |
46 |
}); |
47 |
}, |
48 |
// Should add filter/search/pagination |
72 |
// Should add filter/search/pagination |
49 |
// Not supported yet |
73 |
// Not supported yet |
50 |
'bAutoWidth': false, |
74 |
'bAutoWidth': false, |
Lines 64-116
Link Here
|
64 |
}; |
88 |
}; |
65 |
// Double check on required fields should be avoided |
89 |
// Double check on required fields should be avoided |
66 |
if ( !city.city_name || !city.city_zipcode ) return; |
90 |
if ( !city.city_name || !city.city_zipcode ) return; |
67 |
cityid ? update_city(city) : add_city(city); |
91 |
var jqxhr = cityid ? update_city(city) : add_city(city); |
|
|
92 |
jqxhr.done(function() { |
93 |
$('#city-form').modal('hide'); |
94 |
$('#table_cities').dataTable().fnDraw(); |
95 |
|
96 |
var message; |
97 |
if (cityid) { |
98 |
message = _("The city was successfully updated"); |
99 |
} else { |
100 |
message = _("The city was successfully added"); |
101 |
} |
102 |
display_message(message); |
103 |
}); |
104 |
jqxhr.fail(function(data) { |
105 |
display_error(data); |
106 |
}); |
107 |
}); |
108 |
|
109 |
$('#newcity').on('click', function(e) { |
110 |
e.preventDefault(); |
111 |
$('#city-form').modal({show: true}); |
112 |
}) |
113 |
|
114 |
$('#table_cities').on('click', '.edit', function(e) { |
115 |
e.preventDefault(); |
116 |
var row = $(this).parents('tr'); |
117 |
// FIXME There must be a better way to retrieve city data |
118 |
var city = { |
119 |
id: row.find('td:eq(0)').text(), |
120 |
name: row.find('td:eq(1)').text(), |
121 |
state: row.find('td:eq(2)').text(), |
122 |
zipcode: row.find('td:eq(3)').text(), |
123 |
country: row.find('td:eq(4)').text(), |
124 |
}; |
125 |
var form = $('#city-form').find('form'); |
126 |
form.find('[name="cityid"]').val(city.id); |
127 |
form.find('[name="city_name"]').val(city.name); |
128 |
form.find('[name="city_state"]').val(city.state); |
129 |
form.find('[name="city_zipcode"]').val(city.zipcode); |
130 |
form.find('[name="city_country"]').val(city.country); |
131 |
$('#city-form').modal({show: true}); |
132 |
}); |
133 |
$('#table_cities').on('click', '.delete', function(e) { |
134 |
e.preventDefault(); |
135 |
delete_city($(this).attr('data-cityid')) |
136 |
.done(function(data){ |
137 |
$('#table_cities').dataTable().fnDraw(); |
138 |
|
139 |
display_message(_("The city was successfully deleted")); |
140 |
}) |
141 |
.fail(function(data){ |
142 |
display_error(data); |
143 |
}); |
68 |
}); |
144 |
}); |
69 |
}); |
145 |
}); |
70 |
|
146 |
|
71 |
// The 3 functions should be extracted somewhere else |
147 |
// The 3 functions should be extracted somewhere else |
72 |
function update_city(city) { |
148 |
function update_city(city) { |
73 |
$.ajax({ |
149 |
return $.ajax({ |
74 |
type: 'PUT', |
150 |
type: 'PUT', |
75 |
url: '/api/v1/cities/' + city.cityid, |
151 |
url: '/api/v1/cities/' + city.cityid, |
76 |
data: JSON.stringify(city), |
152 |
data: JSON.stringify(city), |
77 |
success: function(data){ |
|
|
78 |
// Need a better way to redirect, we would like to inform the user that the action succeeded |
79 |
window.location.href='/cgi-bin/koha/admin/cities.pl'; |
80 |
}, |
81 |
error: function(data){ |
82 |
// Need a better way to inform the user that the action has failed |
83 |
alert(data); |
84 |
} |
85 |
}); |
153 |
}); |
86 |
} |
154 |
} |
87 |
function add_city(city) { |
155 |
function add_city(city) { |
88 |
$.ajax({ |
156 |
return $.ajax({ |
89 |
type: 'PUT', |
157 |
type: 'PUT', |
90 |
url: '/api/v1/cities', |
158 |
url: '/api/v1/cities', |
91 |
data: JSON.stringify(city), |
159 |
data: JSON.stringify(city), |
92 |
success: function(data){ |
|
|
93 |
window.location.href='/cgi-bin/koha/admin/cities.pl'; |
94 |
}, |
95 |
error: function(data){ |
96 |
alert(data); |
97 |
} |
98 |
}); |
160 |
}); |
99 |
} |
161 |
} |
100 |
function delete_city(cityid) { |
162 |
function delete_city(cityid) { |
101 |
if ( confirm(_("Are you sure you want to delete this city?")) ) { |
163 |
if ( confirm(_("Are you sure you want to delete this city?")) ) { |
102 |
$.ajax({ |
164 |
return $.ajax({ |
103 |
type: 'DELETE', |
165 |
type: 'DELETE', |
104 |
url: '/api/v1/cities/' + cityid, |
166 |
url: '/api/v1/cities/' + cityid, |
105 |
success: function(data){ |
167 |
}); |
106 |
window.location.href='/cgi-bin/koha/admin/cities.pl'; |
|
|
107 |
}, |
108 |
error: function(data){ |
109 |
alert(data); |
110 |
} |
111 |
}) |
112 |
} |
168 |
} |
113 |
} |
169 |
} |
|
|
170 |
function display_message(msg) { |
171 |
var message = $('<div></div>').addClass('dialog message').html(msg); |
172 |
setTimeout(function() {message.fadeOut();}, 5000); |
173 |
$('#messages').append(message); |
174 |
} |
175 |
function display_error(msg) { |
176 |
var message = $('<div></div>').addClass('dialog alert').html(msg); |
177 |
setTimeout(function() {message.fadeOut();}, 5000); |
178 |
$('#messages').append(message); |
179 |
} |
114 |
//]]> |
180 |
//]]> |
115 |
</script> |
181 |
</script> |
116 |
</head> |
182 |
</head> |
Lines 164-195
Link Here
|
164 |
[% END %] |
230 |
[% END %] |
165 |
|
231 |
|
166 |
<form id="add_city" action="/cgi-bin/koha/admin/cities.pl" name="Aform" method="post" class="validated"> |
232 |
<form id="add_city" action="/cgi-bin/koha/admin/cities.pl" name="Aform" method="post" class="validated"> |
167 |
<input type="hidden" name="op" value="add_validate" /> |
233 |
[% INCLUDE city_form city = city %] |
168 |
<input type="hidden" name="cityid" id="cityid" value="[% city.cityid %]" /> |
|
|
169 |
|
170 |
<fieldset class="rows"> |
171 |
<ol> |
172 |
[% IF city %] |
173 |
<li><span class="label">City ID: </span>[% city.cityid %]</li> |
174 |
[% END %] |
175 |
<li> |
176 |
<label for="city_name" class="required">City: </label> |
177 |
<input type="text" name="city_name" id="city_name" size="80" maxlength="100" value="[% city.city_name |html %]" required="required" class="required" /> <span class="required">Required</span> |
178 |
</li> |
179 |
<li> |
180 |
<label for="city_state">State: </label> |
181 |
<input type="text" name="city_state" id="city_state" size="80" maxlength="100" value="[% city.city_state |html %]" /> |
182 |
</li> |
183 |
<li> |
184 |
<label for="city_zipcode" class="required">ZIP/Postal code: </label> |
185 |
<input type="text" name="city_zipcode" id="city_zipcode" size="20" maxlength="20" value="[% city.city_zipcode %]" required="required" class="required" /> <span class="required">Required</span> |
186 |
</li> |
187 |
<li> |
188 |
<label for="city_country">Country: </label> |
189 |
<input type="text" name="city_country" id="city_country" size="80" maxlength="100" value="[% city.city_country |html %]" /> |
190 |
</li> |
191 |
</ol> |
192 |
</fieldset> |
193 |
|
234 |
|
194 |
<fieldset class="action"> |
235 |
<fieldset class="action"> |
195 |
<input type="submit" value="Submit" /> |
236 |
<input type="submit" value="Submit" /> |
Lines 205-210
Link Here
|
205 |
</div> |
246 |
</div> |
206 |
|
247 |
|
207 |
<h2>Cities</h2> |
248 |
<h2>Cities</h2> |
|
|
249 |
|
250 |
<div id="messages"></div> |
251 |
|
208 |
[% IF searchfield %] |
252 |
[% IF searchfield %] |
209 |
Searching: [% searchfield %] |
253 |
Searching: [% searchfield %] |
210 |
[% END %] |
254 |
[% END %] |
Lines 226-231
Link Here
|
226 |
[% ELSE %] |
270 |
[% ELSE %] |
227 |
There is no city defined. <a href="/cgi-bin/koha/admin/cities.pl?op=add_form">Create a new city</a>. |
271 |
There is no city defined. <a href="/cgi-bin/koha/admin/cities.pl?op=add_form">Create a new city</a>. |
228 |
[% END %] |
272 |
[% END %] |
|
|
273 |
|
274 |
<div id="city-form" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true"> |
275 |
<form id="add_city"> |
276 |
<div class="modal-header"> |
277 |
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button> |
278 |
<h3 id="city-form-label">Add city</h3> |
279 |
</div> |
280 |
<div class="modal-body"> |
281 |
[% INCLUDE city_form %] |
282 |
</div> |
283 |
<div class="modal-footer"> |
284 |
<button class="btn" type="submit">Submit</button> |
285 |
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> |
286 |
</div> |
287 |
</form> |
288 |
</div> |
229 |
[% END %] |
289 |
[% END %] |
230 |
|
290 |
|
231 |
</div> |
291 |
</div> |
232 |
- |
|
|