Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
my $builder = sub { |
6 |
my ($params) = @_; |
7 |
my $field_number = $params->{id}; |
8 |
|
9 |
my $res = " |
10 |
<script type=\"text/javascript\" charset=\"utf-8\"> |
11 |
//<![CDATA[ |
12 |
|
13 |
function Change$field_number() { |
14 |
var cn_value = jQuery('#$field_number').val(); |
15 |
var itemnumber = jQuery('input[name=\"itemnumber\"]').val(); |
16 |
if ( cn_value == '' ) change_color(); |
17 |
else api_item_count( cn_value, itemnumber, change_color ); |
18 |
return 1; |
19 |
} |
20 |
|
21 |
function change_color (color) { |
22 |
jQuery('#$field_number').removeClass( 'callnumber_green callnumber_red' ); |
23 |
if ( color ) jQuery('#$field_number').addClass( 'callnumber_' + color ); |
24 |
} |
25 |
|
26 |
function api_item_count ( cn_value, itemnumber, callback ) { |
27 |
var condition = JSON.stringify( |
28 |
itemnumber ? |
29 |
{ 'callnumber': cn_value, 'itemnumber': { '-not_like' : itemnumber } } : |
30 |
{ 'callnumber': cn_value } ); |
31 |
jQuery.ajax({ |
32 |
method: 'GET', |
33 |
url: '/api/v1/items?q=' + condition, |
34 |
}).done(function (data) { |
35 |
console.log( cn_value + ': ' + data.length ); |
36 |
callback( data.length ? 'red' : 'green' ); |
37 |
}).fail(function () { |
38 |
alert('An error occurred when checking callnumber'); |
39 |
}); |
40 |
} |
41 |
|
42 |
//]]> |
43 |
</script>"; |
44 |
return $res; |
45 |
}; |
46 |
|
47 |
return { builder => $builder }; |