Changeset 2904

Show
Ignore:
Timestamp:
05/12/10 17:30:02
Author:
johnsa
Message:

user client: more work on the "meeting" tab, refactoring javascript widget

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/deployment/webuser/webapp/resources/demoskins/themes/bedeworkTheme/head.xsl

    r2903 r2904  
    174174        // send params: displayId, startRange, endRange, startDate, endDate, startHourRange, endHourRange, attendees, workday, zoom, browserResourcesRoot, fbUrl, organizerUri 
    175175        // example: var bwGrid = new bwSchedulingGrid("bwFreeBusyDisplay","May 5, 2010","May 17, 2010","May 10, 2010 11:00:00","May 10, 2010 11:30:00",8,17,[{name:"Arlen Johnson",uid:"mailto:johnsa@rpi.edu",role:"CHAIR",status:"ACCEPTED",type:"person"}],true,100,"<xsl:value-of select="$resourcesRoot"/>","<xsl:value-of select="$requestFreeBusy"/>",""); 
    176         var bwGrid = new bwSchedulingGrid("bwFreeBusyDisplay","May 5, 2010","May 17, 2010","May 10, 2010 11:00:00","May 10, 2010 11:30:00",8,17,[],true,100,"<xsl:value-of select="$resourcesRoot"/>","<xsl:value-of select="$resourcesRoot"/>/javascript/freebusy.js",""); 
     176        var bwGrid = new bwSchedulingGrid("bwFreeBusyDisplay","May 11, 2010","May 17, 2010","May 13, 2010 11:00:00","May 13, 2010 11:30:00",8,17,[{name:"Arlen Johnson",uid:"mailto:johnsa@mysite.edu",role:"CHAIR",status:"ACCEPTED",type:"person"},{name:"",uid:"mailto:douglm@mysite.edu",role:"REQ-PARTICIPANT",status:"NEEDS-ACTION",type:"person"}],true,100,"<xsl:value-of select="$resourcesRoot"/>","<xsl:value-of select="$resourcesRoot"/>/javascript/freebusy.js",""); 
    177177         
    178178        // send in some attendees - these will come from interaction with the form 
    179         bwGrid.updateAttendee("Arlen Johnson", "mailto:johnsa@mysite.edu", "CHAIR", "ACCEPTED", "person"); 
    180         bwGrid.updateAttendee("Gary Schwartz", "mailto:schwag@mysite.edu", "REQ-PARTICIPANT", "NEEDS-ACTION"); 
    181         bwGrid.updateAttendee("", "mailto:douglm@mysite.edu", "OPT-PARTICIPANT", "DECLINED"); 
     179        // bwGrid.updateAttendee("Gary Schwartz", "mailto:schwag@mysite.edu", "OPT-PARTICIPANT", "DECLINED"); 
    182180         
    183181        // now initialize the grid 
  • trunk/deployment/webuser/webapp/resources/demoskins/themes/bedeworkTheme/javascript/bedeworkScheduling.js

    r2903 r2904  
    8686     
    8787  // function to populate the freebusy objects 
    88   // freebusyStrings: Array of rfc5545 freebusy reply values for the current attendee in the current date range  
    89   this.updateFreeBusy = function(fbStrings) { 
    90     // empty the freebusy array (to refresh on updates) 
    91     this.freebusy.length = 0; 
    92     // push the new freebusy strings into the array 
    93     for (i = 0; i<fbStrings.length; i++) { 
    94       var fb = new bwFreeBusy(fbStrings[i]); 
    95       this.freebusy.push(fb); 
    96     } 
    97   }  
     88  // fbObj: JSON representation of rfc5545 freebusy reply values and types for the current attendee in the current date range  
     89  //        as supplied by Bedework 
     90  
     91  this.updateFreeBusy = function(fbObj) { 
     92    if (fbObj) { 
     93      // empty the freebusy array (to refresh on updates) 
     94      this.freebusy.length = 0; 
     95      // push the new freebusy strings into the array 
     96      for (var i = 0; i < fbObj.length; i++) { 
     97        var type = fbObj[i].fbtype.value; 
     98        for (var j = 0; j < fbObj[i].periods.length; j++) { 
     99          var fb = new bwFreeBusy(fbObj[i].periods[j].value, type); 
     100          this.freebusy.push(fb);           
     101        } 
     102      }   
     103    } 
     104  } 
    98105} 
    99106 
    100107/* A Freebusy object 
    101108 * Provides methods to work on freebusy values 
    102  * fbString: an rfc5545 freebusy string, including FBTYPE parameter if present  
     109 * fbString: an rfc5545 freebusy string  
     110 * fbType:   rfc5545 FBTYPE parameter  
    103111 */ 
    104 var bwFreeBusy = function(fbString) { 
    105   this.name = fbString;   
    106   this.params = "";    // if there are parameters, we will split them from the name and put them here 
    107   this.type = bwFreeBusyDispTypeBusy; // default rfc5545 FBTYPE, "BUSY" 
     112var bwFreeBusy = function(fbString, fbType) { 
     113  this.value = fbString;   
     114  this.params = "";   // placeholder for parameters if we use them 
     115  this.type = fbType;  
     116  this.typeDisplay = bwFreeBusyDispTypeBusy; // default rfc5545 FBTYPE, "BUSY" 
    108117  this.start = "";    // will hold the UTC start value in milliseconds  
    109118  this.end = "";      // will hold the UTC end value in milliseconds 
    110119   
    111   if (this.name.match(":")) { 
    112     // parameters are included with the freebusy string 
    113     // e.g. FBTYPE=BUSY:19980415T133000Z/19980415T170000Z  
    114     this.name = fbString.substr(fbString.indexOf(":")+1); 
    115     this.params = fbString.substring(0,fbString.indexOf(":")); 
    116   } 
    117    
    118   if (this.params.match("FBTYPE=BUSY-TENTATIVE")) { 
    119     this.type = bwFreeBusyDispTypeTentative; 
     120  if (this.type = "BUSY-TENTATIVE") { 
     121    this.typeDisplay = bwFreeBusyDispTypeTentative; 
    120122  } 
    121123   
    122124  // set the freebusy start date 
    123125  var startDate = new Date(); 
    124   startDate.setUTCFullYear(this.name.substring(0,4),this.name.substring(4,6)-1,this.name.substring(6,8)); 
    125   startDate.setUTCHours(this.name.substring(9,11),this.name.substring(11,13),this.name.substring(13,15)); 
     126  startDate.setUTCFullYear(this.value.substring(0,4),this.value.substring(4,6)-1,this.value.substring(6,8)); 
     127  startDate.setUTCHours(this.value.substring(9,11),this.value.substring(11,13),this.value.substring(13,15)); 
    126128   
    127129  // set the start in milliseconds 
     
    129131 
    130132  var endMs; // end in milliseconds 
    131   if (this.name.indexOf("P") > -1) { 
     133  if (this.value.indexOf("P") > -1) { 
    132134    // freebusy value is of the form: 19971015T223000Z/PT6H30M 
    133135    // extract the hours and minutes from the strings and cast as numbers   
    134     var durationHours = this.name.substring(this.name.lastIndexOf("T")+1,this.name.indexOf("H")); 
    135     var durationMins = this.name.substring(this.name.indexOf("H")+1,this.name.indexOf("M")); 
     136    var durationHours = this.value.substring(this.value.lastIndexOf("T")+1,this.value.indexOf("H")); 
     137    var durationMins = 0; 
     138    if (this.value.indexOf("M") > -1) { 
     139      durationMins = this.value.substring(this.value.indexOf("H") + 1, this.value.indexOf("M")); 
     140    } 
    136141    // calculate the duration 
    137142    var duration = (Number(durationHours) * 3600000) + (Number(durationMins) * 60000); 
     
    142147    // set the freebusy end date 
    143148    var endDate = new Date(); 
    144     endDate.setUTCFullYear(this.name.substring(17,21),this.name.substring(21,23)-1,this.name.substring(23,25)); 
    145     endDate.setUTCHours(this.name.substring(26,28),this.name.substring(28,30),this.name.substring(30,32)); 
     149    endDate.setUTCFullYear(this.value.substring(17,21),this.value.substring(21,23)-1,this.value.substring(23,25)); 
     150    endDate.setUTCHours(this.value.substring(26,28),this.value.substring(28,30),this.value.substring(30,32)); 
    146151    endMs = endDate.getTime(); 
    147152  } 
     
    225230    // initialize any incoming attendees on first load 
    226231    // while iterating, build up the array of requests  
    227     for (i = 0; i < attendees.length; i++) { 
     232    for (var i = 0; i < attendees.length; i++) { 
    228233      var newAttendee = new bwAttendee(attendees[i].name,attendees[i].uid, attendees[i].role,attendees[i].status,attendees[i].type); 
    229234      this.attendees.push(newAttendee);  
     
    231236     
    232237    // now go get the freebusy information for the attendees 
    233     this.requestFreeBusy(this.fbUrl); 
     238    if (this.attendees.length) { 
     239      this.requestFreeBusy(this.fbUrl); 
     240    } 
    234241  } 
    235242   
    236243  // add/update attendees 
    237244  /* examples: 
    238      bwGrid.updateAttendee("Venerable Bede", "mailto:vbede@mysite.edu", ["20100421T093000Z/PT2H00M","20100423T174500Z/PT8H30M"], "CHAIR", "ACCEPTED", "person"); 
    239      bwGrid.updateAttendee("Samual Clemens", "mailto:sclemens@mysite.edu", ["20100422T090000Z/PT1H00M"], "REQ-PARTICIPANT", "NEEDS-ACTION"); 
    240      bwGrid.updateAttendee("", "mailto:noname@mysite.edu", ["FBTYPE=BUSY-TENTATIVE:20100421T120000Z/20100421T130000Z","20100422T050000Z/20100422T060000Z"], "OPT-PARTICIPANT", "DECLINED"); 
     245     bwGrid.updateAttendee("Venerable Bede", "mailto:vbede@mysite.edu", "CHAIR", "ACCEPTED", "person"); 
     246     bwGrid.updateAttendee("Samual Clemens", "mailto:sclemens@mysite.edu", "REQ-PARTICIPANT", "NEEDS-ACTION"); 
     247     bwGrid.updateAttendee("", "mailto:noname@mysite.edu", "OPT-PARTICIPANT", "DECLINED"); 
    241248   */ 
    242249  this.updateAttendee = function(name, uid, role, status, type) { 
     
    245252     
    246253    // check to see if attendee already exists 
    247     for (i=0; i < this.attendees.length; i++) { 
    248       //alert(newAttendee.uid + " -- " + this.attendees[i].uid); 
     254    for (var i=0; i < this.attendees.length; i++) { 
    249255      if (newAttendee.uid == this.attendees[i].uid) { 
    250256        attendeeIsNew = false; 
     
    254260     
    255261    if (attendeeIsNew) { 
    256       this.attendees.push(newAttendee);       
    257     } 
    258      
    259     this.display(); 
     262      this.attendees.push(newAttendee);  
     263      this.requestFreeBusy(this.fbUrl);       
     264    } 
     265     
    260266  } 
    261267   
    262268  this.removeAttendee = function(index) { 
    263269    this.attendees.splice(index, 1); 
    264     this.display(); 
     270    this.requestFreeBusy(this.fbUrl);  
    265271  } 
    266272   
    267273  this.requestFreeBusy = function(fburl) { 
    268274    $.getJSON(fburl, function(fb) { 
    269       for (i=0; i < fb.microformats["schedule-response"].length; i++) { 
     275      for (var i=0; i < fb.microformats["schedule-response"].length; i++) { 
    270276        var r = fb.microformats["schedule-response"][i]; // reference the current response 
    271  
    272         // prepare the freebusy strings for the attendee 
    273         var fbStrings = new Array(); 
    274         for (j=0; j < r["calendar-data"].freebusy.periods.length; j++) { 
    275           fbStrings[j] = r["calendar-data"].freebusy.periods[j].value; 
    276         } 
    277  
    278         // find the attendee and update freebusy 
    279         for (j=0; j < bwGrid.attendees.length; j++) { 
    280           //alert(r["calendar-data"].attendee[0].value + " : " + bwGrid.attendees[j].uid); 
    281           if (r["calendar-data"].attendee[0].value == bwGrid.attendees[j].uid) { 
    282             bwGrid.attendees[j].updateFreeBusy(fbStrings); 
     277         
     278        // find the attendee and pass in the freebusy object 
     279        for (var j=0; j < bwGrid.attendees.length; j++) { 
     280          if (bwGrid.attendees[j].uid == r["calendar-data"].attendee[0].value) { 
     281            bwGrid.attendees[j].updateFreeBusy(r["calendar-data"].freebusy); 
    283282          } 
    284283        } 
     
    347346    // now look over the next group of cells to see if the range 
    348347    // we want to select is busy.  If not, store the value for lookup. 
    349     for (i=0; i <= this.fb.length - cellsInDuration; i++) { 
     348    for (var i=0; i <= this.fb.length - cellsInDuration; i++) { 
    350349      var rangeNotBusy = true; 
    351       for (j = i; j < i + cellsInDuration; j++) { 
     350      for (var j = i; j < i + cellsInDuration; j++) { 
    352351        if (this.fb[j][1]) { // we hit a busy cell 
    353352          rangeNotBusy = false;  
     
    388387      var fbDisplayDateRow = fbDisplay.insertRow(fbDisplay.rows.length); 
    389388      $(fbDisplayDateRow).html('<td rowspan="2" colspan="4" class="corner"></td><td class="fbBoundry"></td>'); 
    390       for (i=0; i < range; i++) { 
     389      for (var i=0; i < range; i++) { 
    391390        var curDate = new Date(this.startRange);  
    392391        curDate.addDays(i); 
     
    397396      fbDisplayTimesRow = fbDisplay.insertRow(fbDisplay.rows.length); 
    398397      $(fbDisplayTimesRow).html('<td class="fbBoundry"></td>'); 
    399       for (i=0; i < range; i++) { 
     398      for (var i=0; i < range; i++) { 
    400399        var curDate = new Date(this.startRange);  
    401400        curDate.setHours(startHour); 
     
    419418      $(fbDisplayTimesRow).addClass("allAttendees"); 
    420419      $(fbDisplayTimesRow).html('<td class="status"></td><td class="role"></td><td class="name">All Attendees</td><td></td><td class="fbBoundry"></td>'); 
    421       for (i=0; i < range; i++) { 
     420      for (var i=0; i < range; i++) { 
    422421        var curDate = new Date(this.startRange);  
    423422        curDate.setHours(startHour); 
    424423        curDate.addDays(i); 
    425424        // add the time cells by iterating over the hours 
    426         for (j = 0; j < hourRange; j++) { 
    427           for (k = 0; k < this.hourDivision; k++) { 
     425        for (var j = 0; j < hourRange; j++) { 
     426          for (var k = 0; k < this.hourDivision; k++) { 
    428427            var fbCell = document.createElement("td"); 
    429428            var timeClass = curDate.getTime().toString(); 
     
    438437            // set busy if any freebusy in this timeperiod 
    439438            loop1: // since we only need to know if anyone is busy, provide a simple means of breaking from the inner loop 
    440             for (att = 0; att < this.attendees.length; att++) { 
    441               for (m = 0; m < this.attendees[att].freebusy.length; m++) { 
     439            for (var att = 0; att < this.attendees.length; att++) { 
     440              for (var m = 0; m < this.attendees[att].freebusy.length; m++) { 
    442441                var tzoffset = -curDate.getTimezoneOffset() * 60000; // in milliseconds 
    443442                // adding the hourdivision increment in the calculation below is to correct for a bug 
     
    535534         
    536535        // build the time row for an attendee 
    537         for (i = 0; i < range; i++) { 
     536        for (var i = 0; i < range; i++) { 
    538537          var curDate = new Date(this.startRange); 
    539538          curDate.setHours(startHour); 
    540539          curDate.addDays(i); 
    541540          // add the time cells by iterating over the hours 
    542           for (j = 0; j < hourRange; j++) { 
    543             for (k = 0; k < this.hourDivision; k++) { 
     541          for (var j = 0; j < hourRange; j++) { 
     542            for (var k = 0; k < this.hourDivision; k++) { 
    544543              var fbCell = document.createElement("td"); 
    545544              fbCell.id = curDate.getTime() + "-" + curAttendee.uid.substr(curAttendee.uid.lastIndexOf(":") + 1); 
     
    549548                $(fbCell).addClass("hourBoundry"); 
    550549              } 
    551               for (m = 0; m < curAttendee.freebusy.length; m++) { 
     550              for (var m = 0; m < curAttendee.freebusy.length; m++) { 
    552551                var tzoffset = -curDate.getTimezoneOffset() * 60000; // in milliseconds 
    553552                // adding the hourdivision increment in the calculation below is to correct for a bug 
     
    555554                var curDateUTC = curDate.getTime() + tzoffset + (60 / this.hourDivision * 60000); 
    556555                if (curAttendee.freebusy[m].contains(curDateUTC)) { 
    557                   if (curAttendee.freebusy[m].type.match("TENTATIVE")) { 
     556                  if (curAttendee.freebusy[m].typeDisplay.match("TENTATIVE")) { 
    558557                    $(fbCell).addClass("tentative"); 
    559558                  } else { 
     
    561560                  } 
    562561                  $(fbCell).addClass("activeCell"); 
    563                   $(fbCell).append('<span class="tip">' + curAttendee.freebusy[m].type + '</span>'); 
     562                  $(fbCell).append('<span class="tip">' + curAttendee.freebusy[m].typeDisplay + '</span>'); 
    564563                  break; 
    565564                } 
     
    573572      } 
    574573       
     574      /* DEPRECATED - don't put in grid 
    575575      // generate the "add attendee" row 
    576576      fbDisplayAddAttendeeRow = fbDisplay.insertRow(fbDisplay.rows.length); 
     
    607607        } 
    608608        $(fbDisplayAddAttendeeRow).append('<td class="dayBoundry"></td>'); 
    609       } 
     609      } */ 
    610610       
    611611      // generate a blank row at the end (this is just for visual padding) 
    612612      fbDisplayBlankRow = fbDisplay.insertRow(fbDisplay.rows.length); 
    613613      $(fbDisplayBlankRow).html('<td class="status"></td><td class="role"></td><td class="name"></td><td></td><td class="fbBoundry"></td>'); 
    614       for (i = 0; i < range; i++) { 
     614      for (var i = 0; i < range; i++) { 
    615615        var curDate = new Date(this.startRange); 
    616616        curDate.setHours(startHour); 
    617617        curDate.addDays(i); 
    618618        // add the time cells by iterating over the hours 
    619         for (j = 0; j < hourRange; j++) { 
    620           for (k = 0; k < this.hourDivision; k++) { 
     619        for (var j = 0; j < hourRange; j++) { 
     620          for (var k = 0; k < this.hourDivision; k++) { 
    621621            var fbCell = document.createElement("td"); 
    622622            fbCell.id = curDate.getTime() + "-blank"; 
     
    683683           
    684684          // set the freeTimeIndex to the nearest index for the pickNext/previous buttons 
    685           for (i = 0; i < bwGrid.freeTime.length; i++) { 
     685          for (var i = 0; i < bwGrid.freeTime.length; i++) { 
    686686            if (Number(bwGrid.freeTime[i]) >= Number(startSelectionMils)) { 
    687687              bwGrid.freeTimeIndex = i - 1; // this will make pick previous jump an extra gap after clicking in a busy space, but it makes pick next work correctly in the same circumstance 
  • trunk/deployment/webuser/webapp/resources/demoskins/themes/bedeworkTheme/javascript/freebusy.js

    r2903 r2904  
    3434                            "periods" : [ 
    3535                                { 
    36                                     "value" : "20100513T180000Z\/PT2H" 
     36                                    "value" : "20100513T180000Z/PT2H" 
    3737                                }, 
    3838                                { 
    39                                     "value" : "20100514T120000Z\/PT4H" 
     39                                    "value" : "20100514T120000Z/PT4H" 
    4040                                }  
    4141                            ]  
     
    7676                            "periods" : [ 
    7777                                { 
    78                                     "value" : "20100512T180000Z\/PT3H" 
     78                                    "value" : "20100512T180000Z/PT3H" 
    7979                                }, 
    8080                                { 
    81                                     "value" : "20100514T140000Z\/PT1H" 
     81                                    "value" : "20100514T140000Z/PT1H" 
    8282                                }  
    8383                            ]