View | Details | Raw Unified | Return to bug 19778
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (-21 / +1 lines)
Lines 1-5 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
3
<h2>Prediction pattern</h1>
2
<h2>Prediction pattern</h1>
4
[% IF (not_consistent_end_date) %]
3
[% IF (not_consistent_end_date) %]
5
  <p><em>End date is not consistent with subscription length.</em></p>
4
  <p><em>End date is not consistent with subscription length.</em></p>
Lines 7-32 Link Here
7
[% IF (ask_for_irregularities) %]
6
[% IF (ask_for_irregularities) %]
8
    <p><em>Please check issues that are NOT published (irregularities)</em></p>
7
    <p><em>Please check issues that are NOT published (irregularities)</em></p>
9
    [% IF (daily_options) %]
8
    [% IF (daily_options) %]
10
        <script type="text/javascript">
11
        //<![CDATA[
12
        function Check_boxes(dow) {
13
            if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
14
                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
15
                    $(this).prop('checked', true);
16
                });
17
            } else {
18
                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
19
                    $(this).prop('checked', false);
20
                });
21
            }
22
        }
23
        $(document).ready(function(){
24
            $(".skipday").on("change",function(){
25
                Check_boxes( $(this).data("dow"));
26
            });
27
        });
28
        //]]>
29
        </script>
30
        <p><em>
9
        <p><em>
31
            If there is a day (or more) in the week where issues are never
10
            If there is a day (or more) in the week where issues are never
32
            published, you can check corresponding boxes below.
11
            published, you can check corresponding boxes below.
Lines 104-107 Link Here
104
    [% END %]
83
    [% END %]
105
  </tbody>
84
  </tbody>
106
</table>
85
</table>
86
107
[% END %]
87
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-499 / +32 lines)
Lines 1-514 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
[% USE Branches %]
2
[% USE Branches %]
3
3
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
5
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
6
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'calendar.inc' %]
8
<style type="text/css">
7
<style type="text/css">
9
fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
8
fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
10
.yui-u li p label.widelabel {
9
.yui-u li p label.widelabel {
11
    width: 300px;  /* not enough for IE7 apparently */
10
    width: 300px;  /* not enough for IE7 apparently */
12
}
11
}
13
</style>
12
</style>
14
<script type="text/javascript">
15
//<![CDATA[
16
17
var globalnumpatterndata;
18
var globalfreqdata;
19
var advancedpatternlocked;
20
var patternneedtobetested = 0;
21
[% IF ( irregularity ) %]patternneedtobetested = 1;[% END %]
22
23
function check_issues(){
24
    if (globalfreqdata.unit.length >0) {
25
        if (document.f.subtype.value == globalfreqdata.unit){
26
            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
27
        } else if (document.f.subtype.value != "issues"){
28
            alert(_("Frequency and subscription length provided doesn't combine well. Please consider entering an issue count rather than a time period."));
29
        }
30
    }
31
}
32
33
function addbiblioPopup(biblionumber) {
34
    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
35
    if(biblionumber){
36
        destination += "&biblionumber="+biblionumber;
37
    }
38
    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
39
}
40
41
function Plugin()
42
{
43
    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
44
}
45
46
function FindAcqui()
47
{
48
    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
49
}
50
51
function Find_ISSN(f)
52
{
53
    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
54
}
55
56
function Clear(id) {
57
    $("#"+id).val('');
58
}
59
60
function Check_page1() {
61
    if ( $("#aqbooksellerid").val().length == 0) {
62
        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"));
63
        if (input_box==false) {
64
            return false;
65
        }
66
    }
67
    if ($("#biblionumber").val().length == 0) {
68
        alert(_("You must choose or create a biblio"));
69
        return false;
70
    }
71
72
    return true;
73
}
74
75
function Check_page2(){
76
    [% UNLESS (more_than_one_serial) %]
77
      if($("#acqui_date").val().length == 0){
78
          alert(_("You must choose a first publication date"));
79
          return false;
80
      }
81
    [% END %]
82
    if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
83
        alert(_("You must choose a subscription length or an end date."));
84
        return false;
85
    }
86
    if(advancedpatternlocked == 0){
87
        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
88
        return false;
89
    }
90
    if(patternneedtobetested){
91
        [% IF (irregularity) %]
92
           alert(_("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid"));
93
        [% ELSE %]alert(_("Please click on 'Test prediction pattern' before saving subscription."));[% END %]
94
        return false;
95
    }
96
97
    return true;
98
}
99
100
function frequencyload(){
101
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
102
        function(freqdata){
103
            globalfreqdata=freqdata;
104
            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
105
                var option = $("#subtype option[value='issues']");
106
                $(option).attr('selected', 'selected');
107
                $("#subtype option[value!='issues']").prop('disabled', true)
108
            } else {
109
                $("#subtype option").prop('disabled', false)
110
            }
111
        }
112
    )
113
}
114
115
function numberpatternload(){
116
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
117
        function(numpatterndata){
118
            globalnumpatterndata=numpatterndata;
119
            if (globalnumpatterndata==undefined){
120
                return false;
121
            }
122
            displaymoreoptions();
123
            restoreAdvancedPattern();
124
        }
125
    );
126
}
127
128
function displaymoreoptions() {
129
    if(globalnumpatterndata == undefined){
130
        $("#moreoptionst").hide();
131
        return false;
132
    }
133
134
    var X = 0, Y = 0, Z = 0;
135
    var numberingmethod = globalnumpatterndata.numberingmethod;
136
    if(numberingmethod.match(/{X}/)) X = 1;
137
    if(numberingmethod.match(/{Y}/)) Y = 1;
138
    if(numberingmethod.match(/{Z}/)) Z = 1;
139
140
    if(X || Y || Z) {
141
        $("#moreoptionst").show();
142
    } else {
143
        $("#moreoptionst").hide();
144
    }
145
146
    if(X) {
147
        if(globalnumpatterndata.label1) {
148
            $("#headerX").html(globalnumpatterndata.label1);
149
        } else {
150
            $("#headerX").html("X");
151
        }
152
        $("#headerX").show();
153
        $("#beginsX").show();
154
        $("#innerX").show();
155
    } else {
156
        $("#headerX").hide();
157
        $("#beginsX").hide();
158
        $("#innerX").hide();
159
        $("#lastvaluetemp1").val('');
160
        $("#innerlooptemp1").val('');
161
    }
162
    if(Y) {
163
        if(globalnumpatterndata.label2) {
164
            $("#headerY").html(globalnumpatterndata.label2);
165
        } else {
166
            $("#headerY").html("Y");
167
        }
168
        $("#headerY").show();
169
        $("#beginsY").show();
170
        $("#innerY").show();
171
    } else {
172
        $("#headerY").hide();
173
        $("#beginsY").hide();
174
        $("#innerY").hide();
175
        $("#lastvaluetemp2").val('');
176
        $("#innerlooptemp2").val('');
177
    }
178
    if(Z) {
179
        if(globalnumpatterndata.label3) {
180
            $("#headerZ").html(globalnumpatterndata.label3);
181
        } else {
182
            $("#headerZ").html("Z");
183
        }
184
        $("#headerZ").show();
185
        $("#beginsZ").show();
186
        $("#innerZ").show();
187
    } else {
188
        $("#headerZ").hide();
189
        $("#beginsZ").hide();
190
        $("#innerZ").hide();
191
        $("#lastvaluetemp3").val('');
192
        $("#innerlooptemp3").val('');
193
    }
194
}
195
196
function modifyAdvancedPattern() {
197
    $("#patternname").prop('readOnly', false).val('');
198
    $("#numberingmethod").prop('readOnly', false);
199
200
    $("#advancedpredictionpatternt input").each(function() {
201
        $(this).prop('readOnly', false);
202
    });
203
    $("#advancedpredictionpatternt select").each(function() {
204
        $(this).prop('disabled', false);
205
    });
206
207
    $("#restoreadvancedpatternbutton").show();
208
    $("#saveadvancedpatternbutton").show();
209
    $("#modifyadvancedpatternbutton").hide();
210
211
    advancedpatternlocked = 0;
212
}
213
214
function restoreAdvancedPattern() {
215
    $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label);
216
    $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod);
217
218
    $("#advancedpredictionpatternt input").each(function() {
219
        $(this).prop('readOnly', true);
220
        var id = $(this).attr('id');
221
        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
222
            var tempid = id.replace(/(\d)/, "temp$1");
223
            $(this).val($("#"+tempid).val());
224
        } else {
225
            $(this).val(globalnumpatterndata[id]);
226
        }
227
    });
228
    $("#advancedpredictionpatternt select").each(function() {
229
        $(this).prop('disabled', true);
230
        var id = $(this).attr('id');
231
        $(this).val(globalnumpatterndata[id]);
232
    });
233
234
    $("#restoreadvancedpatternbutton").hide();
235
    $("#saveadvancedpatternbutton").hide();
236
    $("#modifyadvancedpatternbutton").show();
237
238
    advancedpatternlocked = 1;
239
}
240
241
function testPredictionPattern() {
242
    var frequencyid = $("#frequency").val();
243
    var acquidate;
244
    var error = 0;
245
    var error_msg = "";
246
    if(frequencyid == undefined || frequencyid == ""){
247
        error_msg += _("- Frequency is not defined") + "\n";
248
        error ++;
249
    }
250
    acquidate = $("#acqui_date").val();
251
    if(acquidate == undefined || acquidate == ""){
252
        error_msg += _("- First publication date is not defined") + "\n";
253
        error ++;
254
    }
255
    [% IF (more_than_one_serial) %]
256
      var nextacquidate = $("#nextacquidate").val();
257
      if(nextacquidate == undefined || nextacquidate == ""){
258
        error_msg += _("- Next issue publication date is not defined") + "\n";
259
        error ++;
260
      }
261
    [% END %]
262
263
    if(error){
264
        alert(_("Cannot test prediction pattern for the following reason(s): %s").format(error_msg));
265
        return false;
266
    }
267
268
    var custompattern = 0;
269
    if(advancedpatternlocked == 0) {
270
        custompattern = 1;
271
    }
272
273
    var ajaxData = {
274
        'custompattern': custompattern,
275
        [% IF (subscriptionid) %]
276
            'subscriptionid': [% subscriptionid %],
277
        [% END %]
278
        [% IF (more_than_one_serial) %]
279
          'nextacquidate': nextacquidate,
280
        [% END %]
281
        'firstacquidate': acquidate
282
    };
283
    var ajaxParams = [
284
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
285
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
286
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
287
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
288
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
289
    ];
290
    for(i in ajaxParams) {
291
        var param = ajaxParams[i];
292
        var value = $("#"+param).val();
293
        if(value.length > 0)
294
            ajaxData[param] = value;
295
    }
296
297
    $.ajax({
298
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
299
        data: ajaxData,
300
        success: function(data) {
301
            $("#displayexample").html(data);
302
            patternneedtobetested = 0;
303
        }
304
    });
305
}
306
307
function saveAdvancedPattern() {
308
    if ($("#patternname").val().length == 0) {
309
        alert(_("Please enter a name for this pattern"));
310
        return false;
311
    }
312
313
    // Check if patternname already exists, and modify pattern
314
    // instead of creating it if so
315
    var found = 0;
316
    $("#numberpattern option").each(function(){
317
        if($(this).text() == $("#patternname").val()){
318
            found = 1;
319
            return false;
320
        }
321
    });
322
    var cnfrm = 1;
323
    if(found){
324
        var msg = _("This pattern name already exists. Do you want to modify it?")
325
            + "\n" + _("Warning: it will modify the pattern for all subscriptions that are using it.");
326
        cnfrm = confirm(msg);
327
    }
328
329
    if(cnfrm) {
330
        var ajaxData = {};
331
        var ajaxParams = [
332
            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
333
            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
334
            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
335
            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
336
        ];
337
        for(i in ajaxParams) {
338
            var param = ajaxParams[i];
339
            var value = $("#"+param).val();
340
            if(value.length > 0)
341
                ajaxData[param] = value;
342
        }
343
344
        $.getJSON(
345
            "/cgi-bin/koha/serials/create-numberpattern.pl",
346
            ajaxData,
347
            function(data){
348
                if (data.numberpatternid) {
349
                    if(found == 0){
350
                        $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
351
                    }
352
                    $("#numberpattern").val(data.numberpatternid);
353
                    numberpatternload();
354
                } else {
355
                    alert(_("Something went wrong. Unable to create a new numbering pattern."));
356
                }
357
            }
358
        );
359
    }
360
}
361
362
function show_page_1() {
363
    $("#page_1").show();
364
    $("#page_2").hide();
365
    $("#page_number").text("1/2");
366
}
367
368
function show_page_2() {
369
    $("#page_1").hide();
370
    $("#page_2").show();
371
    $("#page_number").text("2/2");
372
    displaymoreoptions();
373
}
374
375
376
$(document).ready(function() {
377
    $("#aqbooksellerid").on('keypress', function(e) {
378
        if (e.keyCode == 13) {
379
            e.preventDefault();
380
            FindAcqui();
381
        }
382
    });
383
    $("#biblionumber").on('keypress', function(e) {
384
        if (e.keyCode == 13) {
385
            e.preventDefault();
386
            Plugin();
387
        }
388
    });
389
    $("select#frequency").change(function(){
390
        patternneedtobetested = 1;
391
        $("input[name='enddate']").val('');
392
        frequencyload();
393
    });
394
    $("select#numberpattern").change(function(){
395
        patternneedtobetested = 1;
396
        numberpatternload();
397
    });
398
    $("#subtype").change(function(){
399
        $("input[name='enddate']").val('');
400
    });
401
    $("#sublength").change(function(){
402
        $("input[name='enddate']").val('');
403
    });
404
    $("#lastvaluetemp1").keyup(function(){
405
        $("#lastvalue1").val($(this).val());
406
    });
407
    $("#lastvaluetemp2").keyup(function(){
408
        $("#lastvalue2").val($(this).val());
409
    });
410
    $("#lastvaluetemp3").keyup(function(){
411
        $("#lastvalue3").val($(this).val());
412
    });
413
    $("#lastvalue1").keyup(function(){
414
        $("#lastvaluetemp1").val($(this).val());
415
    });
416
    $("#lastvalue2").keyup(function(){
417
        $("#lastvaluetemp2").val($(this).val());
418
    });
419
    $("#lastvalue3").keyup(function(){
420
        $("#lastvaluetemp3").val($(this).val());
421
    });
422
423
    $("#innerlooptemp1").keyup(function(){
424
        $("#innerloop1").val($(this).val());
425
    });
426
    $("#innerlooptemp2").keyup(function(){
427
        $("#innerloop2").val($(this).val());
428
    });
429
    $("#innerlooptemp3").keyup(function(){
430
        $("#innerloop3").val($(this).val());
431
    });
432
    $("#innerloop1").keyup(function(){
433
        $("#innerlooptemp1").val($(this).val());
434
    });
435
    $("#innerloop2").keyup(function(){
436
        $("#innerlooptemp2").val($(this).val());
437
    });
438
    $("#innerloop3").keyup(function(){
439
        $("#innerlooptemp3").val($(this).val());
440
    });
441
442
    if($("#frequency").val() != ""){
443
        frequencyload();
444
    }
445
    if($("#numberpattern").val() != ""){
446
        numberpatternload();
447
    }
448
449
    var node;
450
    [% FOREACH field IN dont_export_field_loop %]
451
        node = $("[name='[% field.fieldid %]']");
452
        if ( $(node).is('input') || $(node).is('textarea') ) {
453
            $(node).val("");
454
        } else if ( $(node).is('select') ) {
455
            $(node).find("option:first").attr('selected','selected');
456
        }
457
    [% END %]
458
459
    show_page_1();
460
    $("#subscription_add_form").on("submit",function(){
461
        return Check_page2();
462
    });
463
    $("#vendor_search").on("click",function(e){
464
        e.preventDefault();
465
        FindAcqui();
466
    });
467
    $("#record_search").on("click",function(e){
468
        e.preventDefault();
469
        Plugin();
470
    });
471
    $("#biblio_add_edit").on("click",function(e){
472
        e.preventDefault();
473
        if( $(this).data("biblionumber") ){
474
            addbiblioPopup( $(this).data("biblionumber") );
475
        } else {
476
            addbiblioPopup();
477
        }
478
    });
479
    $("#subscription_add_next").on("click",function(){
480
        if ( Check_page1() ){
481
            show_page_2();
482
        }
483
    });
484
    $("#subscription_add_previous").on("click",function(){
485
        show_page_1();
486
    });
487
    $(".toggle_advanced_pattern").on("click",function(e){
488
        e.preventDefault();
489
        $("#advancedpredictionpattern").toggle();
490
        $(".toggle_advanced_pattern").toggle();
491
    });
492
    $("#modifyadvancedpatternbutton").on("click",function(e){
493
        e.preventDefault();
494
        modifyAdvancedPattern();
495
    });
496
    $("#restoreadvancedpatternbutton").on("click",function(e){
497
        e.preventDefault();
498
        restoreAdvancedPattern();
499
    });
500
    $("#saveadvancedpatternbutton").on("click",function(e){
501
        e.preventDefault();
502
        saveAdvancedPattern();
503
    });
504
    $("#testpatternbutton").on("click",function(e){
505
        e.preventDefault();
506
        testPredictionPattern();
507
    });
508
});
509
//]]>
510
</script>
511
</head>
13
</head>
14
512
<body id="ser_subscription-add" class="ser">
15
<body id="ser_subscription-add" class="ser">
513
[% INCLUDE 'header.inc' %]
16
[% INCLUDE 'header.inc' %]
514
[% INCLUDE 'serials-search.inc' %]
17
[% INCLUDE 'serials-search.inc' %]
Lines 981-984 $(document).ready(function() { Link Here
981
    </div>
484
    </div>
982
</div>
485
</div>
983
486
487
[% MACRO jsinclude BLOCK %]
488
    [% INCLUDE 'calendar.inc' %]
489
    <script type="text/javascript">
490
        var subscriptionid = "[% subscriptionid %]";
491
        var irregularity = "[% irregularity %]";
492
        var more_than_one_serial = "[% more_than_one_serial %]";
493
        var tags = [];
494
        [% FOREACH field IN dont_export_field_loop %]
495
            tags.push("[% field.fieldid %]");
496
        [% END %]
497
        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");
498
        var MSG_LINK_BIBLIO = _("You must choose or create a bibliographic record");
499
        var MSG_REQUIRED_SUB_LENGTH = _("You must choose a subscription length or an end date.");
500
        var MSG_TEST_PREDICTION = _("Please click on 'Test prediction pattern' before saving subscription.");
501
        var MSG_REQUIRED_PUB_DATE = _("You must choose a first publication date");
502
        var MSG = _("You have modified the advanced prediction pattern. Please save your work or cancel modifications.");
503
        var MSG_PATTERN_IRREG = _("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid")
504
        var MSG_PATTERN_NAME = _("Please enter a name for this pattern");
505
        var MSG_PATTERN_NAME_EXISTS = _("This pattern name already exists. Do you want to modify it?");
506
        var MSG_OVERWRITE_PATTERNS = _("Warning: it will modify the pattern for all subscriptions that are using it.");
507
        var MSG_PATTERN_CREATE_FAILED = _("Something went wrong. Unable to create a new numbering pattern.");
508
        var MSG_PATTERN_TEST_FAILED = _("Cannot test prediction pattern for the following reason(s): %s");
509
        var MSG_FREQUENCY_UNDEFINED = _("Frequency is not defined");
510
        var MSG_PUB_DATE_UNDEFINED = _("First publication date is not defined");
511
        var MSG_NEXT_ISSUE_UNDEFINED = _("Next issue publication date is not defined");
512
    </script>
513
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/subscription-add.js"></script>
514
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/showpredictionpattern.js"></script>
515
[% END %]
516
984
[% INCLUDE 'intranet-bottom.inc' %]
517
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-frequencies.tt (-69 / +72 lines)
Lines 1-75 Link Here
1
[% SET footerjs = 1 %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Frequencies</title>
3
<title>Koha &rsaquo; Serials &rsaquo; Frequencies</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
function confirmDelete() {
7
  return confirm(_("Are you sure you want to delete this subscription frequency?"));
8
}
9
10
function check_form() {
11
    var description = $("#description").val();
12
    var unit = $("#unit").val();
13
    var issuesperunit = $("#issuesperunit").val();
14
    var unitsperissue = $("#unitsperissue").val();
15
    var alert_msg = _("Some fields are not valid:") + "\n";
16
    var errors = 0;
17
18
    if(description.length == 0) {
19
        alert_msg += "\t - " + _("Description is required");
20
        errors ++;
21
    }
22
    if(unit.length > 0) {
23
        if(isNaN(issuesperunit) || issuesperunit == 0) {
24
            alert_msg += "\n\t - " + _("Issues per unit is required")
25
                + " " + _("(must be a number greater than 0)");
26
            errors ++;
27
        }
28
        if(isNaN(unitsperissue) || unitsperissue == 0) {
29
            alert_msg += "\n\t - " + _("Units per issue is required")
30
                + " " + _("(must be a number greater than 0)");
31
            errors ++;
32
        }
33
        if(issuesperunit > 1 && unitsperissue > 1) {
34
            alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
35
            errors ++;
36
        }
37
    }
38
39
    if(errors == 0) {
40
        return true;
41
    }
42
43
    alert(alert_msg);
44
    return false;
45
}
46
47
$(document).ready(function() {
48
    $("#issuesperunit").change(function() {
49
        var value = $(this).val();
50
        if(!isNaN(value) && value > 1) {
51
            $("#unitsperissue").val(1);
52
        }
53
    });
54
    $("#unitsperissue").change(function() {
55
        var value = $(this).val();
56
        if(!isNaN(value) && value > 1) {
57
            $("#issuesperunit").val(1);
58
        }
59
    });
60
    $(".delete_frequency").on("click",function(){
61
        return confirmDelete();
62
    });
63
    $("#add_frequency_form").on("submit",function(){
64
        return check_form();
65
    });
66
    $("#show_blocking_subs").on("click",function(e){
67
        e.preventDefault();
68
        $("#blocking_subs").show();
69
    });
70
});
71
//]]>
72
</script>
73
</head>
5
</head>
74
6
75
<body id="ser_subscription_frequencies" class="ser">
7
<body id="ser_subscription_frequencies" class="ser">
Lines 231-234 $(document).ready(function() { Link Here
231
    [% INCLUDE 'serials-menu.inc' %]
163
    [% INCLUDE 'serials-menu.inc' %]
232
  </div>
164
  </div>
233
</div>
165
</div>
166
167
[% MACRO jsinclude BLOCK %]
168
    <script type="text/javascript">
169
        function confirmDelete() {
170
            return confirm(_("Are you sure you want to delete this subscription frequency?"));
171
        }
172
173
        function check_form() {
174
            var description = $("#description").val();
175
            var unit = $("#unit").val();
176
            var issuesperunit = $("#issuesperunit").val();
177
            var unitsperissue = $("#unitsperissue").val();
178
            var alert_msg = _("Some fields are not valid:") + "\n";
179
            var errors = 0;
180
181
            if(description.length == 0) {
182
                alert_msg += "\t - " + _("Description is required");
183
                errors ++;
184
            }
185
            if(unit.length > 0) {
186
                if(isNaN(issuesperunit) || issuesperunit == 0) {
187
                    alert_msg += "\n\t - " + _("Issues per unit is required")
188
                        + " " + _("(must be a number greater than 0)");
189
                    errors ++;
190
                }
191
                if(isNaN(unitsperissue) || unitsperissue == 0) {
192
                    alert_msg += "\n\t - " + _("Units per issue is required")
193
                        + " " + _("(must be a number greater than 0)");
194
                    errors ++;
195
                }
196
                if(issuesperunit > 1 && unitsperissue > 1) {
197
                    alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
198
                    errors ++;
199
                }
200
            }
201
202
            if(errors == 0) {
203
                return true;
204
            }
205
206
            alert(alert_msg);
207
            return false;
208
        }
209
210
        $(document).ready(function() {
211
            $("#issuesperunit").change(function() {
212
                var value = $(this).val();
213
                if(!isNaN(value) && value > 1) {
214
                    $("#unitsperissue").val(1);
215
                }
216
            });
217
            $("#unitsperissue").change(function() {
218
                var value = $(this).val();
219
                if(!isNaN(value) && value > 1) {
220
                    $("#issuesperunit").val(1);
221
                }
222
            });
223
            $(".delete_frequency").on("click",function(){
224
                return confirmDelete();
225
            });
226
            $("#add_frequency_form").on("submit",function(){
227
                return check_form();
228
            });
229
            $("#show_blocking_subs").on("click",function(e){
230
                e.preventDefault();
231
                $("#blocking_subs").show();
232
            });
233
        });
234
    </script>
235
[% END %]
236
234
[% INCLUDE 'intranet-bottom.inc' %]
237
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-history.tt (-2 / +6 lines)
Lines 1-9 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
2
[% SET footerjs = 1 %]
3
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Serials &rsaquo; Subscription history</title>
4
<title>Koha &rsaquo; Serials &rsaquo; Subscription history</title>
5
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'calendar.inc' %]
7
</head>
6
</head>
8
7
9
<body id="ser_subscription_history" class="ser">
8
<body id="ser_subscription_history" class="ser">
Lines 64-67 Link Here
64
    [% INCLUDE 'serials-menu.inc' %]
63
    [% INCLUDE 'serials-menu.inc' %]
65
  </div>
64
  </div>
66
</div>
65
</div>
66
67
[% MACRO jsinclude BLOCK %]
68
    [% INCLUDE 'calendar.inc' %]
69
[% END %]
70
67
[% INCLUDE 'intranet-bottom.inc' %]
71
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt (-84 / +89 lines)
Lines 1-91 Link Here
1
[% SET footerjs = 1 %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Numbering patterns</title>
3
<title>Koha &rsaquo; Serials &rsaquo; Numbering patterns</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
5
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
6
[% INCLUDE 'datatables.inc' %]
7
<script type="text/javascript">
8
//<![CDATA[
9
10
function confirmDelete() {
11
  return confirm(_("Are you sure you want to delete this numbering pattern?"));
12
}
13
14
[% IF (new or modify) %]
15
  function testPattern() {
16
      var frequencyid = $("#frequency").val();
17
      var firstacquidate = $("#firstacquidate").val();
18
      var error = 0;
19
      var error_msg = "";
20
      if(frequencyid == undefined || frequencyid == "") {
21
          error_msg += _("- Frequency is not defined") + "\n";
22
          error ++;
23
      }
24
      if(firstacquidate == undefined || firstacquidate == "") {
25
          error_msg += _("- First publication date is not defined") + "\n";
26
          error ++;
27
      }
28
29
      if(error){
30
          alert(_("Cannot test prediction pattern for the following reason(s):") + "\n\n"
31
              + error_msg);
32
          return false;
33
      }
34
35
      var ajaxData = {
36
          'custompattern': true,
37
      };
38
      var ajaxParams = [
39
          'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
40
          'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
41
          'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
42
          'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
43
          'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
44
      ];
45
      for(i in ajaxParams) {
46
          var param = ajaxParams[i];
47
          var value = $("#"+param).val();
48
          if(value.length > 0)
49
              ajaxData[param] = value;
50
      }
51
52
      $.ajax({
53
          url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
54
          data: ajaxData,
55
          async: false,
56
          dataType: "text",
57
          success: function(data) {
58
              $("#predictionpattern").html(data);
59
          }
60
      });
61
  }
62
[% END %]
63
64
function show_blocking_subs() {
65
    $("#blocking_subs").show();
66
}
67
$(document).ready(function(){
68
69
    $("#numberpatternst").dataTable($.extend(true, {}, dataTablesDefaults, {
70
        "aoColumnDefs": [
71
            { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
72
        ],
73
        "sPaginationType": "four_button"
74
    }));
75
76
    $(".delete_pattern").on("click",function(){
77
        return confirmDelete();
78
    });
79
    $("#show_blocking_subs").on("click",function(e){
80
        e.preventDefault();
81
        $("#blocking_subs").show();
82
    });
83
    $("#test_pattern").on("click",function(){
84
         testPattern();
85
    });
86
});
87
//]]>
88
</script>
89
</head>
6
</head>
90
7
91
<body id="ser_subscription_numberpatterns" class="ser">
8
<body id="ser_subscription_numberpatterns" class="ser">
Lines 381-384 $(document).ready(function(){ Link Here
381
    [% INCLUDE 'serials-menu.inc' %]
298
    [% INCLUDE 'serials-menu.inc' %]
382
  </div>
299
  </div>
383
</div>
300
</div>
301
302
[% MACRO jsinclude BLOCK %]
303
    [% IF (daily_options) %]
304
        <script type="text/javascript" src="[% interface %]/[% theme %]/js/showpredictionpattern.js"></script>
305
    [% END %]
306
    [% INCLUDE 'calendar.inc' %]
307
    [% INCLUDE 'datatables.inc' %]
308
    <script type="text/javascript">
309
        function confirmDelete() {
310
            return confirm(_("Are you sure you want to delete this numbering pattern?"));
311
        }
312
313
        [% IF (new or modify) %]
314
            function testPattern() {
315
                var frequencyid = $("#frequency").val();
316
                var firstacquidate = $("#firstacquidate").val();
317
                var error = 0;
318
                var error_msg = "";
319
                if(frequencyid == undefined || frequencyid == "") {
320
                    error_msg += _("- Frequency is not defined") + "\n";
321
                    error ++;
322
                }
323
                if(firstacquidate == undefined || firstacquidate == "") {
324
                    error_msg += _("- First publication date is not defined") + "\n";
325
                    error ++;
326
                }
327
328
                if(error){
329
                    alert(_("Cannot test prediction pattern for the following reason(s):") + "\n\n"
330
                        + error_msg);
331
                    return false;
332
                }
333
334
                var ajaxData = {
335
                    'custompattern': true,
336
                };
337
                var ajaxParams = [
338
                    'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
339
                    'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
340
                    'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
341
                    'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
342
                    'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
343
                ];
344
                for(i in ajaxParams) {
345
                    var param = ajaxParams[i];
346
                    var value = $("#"+param).val();
347
                    if(value.length > 0)
348
                        ajaxData[param] = value;
349
                }
350
351
                $.ajax({
352
                    url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
353
                    data: ajaxData,
354
                    async: false,
355
                    dataType: "text",
356
                    success: function(data) {
357
                        $("#predictionpattern").html(data);
358
                    }
359
                });
360
            }
361
        [% END %]
362
363
        function show_blocking_subs() {
364
            $("#blocking_subs").show();
365
        }
366
        $(document).ready(function(){
367
368
            $("#numberpatternst").dataTable($.extend(true, {}, dataTablesDefaults, {
369
                "aoColumnDefs": [
370
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
371
                ],
372
                "sPaginationType": "four_button"
373
            }));
374
375
            $(".delete_pattern").on("click",function(){
376
                return confirmDelete();
377
            });
378
            $("#show_blocking_subs").on("click",function(e){
379
                e.preventDefault();
380
                $("#blocking_subs").show();
381
            });
382
            $("#test_pattern").on("click",function(){
383
                 testPattern();
384
            });
385
        });
386
    </script>
387
[% END %]
388
384
[% INCLUDE 'intranet-bottom.inc' %]
389
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (-1 / +6 lines)
Lines 1-11 Link Here
1
[% SET footerjs = 1 %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials subscription renew #[% subscriptionid %]</title>
3
<title>Koha &rsaquo; Serials subscription renew #[% subscriptionid %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
<style type="text/css">
5
<style type="text/css">
6
   #custom-doc { width:39.85em;*width:38.86em;min-width:531px; margin:auto; text-align:left; }
6
   #custom-doc { width:39.85em;*width:38.86em;min-width:531px; margin:auto; text-align:left; }
7
   </style>
7
   </style>
8
</head>
8
</head>
9
9
<body id="ser_subscription-renew" class="ser">
10
<body id="ser_subscription-renew" class="ser">
10
11
11
<div id="custom-doc" class="yui-t7">
12
<div id="custom-doc" class="yui-t7">
Lines 42-46 Link Here
42
</div>
43
</div>
43
[% END %]
44
[% END %]
44
45
46
[% MACRO jsinclude BLOCK %]
47
    [% INCLUDE 'calendar.inc' %]
48
[% END %]
49
45
[% INCLUDE 'intranet-bottom.inc' %]
50
[% INCLUDE 'intranet-bottom.inc' %]
46
51
(-)a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js (+16 lines)
Line 0 Link Here
1
function Check_boxes(dow) {
2
    if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
3
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
4
            $(this).prop('checked', true);
5
        });
6
    } else {
7
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
8
            $(this).prop('checked', false);
9
        });
10
    }
11
}
12
$(document).ready(function(){
13
    $("#displayexample").on("change",".skipday",function(){
14
        Check_boxes( $(this).data("dow"));
15
    });
16
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-1 / +499 lines)
Line 0 Link Here
0
- 
1
/* global irregularity more_than_one_serial subscriptionid tags */
2
3
var globalnumpatterndata;
4
var globalfreqdata;
5
var advancedpatternlocked;
6
var patternneedtobetested = 0;
7
if ( irregularity !== "" ){
8
    patternneedtobetested = 1;
9
}
10
11
function check_issues(){
12
    if (globalfreqdata.unit.length >0) {
13
        if (document.f.subtype.value == globalfreqdata.unit){
14
            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
15
        } else if (document.f.subtype.value != "issues"){
16
            alert( MSG_FREQUENCY_LENGTH_ERROR );
17
        }
18
    }
19
}
20
21
function addbiblioPopup(biblionumber) {
22
    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
23
    if(biblionumber){
24
        destination += "&biblionumber="+biblionumber;
25
    }
26
    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
27
}
28
29
function Plugin(){
30
    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
31
}
32
33
function FindAcqui(){
34
    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
35
}
36
37
function Find_ISSN(f){
38
    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
39
}
40
41
function Clear(id) {
42
    $("#"+id).val('');
43
}
44
45
function Check_page1() {
46
    if ( $("#aqbooksellerid").val().length == 0) {
47
        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"));
48
        if (input_box==false) {
49
            return false;
50
        }
51
    }
52
    if ($("#biblionumber").val().length == 0) {
53
        alert(_("You must choose or create a biblio"));
54
        return false;
55
    }
56
57
    return true;
58
}
59
60
function Check_page2(){
61
    if( more_than_one_serial == "" ){
62
        if($("#acqui_date").val().length == 0){
63
            alert(_("You must choose a first publication date"));
64
            return false;
65
        }
66
    }
67
    if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
68
        alert(_("You must choose a subscription length or an end date."));
69
        return false;
70
    }
71
    if(advancedpatternlocked == 0){
72
        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
73
        return false;
74
    }
75
    if(patternneedtobetested){
76
        if( irregularity !== "" ){
77
           alert(_("Warning! Present pattern has planned irregularities. Click on 'Test prediction pattern' to check if it's still valid"));
78
        } else {
79
            alert(_("Please click on 'Test prediction pattern' before saving subscription."));
80
        }
81
        return false;
82
    }
83
84
    return true;
85
}
86
87
function frequencyload(){
88
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
89
        function(freqdata){
90
            globalfreqdata=freqdata;
91
            if ( globalfreqdata.unit && globalfreqdata.unit.length == 0 ) {
92
                var option = $("#subtype option[value='issues']");
93
                $(option).attr('selected', 'selected');
94
                $("#subtype option[value!='issues']").prop('disabled', true)
95
            } else {
96
                $("#subtype option").prop('disabled', false)
97
            }
98
        }
99
    )
100
}
101
102
function numberpatternload(){
103
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
104
        function(numpatterndata){
105
            globalnumpatterndata=numpatterndata;
106
            if (globalnumpatterndata==undefined){
107
                return false;
108
            }
109
            displaymoreoptions();
110
            restoreAdvancedPattern();
111
        }
112
    );
113
}
114
115
function displaymoreoptions() {
116
    if(globalnumpatterndata == undefined){
117
        $("#moreoptionst").hide();
118
        return false;
119
    }
120
121
    var X = 0, Y = 0, Z = 0;
122
    var numberingmethod = globalnumpatterndata.numberingmethod;
123
    if(numberingmethod.match(/{X}/)) X = 1;
124
    if(numberingmethod.match(/{Y}/)) Y = 1;
125
    if(numberingmethod.match(/{Z}/)) Z = 1;
126
127
    if(X || Y || Z) {
128
        $("#moreoptionst").show();
129
    } else {
130
        $("#moreoptionst").hide();
131
    }
132
133
    if(X) {
134
        if(globalnumpatterndata.label1) {
135
            $("#headerX").html(globalnumpatterndata.label1);
136
        } else {
137
            $("#headerX").html("X");
138
        }
139
        $("#headerX").show();
140
        $("#beginsX").show();
141
        $("#innerX").show();
142
    } else {
143
        $("#headerX").hide();
144
        $("#beginsX").hide();
145
        $("#innerX").hide();
146
        $("#lastvaluetemp1").val('');
147
        $("#innerlooptemp1").val('');
148
    }
149
    if(Y) {
150
        if(globalnumpatterndata.label2) {
151
            $("#headerY").html(globalnumpatterndata.label2);
152
        } else {
153
            $("#headerY").html("Y");
154
        }
155
        $("#headerY").show();
156
        $("#beginsY").show();
157
        $("#innerY").show();
158
    } else {
159
        $("#headerY").hide();
160
        $("#beginsY").hide();
161
        $("#innerY").hide();
162
        $("#lastvaluetemp2").val('');
163
        $("#innerlooptemp2").val('');
164
    }
165
    if(Z) {
166
        if(globalnumpatterndata.label3) {
167
            $("#headerZ").html(globalnumpatterndata.label3);
168
        } else {
169
            $("#headerZ").html("Z");
170
        }
171
        $("#headerZ").show();
172
        $("#beginsZ").show();
173
        $("#innerZ").show();
174
    } else {
175
        $("#headerZ").hide();
176
        $("#beginsZ").hide();
177
        $("#innerZ").hide();
178
        $("#lastvaluetemp3").val('');
179
        $("#innerlooptemp3").val('');
180
    }
181
}
182
183
function modifyAdvancedPattern() {
184
    $("#patternname").prop('readOnly', false).val('');
185
    $("#numberingmethod").prop('readOnly', false);
186
187
    $("#advancedpredictionpatternt input").each(function() {
188
        $(this).prop('readOnly', false);
189
    });
190
    $("#advancedpredictionpatternt select").each(function() {
191
        $(this).prop('disabled', false);
192
    });
193
194
    $("#restoreadvancedpatternbutton").show();
195
    $("#saveadvancedpatternbutton").show();
196
    $("#modifyadvancedpatternbutton").hide();
197
198
    advancedpatternlocked = 0;
199
}
200
201
function restoreAdvancedPattern() {
202
    $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label);
203
    $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod);
204
205
    $("#advancedpredictionpatternt input").each(function() {
206
        $(this).prop('readOnly', true);
207
        var id = $(this).attr('id');
208
        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
209
            var tempid = id.replace(/(\d)/, "temp$1");
210
            $(this).val($("#"+tempid).val());
211
        } else {
212
            $(this).val(globalnumpatterndata[id]);
213
        }
214
    });
215
    $("#advancedpredictionpatternt select").each(function() {
216
        $(this).prop('disabled', true);
217
        var id = $(this).attr('id');
218
        $(this).val(globalnumpatterndata[id]);
219
    });
220
221
    $("#restoreadvancedpatternbutton").hide();
222
    $("#saveadvancedpatternbutton").hide();
223
    $("#modifyadvancedpatternbutton").show();
224
225
    advancedpatternlocked = 1;
226
}
227
228
function testPredictionPattern() {
229
    var frequencyid = $("#frequency").val();
230
    var acquidate;
231
    var error = 0;
232
    var error_msg = "";
233
    if(frequencyid == undefined || frequencyid == ""){
234
        error_msg += _("- Frequency is not defined") + "\n";
235
        error ++;
236
    }
237
    acquidate = $("#acqui_date").val();
238
    if(acquidate == undefined || acquidate == ""){
239
        error_msg += _("- First publication date is not defined") + "\n";
240
        error ++;
241
    }
242
    if( more_than_one_serial !== "" ){
243
        var nextacquidate = $("#nextacquidate").val();
244
        if(nextacquidate == undefined || nextacquidate == ""){
245
            error_msg += _("- Next issue publication date is not defined") + "\n";
246
            error ++;
247
        }
248
    }
249
250
    if(error){
251
        alert(_("Cannot test prediction pattern for the following reason(s): %s").format(error_msg));
252
        return false;
253
    }
254
255
    var custompattern = 0;
256
    if(advancedpatternlocked == 0) {
257
        custompattern = 1;
258
    }
259
260
    var ajaxData = {
261
        'custompattern': custompattern,
262
        'firstacquidate': acquidate
263
    };
264
265
    if( subscriptionid !== "" ){
266
        ajaxData.subscriptionid = subscriptionid;
267
    }
268
    if( more_than_one_serial !== "" ){
269
        ajaxData.nextacquidate = nextacquidate;
270
    }
271
272
273
    var ajaxParams = [
274
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
275
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
276
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
277
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
278
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
279
    ];
280
    for(i in ajaxParams) {
281
        var param = ajaxParams[i];
282
        var value = $("#"+param).val();
283
        if(value.length > 0)
284
            ajaxData[param] = value;
285
    }
286
287
    $.ajax({
288
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
289
        data: ajaxData,
290
        success: function(data) {
291
            $("#displayexample").html(data);
292
            patternneedtobetested = 0;
293
        }
294
    });
295
}
296
297
function saveAdvancedPattern() {
298
    if ($("#patternname").val().length == 0) {
299
        alert(_("Please enter a name for this pattern"));
300
        return false;
301
    }
302
303
    // Check if patternname already exists, and modify pattern
304
    // instead of creating it if so
305
    var found = 0;
306
    $("#numberpattern option").each(function(){
307
        if($(this).text() == $("#patternname").val()){
308
            found = 1;
309
            return false;
310
        }
311
    });
312
    var cnfrm = 1;
313
    if(found){
314
        var msg = _("This pattern name already exists. Do you want to modify it?")
315
            + "\n" + _("Warning: it will modify the pattern for all subscriptions that are using it.");
316
        cnfrm = confirm(msg);
317
    }
318
319
    if(cnfrm) {
320
        var ajaxData = {};
321
        var ajaxParams = [
322
            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
323
            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
324
            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
325
            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
326
        ];
327
        for(i in ajaxParams) {
328
            var param = ajaxParams[i];
329
            var value = $("#"+param).val();
330
            if(value.length > 0)
331
                ajaxData[param] = value;
332
        }
333
334
        $.getJSON(
335
            "/cgi-bin/koha/serials/create-numberpattern.pl",
336
            ajaxData,
337
            function(data){
338
                if (data.numberpatternid) {
339
                    if(found == 0){
340
                        $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
341
                    }
342
                    $("#numberpattern").val(data.numberpatternid);
343
                    numberpatternload();
344
                } else {
345
                    alert(_("Something went wrong. Unable to create a new numbering pattern."));
346
                }
347
            }
348
        );
349
    }
350
}
351
352
function show_page_1() {
353
    $("#page_1").show();
354
    $("#page_2").hide();
355
    $("#page_number").text("1/2");
356
}
357
358
function show_page_2() {
359
    $("#page_1").hide();
360
    $("#page_2").show();
361
    $("#page_number").text("2/2");
362
    displaymoreoptions();
363
}
364
365
366
$(document).ready(function() {
367
    $("#aqbooksellerid").on('keypress', function(e) {
368
        if (e.keyCode == 13) {
369
            e.preventDefault();
370
            FindAcqui();
371
        }
372
    });
373
    $("#biblionumber").on('keypress', function(e) {
374
        if (e.keyCode == 13) {
375
            e.preventDefault();
376
            Plugin();
377
        }
378
    });
379
    $("select#frequency").change(function(){
380
        patternneedtobetested = 1;
381
        $("input[name='enddate']").val('');
382
        frequencyload();
383
    });
384
    $("select#numberpattern").change(function(){
385
        patternneedtobetested = 1;
386
        numberpatternload();
387
    });
388
    $("#subtype").change(function(){
389
        $("input[name='enddate']").val('');
390
    });
391
    $("#sublength").change(function(){
392
        $("input[name='enddate']").val('');
393
    });
394
    $("#lastvaluetemp1").keyup(function(){
395
        $("#lastvalue1").val($(this).val());
396
    });
397
    $("#lastvaluetemp2").keyup(function(){
398
        $("#lastvalue2").val($(this).val());
399
    });
400
    $("#lastvaluetemp3").keyup(function(){
401
        $("#lastvalue3").val($(this).val());
402
    });
403
    $("#lastvalue1").keyup(function(){
404
        $("#lastvaluetemp1").val($(this).val());
405
    });
406
    $("#lastvalue2").keyup(function(){
407
        $("#lastvaluetemp2").val($(this).val());
408
    });
409
    $("#lastvalue3").keyup(function(){
410
        $("#lastvaluetemp3").val($(this).val());
411
    });
412
413
    $("#innerlooptemp1").keyup(function(){
414
        $("#innerloop1").val($(this).val());
415
    });
416
    $("#innerlooptemp2").keyup(function(){
417
        $("#innerloop2").val($(this).val());
418
    });
419
    $("#innerlooptemp3").keyup(function(){
420
        $("#innerloop3").val($(this).val());
421
    });
422
    $("#innerloop1").keyup(function(){
423
        $("#innerlooptemp1").val($(this).val());
424
    });
425
    $("#innerloop2").keyup(function(){
426
        $("#innerlooptemp2").val($(this).val());
427
    });
428
    $("#innerloop3").keyup(function(){
429
        $("#innerlooptemp3").val($(this).val());
430
    });
431
432
    if($("#frequency").val() != ""){
433
        frequencyload();
434
    }
435
    if($("#numberpattern").val() != ""){
436
        numberpatternload();
437
    }
438
439
    if( tags.length > 0 ){
440
        tags.forEach( function( item ) {
441
            var node = $("[name='" + item + "']");
442
            if ( $(node).is('input') || $(node).is('textarea') ) {
443
                $(node).val("");
444
            } else if ( $(node).is('select') ) {
445
                $(node).find("option:first").attr('selected','selected');
446
            }
447
        });
448
    }
449
450
    show_page_1();
451
    $("#subscription_add_form").on("submit",function(){
452
        return Check_page2();
453
    });
454
    $("#vendor_search").on("click",function(e){
455
        e.preventDefault();
456
        FindAcqui();
457
    });
458
    $("#record_search").on("click",function(e){
459
        e.preventDefault();
460
        Plugin();
461
    });
462
    $("#biblio_add_edit").on("click",function(e){
463
        e.preventDefault();
464
        if( $(this).data("biblionumber") ){
465
            addbiblioPopup( $(this).data("biblionumber") );
466
        } else {
467
            addbiblioPopup();
468
        }
469
    });
470
    $("#subscription_add_next").on("click",function(){
471
        if ( Check_page1() ){
472
            show_page_2();
473
        }
474
    });
475
    $("#subscription_add_previous").on("click",function(){
476
        show_page_1();
477
    });
478
    $(".toggle_advanced_pattern").on("click",function(e){
479
        e.preventDefault();
480
        $("#advancedpredictionpattern").toggle();
481
        $(".toggle_advanced_pattern").toggle();
482
    });
483
    $("#modifyadvancedpatternbutton").on("click",function(e){
484
        e.preventDefault();
485
        modifyAdvancedPattern();
486
    });
487
    $("#restoreadvancedpatternbutton").on("click",function(e){
488
        e.preventDefault();
489
        restoreAdvancedPattern();
490
    });
491
    $("#saveadvancedpatternbutton").on("click",function(e){
492
        e.preventDefault();
493
        saveAdvancedPattern();
494
    });
495
    $("#testpatternbutton").on("click",function(e){
496
        e.preventDefault();
497
        testPredictionPattern();
498
    });
499
});

Return to bug 19778