|
Lines 5-20
Link Here
|
| 5 |
[% INCLUDE 'datatables.inc' %] |
5 |
[% INCLUDE 'datatables.inc' %] |
| 6 |
<script type="text/javascript"> |
6 |
<script type="text/javascript"> |
| 7 |
//<![CDATA[ |
7 |
//<![CDATA[ |
|
|
8 |
var aDataSet = []; |
| 8 |
$(document).ready(function() { |
9 |
$(document).ready(function() { |
| 9 |
$("#table_cities").dataTable($.extend(true, {}, dataTablesDefaults, { |
10 |
|
| 10 |
"aoColumnDefs": [ |
11 |
var dtCityResults = $("#table_cities").dataTable($.extend(true, {}, dataTablesDefaults, { |
| 11 |
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false }, |
12 |
'bServerSide': true, |
| 12 |
], |
13 |
'sAjaxSource': "/api/v1/cities", |
| 13 |
"aaSorting": [[ 1, "asc" ]], |
14 |
'fnServerData': function(sSource, aoData, fnCallback) { |
| 14 |
"iDisplayLength": 10, |
15 |
var echo = aoData[0].value; |
| 15 |
"sPaginationType": "full_numbers" |
16 |
$.ajax({ |
|
|
17 |
dataType: 'json', |
| 18 |
type: 'GET', |
| 19 |
url: sSource, |
| 20 |
//data: aoData, |
| 21 |
success: function(data){ |
| 22 |
aDataSet = []; |
| 23 |
var json = {}; |
| 24 |
$.each(data, function() { |
| 25 |
aDataSet.push([ |
| 26 |
this.cityid, |
| 27 |
this.city_name, |
| 28 |
this.city_state, |
| 29 |
this.city_zipcode, |
| 30 |
this.city_country, |
| 31 |
"<a href='/cgi-bin/koha/admin/cities.pl?op=add_form&cityid=" + this.cityid + "'>" + _("Edit") + "</a>", |
| 32 |
"<a data-cityid='" + this.cityid + "' href='#'>" + _("Delete") + "</a>" |
| 33 |
]); |
| 34 |
}); |
| 35 |
json.iTotalRecords = data.length; |
| 36 |
json.iTotalDisplayRecords = data.length; |
| 37 |
json.sEcho = echo; |
| 38 |
json.aaData = aDataSet; |
| 39 |
fnCallback(json); |
| 40 |
} |
| 41 |
}); |
| 42 |
}, |
| 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 |
| 49 |
// Not supported yet |
| 50 |
'bAutoWidth': false, |
| 51 |
'bPaginate': false, |
| 52 |
'bSort': false, |
| 53 |
'bFilter': false |
| 16 |
})); |
54 |
})); |
|
|
55 |
|
| 56 |
$("#add_city").on('submit', function(e){ |
| 57 |
e.preventDefault(); |
| 58 |
var city = { |
| 59 |
cityid: $("#cityid").val(), |
| 60 |
city_name: $("#city_name").val(), |
| 61 |
city_state: $("#city_state").val(), |
| 62 |
city_zipcode: $("#city_zipcode").val(), |
| 63 |
city_country: $("#city_country").val() |
| 64 |
}; |
| 65 |
// Double check on required fields should be avoided |
| 66 |
if ( !city.city_name || !city.city_zipcode ) return; |
| 67 |
cityid ? update_city(city) : add_city(city); |
| 68 |
}); |
| 17 |
}); |
69 |
}); |
|
|
70 |
|
| 71 |
// The 3 functions should be extracted somewhere else |
| 72 |
function update_city(city) { |
| 73 |
$.ajax({ |
| 74 |
type: 'PUT', |
| 75 |
url: '/api/v1/cities/' + city.cityid, |
| 76 |
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 |
}); |
| 86 |
} |
| 87 |
function add_city(city) { |
| 88 |
$.ajax({ |
| 89 |
type: 'PUT', |
| 90 |
url: '/api/v1/cities', |
| 91 |
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 |
}); |
| 99 |
} |
| 100 |
function delete_city(cityid) { |
| 101 |
if ( confirm(_("Are you sure you want to delete this city?")) ) { |
| 102 |
$.ajax({ |
| 103 |
type: 'DELETE', |
| 104 |
url: '/api/v1/cities/' + cityid, |
| 105 |
success: function(data){ |
| 106 |
window.location.href='/cgi-bin/koha/admin/cities.pl'; |
| 107 |
}, |
| 108 |
error: function(data){ |
| 109 |
alert(data); |
| 110 |
} |
| 111 |
}) |
| 112 |
} |
| 113 |
} |
| 18 |
//]]> |
114 |
//]]> |
| 19 |
</script> |
115 |
</script> |
| 20 |
</head> |
116 |
</head> |
|
Lines 39-59
Link Here
|
| 39 |
<div id="yui-main"> |
135 |
<div id="yui-main"> |
| 40 |
<div class="yui-b"> |
136 |
<div class="yui-b"> |
| 41 |
|
137 |
|
| 42 |
[% FOR m IN messages %] |
138 |
[% IF message %] |
| 43 |
<div class="dialog [% m.type %]"> |
139 |
<div class="dialog message"> |
| 44 |
[% SWITCH m.code %] |
140 |
[% SWITCH message %] |
| 45 |
[% CASE 'error_on_update' %] |
141 |
[% CASE 'updated' %] |
| 46 |
An error occurred when updating this city. Perhaps it already exists. |
142 |
City updated successfully. |
|
|
143 |
[% CASE 'added' %] |
| 144 |
City added successfully. |
| 145 |
[% CASE 'deleted' %] |
| 146 |
City deleted successfully. |
| 47 |
[% CASE 'error_on_insert' %] |
147 |
[% CASE 'error_on_insert' %] |
| 48 |
An error occurred when adding this city. The city id might already exist. |
148 |
An error occurred when adding this city. The city id might already exist. |
| 49 |
[% CASE 'error_on_delete' %] |
149 |
[% CASE 'error_on_delete' %] |
| 50 |
An error occurred when deleting this city. Check the logs. |
150 |
An error occurred when deleting this city. Check the logs. |
| 51 |
[% CASE 'success_on_update' %] |
|
|
| 52 |
City updated successfully. |
| 53 |
[% CASE 'success_on_insert' %] |
| 54 |
City added successfully. |
| 55 |
[% CASE 'success_on_delete' %] |
| 56 |
City deleted successfully. |
| 57 |
[% CASE 'already_exists' %] |
151 |
[% CASE 'already_exists' %] |
| 58 |
This city already exists. |
152 |
This city already exists. |
| 59 |
[% CASE %] |
153 |
[% CASE %] |
|
Lines 69-77
Link Here
|
| 69 |
<h1>New city</h1> |
163 |
<h1>New city</h1> |
| 70 |
[% END %] |
164 |
[% END %] |
| 71 |
|
165 |
|
| 72 |
<form action="/cgi-bin/koha/admin/cities.pl" name="Aform" method="post" class="validated"> |
166 |
<form id="add_city" action="/cgi-bin/koha/admin/cities.pl" name="Aform" method="post" class="validated"> |
| 73 |
<input type="hidden" name="op" value="add_validate" /> |
167 |
<input type="hidden" name="op" value="add_validate" /> |
| 74 |
<input type="hidden" name="cityid" value="[% city.cityid %]" /> |
168 |
<input type="hidden" name="cityid" id="cityid" value="[% city.cityid %]" /> |
| 75 |
|
169 |
|
| 76 |
<fieldset class="rows"> |
170 |
<fieldset class="rows"> |
| 77 |
<ol> |
171 |
<ol> |
|
Lines 104-140
Link Here
|
| 104 |
</form> |
198 |
</form> |
| 105 |
[% END %] |
199 |
[% END %] |
| 106 |
|
200 |
|
| 107 |
[% IF op == 'delete_confirm' %] |
|
|
| 108 |
<div class="dialog alert"> |
| 109 |
<h3>Delete City "[% city.city_name %]?"</h3> |
| 110 |
<table> |
| 111 |
<tr><th>City id</th> |
| 112 |
<td>[% city.cityid %]</td> |
| 113 |
</tr> |
| 114 |
<tr><th>City</th> |
| 115 |
<td>[% city.city_name %]</td> |
| 116 |
</tr> |
| 117 |
<tr><th>State</th> |
| 118 |
<td>[% city.city_state %]</td> |
| 119 |
</tr> |
| 120 |
<tr><th>Zip/Postal code</th> |
| 121 |
<td>[% city.city_zipcode %]</td> |
| 122 |
</tr> |
| 123 |
<tr><th>Country</th> |
| 124 |
<td>[% city.city_country %]</td> |
| 125 |
</tr> |
| 126 |
</table> |
| 127 |
<form action="/cgi-bin/koha/admin/cities.pl" method="post"> |
| 128 |
<input type="hidden" name="op" value="delete_confirmed" /> |
| 129 |
<input type="hidden" name="cityid" value="[% city.cityid %]" /> |
| 130 |
<input type="submit" class="approve" value="Yes, delete" /> |
| 131 |
</form> |
| 132 |
<form action="/cgi-bin/koha/admin/cities.pl" method="get"> |
| 133 |
<input type="submit" class="deny" value="No, do not Delete" /> |
| 134 |
</form> |
| 135 |
</div> |
| 136 |
[% END %] |
| 137 |
|
| 138 |
[% IF op == 'list' %] |
201 |
[% IF op == 'list' %] |
| 139 |
|
202 |
|
| 140 |
<div id="toolbar" class="btn-toolbar"> |
203 |
<div id="toolbar" class="btn-toolbar"> |
|
Lines 158-174
Link Here
|
| 158 |
<th> </th> |
221 |
<th> </th> |
| 159 |
</thead> |
222 |
</thead> |
| 160 |
<tbody> |
223 |
<tbody> |
| 161 |
[% FOREACH city IN cities %] |
|
|
| 162 |
<tr> |
| 163 |
<td>[% city.cityid %]</td> |
| 164 |
<td>[% city.city_name %]</td> |
| 165 |
<td>[% city.city_state %]</td> |
| 166 |
<td>[% city.city_zipcode %]</td> |
| 167 |
<td>[% city.city_country %]</td> |
| 168 |
<td><a href="/cgi-bin/koha/admin/cities.pl?op=add_form&cityid=[% city.cityid %]">Edit</a></td> |
| 169 |
<td><a href="/cgi-bin/koha/admin/cities.pl?op=delete_confirm&cityid=[% city.cityid %]">Delete</a></td> |
| 170 |
</tr> |
| 171 |
[% END %] |
| 172 |
</tbody> |
224 |
</tbody> |
| 173 |
</table> |
225 |
</table> |
| 174 |
[% ELSE %] |
226 |
[% ELSE %] |
| 175 |
- |
|
|