Bug 19778: Move template JavaScript to the footer: Serials, part 4
authorOwen Leonard <oleonard@myacpl.org>
Fri, 8 Dec 2017 16:04:15 +0000 (16:04 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 14 Dec 2017 19:58:13 +0000 (16:58 -0300)
This patch modifies more and more staff client serials templates so
that JavaScript is included in the footer instead of the header.

This patch adds a new JavaScript include, showpredictionpattern.js,
which is used by subscription-add.tt and subscription-numberpatterns.tt.
it also adds subscription-add.js, moving most of the JS embedded in
subscription-add.tt into an external file.

To test, apply the patch and test the JavaScript-driven features of the
modified templates: All button controls, DataTables functionality, tabs,
etc.

 - Serials -> New subscription
   - Date pickers
   - Popup search windows for vendors and bibliographic
     records
   - Next / Previous buttons
   - Form validation
   - Prediction pattern operations

   Test with new subscriptions, editing existing subscriptions, and
   duplicating subscriptions.

 - Serials -> Manage Numbering Patterns
   - Datatable
   - Delete confirmation
   -> Edit
      - Datepicker, test pattern
 - Serials -> Manage frequencies
   - Delete confirmation
   -> Edit
      - Form validation
 - Serials -> Subscription details -> Planning tab
   -> Edit history
      -> Datepicker
 - Serials -> Subscription details -> Renew
   - Datepicker

Signed-off-by: Dominic Pichette <dominic@inlibro.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-frequencies.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-history.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt
koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/js/subscription-add.js [new file with mode: 0644]

index 0df881a..c137a77 100644 (file)
@@ -1,5 +1,4 @@
 [% USE KohaDates %]
-
 <h2>Prediction pattern</h1>
 [% IF (not_consistent_end_date) %]
   <p><em>End date is not consistent with subscription length.</em></p>
@@ -7,26 +6,6 @@
 [% IF (ask_for_irregularities) %]
     <p><em>Please check issues that are NOT published (irregularities)</em></p>
     [% IF (daily_options) %]
-        <script type="text/javascript">
-        //<![CDATA[
-        function Check_boxes(dow) {
-            if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
-                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
-                    $(this).prop('checked', true);
-                });
-            } else {
-                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
-                    $(this).prop('checked', false);
-                });
-            }
-        }
-        $(document).ready(function(){
-            $(".skipday").on("change",function(){
-                Check_boxes( $(this).data("dow"));
-            });
-        });
-        //]]>
-        </script>
         <p><em>
             If there is a day (or more) in the week where issues are never
             published, you can check corresponding boxes below.
     [% END %]
   </tbody>
 </table>
+
 [% END %]
index ff918b0..f9c0cae 100644 (file)
 [% USE KohaDates %]
 [% USE Branches %]
-
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <style type="text/css">
 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
 .yui-u li p label.widelabel {
     width: 300px;  /* not enough for IE7 apparently */
 }
 </style>
-<script type="text/javascript">
-//<![CDATA[
-
-var globalnumpatterndata;
-var globalfreqdata;
-var advancedpatternlocked;
-var patternneedtobetested = 0;
-[% IF ( irregularity ) %]patternneedtobetested = 1;[% END %]
-
-function check_issues(){
-    if (globalfreqdata.unit.length >0) {
-        if (document.f.subtype.value == globalfreqdata.unit){
-            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
-        } else if (document.f.subtype.value != "issues"){
-            alert(_("Frequency and subscription length provided doesn't combine well. Please consider entering an issue count rather than a time period."));
-        }
-    }
-}
-
-function addbiblioPopup(biblionumber) {
-    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
-    if(biblionumber){
-        destination += "&biblionumber="+biblionumber;
-    }
-    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
-}
-
-function Plugin()
-{
-    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
-}
-
-function FindAcqui()
-{
-    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
-}
-
-function Find_ISSN(f)
-{
-    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
-}
-
-function Clear(id) {
-    $("#"+id).val('');
-}
-
-function Check_page1() {
-    if ( $("#aqbooksellerid").val().length == 0) {
-        input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
-        if (input_box==false) {
-            return false;
-        }
-    }
-    if ($("#biblionumber").val().length == 0) {
-        alert(_("You must choose or create a biblio"));
-        return false;
-    }
-
-    return true;
-}
-
-function Check_page2(){
-    [% UNLESS (more_than_one_serial) %]
-      if($("#acqui_date").val().length == 0){
-          alert(_("You must choose a first publication date"));
-          return false;
-      }
-    [% END %]
-    if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
-        alert(_("You must choose a subscription length or an end date."));
-        return false;
-    }
-    if(advancedpatternlocked == 0){
-        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
-        return false;
-    }
-    if(patternneedtobetested){
-        [% IF (irregularity) %]
-           alert(_("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid"));
-        [% ELSE %]alert(_("Please click on 'Test prediction pattern' before saving subscription."));[% END %]
-        return false;
-    }
-
-    return true;
-}
-
-function frequencyload(){
-    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
-        function(freqdata){
-            globalfreqdata=freqdata;
-            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
-                var option = $("#subtype option[value='issues']");
-                $(option).attr('selected', 'selected');
-                $("#subtype option[value!='issues']").prop('disabled', true)
-            } else {
-                $("#subtype option").prop('disabled', false)
-            }
-        }
-    )
-}
-
-function numberpatternload(){
-    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
-        function(numpatterndata){
-            globalnumpatterndata=numpatterndata;
-            if (globalnumpatterndata==undefined){
-                return false;
-            }
-            displaymoreoptions();
-            restoreAdvancedPattern();
-        }
-    );
-}
-
-function displaymoreoptions() {
-    if(globalnumpatterndata == undefined){
-        $("#moreoptionst").hide();
-        return false;
-    }
-
-    var X = 0, Y = 0, Z = 0;
-    var numberingmethod = globalnumpatterndata.numberingmethod;
-    if(numberingmethod.match(/{X}/)) X = 1;
-    if(numberingmethod.match(/{Y}/)) Y = 1;
-    if(numberingmethod.match(/{Z}/)) Z = 1;
-
-    if(X || Y || Z) {
-        $("#moreoptionst").show();
-    } else {
-        $("#moreoptionst").hide();
-    }
-
-    if(X) {
-        if(globalnumpatterndata.label1) {
-            $("#headerX").html(globalnumpatterndata.label1);
-        } else {
-            $("#headerX").html("X");
-        }
-        $("#headerX").show();
-        $("#beginsX").show();
-        $("#innerX").show();
-    } else {
-        $("#headerX").hide();
-        $("#beginsX").hide();
-        $("#innerX").hide();
-        $("#lastvaluetemp1").val('');
-        $("#innerlooptemp1").val('');
-    }
-    if(Y) {
-        if(globalnumpatterndata.label2) {
-            $("#headerY").html(globalnumpatterndata.label2);
-        } else {
-            $("#headerY").html("Y");
-        }
-        $("#headerY").show();
-        $("#beginsY").show();
-        $("#innerY").show();
-    } else {
-        $("#headerY").hide();
-        $("#beginsY").hide();
-        $("#innerY").hide();
-        $("#lastvaluetemp2").val('');
-        $("#innerlooptemp2").val('');
-    }
-    if(Z) {
-        if(globalnumpatterndata.label3) {
-            $("#headerZ").html(globalnumpatterndata.label3);
-        } else {
-            $("#headerZ").html("Z");
-        }
-        $("#headerZ").show();
-        $("#beginsZ").show();
-        $("#innerZ").show();
-    } else {
-        $("#headerZ").hide();
-        $("#beginsZ").hide();
-        $("#innerZ").hide();
-        $("#lastvaluetemp3").val('');
-        $("#innerlooptemp3").val('');
-    }
-}
-
-function modifyAdvancedPattern() {
-    $("#patternname").prop('readOnly', false).val('');
-    $("#numberingmethod").prop('readOnly', false);
-
-    $("#advancedpredictionpatternt input").each(function() {
-        $(this).prop('readOnly', false);
-    });
-    $("#advancedpredictionpatternt select").each(function() {
-        $(this).prop('disabled', false);
-    });
-
-    $("#restoreadvancedpatternbutton").show();
-    $("#saveadvancedpatternbutton").show();
-    $("#modifyadvancedpatternbutton").hide();
-
-    advancedpatternlocked = 0;
-}
-
-function restoreAdvancedPattern() {
-    $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label);
-    $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod);
-
-    $("#advancedpredictionpatternt input").each(function() {
-        $(this).prop('readOnly', true);
-        var id = $(this).attr('id');
-        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
-            var tempid = id.replace(/(\d)/, "temp$1");
-            $(this).val($("#"+tempid).val());
-        } else {
-            $(this).val(globalnumpatterndata[id]);
-        }
-    });
-    $("#advancedpredictionpatternt select").each(function() {
-        $(this).prop('disabled', true);
-        var id = $(this).attr('id');
-        $(this).val(globalnumpatterndata[id]);
-    });
-
-    $("#restoreadvancedpatternbutton").hide();
-    $("#saveadvancedpatternbutton").hide();
-    $("#modifyadvancedpatternbutton").show();
-
-    advancedpatternlocked = 1;
-}
-
-function testPredictionPattern() {
-    var frequencyid = $("#frequency").val();
-    var acquidate;
-    var error = 0;
-    var error_msg = "";
-    if(frequencyid == undefined || frequencyid == ""){
-        error_msg += _("- Frequency is not defined") + "\n";
-        error ++;
-    }
-    acquidate = $("#acqui_date").val();
-    if(acquidate == undefined || acquidate == ""){
-        error_msg += _("- First publication date is not defined") + "\n";
-        error ++;
-    }
-    [% IF (more_than_one_serial) %]
-      var nextacquidate = $("#nextacquidate").val();
-      if(nextacquidate == undefined || nextacquidate == ""){
-        error_msg += _("- Next issue publication date is not defined") + "\n";
-        error ++;
-      }
-    [% END %]
-
-    if(error){
-        alert(_("Cannot test prediction pattern for the following reason(s): %s").format(error_msg));
-        return false;
-    }
-
-    var custompattern = 0;
-    if(advancedpatternlocked == 0) {
-        custompattern = 1;
-    }
-
-    var ajaxData = {
-        'custompattern': custompattern,
-        [% IF (subscriptionid) %]
-            'subscriptionid': [% subscriptionid %],
-        [% END %]
-        [% IF (more_than_one_serial) %]
-          'nextacquidate': nextacquidate,
-        [% END %]
-        'firstacquidate': acquidate
-    };
-    var ajaxParams = [
-        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
-        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
-        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
-        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
-        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
-    ];
-    for(i in ajaxParams) {
-        var param = ajaxParams[i];
-        var value = $("#"+param).val();
-        if(value.length > 0)
-            ajaxData[param] = value;
-    }
-
-    $.ajax({
-        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
-        data: ajaxData,
-        success: function(data) {
-            $("#displayexample").html(data);
-            patternneedtobetested = 0;
-        }
-    });
-}
-
-function saveAdvancedPattern() {
-    if ($("#patternname").val().length == 0) {
-        alert(_("Please enter a name for this pattern"));
-        return false;
-    }
-
-    // Check if patternname already exists, and modify pattern
-    // instead of creating it if so
-    var found = 0;
-    $("#numberpattern option").each(function(){
-        if($(this).text() == $("#patternname").val()){
-            found = 1;
-            return false;
-        }
-    });
-    var cnfrm = 1;
-    if(found){
-        var msg = _("This pattern name already exists. Do you want to modify it?")
-            + "\n" + _("Warning: it will modify the pattern for all subscriptions that are using it.");
-        cnfrm = confirm(msg);
-    }
-
-    if(cnfrm) {
-        var ajaxData = {};
-        var ajaxParams = [
-            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
-            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
-            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
-            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
-        ];
-        for(i in ajaxParams) {
-            var param = ajaxParams[i];
-            var value = $("#"+param).val();
-            if(value.length > 0)
-                ajaxData[param] = value;
-        }
-
-        $.getJSON(
-            "/cgi-bin/koha/serials/create-numberpattern.pl",
-            ajaxData,
-            function(data){
-                if (data.numberpatternid) {
-                    if(found == 0){
-                        $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
-                    }
-                    $("#numberpattern").val(data.numberpatternid);
-                    numberpatternload();
-                } else {
-                    alert(_("Something went wrong. Unable to create a new numbering pattern."));
-                }
-            }
-        );
-    }
-}
-
-function show_page_1() {
-    $("#page_1").show();
-    $("#page_2").hide();
-    $("#page_number").text("1/2");
-}
-
-function show_page_2() {
-    $("#page_1").hide();
-    $("#page_2").show();
-    $("#page_number").text("2/2");
-    displaymoreoptions();
-}
-
-
-$(document).ready(function() {
-    $("#aqbooksellerid").on('keypress', function(e) {
-        if (e.keyCode == 13) {
-            e.preventDefault();
-            FindAcqui();
-        }
-    });
-    $("#biblionumber").on('keypress', function(e) {
-        if (e.keyCode == 13) {
-            e.preventDefault();
-            Plugin();
-        }
-    });
-    $("select#frequency").change(function(){
-        patternneedtobetested = 1;
-        $("input[name='enddate']").val('');
-        frequencyload();
-    });
-    $("select#numberpattern").change(function(){
-        patternneedtobetested = 1;
-        numberpatternload();
-    });
-    $("#subtype").change(function(){
-        $("input[name='enddate']").val('');
-    });
-    $("#sublength").change(function(){
-        $("input[name='enddate']").val('');
-    });
-    $("#lastvaluetemp1").keyup(function(){
-        $("#lastvalue1").val($(this).val());
-    });
-    $("#lastvaluetemp2").keyup(function(){
-        $("#lastvalue2").val($(this).val());
-    });
-    $("#lastvaluetemp3").keyup(function(){
-        $("#lastvalue3").val($(this).val());
-    });
-    $("#lastvalue1").keyup(function(){
-        $("#lastvaluetemp1").val($(this).val());
-    });
-    $("#lastvalue2").keyup(function(){
-        $("#lastvaluetemp2").val($(this).val());
-    });
-    $("#lastvalue3").keyup(function(){
-        $("#lastvaluetemp3").val($(this).val());
-    });
-
-    $("#innerlooptemp1").keyup(function(){
-        $("#innerloop1").val($(this).val());
-    });
-    $("#innerlooptemp2").keyup(function(){
-        $("#innerloop2").val($(this).val());
-    });
-    $("#innerlooptemp3").keyup(function(){
-        $("#innerloop3").val($(this).val());
-    });
-    $("#innerloop1").keyup(function(){
-        $("#innerlooptemp1").val($(this).val());
-    });
-    $("#innerloop2").keyup(function(){
-        $("#innerlooptemp2").val($(this).val());
-    });
-    $("#innerloop3").keyup(function(){
-        $("#innerlooptemp3").val($(this).val());
-    });
-
-    if($("#frequency").val() != ""){
-        frequencyload();
-    }
-    if($("#numberpattern").val() != ""){
-        numberpatternload();
-    }
-
-    var node;
-    [% FOREACH field IN dont_export_field_loop %]
-        node = $("[name='[% field.fieldid %]']");
-        if ( $(node).is('input') || $(node).is('textarea') ) {
-            $(node).val("");
-        } else if ( $(node).is('select') ) {
-            $(node).find("option:first").attr('selected','selected');
-        }
-    [% END %]
-
-    show_page_1();
-    $("#subscription_add_form").on("submit",function(){
-        return Check_page2();
-    });
-    $("#vendor_search").on("click",function(e){
-        e.preventDefault();
-        FindAcqui();
-    });
-    $("#record_search").on("click",function(e){
-        e.preventDefault();
-        Plugin();
-    });
-    $("#biblio_add_edit").on("click",function(e){
-        e.preventDefault();
-        if( $(this).data("biblionumber") ){
-            addbiblioPopup( $(this).data("biblionumber") );
-        } else {
-            addbiblioPopup();
-        }
-    });
-    $("#subscription_add_next").on("click",function(){
-        if ( Check_page1() ){
-            show_page_2();
-        }
-    });
-    $("#subscription_add_previous").on("click",function(){
-        show_page_1();
-    });
-    $(".toggle_advanced_pattern").on("click",function(e){
-        e.preventDefault();
-        $("#advancedpredictionpattern").toggle();
-        $(".toggle_advanced_pattern").toggle();
-    });
-    $("#modifyadvancedpatternbutton").on("click",function(e){
-        e.preventDefault();
-        modifyAdvancedPattern();
-    });
-    $("#restoreadvancedpatternbutton").on("click",function(e){
-        e.preventDefault();
-        restoreAdvancedPattern();
-    });
-    $("#saveadvancedpatternbutton").on("click",function(e){
-        e.preventDefault();
-        saveAdvancedPattern();
-    });
-    $("#testpatternbutton").on("click",function(e){
-        e.preventDefault();
-        testPredictionPattern();
-    });
-});
-//]]>
-</script>
 </head>
+
 <body id="ser_subscription-add" class="ser">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'serials-search.inc' %]
@@ -981,4 +484,34 @@ $(document).ready(function() {
     </div>
 </div>
 
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript">
+        var subscriptionid = "[% subscriptionid %]";
+        var irregularity = "[% irregularity %]";
+        var more_than_one_serial = "[% more_than_one_serial %]";
+        var tags = [];
+        [% FOREACH field IN dont_export_field_loop %]
+            tags.push("[% field.fieldid %]");
+        [% END %]
+        var MSG_LINK_TO_VENDOR = _("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor");
+        var MSG_LINK_BIBLIO = _("You must choose or create a bibliographic record");
+        var MSG_REQUIRED_SUB_LENGTH = _("You must choose a subscription length or an end date.");
+        var MSG_TEST_PREDICTION = _("Please click on 'Test prediction pattern' before saving subscription.");
+        var MSG_REQUIRED_PUB_DATE = _("You must choose a first publication date");
+        var MSG = _("You have modified the advanced prediction pattern. Please save your work or cancel modifications.");
+        var MSG_PATTERN_IRREG = _("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid")
+        var MSG_PATTERN_NAME = _("Please enter a name for this pattern");
+        var MSG_PATTERN_NAME_EXISTS = _("This pattern name already exists. Do you want to modify it?");
+        var MSG_OVERWRITE_PATTERNS = _("Warning: it will modify the pattern for all subscriptions that are using it.");
+        var MSG_PATTERN_CREATE_FAILED = _("Something went wrong. Unable to create a new numbering pattern.");
+        var MSG_PATTERN_TEST_FAILED = _("Cannot test prediction pattern for the following reason(s): %s");
+        var MSG_FREQUENCY_UNDEFINED = _("Frequency is not defined");
+        var MSG_PUB_DATE_UNDEFINED = _("First publication date is not defined");
+        var MSG_NEXT_ISSUE_UNDEFINED = _("Next issue publication date is not defined");
+    </script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/subscription-add.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/showpredictionpattern.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 62696fb..9414baa 100644 (file)
@@ -1,75 +1,7 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; Frequencies</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-function confirmDelete() {
-  return confirm(_("Are you sure you want to delete this subscription frequency?"));
-}
-
-function check_form() {
-    var description = $("#description").val();
-    var unit = $("#unit").val();
-    var issuesperunit = $("#issuesperunit").val();
-    var unitsperissue = $("#unitsperissue").val();
-    var alert_msg = _("Some fields are not valid:") + "\n";
-    var errors = 0;
-
-    if(description.length == 0) {
-        alert_msg += "\t - " + _("Description is required");
-        errors ++;
-    }
-    if(unit.length > 0) {
-        if(isNaN(issuesperunit) || issuesperunit == 0) {
-            alert_msg += "\n\t - " + _("Issues per unit is required")
-                + " " + _("(must be a number greater than 0)");
-            errors ++;
-        }
-        if(isNaN(unitsperissue) || unitsperissue == 0) {
-            alert_msg += "\n\t - " + _("Units per issue is required")
-                + " " + _("(must be a number greater than 0)");
-            errors ++;
-        }
-        if(issuesperunit > 1 && unitsperissue > 1) {
-            alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
-            errors ++;
-        }
-    }
-
-    if(errors == 0) {
-        return true;
-    }
-
-    alert(alert_msg);
-    return false;
-}
-
-$(document).ready(function() {
-    $("#issuesperunit").change(function() {
-        var value = $(this).val();
-        if(!isNaN(value) && value > 1) {
-            $("#unitsperissue").val(1);
-        }
-    });
-    $("#unitsperissue").change(function() {
-        var value = $(this).val();
-        if(!isNaN(value) && value > 1) {
-            $("#issuesperunit").val(1);
-        }
-    });
-    $(".delete_frequency").on("click",function(){
-        return confirmDelete();
-    });
-    $("#add_frequency_form").on("submit",function(){
-        return check_form();
-    });
-    $("#show_blocking_subs").on("click",function(e){
-        e.preventDefault();
-        $("#blocking_subs").show();
-    });
-});
-//]]>
-</script>
 </head>
 
 <body id="ser_subscription_frequencies" class="ser">
@@ -231,4 +163,75 @@ $(document).ready(function() {
     [% INCLUDE 'serials-menu.inc' %]
   </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript">
+        function confirmDelete() {
+            return confirm(_("Are you sure you want to delete this subscription frequency?"));
+        }
+
+        function check_form() {
+            var description = $("#description").val();
+            var unit = $("#unit").val();
+            var issuesperunit = $("#issuesperunit").val();
+            var unitsperissue = $("#unitsperissue").val();
+            var alert_msg = _("Some fields are not valid:") + "\n";
+            var errors = 0;
+
+            if(description.length == 0) {
+                alert_msg += "\t - " + _("Description is required");
+                errors ++;
+            }
+            if(unit.length > 0) {
+                if(isNaN(issuesperunit) || issuesperunit == 0) {
+                    alert_msg += "\n\t - " + _("Issues per unit is required")
+                        + " " + _("(must be a number greater than 0)");
+                    errors ++;
+                }
+                if(isNaN(unitsperissue) || unitsperissue == 0) {
+                    alert_msg += "\n\t - " + _("Units per issue is required")
+                        + " " + _("(must be a number greater than 0)");
+                    errors ++;
+                }
+                if(issuesperunit > 1 && unitsperissue > 1) {
+                    alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
+                    errors ++;
+                }
+            }
+
+            if(errors == 0) {
+                return true;
+            }
+
+            alert(alert_msg);
+            return false;
+        }
+
+        $(document).ready(function() {
+            $("#issuesperunit").change(function() {
+                var value = $(this).val();
+                if(!isNaN(value) && value > 1) {
+                    $("#unitsperissue").val(1);
+                }
+            });
+            $("#unitsperissue").change(function() {
+                var value = $(this).val();
+                if(!isNaN(value) && value > 1) {
+                    $("#issuesperunit").val(1);
+                }
+            });
+            $(".delete_frequency").on("click",function(){
+                return confirmDelete();
+            });
+            $("#add_frequency_form").on("submit",function(){
+                return check_form();
+            });
+            $("#show_blocking_subs").on("click",function(e){
+                e.preventDefault();
+                $("#blocking_subs").show();
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index cbfb0a5..02613b5 100644 (file)
@@ -1,9 +1,8 @@
 [% USE KohaDates %]
-
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; Subscription history</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 </head>
 
 <body id="ser_subscription_history" class="ser">
@@ -64,4 +63,9 @@
     [% INCLUDE 'serials-menu.inc' %]
   </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 1d76890..657e586 100644 (file)
@@ -1,91 +1,8 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; Numbering patterns</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-
-function confirmDelete() {
-  return confirm(_("Are you sure you want to delete this numbering pattern?"));
-}
-
-[% IF (new or modify) %]
-  function testPattern() {
-      var frequencyid = $("#frequency").val();
-      var firstacquidate = $("#firstacquidate").val();
-      var error = 0;
-      var error_msg = "";
-      if(frequencyid == undefined || frequencyid == "") {
-          error_msg += _("- Frequency is not defined") + "\n";
-          error ++;
-      }
-      if(firstacquidate == undefined || firstacquidate == "") {
-          error_msg += _("- First publication date is not defined") + "\n";
-          error ++;
-      }
-
-      if(error){
-          alert(_("Cannot test prediction pattern for the following reason(s):") + "\n\n"
-              + error_msg);
-          return false;
-      }
-
-      var ajaxData = {
-          'custompattern': true,
-      };
-      var ajaxParams = [
-          'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
-          'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
-          'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
-          'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
-          'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
-      ];
-      for(i in ajaxParams) {
-          var param = ajaxParams[i];
-          var value = $("#"+param).val();
-          if(value.length > 0)
-              ajaxData[param] = value;
-      }
-
-      $.ajax({
-          url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
-          data: ajaxData,
-          async: false,
-          dataType: "text",
-          success: function(data) {
-              $("#predictionpattern").html(data);
-          }
-      });
-  }
-[% END %]
-
-function show_blocking_subs() {
-    $("#blocking_subs").show();
-}
-$(document).ready(function(){
-
-    $("#numberpatternst").dataTable($.extend(true, {}, dataTablesDefaults, {
-        "aoColumnDefs": [
-            { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
-        ],
-        "sPaginationType": "four_button"
-    }));
-
-    $(".delete_pattern").on("click",function(){
-        return confirmDelete();
-    });
-    $("#show_blocking_subs").on("click",function(e){
-        e.preventDefault();
-        $("#blocking_subs").show();
-    });
-    $("#test_pattern").on("click",function(){
-         testPattern();
-    });
-});
-//]]>
-</script>
 </head>
 
 <body id="ser_subscription_numberpatterns" class="ser">
@@ -381,4 +298,92 @@ $(document).ready(function(){
     [% INCLUDE 'serials-menu.inc' %]
   </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% IF (daily_options) %]
+        <script type="text/javascript" src="[% interface %]/[% theme %]/js/showpredictionpattern.js"></script>
+    [% END %]
+    [% INCLUDE 'calendar.inc' %]
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+        function confirmDelete() {
+            return confirm(_("Are you sure you want to delete this numbering pattern?"));
+        }
+
+        [% IF (new or modify) %]
+            function testPattern() {
+                var frequencyid = $("#frequency").val();
+                var firstacquidate = $("#firstacquidate").val();
+                var error = 0;
+                var error_msg = "";
+                if(frequencyid == undefined || frequencyid == "") {
+                    error_msg += _("- Frequency is not defined") + "\n";
+                    error ++;
+                }
+                if(firstacquidate == undefined || firstacquidate == "") {
+                    error_msg += _("- First publication date is not defined") + "\n";
+                    error ++;
+                }
+
+                if(error){
+                    alert(_("Cannot test prediction pattern for the following reason(s):") + "\n\n"
+                        + error_msg);
+                    return false;
+                }
+
+                var ajaxData = {
+                    'custompattern': true,
+                };
+                var ajaxParams = [
+                    'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
+                    'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
+                    'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
+                    'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
+                    'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
+                ];
+                for(i in ajaxParams) {
+                    var param = ajaxParams[i];
+                    var value = $("#"+param).val();
+                    if(value.length > 0)
+                        ajaxData[param] = value;
+                }
+
+                $.ajax({
+                    url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
+                    data: ajaxData,
+                    async: false,
+                    dataType: "text",
+                    success: function(data) {
+                        $("#predictionpattern").html(data);
+                    }
+                });
+            }
+        [% END %]
+
+        function show_blocking_subs() {
+            $("#blocking_subs").show();
+        }
+        $(document).ready(function(){
+
+            $("#numberpatternst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                "aoColumnDefs": [
+                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
+                ],
+                "sPaginationType": "four_button"
+            }));
+
+            $(".delete_pattern").on("click",function(){
+                return confirmDelete();
+            });
+            $("#show_blocking_subs").on("click",function(e){
+                e.preventDefault();
+                $("#blocking_subs").show();
+            });
+            $("#test_pattern").on("click",function(){
+                 testPattern();
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index e7eb83d..64a264e 100644 (file)
@@ -1,11 +1,12 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials subscription renew #[% subscriptionid %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <style type="text/css">
    #custom-doc { width:39.85em;*width:38.86em;min-width:531px; margin:auto; text-align:left; }
    </style>
 </head>
+
 <body id="ser_subscription-renew" class="ser">
 
 <div id="custom-doc" class="yui-t7">
@@ -42,5 +43,9 @@
 </div>
 [% END %]
 
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
 
diff --git a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js b/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js
new file mode 100644 (file)
index 0000000..f5c38a0
--- /dev/null
@@ -0,0 +1,16 @@
+function Check_boxes(dow) {
+    if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
+        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
+            $(this).prop('checked', true);
+        });
+    } else {
+        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
+            $(this).prop('checked', false);
+        });
+    }
+}
+$(document).ready(function(){
+    $("#displayexample").on("change",".skipday",function(){
+        Check_boxes( $(this).data("dow"));
+    });
+});
diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js
new file mode 100644 (file)
index 0000000..c995751
--- /dev/null
@@ -0,0 +1,499 @@
+/* global irregularity more_than_one_serial subscriptionid tags */
+
+var globalnumpatterndata;
+var globalfreqdata;
+var advancedpatternlocked;
+var patternneedtobetested = 0;
+if ( irregularity !== "" ){
+    patternneedtobetested = 1;
+}
+
+function check_issues(){
+    if (globalfreqdata.unit.length >0) {
+        if (document.f.subtype.value == globalfreqdata.unit){
+            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
+        } else if (document.f.subtype.value != "issues"){
+            alert( MSG_FREQUENCY_LENGTH_ERROR );
+        }
+    }
+}
+
+function addbiblioPopup(biblionumber) {
+    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
+    if(biblionumber){
+        destination += "&biblionumber="+biblionumber;
+    }
+    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
+}
+
+function Plugin(){
+    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
+}
+
+function FindAcqui(){
+    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
+}
+
+function Find_ISSN(f){
+    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
+}
+
+function Clear(id) {
+    $("#"+id).val('');
+}
+
+function Check_page1() {
+    if ( $("#aqbooksellerid").val().length == 0) {
+        input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
+        if (input_box==false) {
+            return false;
+        }
+    }
+    if ($("#biblionumber").val().length == 0) {
+        alert(_("You must choose or create a biblio"));
+        return false;
+    }
+
+    return true;
+}
+
+function Check_page2(){
+    if( more_than_one_serial == "" ){
+        if($("#acqui_date").val().length == 0){
+            alert(_("You must choose a first publication date"));
+            return false;
+        }
+    }
+    if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
+        alert(_("You must choose a subscription length or an end date."));
+        return false;
+    }
+    if(advancedpatternlocked == 0){
+        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
+        return false;
+    }
+    if(patternneedtobetested){
+        if( irregularity !== "" ){
+           alert(_("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid"));
+        } else {
+            alert(_("Please click on 'Test prediction pattern' before saving subscription."));
+        }
+        return false;
+    }
+
+    return true;
+}
+
+function frequencyload(){
+    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
+        function(freqdata){
+            globalfreqdata=freqdata;
+            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
+                var option = $("#subtype option[value='issues']");
+                $(option).attr('selected', 'selected');
+                $("#subtype option[value!='issues']").prop('disabled', true)
+            } else {
+                $("#subtype option").prop('disabled', false)
+            }
+        }
+    )
+}
+
+function numberpatternload(){
+    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
+        function(numpatterndata){
+            globalnumpatterndata=numpatterndata;
+            if (globalnumpatterndata==undefined){
+                return false;
+            }
+            displaymoreoptions();
+            restoreAdvancedPattern();
+        }
+    );
+}
+
+function displaymoreoptions() {
+    if(globalnumpatterndata == undefined){
+        $("#moreoptionst").hide();
+        return false;
+    }
+
+    var X = 0, Y = 0, Z = 0;
+    var numberingmethod = globalnumpatterndata.numberingmethod;
+    if(numberingmethod.match(/{X}/)) X = 1;
+    if(numberingmethod.match(/{Y}/)) Y = 1;
+    if(numberingmethod.match(/{Z}/)) Z = 1;
+
+    if(X || Y || Z) {
+        $("#moreoptionst").show();
+    } else {
+        $("#moreoptionst").hide();
+    }
+
+    if(X) {
+        if(globalnumpatterndata.label1) {
+            $("#headerX").html(globalnumpatterndata.label1);
+        } else {
+            $("#headerX").html("X");
+        }
+        $("#headerX").show();
+        $("#beginsX").show();
+        $("#innerX").show();
+    } else {
+        $("#headerX").hide();
+        $("#beginsX").hide();
+        $("#innerX").hide();
+        $("#lastvaluetemp1").val('');
+        $("#innerlooptemp1").val('');
+    }
+    if(Y) {
+        if(globalnumpatterndata.label2) {
+            $("#headerY").html(globalnumpatterndata.label2);
+        } else {
+            $("#headerY").html("Y");
+        }
+        $("#headerY").show();
+        $("#beginsY").show();
+        $("#innerY").show();
+    } else {
+        $("#headerY").hide();
+        $("#beginsY").hide();
+        $("#innerY").hide();
+        $("#lastvaluetemp2").val('');
+        $("#innerlooptemp2").val('');
+    }
+    if(Z) {
+        if(globalnumpatterndata.label3) {
+            $("#headerZ").html(globalnumpatterndata.label3);
+        } else {
+            $("#headerZ").html("Z");
+        }
+        $("#headerZ").show();
+        $("#beginsZ").show();
+        $("#innerZ").show();
+    } else {
+        $("#headerZ").hide();
+        $("#beginsZ").hide();
+        $("#innerZ").hide();
+        $("#lastvaluetemp3").val('');
+        $("#innerlooptemp3").val('');
+    }
+}
+
+function modifyAdvancedPattern() {
+    $("#patternname").prop('readOnly', false).val('');
+    $("#numberingmethod").prop('readOnly', false);
+
+    $("#advancedpredictionpatternt input").each(function() {
+        $(this).prop('readOnly', false);
+    });
+    $("#advancedpredictionpatternt select").each(function() {
+        $(this).prop('disabled', false);
+    });
+
+    $("#restoreadvancedpatternbutton").show();
+    $("#saveadvancedpatternbutton").show();
+    $("#modifyadvancedpatternbutton").hide();
+
+    advancedpatternlocked = 0;
+}
+
+function restoreAdvancedPattern() {
+    $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label);
+    $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod);
+
+    $("#advancedpredictionpatternt input").each(function() {
+        $(this).prop('readOnly', true);
+        var id = $(this).attr('id');
+        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
+            var tempid = id.replace(/(\d)/, "temp$1");
+            $(this).val($("#"+tempid).val());
+        } else {
+            $(this).val(globalnumpatterndata[id]);
+        }
+    });
+    $("#advancedpredictionpatternt select").each(function() {
+        $(this).prop('disabled', true);
+        var id = $(this).attr('id');
+        $(this).val(globalnumpatterndata[id]);
+    });
+
+    $("#restoreadvancedpatternbutton").hide();
+    $("#saveadvancedpatternbutton").hide();
+    $("#modifyadvancedpatternbutton").show();
+
+    advancedpatternlocked = 1;
+}
+
+function testPredictionPattern() {
+    var frequencyid = $("#frequency").val();
+    var acquidate;
+    var error = 0;
+    var error_msg = "";
+    if(frequencyid == undefined || frequencyid == ""){
+        error_msg += _("- Frequency is not defined") + "\n";
+        error ++;
+    }
+    acquidate = $("#acqui_date").val();
+    if(acquidate == undefined || acquidate == ""){
+        error_msg += _("- First publication date is not defined") + "\n";
+        error ++;
+    }
+    if( more_than_one_serial !== "" ){
+        var nextacquidate = $("#nextacquidate").val();
+        if(nextacquidate == undefined || nextacquidate == ""){
+            error_msg += _("- Next issue publication date is not defined") + "\n";
+            error ++;
+        }
+    }
+
+    if(error){
+        alert(_("Cannot test prediction pattern for the following reason(s): %s").format(error_msg));
+        return false;
+    }
+
+    var custompattern = 0;
+    if(advancedpatternlocked == 0) {
+        custompattern = 1;
+    }
+
+    var ajaxData = {
+        'custompattern': custompattern,
+        'firstacquidate': acquidate
+    };
+
+    if( subscriptionid !== "" ){
+        ajaxData.subscriptionid = subscriptionid;
+    }
+    if( more_than_one_serial !== "" ){
+        ajaxData.nextacquidate = nextacquidate;
+    }
+
+
+    var ajaxParams = [
+        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
+        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
+        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
+        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
+        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
+    ];
+    for(i in ajaxParams) {
+        var param = ajaxParams[i];
+        var value = $("#"+param).val();
+        if(value.length > 0)
+            ajaxData[param] = value;
+    }
+
+    $.ajax({
+        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
+        data: ajaxData,
+        success: function(data) {
+            $("#displayexample").html(data);
+            patternneedtobetested = 0;
+        }
+    });
+}
+
+function saveAdvancedPattern() {
+    if ($("#patternname").val().length == 0) {
+        alert(_("Please enter a name for this pattern"));
+        return false;
+    }
+
+    // Check if patternname already exists, and modify pattern
+    // instead of creating it if so
+    var found = 0;
+    $("#numberpattern option").each(function(){
+        if($(this).text() == $("#patternname").val()){
+            found = 1;
+            return false;
+        }
+    });
+    var cnfrm = 1;
+    if(found){
+        var msg = _("This pattern name already exists. Do you want to modify it?")
+            + "\n" + _("Warning: it will modify the pattern for all subscriptions that are using it.");
+        cnfrm = confirm(msg);
+    }
+
+    if(cnfrm) {
+        var ajaxData = {};
+        var ajaxParams = [
+            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
+            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
+            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
+            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
+        ];
+        for(i in ajaxParams) {
+            var param = ajaxParams[i];
+            var value = $("#"+param).val();
+            if(value.length > 0)
+                ajaxData[param] = value;
+        }
+
+        $.getJSON(
+            "/cgi-bin/koha/serials/create-numberpattern.pl",
+            ajaxData,
+            function(data){
+                if (data.numberpatternid) {
+                    if(found == 0){
+                        $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
+                    }
+                    $("#numberpattern").val(data.numberpatternid);
+                    numberpatternload();
+                } else {
+                    alert(_("Something went wrong. Unable to create a new numbering pattern."));
+                }
+            }
+        );
+    }
+}
+
+function show_page_1() {
+    $("#page_1").show();
+    $("#page_2").hide();
+    $("#page_number").text("1/2");
+}
+
+function show_page_2() {
+    $("#page_1").hide();
+    $("#page_2").show();
+    $("#page_number").text("2/2");
+    displaymoreoptions();
+}
+
+
+$(document).ready(function() {
+    $("#aqbooksellerid").on('keypress', function(e) {
+        if (e.keyCode == 13) {
+            e.preventDefault();
+            FindAcqui();
+        }
+    });
+    $("#biblionumber").on('keypress', function(e) {
+        if (e.keyCode == 13) {
+            e.preventDefault();
+            Plugin();
+        }
+    });
+    $("select#frequency").change(function(){
+        patternneedtobetested = 1;
+        $("input[name='enddate']").val('');
+        frequencyload();
+    });
+    $("select#numberpattern").change(function(){
+        patternneedtobetested = 1;
+        numberpatternload();
+    });
+    $("#subtype").change(function(){
+        $("input[name='enddate']").val('');
+    });
+    $("#sublength").change(function(){
+        $("input[name='enddate']").val('');
+    });
+    $("#lastvaluetemp1").keyup(function(){
+        $("#lastvalue1").val($(this).val());
+    });
+    $("#lastvaluetemp2").keyup(function(){
+        $("#lastvalue2").val($(this).val());
+    });
+    $("#lastvaluetemp3").keyup(function(){
+        $("#lastvalue3").val($(this).val());
+    });
+    $("#lastvalue1").keyup(function(){
+        $("#lastvaluetemp1").val($(this).val());
+    });
+    $("#lastvalue2").keyup(function(){
+        $("#lastvaluetemp2").val($(this).val());
+    });
+    $("#lastvalue3").keyup(function(){
+        $("#lastvaluetemp3").val($(this).val());
+    });
+
+    $("#innerlooptemp1").keyup(function(){
+        $("#innerloop1").val($(this).val());
+    });
+    $("#innerlooptemp2").keyup(function(){
+        $("#innerloop2").val($(this).val());
+    });
+    $("#innerlooptemp3").keyup(function(){
+        $("#innerloop3").val($(this).val());
+    });
+    $("#innerloop1").keyup(function(){
+        $("#innerlooptemp1").val($(this).val());
+    });
+    $("#innerloop2").keyup(function(){
+        $("#innerlooptemp2").val($(this).val());
+    });
+    $("#innerloop3").keyup(function(){
+        $("#innerlooptemp3").val($(this).val());
+    });
+
+    if($("#frequency").val() != ""){
+        frequencyload();
+    }
+    if($("#numberpattern").val() != ""){
+        numberpatternload();
+    }
+
+    if( tags.length > 0 ){
+        tags.forEach( function( item ) {
+            var node = $("[name='" + item + "']");
+            if ( $(node).is('input') || $(node).is('textarea') ) {
+                $(node).val("");
+            } else if ( $(node).is('select') ) {
+                $(node).find("option:first").attr('selected','selected');
+            }
+        });
+    }
+
+    show_page_1();
+    $("#subscription_add_form").on("submit",function(){
+        return Check_page2();
+    });
+    $("#vendor_search").on("click",function(e){
+        e.preventDefault();
+        FindAcqui();
+    });
+    $("#record_search").on("click",function(e){
+        e.preventDefault();
+        Plugin();
+    });
+    $("#biblio_add_edit").on("click",function(e){
+        e.preventDefault();
+        if( $(this).data("biblionumber") ){
+            addbiblioPopup( $(this).data("biblionumber") );
+        } else {
+            addbiblioPopup();
+        }
+    });
+    $("#subscription_add_next").on("click",function(){
+        if ( Check_page1() ){
+            show_page_2();
+        }
+    });
+    $("#subscription_add_previous").on("click",function(){
+        show_page_1();
+    });
+    $(".toggle_advanced_pattern").on("click",function(e){
+        e.preventDefault();
+        $("#advancedpredictionpattern").toggle();
+        $(".toggle_advanced_pattern").toggle();
+    });
+    $("#modifyadvancedpatternbutton").on("click",function(e){
+        e.preventDefault();
+        modifyAdvancedPattern();
+    });
+    $("#restoreadvancedpatternbutton").on("click",function(e){
+        e.preventDefault();
+        restoreAdvancedPattern();
+    });
+    $("#saveadvancedpatternbutton").on("click",function(e){
+        e.preventDefault();
+        saveAdvancedPattern();
+    });
+    $("#testpatternbutton").on("click",function(e){
+        e.preventDefault();
+        testPredictionPattern();
+    });
+});
\ No newline at end of file