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": "four_button",
14 var all_budget_id = $("#all_budget_id");
16 if( !all_budget_id.val() ){
17 $(".fund label, .fund select").addClass("required").prop("required", true);
18 $(".fund span.required").show();
21 all_budget_id.on("change", function(){
22 if( $(this).val() != "" ){
23 $(".fund label, .fund select").removeClass("required").prop("required", false);
24 $(".fund select").each(function(){
25 if( $(this).val() == '' ){
26 $(this).val( all_budget_id.val() );
29 $(".fund span.required").hide();
31 $(".fund label, .fund select").addClass("required").prop("required", true);
32 $(".fund span.required").show();
36 $("#records_to_import fieldset.rows div").hide();
37 $('input:checkbox[name="import_record_id"]').change(function(){
38 var container = $(this).parents("fieldset");
39 if ( $(this).is(':checked') ) {
40 $(container).addClass("selected");
41 $(container).removeClass("unselected");
42 $(container).find("div").toggle(true);
44 $(container).addClass("unselected");
45 $(container).removeClass("selected");
46 $(container).find("div").toggle(false);
50 $("input:checkbox").prop("checked", false);
51 $("div.biblio.unselected select").prop('disabled', false);
52 $("div.biblio.unselected input").prop('disabled', false);
54 $("#checkAll").click(function(){
55 $("#Aform").checkCheckboxes();
56 $("input:checkbox[name='import_record_id']").change();
59 $("#unCheckAll").click(function(){
60 $("#Aform").unCheckCheckboxes();
61 $("input:checkbox[name='import_record_id']").change();
65 $("#Aform").on("submit", function(){
66 if ( $("input:checkbox[name='import_record_id']:checked").length < 1 ) {
67 alert( ERR_NO_RECORD_SELECTED );
72 $("input:checkbox[name='import_record_id']:checked").parents('fieldset').find('input[name="quantity"]').each(function(){
73 if ( $(this).val().length < 1 || isNaN( $(this).val() ) ) {
78 alert( error + " " + ERR_INVALID_QUANTITY );
83 if (! all_budget_id.val() ) {
84 // If there is no default fund
86 $(".selected [name='budget_id']").each(function(){
92 alert( ERR_FUNDS_MISSING );
97 return disableUnchecked($(this));
101 $(".previewData").on("click", function(e){
103 var ltitle = $(this).text();
104 var page = $(this).attr("href");
105 $("#dataPreviewLabel").text(ltitle);
106 $("#dataPreview .modal-body").load(page + " div");
107 $('#dataPreview').modal({show:true});
109 $("#dataPreview").on("hidden.bs.modal", function(){
110 $("#dataPreviewLabel").html("");
111 $("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + MSG_LOADING + "</div>");
115 function disableUnchecked(){
116 $("fieldset.biblio.unselected").each(function(){