1 /* global dataTablesDefaults ERR_NO_RECORD_SELECTED ERR_INVALID_QUANTITY ERR_FUNDS_MISSING MSG_LOADING */
3 $(document).ready(function() {
4 $("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
6 { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
7 { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
8 { "sType": "title-string", "aTargets" : [ "title-string" ] }
10 "sPaginationType": "full",
15 var all_budget_id = $("#all_budget_id");
17 $("#all_budget_id,[name='budget_id'],.budget_code_item,[name='import_record_id']").on("change", function(){
21 $("#records_to_import fieldset.rows div").hide();
22 $('input:checkbox[name="import_record_id"]').change(function(){
23 var container = $(this).parents("fieldset");
24 if ( $(this).is(':checked') ) {
25 $(container).addClass("selected");
26 $(container).removeClass("unselected");
27 $(container).find("div").toggle(true);
29 $(container).addClass("unselected");
30 $(container).removeClass("selected");
31 $(container).find("div").toggle(false);
35 $("input:checkbox").prop("checked", false);
36 $("div.biblio.unselected select").prop('disabled', false);
37 $("div.biblio.unselected input").prop('disabled', false);
39 $("#checkAll").click(function(){
40 $("#Aform").checkCheckboxes();
41 $("input:checkbox[name='import_record_id']").change();
44 $("#unCheckAll").click(function(){
45 $("#Aform").unCheckCheckboxes();
46 $("input:checkbox[name='import_record_id']").change();
50 $("#Aform").on("submit", function(){
51 if ( $("input:checkbox[name='import_record_id']:checked").length < 1 ) {
52 alert( ERR_NO_RECORD_SELECTED );
57 $("input:checkbox[name='import_record_id']:checked").parents('fieldset').find('input[name="quantity"]').each(function(){
58 if ( $(this).val().length < 1 || isNaN( $(this).val() ) ) {
63 alert( error + " " + ERR_INVALID_QUANTITY );
68 error = checkOrderBudgets();
70 alert( ERR_FUNDS_MISSING );
74 return disableUnchecked($(this));
78 $(".previewData").on("click", function(e){
80 var ltitle = $(this).text();
81 var page = $(this).attr("href");
82 $("#dataPreviewLabel").text(ltitle);
83 $("#dataPreview .modal-body").load(page + " div");
84 $('#dataPreview').modal({show:true});
86 $("#dataPreview").on("hidden.bs.modal", function(){
87 $("#dataPreviewLabel").html("");
88 $("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + MSG_LOADING + "</div>");
92 function disableUnchecked(){
93 $("fieldset.biblio.unselected").each(function(){
99 function checkOrderBudgets(){
101 var all_budget_id = $("#all_budget_id");
102 // If we don't have an overarching default set we need to check each selected order
103 if ( !all_budget_id.val() ) {
104 $("fieldset.biblio.rows.selected").each(function(){
105 var default_order_fund = $(this).find("[name='budget_id']");
106 // For each order we see if budget is set for order
107 if( !default_order_fund.val() ){
108 $(this).find(".item_fund.required").show();
109 //If not we need to check each item on the order
110 var item_funds = $(this).find(".budget_code_item");
111 if( item_funds.length ){
112 item_funds.each(function(){
113 if( !$(this).val() ){
114 $(this).addClass('required').prop("required", true);
117 $(this).removeClass('required').prop("required", false);
121 //If the order has no items defined then the order level fund is required
122 default_order_fund.addClass('required').prop("required", true);
123 $(this).find(".fund span.required").show();
124 $(this).find(".item_fund.required").hide();
128 $(this).find(".fund span.required").hide();
129 // If fund is set for order then none of the others are required
130 $(this).find(".budget_code_item").each(function(){
131 if( !$(this).val() ){
132 $(this).val( default_order_fund.val() );
133 $(this).removeClass('required').prop("required", false);
136 $(this).removeClass('required').prop("required", false);
140 // Default is set overall, we just need to populate it through
141 // to each order/item
142 $("[name='budget_id'],.budget_code_item").each(function(){
143 if( !$(this).val() ){
144 $(this).val( all_budget_id.val() );
145 $(this).removeClass('required').prop("required", false);
146 $(".item_fund.required").hide();
147 $(".fund span.required").hide();