[% ELSE %]
<label for="fund_record_[% biblio.import_record_id | html %]">Fund: </label>
<select id="fund_record_[% biblio.import_record_id | html %]" size="1" name="budget_id">
- <option value="">Select a fund</option>
+ <option value="">Select a fund (will use default if set)</option>
[% FOREACH budget IN budget_loop %]
[% IF ( budget.b_id == biblio.budget_id ) %]
[% IF budget.b_active %]
</li>
<li><label for="uri_item_[% item.item_id | html %]">uri</label><input type="text" id="uri_item_[% item.item_id | html %]" name="uri_[% item.biblio_count | html %]" value="[% item.uri | html %]"></li>
<li><label for="copyno_item_[% item.item_id | html %]">copyno</label><input type="text" id="copyno_item_[% item.item_id | html %]" name="copyno_[% item.biblio_count | html %]" value="[% item.copyno | html %]"></li>
- <li><label for="budget_code_item_[% item.item_id | html %]">budget_code</label><select id="budget_code_item_[% item.item_id | html %]" name="budget_code_[% item.biblio_count | html %]">
- <option value="">Select a fund</option>
+ <li><label for="budget_code_item_[% item.item_id | html %]">budget_code</label><select class="budget_code_item" id="budget_code_item_[% item.item_id | html %]" name="budget_code_[% item.biblio_count | html %]">
+ <option value="">Select a fund (will use default if set)</option>
[% FOREACH budget_loo IN budget_loop %]
[% IF ( budget_loo.b_id ) == ( item.budget_id ) %]<option value="[% budget_loo.b_id | html %]" selected="selected">[% budget_loo.b_txt | html %]</option>
[% ELSE %]<option value="[% budget_loo.b_id | html %]">[% budget_loo.b_txt | html %]</option>
[% END %]
[% END %]
</select>
+ <span class="item_fund required">Required</span>
</li>
<li><label for="price_item_[% item.item_id | html %]">price</label><input type="text" id="price_item_[% item.item_id | html %]" name="itemprice_[% item.biblio_count | html %]" value="[% item.itemprice | html %]"></li>
<li><label for="replacementprice_item_[% item.item_id | html %]">replacement price</label><input type="text" id="replacementprice_item_[% item.item_id | html %]" name="replacementprice_[% item.biblio_count | html %]" value="[% item.replacementprice | html %]"></li>
<li>
<label for="all_budget_id">Fund: </label>
<select id="all_budget_id" size="1" name="all_budget_id">
- <option value="">Select a fund</option>
+ <option value="">Select a fund (will populate orders/items if set)</option>
[% FOREACH budget_loo IN budget_loop %]
[% IF ( budget_loo.b_active ) %]<option value="[% budget_loo.b_id | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %]</option>
[% ELSE %]<option value="[% budget_loo.b_id | html %]" class="b_inactive" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %] (inactive)</option>
"aaSorting": []
}) );
+ checkOrderBudgets();
var all_budget_id = $("#all_budget_id");
- if( !all_budget_id.val() ){
- $(".fund label, .fund select").addClass("required").prop("required", true);
- $(".fund span.required").show();
- }
-
- all_budget_id.on("change", function(){
- if( $(this).val() != "" ){
- $(".fund label, .fund select").removeClass("required").prop("required", false);
- $(".fund select").each(function(){
- if( $(this).val() == '' ){
- $(this).val( all_budget_id.val() );
- }
- });
- $(".fund span.required").hide();
- } else {
- $(".fund label, .fund select").addClass("required").prop("required", true);
- $(".fund span.required").show();
- }
+ $("#all_budget_id,[name='budget_id'],.budget_code_item,[name='import_record_id']").on("change", function(){
+ checkOrderBudgets();
});
$("#records_to_import fieldset.rows div").hide();
}
- if (! all_budget_id.val() ) {
- // If there is no default fund
- error = 0;
- $(".selected [name='budget_id']").each(function(){
- if (!$(this).val()) {
- error++;
- }
- });
- if ( error > 0 ) {
- alert( ERR_FUNDS_MISSING );
- return false;
- }
+ error = checkOrderBudgets();
+ if ( error > 0 ) {
+ alert( ERR_FUNDS_MISSING );
+ return false;
}
return disableUnchecked($(this));
$(this).remove();
});
return 1;
-}
\ No newline at end of file
+}
+
+function checkOrderBudgets(){
+ var unset_funds = 0;
+ var all_budget_id = $("#all_budget_id");
+ // If we don't have an overarching default set we need to check each selected order
+ if ( !all_budget_id.val() ) {
+ $("fieldset.biblio.rows.selected").each(function(){
+ var default_order_fund = $(this).find("[name='budget_id']");
+ // For each order we see if budget is set for order
+ if( !default_order_fund.val() ){
+ $(this).find(".item_fund.required").show();
+ //If not we need to check each item on the order
+ var item_funds = $(this).find(".budget_code_item");
+ if( item_funds.length ){
+ item_funds.each(function(){
+ if( !$(this).val() ){
+ $(this).addClass('required').prop("required", true);
+ unset_funds++;
+ } else {
+ $(this).removeClass('required').prop("required", false);
+ }
+ });
+ } else {
+ //If the order has no items defined then the order level fund is required
+ default_order_fund.addClass('required').prop("required", true);
+ $(this).find(".fund span.required").show();
+ $(this).find(".item_fund.required").hide();
+ unset_funds++;
+ }
+ } else {
+ $(this).find(".fund span.required").hide();
+ // If fund is set for order then none of the others are required
+ $(this).find(".budget_code_item").each(function(){
+ if( !$(this).val() ){
+ $(this).val( default_order_fund.val() );
+ $(this).removeClass('required').prop("required", false);
+ }
+ });
+ $(this).removeClass('required').prop("required", false);
+ }
+ });
+ } else {
+ // Default is set overall, we just need to populate it through
+ // to each order/item
+ $("[name='budget_id'],.budget_code_item").each(function(){
+ if( !$(this).val() ){
+ $(this).val( all_budget_id.val() );
+ $(this).removeClass('required').prop("required", false);
+ $(".item_fund.required").hide();
+ $(".fund span.required").hide();
+ }
+ });
+ }
+ return unset_funds;
+}