Koha/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js
Alex Buckley bed1646444 Bug 22827: Add age dependency on other fields than dateaccessioned
A new agefield has been added to the 'Automatic item modifications by
age' tool. The options for the agefield are: replacementpricedate, datelastborrowed,
datelastseen, damaged_on, itemlost_on, withdrawn_on

If no option is selected then Koha will default to saving 'agefield' =
items.dateaccessioned

Similarly, if a Koha instance has an old item rule without 'agefield'
defined then Koha will default to using 'items.dateaccessioned'.
This is confirmed by the AutomaticItemModificationByAge.t unit test.

Test plan:

1. Go to: Tools > Catalog > Automatic item modifications by age
2. Observe there is a new 'Age field' dropdown in the rule form.
3. Create a rule, set the values:
- 'Age in days' = 20
- Leave 'Age field' = 'Choose an age field'
- 'Substitutions': 'items.barcode' = 'test'
- Save the rule
4. Confirm the 'List of rules' page displays 'items.dateaccessioned in the 'Age field' column
5. Add another rule:
- 'Age in days' = 2
- 'Age field' = 'items.datelastseen'
- 'Substitutions': 'items.barcode' = 'test2'
- Save the rule
6. Confirm the 'List of rules' page displays 'items.datelastseen' in
the 'Age field' column for that second rule
7. Add some more rules and confirm you can delete them
8. Edit a record:
- Make the items.dateaccessioned = 3 day ago (so rule 1 is false)
- Make the items.datelastseen = 3 days ago (so rule 2 is true)
9. Run the automatic_items_modification_by_age.pl:
- sudo koha-shell <instance>
- cd misc/cronjobs
- ./automatic_item_modification_by_age.pl -v -c
10. Confirm the item has it's barcode set to 'test2'
11. Run unit tests:
- sudo koha-shell <instance>
- prove t/db_dependent/Items/AutomaticItemModificationByAge.t -v

Sponsored-By: Catalyst IT

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-04-08 15:49:16 +02:00

125 lines
3.9 KiB
JavaScript

function clear_inputs(node, new_node) {
var selects = $(node).find("select");
$(selects).each(function(i) {
var select = this;
$(new_node).find("select").eq(i).val($(select).val());
});
var inputs = $(node).find("input");
$(inputs).each(function(i) {
var input = this;
$(new_node).find("input").eq(i).val($(input).val());
});
}
function remove_block_action( link ) {
var blocks = $(link).parent().parent();
if( $(blocks).find(".block").length > 2 ) {
$(blocks).find("a.remove_block").show();
} else {
$(blocks).find("a.remove_block").hide();
}
$(link).parent().remove();
}
function remove_rule_action( link ) {
if( $("#rules").find(".rule").length < 2 ) {
$("#rules").hide();
$("#norules").show();
}
$(link).parent().parent().remove();
update_rule_count();
}
function clone_block(block) {
var new_block = $(block).clone(1);
clear_inputs(block, new_block);
$(new_block).find('a.remove_block').show();
var blocks = $(block).parent();
$(blocks).append(new_block);
$(blocks).find('a.remove_block').click(function(e){
e.preventDefault();
remove_block_action($(this));
}).show();
}
function update_rule_count(){
rules = $(".rulecount");
rules.each( function( i ){
$(this).text( i + 1 );
});
}
$(document).ready(function() {
$("#new_rule .remove_rule").hide();
$("#new_rule a.remove_block").hide();
$("#rules a.remove_block").click(function(e){
e.preventDefault();
remove_block_action($(this));
});
$("#rules .remove_rule").click(function(e){
e.preventDefault();
remove_rule_action($(this));
});
var unique_id = $(".rule").length + 1;
$(".add_rule").click(function(e){
e.preventDefault();
var rule = $("#new_rule");
var rules = $("#rules");
var new_rule = rule.clone(1);
new_rule.removeAttr('id');
new_rule.attr('class', 'rule');
clear_inputs(rule, new_rule);
new_rule.find("select[name='condition_field']").attr('name', 'condition_field_' + unique_id);
new_rule.find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
new_rule.find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
new_rule.find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
new_rule.find("input[name='age']").attr('name', 'age_' + unique_id);
new_rule.find("select[name='agefield']").attr('name', 'agefield_' + unique_id);
new_rule.find("input[name='unique_id']").val(unique_id);
$("#rules").append(new_rule);
update_rule_count();
var scrollToPoint = new_rule.position();
window.scroll(0, scrollToPoint.top - $("#toolbar").height() );
if( $("#rules").find(".rule").length > 0 ) {
$("#rules").show();
$("#norules").hide();
}
if( $("#rules").find(".conditions > .condition").length > 1 ) {
}
if( $("#rules").find(".conditions > .condition").length > 1 ) {
}
new_rule.find('.remove_rule').click(function(e){
e.preventDefault();
remove_rule_action( $(this) );
}).show();
new_rule.find('.add_rule').remove();
unique_id++;
});
$("a.add_block").click(function(e){
e.preventDefault();
clone_block( $(this).parent() );
});
if( $("#rules").find(".rule").length < 1 ) {
$("#rules").hide();
$("#norules").show();
}
$("#rules .rule .blocks").each(function(){
if ( $(this).find(".block").length == 1 ) {
$(this).find("a.remove_block").hide();
}
});
jQuery.validator.addClassRules("age", {
digits: true
});
$("#rules_form").validate();
});