From 44d1aa5eb0e4081c1403a969e238408be5223352 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Sun, 3 Aug 2008 20:05:55 -0500 Subject: [PATCH] Serials planning updates patch 1/3 This patch addresses usability and interface bugs in the javascript irregularity checks by adding extra controls: 'test pattern' button (always visible) replaces the 'irregularity' link that was previously only sometimes visible. A 'show advanced pattern' button will display/hide the base prediction table at any time. A 'reset pattern' button is added. The form may now also be submitted even if it fails the irregularity test, as there are cases when this will result in the desired behavior. Signed-off-by: Joshua Ferraro --- .../prog/en/css/staff-global.css | 10 + .../en/modules/serials/subscription-add.tmpl | 301 ++++++++++++------ serials/subscription-add.pl | 68 ++-- 3 files changed, 241 insertions(+), 138 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index ab7b2c75e4..3dd136b286 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -1406,6 +1406,16 @@ a.yuimenuitemlabel:hover { color : #000; } +#displayexample { + padding: 5px; + margin-bottom: 10px; + background-color: #CCCCCC; +} + +#irregularity_summary { + vertical-align : top; +} + #toplevelnav { float : left; margin-left : .5em; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl index 7ca71431a5..c0f3c21ef0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl @@ -11,6 +11,39 @@ var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_(" _("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year")); var is_season = 0; var is_hemisphere = 1; +var irregular_issues; // will hold irregularity object. + + + var weeks = new Array(); + + +function formatDate(myDate) { + var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate()); + if(d[1].toString().length == 1) { d[1] = '0'+d[1] }; + if(d[2].toString().length == 1) { d[2] = '0'+d[2] }; + + return(d[1] + '/' + d[2] + '/' + d[0]) ; + + return(d[2] + '/' + d[1] + '/' + d[0]) ; + + return(''+d[0] + '-' + d[1] + '-' + d[2]) ; + +} + +Date.prototype.addDays = function(days) { + this.setDate(this.getDate()+days); +} + +function getWeeksArray(startDate) { +// returns a 52 element array with dates starting with startDate. + var weeksArray = new Array; + var myDate = new Date; + for(var i=0;i<52;i++) { + startDate.addDays( 7 ); + weeksArray[i] = formatDate(startDate); + } + return weeksArray; +} function YMDaToYWDa(S) { with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) { @@ -33,8 +66,64 @@ return ddiff+1; } +// create irregularity object. +function IrregularPattern() { + this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December")); + this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall")); + this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday")); + + this.weeks = new Array(); + + this.numskipped = 0; + // init: + var irregular = ''; + // var periodicity = document.f.periodicity.value; + this.skipped = irregular.split(','); +} + +IrregularPattern.prototype.update = function() { + this.skipped= new Array; + var cnt = 0; + // daily periodicity, we interpret irregular array as which days of week to skip. + // else irregular array is list of issues to skip + var summary_str = ''; + this.numskipped = 0; + for( var i in document.f.irregularity_select.options ) { + if( document.f.irregularity_select.options[i].selected ) { + this.skipped[cnt] = document.f.irregularity_select.options[i].value ; + summary_str += document.f.irregularity_select.options[i].text + "\n" ; + cnt++; + this.numskipped++; + } + } + var summary = document.getElementById("irregularity_summary"); + if(summary) { + summary.value = summary_str; + summary.rows= ( cnt > 6 ) ? cnt : 6 ; + } +} + +IrregularPattern.prototype.irregular = function(index) { + for( var i in this.skipped) { + if( this.skipped[i] == index) { + return true; + } + } + return false; +} + +function init_pattern() { + irregular_issues = new IrregularPattern(); +} +function reset_pattern() { + document.getElementById("numberpattern").value = ''; +// document.getElementById("numberpattern").value = ''; + init_pattern(); + reset_num_pattern(); + +} // common pre defined number patterns -function num_pattern() { +function reset_num_pattern() { var patternchoice = document.getElementById("numberpattern").value; switch(patternchoice){ case "2": @@ -50,9 +139,9 @@ var patternchoice = document.getElementById("numberpattern").value; document.f.setto1.value=0; document.f.setto2.value=1; document.f.setto3.value=1; -/* document.f.lastvalue1.value=1; + document.f.lastvalue1.value=1; document.f.lastvalue2.value=1; - document.f.lastvalue3.value=1;*/ + document.f.lastvalue3.value=1; document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}"); moreoptions(text[1],text[0],text[2]); display_table(0); // toggle info box on (1) or off (0) @@ -70,9 +159,9 @@ var patternchoice = document.getElementById("numberpattern").value; document.f.setto1.value=0; document.f.setto2.value=1; document.f.setto3.value=''; -/* document.f.lastvalue1.value=1; + document.f.lastvalue1.value=1; document.f.lastvalue2.value=1; - document.f.lastvalue3.value='';*/ + document.f.lastvalue3.value=''; document.f.numberingmethod.value=_("Vol {X}, No {Y}"); moreoptions(text[1],text[0]); display_table(0); @@ -90,6 +179,9 @@ var patternchoice = document.getElementById("numberpattern").value; document.f.setto1.value=0; document.f.setto2.value=1; document.f.setto3.value=''; + document.f.lastvalue1.value=1; + document.f.lastvalue2.value=1; + document.f.lastvalue3.value=''; document.f.numberingmethod.value=_("Vol {X}, Issue {Y}"); moreoptions(text[1],text[2]); display_table(0); @@ -158,7 +250,6 @@ var patternchoice = document.getElementById("numberpattern").value; document.f.setto1.value=0; document.f.setto2.value=1; document.f.setto3.value=''; -// document.f.setto3.value=''; if (document.f.lastvalue1.value==0){document.f.lastvalue1.value=sYear}; if (document.f.lastvalue2.value==0 ||document.f.lastvalue2.value=='' ){ switch (document.f.periodicity.value){ @@ -223,11 +314,12 @@ var patternchoice = document.getElementById("numberpattern").value; document.f.setto1.value=0; document.f.setto2.value=''; document.f.setto3.value=''; -/* document.f.lastvalue1.value=1; + document.f.lastvalue1.value=1; document.f.lastvalue2.value=''; - document.f.lastvalue3.value='';*/ + document.f.lastvalue3.value=''; document.f.numberingmethod.value='{X}'; - moreoptions_daily_check(text[0]); +// moreoptions_daily_check(text[0]); + moreoptions(text[0]); document.f.irreg_check.value=1; display_table(0); break; @@ -237,15 +329,18 @@ var patternchoice = document.getElementById("numberpattern").value; function display_table(n) { if(n==1){ document.getElementById("basetable").style.display = 'block'; - } else { + } else if(n==0){ document.getElementById("basetable").style.display = 'none'; - } + } else { + var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ; + document.getElementById("basetable").style.display = disp_val; + } } -function modify_num_pattern() { +function set_num_pattern_from_template_vars() { if(!document.getElementById("numberpattern")){ return false; } document.getElementById("numberpattern").value = ''; - num_pattern(); + reset_num_pattern(); document.f.add1.value=''; document.f.add2.value=''; @@ -276,7 +371,6 @@ function modify_num_pattern() { more_strZ="Z"; } - document.f.lastvaluetemp1.value=''; if(more_strY){ document.f.lastvaluetemp2.value=''; @@ -289,15 +383,15 @@ function modify_num_pattern() { } // a pre check with more options to see if 'number' and '1/day' are chosen + function moreoptions_daily_check(x) { var periodicity = document.f.periodicity.value; var errortext=''; - if(periodicity == 1){ + if(periodicity == 1){ // i.e. daily document.getElementById("irregularity").innerHTML = ''; - var daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday")); errortext =_("Please indicate which days of the week you DO NOT<\/b> expect to receive issues.
"); - for(var j=0;j"+daynames[j]+"   "; + for(var j=0;j"+irregular_issues.daynames[j]+"   "; } var error = errortext; moreoptions(x); @@ -309,6 +403,7 @@ function moreoptions_daily_check(x) { } } + // to dispaly the more options section function moreoptions(x,y,z){ document.getElementById("irregularity").innerHTML = ''; @@ -334,14 +429,14 @@ var textbox = ''; textbox +="<\/tr>\n"; if(y){ textbox +=""+text[6]+"<\/th>"; - textbox +=""+_("Irregularity?")+"<\/a><\/td>\n"; + textbox +=" <\/td>\n"; textbox +="<\/td>\n"; if(z){ textbox +="<\/td>\n"; } textbox +="<\/tr>"; } else { - textbox +=" "+_("issues expected")+"
"+_("Irregularity?")+""; + textbox +=" "+_("issues expected")+""; } textbox +="<\/table>\n"; } @@ -354,7 +449,7 @@ var selbox = document.getElementById("season1"); var selboxselected = selbox.options[selbox.selectedIndex].value; selbox.options.length = 0; - if (chosen == "1") { + if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) { selbox.options[selbox.options.length] = new Option(text[11],'1'); selbox.options[selbox.options.length] = new Option(text[12],'2'); selbox.options[selbox.options.length] = new Option(text[13],'3'); @@ -363,7 +458,7 @@ var selbox = document.getElementById("season1"); selbox.options[selboxselected-1].selected = true; } - if (chosen == "2") { + if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) { selbox.options[selbox.options.length] = new Option(text[13],'1'); selbox.options[selbox.options.length] = new Option(text[10],'2'); selbox.options[selbox.options.length] = new Option(text[11],'3'); @@ -374,7 +469,7 @@ var selbox = document.getElementById("season1"); } } -// to dispaly the more options section for seasons +// to display the more options section for seasons function moreoptions_seasons(x,y){ document.getElementById("irregularity").innerHTML = ''; document.getElementById("more_options").innerHTML = ''; @@ -404,7 +499,6 @@ var textbox = ''; } textbox +="<\/select><\/td><\/tr>\n"; textbox +=""+text[6]+"<\/th>"; - textbox +=""+_("Irregularity?")+"<\/a><\/td>\n"; textbox +="<\/td>\n"; textbox +="<\/tr><\/table>\n"; @@ -416,11 +510,15 @@ function irregularity_check(){ document.f.irreg_check.value = 1; // Irregularity button now pushed var periodicity = document.f.periodicity.value; var rollover = document.f.issuesexpected1.value; - if(document.f.whenmorethantemp2){ - rollover = document.f.whenmorethantemp2.value; + if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){ + rollover = document.f.whenmorethan2.value; } - if(document.f.whenmorethantemp3){ - rollover = document.f.whenmorethantemp3.value; + if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){ + // FIXME: This assumes that whenmorethan3 issues are published in one year. + // the other option is that whenmorethan3 * whenmorethan2 issues are published, + // e.g. where there are two volumes of six issues each in one year. + // a way to distinguish between these two cases is needed. + rollover = document.f.whenmorethan3.value; } var error=''; var toobig; @@ -515,24 +613,19 @@ function irregularity_check(){ break; } if(expected){ - if(expected == 365 || expected==730){ - var daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday")); + if(expected == 365 || expected==730){ // what about leap years ? + // FIXME: We interpret irregularity as which days per week for periodicity==1. + // We need two cases: one in which we're published n days/week, in which case irregularity should be per week, + // and a regular daily pub, where irregularity should be per year. errortext += _("Please indicate which days of the week you DO NOT<\/b> expect to receive issues.
"); - for(var j=0;j"+daynames[j]+"   "; - } - error=errortext; } else { errortext +=expected+_(" issues expected, ")+rollover+_(" were entered.
Please indicate which date(s) an issue is not expected
"); - var count=0; - for(var i=rollover;i\n"; - errortext +=irregular_options(periodicity); - errortext +="<\/select>\n"; - count++; - } - error=errortext; - } + irregular_issues.numskipped = expected - rollover; + } + errortext +="\n