[Koha-patches] [PATCH] Add ajax function to return new weeks array in irregularities check: BUG 1842

Joshua Ferraro jmf at liblime.com
Mon Jul 28 13:37:26 CEST 2008


Ryan, let me know if you'd like to refactor this to use jquery and
I'll hold off on applying it.

On Sun, Jul 27, 2008 at 7:30 PM, Jesse Weaver <jesse.weaver at liblime.com> wrote:
>
>
> On Sun, Jul 27, 2008 at 12:25 PM, Ryan Higgins <rch at liblime.com> wrote:
>>
>> ---
>>  .../prog/en/modules/serials/subscription-add.tmpl  |   40
>> ++++++++++++++++++--
>>  serials/serials_planning_ajax.pl                   |   31 +++++++++++++++
>>  2 files changed, 67 insertions(+), 4 deletions(-)
>>  create mode 100755 serials/serials_planning_ajax.pl
>>
>> 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 134a72a..b048091 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,41 @@ var text = new
>> Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("
>>
>>  _("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
>>  var is_season = 0;
>>  var is_hemisphere = 1;
>> +<!-- TMPL_IF NAME="weekarrayjs" -->
>> +    var weeks = new Array(<!-- TMPL_VAR NAME="weekarrayjs" -->);
>> +<!-- /TMPL_IF -->
>> +function xmlhttpPost(strURL) {
>> +    var xmlHttpReq = false;
>> +    var self = this;
>> +    // Mozilla/Safari
>> +    if (window.XMLHttpRequest) {
>> +        self.xmlHttpReq = new XMLHttpRequest();
>> +    }
>> +    // IE
>> +    else if (window.ActiveXObject) {
>> +        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
>> +    }
>> +    self.xmlHttpReq.open('POST', strURL, true);
>> +    self.xmlHttpReq.setRequestHeader('Content-Type',
>> 'application/x-www-form-urlencoded');
>> +    self.xmlHttpReq.onreadystatechange = function() {
>> +        if (self.xmlHttpReq.readyState == 4) {
>> +            updatepage(self.xmlHttpReq.responseText);
>> +        }
>> +    }
>> +    self.xmlHttpReq.send(getquerystring());
>> +}
>> +function getquerystring() {
>> +    var firstdate = document.getElementById("acqui_date").value;
>> +       qstr = 'start=' + escape(firstdate) ;
>> +    return qstr;
>> +}
>> +
>> +function updatepage(str){
>> +    //document.getElementById("notes").innerHTML = str;
>> +       weeks = eval("(" + str + ")");
>> +       var titles = weeks;
>> +}
>> +
>>
>>  function YMDaToYWDa(S) {
>>     with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
>> @@ -548,9 +583,6 @@ function irregularity_check(){
>>  function irregular_options(periodicity){
>>     var titles;
>>     var count;
>> -<!-- TMPL_IF NAME="weekarrayjs" -->
>> -    var weeks = new Array(<!-- TMPL_VAR NAME="weekarrayjs" -->);
>> -<!-- /TMPL_IF -->
>>     var months = new
>> Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
>>     var seasons = new
>> Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
>>     var errortext='';
>> @@ -918,7 +950,7 @@ window.onload = irregular_order();
>>            <label for="firstacquidate"> First issue publication
>> date:</label>
>>
>>                 <img src="<!-- TMPL_VAR Name="themelang"
>> -->/lib/calendar/cal.gif" id="button2" style="cursor: pointer;" alt="Show
>> Calendar" title="Show Calendar" />
>> -                <input type="text" name="firstacquidate" value="<!--
>> TMPL_VAR name="firstacquidate" -->" size="13" maxlength="10" id="acqui_date"
>> style="border-width: 0px;" />
>> +                <input type="text" name="firstacquidate" value="<!--
>> TMPL_VAR name="firstacquidate" -->" size="13" maxlength="10" id="acqui_date"
>> style="border-width: 0px;"
>> onchange='JavaScript:xmlhttpPost("/cgi-bin/koha/serials/serials_planning_ajax.pl");
>> return false;'  />
>>                 <!-- both scripts for calendar must follow the input field
>> -->
>>                 <script type="text/javascript">
>>                     Calendar.setup({
>> diff --git a/serials/serials_planning_ajax.pl
>> b/serials/serials_planning_ajax.pl
>> new file mode 100755
>> index 0000000..200371a
>> --- /dev/null
>> +++ b/serials/serials_planning_ajax.pl
>> @@ -0,0 +1,31 @@
>> +#!/usr/bin/perl
>> +
>> +use strict;
>> +use warnings;
>> +use CGI;
>> +use Date::Calc qw( Add_Delta_Days Weeks_in_Year Week_of_Year
>> Monday_of_Week);
>> +use C4::Auth;
>> +use C4::Context;
>> +use C4::Dates;
>> +
>> +my $query = new CGI;
>> +my ( $user, $cookie, $sessionID, $flags ) = checkauth( $query , 0,
>> {serials => 1} , "intranet");
>> +if($user) {
>> +       # using dates in Date::Calc format of (year, month, day)
>> +       my @startdate = split( /-/, C4::Dates->new(
>> $query->param('start'))->output('iso'));
>> +       my $numweeks = $query->param('n');
>> +       my ($week,$yr) = Week_of_Year(@startdate);
>> +       my @weeks;
>> +       my $thisyear=$yr;
>> +       my @thisweek = @startdate;
>> +       for ( my $i=$week ; $i<$week+Weeks_in_Year($yr) ; $i++ ) {
>> +               $thisyear++ if ($i>Weeks_in_Year($yr) );
>> +               @thisweek = Add_Delta_Days(@thisweek , 7);
>> +               my $weeknumber = Week_of_Year(@thisweek);
>> +               my $weekdate =  C4::Dates->new(
>> sprintf("%4d-%02d-%02d", at thisweek),'iso')->output() ;
>> +               push @weeks, "$weekdate ( $weeknumber )";
>> +       }
>> +       print $query->header;
>> +
>> +       print "[ '" . join("' , '", at weeks) . "' ]";
>> +}
>> --
>> 1.5.5.GIT
>
> Why make a new ajax request function when jQuery has it built in?
> http://docs.jquery.com/Ajax
>
> _______________________________________________
> Koha-patches mailing list
> Koha-patches at lists.koha.org
> http://lists.koha.org/mailman/listinfo/koha-patches
>
>



-- 
Joshua Ferraro SUPPORT FOR OPEN-SOURCE SOFTWARE
CEO migration, training, maintenance, support
LibLime Featuring Koha Open-Source ILS
jmf at liblime.com |Full Demos at http://liblime.com/koha |1(888)KohaILS



More information about the Koha-patches mailing list