1 /* global dataTablesDefaults __ */
3 $(document).ready(function() {
4 $("#Aform").preventDoubleFormSubmit();
5 $("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
7 { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
8 { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
9 { "sType": "title-string", "aTargets" : [ "title-string" ] }
11 "sPaginationType": "full",
16 var all_budget_id = $("#all_budget_id");
18 $("#all_budget_id,[name='budget_id'],.budget_code_item,[name='import_record_id']").on("change", function(){
22 $("#records_to_import fieldset.rows div").hide();
23 $('input:checkbox[name="import_record_id"]').change(function(){
24 var container = $(this).parents("fieldset");
25 if ( $(this).is(':checked') ) {
26 $(container).addClass("selected");
27 $(container).removeClass("unselected");
28 $(container).find("div").toggle(true);
30 $(container).addClass("unselected");
31 $(container).removeClass("selected");
32 $(container).find("div").toggle(false);
36 $("input:checkbox").prop("checked", false);
37 $("div.biblio.unselected select").prop('disabled', false);
38 $("div.biblio.unselected input").prop('disabled', false);
40 $("#checkAll").click(function(e){
42 $("input:checkbox[name='import_record_id']").prop("checked", true).change();
44 $("#unCheckAll").click(function(e){
46 $("input:checkbox[name='import_record_id']").prop("checked", false).change();
49 $("input#add_order").on("click", function(e){
52 if ( $("input:checkbox[name='import_record_id']:checked").length < 1 ) {
53 alert( __("There is no record selected") );
58 $("input:checkbox[name='import_record_id']:checked").parents('fieldset').find('input[name="quantity"]').each(function(){
59 if ( $(this).val().length < 1 || isNaN( $(this).val() ) ) {
64 alert(error + " " + __("quantity values are not filled in or are not numbers") );
69 error = checkOrderBudgets();
71 alert( __("Some budgets are not defined in item records") );
75 disableUnchecked($(this.form));
77 $(this.form).submit();
81 $(".previewData").on("click", function(e){
83 var ltitle = $(this).text();
84 var page = $(this).attr("href");
85 $("#dataPreviewLabel").text(ltitle);
86 $("#dataPreview .modal-body").load(page + " div");
87 $('#dataPreview').modal({show:true});
89 $("#dataPreview").on("hidden.bs.modal", function(){
90 $("#dataPreviewLabel").html("");
91 $("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + __("Loading") + "</div>");
95 function disableUnchecked(){
96 $("fieldset.biblio.unselected").each(function(){
102 function checkOrderBudgets(){
104 var all_budget_id = $("#all_budget_id");
105 // If we don't have an overarching default set we need to check each selected order
106 if ( !all_budget_id.val() ) {
107 $("fieldset.biblio.rows.selected").each(function(){
108 var default_order_fund = $(this).find("[name='budget_id']");
109 // For each order we see if budget is set for order
110 if( !default_order_fund.val() ){
111 $(this).find(".item_fund.required").show();
112 //If not we need to check each item on the order
113 var item_funds = $(this).find(".budget_code_item");
114 if( item_funds.length ){
115 item_funds.each(function(){
116 if( !$(this).val() ){
117 $(this).addClass('required').prop("required", true);
120 $(this).removeClass('required').prop("required", false);
124 //If the order has no items defined then the order level fund is required
125 default_order_fund.addClass('required').prop("required", true);
126 $(this).find(".fund span.required").show();
127 $(this).find(".item_fund.required").hide();
131 $(this).find(".fund span.required").hide();
132 // If fund is set for order then none of the others are required
133 $(this).find(".budget_code_item").each(function(){
134 if( !$(this).val() ){
135 $(this).val( default_order_fund.val() );
136 $(this).removeClass('required').prop("required", false);
139 $(this).removeClass('required').prop("required", false);
143 // Default is set overall, we just need to populate it through
144 // to each order/item
145 $("[name='budget_id'],.budget_code_item").each(function(){
146 if( !$(this).val() ){
147 $(this).val( all_budget_id.val() );
148 $(this).removeClass('required').prop("required", false);
149 $(".item_fund.required").hide();
150 $(".fund span.required").hide();