1 /* global irregularity more_than_one_serial subscriptionid tags */
3 var globalnumpatterndata;
5 var advancedpatternlocked;
6 var patternneedtobetested = 0;
7 if ( irregularity !== "" ){
8 patternneedtobetested = 1;
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 );
21 function addbiblioPopup(biblionumber) {
22 var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
24 destination += "&biblionumber="+biblionumber;
26 window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
30 window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
34 window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
37 function Find_ISSN(f){
38 window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
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) {
52 if ($("#biblionumber").val().length == 0) {
53 alert(_("You must choose or create a biblio"));
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"));
67 if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
68 alert(_("You must choose a subscription length or an end date."));
71 if(advancedpatternlocked == 0){
72 alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
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"));
79 alert(_("Please click on 'Test prediction pattern' before saving subscription."));
87 function frequencyload(){
88 $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
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)
96 $("#subtype option").prop('disabled', false)
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){
109 displaymoreoptions();
110 restoreAdvancedPattern();
115 function displaymoreoptions() {
116 if(globalnumpatterndata == undefined){
117 $("#moreoptionst").hide();
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;
128 $("#moreoptionst").show();
130 $("#moreoptionst").hide();
134 if(globalnumpatterndata.label1) {
135 $("#headerX").html(globalnumpatterndata.label1);
137 $("#headerX").html("X");
139 $("#headerX").show();
140 $("#beginsX").show();
143 $("#headerX").hide();
144 $("#beginsX").hide();
146 $("#lastvaluetemp1").val('');
147 $("#innerlooptemp1").val('');
150 if(globalnumpatterndata.label2) {
151 $("#headerY").html(globalnumpatterndata.label2);
153 $("#headerY").html("Y");
155 $("#headerY").show();
156 $("#beginsY").show();
159 $("#headerY").hide();
160 $("#beginsY").hide();
162 $("#lastvaluetemp2").val('');
163 $("#innerlooptemp2").val('');
166 if(globalnumpatterndata.label3) {
167 $("#headerZ").html(globalnumpatterndata.label3);
169 $("#headerZ").html("Z");
171 $("#headerZ").show();
172 $("#beginsZ").show();
175 $("#headerZ").hide();
176 $("#beginsZ").hide();
178 $("#lastvaluetemp3").val('');
179 $("#innerlooptemp3").val('');
183 function modifyAdvancedPattern() {
184 $("#patternname").prop('readOnly', false).val('');
185 $("#numberingmethod").prop('readOnly', false);
187 $("#advancedpredictionpatternt input").each(function() {
188 $(this).prop('readOnly', false);
190 $("#advancedpredictionpatternt select").each(function() {
191 $(this).prop('disabled', false);
194 $("#restoreadvancedpatternbutton").show();
195 $("#saveadvancedpatternbutton").show();
196 $("#modifyadvancedpatternbutton").hide();
198 advancedpatternlocked = 0;
201 function restoreAdvancedPattern() {
202 $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label);
203 $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod);
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());
212 $(this).val(globalnumpatterndata[id]);
215 $("#advancedpredictionpatternt select").each(function() {
216 $(this).prop('disabled', true);
217 var id = $(this).attr('id');
218 $(this).val(globalnumpatterndata[id]);
221 $("#restoreadvancedpatternbutton").hide();
222 $("#saveadvancedpatternbutton").hide();
223 $("#modifyadvancedpatternbutton").show();
225 advancedpatternlocked = 1;
228 function testPredictionPattern() {
229 var frequencyid = $("#frequency").val();
233 if(frequencyid == undefined || frequencyid == ""){
234 error_msg += _("- Frequency is not defined") + "\n";
237 acquidate = $("#acqui_date").val();
238 if(acquidate == undefined || acquidate == ""){
239 error_msg += _("- First publication date is not defined") + "\n";
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";
251 alert(_("Cannot test prediction pattern for the following reason(s): %s").format(error_msg));
255 var custompattern = 0;
256 if(advancedpatternlocked == 0) {
261 'custompattern': custompattern,
262 'firstacquidate': acquidate
265 if( subscriptionid !== "" ){
266 ajaxData.subscriptionid = subscriptionid;
268 if( more_than_one_serial !== "" ){
269 ajaxData.nextacquidate = nextacquidate;
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'
280 for(i in ajaxParams) {
281 var param = ajaxParams[i];
282 var value = $("#"+param).val();
284 ajaxData[param] = value;
288 url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
290 success: function(data) {
291 $("#displayexample").html(data);
292 patternneedtobetested = 0;
297 function saveAdvancedPattern() {
298 if ($("#patternname").val().length == 0) {
299 alert(_("Please enter a name for this pattern"));
303 // Check if patternname already exists, and modify pattern
304 // instead of creating it if so
306 $("#numberpattern option").each(function(){
307 if($(this).text() == $("#patternname").val()){
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);
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'
327 for(i in ajaxParams) {
328 var param = ajaxParams[i];
329 var value = $("#"+param).val();
331 ajaxData[param] = value;
335 "/cgi-bin/koha/serials/create-numberpattern.pl",
338 if (data.numberpatternid) {
340 $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
342 $("#numberpattern").val(data.numberpatternid);
345 alert(_("Something went wrong. Unable to create a new numbering pattern."));
352 function show_page_1() {
355 $("#page_number").text("1/2");
358 function show_page_2() {
361 $("#page_number").text("2/2");
362 displaymoreoptions();
366 $(document).ready(function() {
367 $("#aqbooksellerid").on('keypress', function(e) {
368 if (e.keyCode == 13) {
373 $("#biblionumber").on('keypress', function(e) {
374 if (e.keyCode == 13) {
379 $("select#frequency").change(function(){
380 patternneedtobetested = 1;
381 $("input[name='enddate']").val('');
384 $("select#numberpattern").change(function(){
385 patternneedtobetested = 1;
388 $("#subtype").change(function(){
389 $("input[name='enddate']").val('');
391 $("#sublength").change(function(){
392 $("input[name='enddate']").val('');
394 $("#lastvaluetemp1").keyup(function(){
395 $("#lastvalue1").val($(this).val());
397 $("#lastvaluetemp2").keyup(function(){
398 $("#lastvalue2").val($(this).val());
400 $("#lastvaluetemp3").keyup(function(){
401 $("#lastvalue3").val($(this).val());
403 $("#lastvalue1").keyup(function(){
404 $("#lastvaluetemp1").val($(this).val());
406 $("#lastvalue2").keyup(function(){
407 $("#lastvaluetemp2").val($(this).val());
409 $("#lastvalue3").keyup(function(){
410 $("#lastvaluetemp3").val($(this).val());
413 $("#innerlooptemp1").keyup(function(){
414 $("#innerloop1").val($(this).val());
416 $("#innerlooptemp2").keyup(function(){
417 $("#innerloop2").val($(this).val());
419 $("#innerlooptemp3").keyup(function(){
420 $("#innerloop3").val($(this).val());
422 $("#innerloop1").keyup(function(){
423 $("#innerlooptemp1").val($(this).val());
425 $("#innerloop2").keyup(function(){
426 $("#innerlooptemp2").val($(this).val());
428 $("#innerloop3").keyup(function(){
429 $("#innerlooptemp3").val($(this).val());
432 if($("#frequency").val() != ""){
435 if($("#numberpattern").val() != ""){
439 if( tags.length > 0 ){
440 tags.forEach( function( item ) {
441 var node = $("[name='" + item + "']");
442 if ( $(node).is('input') || $(node).is('textarea') ) {
444 } else if ( $(node).is('select') ) {
445 $(node).find("option:first").attr('selected','selected');
451 $("#subscription_add_form").on("submit",function(){
452 return Check_page2();
454 $("#vendor_search").on("click",function(e){
458 $("#record_search").on("click",function(e){
462 $("#biblio_add_edit").on("click",function(e){
464 if( $(this).data("biblionumber") ){
465 addbiblioPopup( $(this).data("biblionumber") );
470 $("#subscription_add_next").on("click",function(){
471 if ( Check_page1() ){
475 $("#subscription_add_previous").on("click",function(){
478 $(".toggle_advanced_pattern").on("click",function(e){
480 $("#advancedpredictionpattern").toggle();
481 $(".toggle_advanced_pattern").toggle();
483 $("#modifyadvancedpatternbutton").on("click",function(e){
485 modifyAdvancedPattern();
487 $("#restoreadvancedpatternbutton").on("click",function(e){
489 restoreAdvancedPattern();
491 $("#saveadvancedpatternbutton").on("click",function(e){
493 saveAdvancedPattern();
495 $("#testpatternbutton").on("click",function(e){
497 testPredictionPattern();