Changeset 2887

Show
Ignore:
Timestamp:
04/28/10 17:06:14
Author:
johnsa
Message:

ongoing update to free/busy mockup - pick next/pick previous

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/deployment/webuser/webapp/resources/demoskins/fbMockup/bedeworkFb.js

    r2886 r2887  
    176176  this.attendees = new Array();  // array of bwAttendee objects 
    177177   
     178  // 2D array of time and busy state for all attendees 
     179  // [millisecond value,true/false if busy] 
     180  // this value is initialized when we draw the allAttendees row 
     181  this.fb = new Array();   
     182  // a lookup table of free times based on the duration of the meeting, calculated from the fb array 
     183  this.freeTime = new Array(); 
     184  this.freeTimeIndex = 0; 
     185   
    178186  // initialize any incoming attendees on first load 
    179187  for (i = 0; i < attendees.length; i++) { 
     
    207215  } 
    208216   
    209   this.pickNext = function(gridObj) { 
     217  this.pickNext = function() { 
    210218    // clear highlighting 
    211219    $("#bwScheduleTable .fbcell").removeClass("highlight"); 
    212220     
    213     // increment the start time 
    214     startSelectionMils = Number(startSelectionMils) + Number(incrementMils); 
    215     // set the end time based on duration 
    216     endSelectionMils = Number(startSelectionMils) + Number(durationMils); 
    217      
    218     // highlight the cells if no collision, otherwise try the next spot 
    219     $("#bwScheduleTable .fbcell").each(function(index) { 
    220       var splId = $(this).attr("id").split("-"); 
    221       if (splId[0] >= startSelectionMils && splId[0] < endSelectionMils) { 
    222         if ($(this).hasClass("busy")) { 
    223            alert("hit a busytime!"); 
    224            //this.pickNext(); 
    225         } else { 
    226           $(this).addClass("highlight"); 
    227         } 
    228       } 
     221    // go to the next freeTime if available and highlight it 
     222    if (this.freeTimeIndex < this.freeTime.length - 1) { 
     223      this.freeTimeIndex += 1; 
     224    } 
     225    var curSelectionTime = Number(this.freeTime[this.freeTimeIndex]); 
     226    $("#bwScheduleTable ." + curSelectionTime).each(function(index) { 
     227      //if (curSelectionTime >= startSelectionMils && curSelectionTime < endSelectionMils) { 
     228        $(this).addClass("highlight"); 
     229      //} 
    229230    }); 
    230231  }  
     
    234235    $("#bwScheduleTable .fbcell").removeClass("highlight"); 
    235236     
    236     // decrement the start time 
    237     startSelectionMils = Number(startSelectionMils) - Number(incrementMils); 
    238     // set the end time based on duration 
    239     endSelectionMils = Number(startSelectionMils) + Number(durationMils); 
    240      
    241     // highlight the cells if no collision, otherwise try the next spot 
    242     $("#bwScheduleTable .fbcell").each(function(index) { 
    243       var splId = $(this).attr("id").split("-"); 
    244       if (splId[0] >= startSelectionMils && splId[0] < endSelectionMils) { 
     237    // go to the previous freeTime if available and highlight it 
     238    if (this.freeTimeIndex > 0) { 
     239      this.freeTimeIndex -= 1; 
     240    } 
     241    var curSelectionTime = Number(this.freeTime[this.freeTimeIndex]); 
     242    $("#bwScheduleTable ." + curSelectionTime).each(function(index) { 
     243      //if (curSelectionTime >= startSelectionMils && curSelectionTime < endSelectionMils) { 
    245244        $(this).addClass("highlight"); 
    246      
     245      //
    247246    }); 
     247  } 
     248   
     249  // create the lookup values for a free window for use with picknext/previous 
     250  this.setFreeTime = function() { 
     251    // this assumes we have a properly populated fb array 
     252     
     253    // empty the array 
     254    this.freeTime.length = 0; 
     255     
     256    // now look over the next group of cells to see if the range 
     257    // we want to select is busy.  If not, store the value for lookup. 
     258    for (i=0; i < this.fb.length - this.hourDivision; i++) { 
     259      var rangeNotBusy = true; 
     260      for (j = i; j < i + this.hourDivision; j++) { 
     261        if (this.fb[j][1]) { // we hit a busy cell 
     262          rangeNotBusy = false;  
     263        }          
     264      } 
     265      if (rangeNotBusy) { 
     266        this.freeTime.push(this.fb[i][0]);   
     267      } 
     268    } 
    248269  } 
    249270   
     
    295316      } 
    296317       
    297       // generate the "All Attendees" row 
     318      // empty out the fb array so we can refill it 
     319      this.fb.length = 0; 
     320 
     321      // generate the "All Attendees" row, and populate the (now empty) fb array 
    298322      fbDisplayTimesRow = fbDisplay.insertRow(fbDisplay.rows.length); 
    299323      $(fbDisplayTimesRow).addClass("allAttendees"); 
     
    307331          for (k = 0; k < this.hourDivision; k++) { 
    308332            var fbCell = document.createElement("td"); 
    309             fbCell.id = curDate.getTime() + "-AllAttendees"; 
     333            var timeClass = curDate.getTime().toString(); 
     334            fbCell.id = timeClass + "-AllAttendees"; 
    310335            $(fbCell).addClass("fbcell"); 
    311               $(fbCell).addClass(curDate.getTime().toString()); 
     336            $(fbCell).addClass(timeClass); 
    312337            if (curDate.getMinutes() == 0 && j != 0) { 
    313338              $(fbCell).addClass("hourBoundry"); 
    314339            }  
     340            // create a hash of the freebusy time/busy state, default to false 
     341            this.fb.push([timeClass,false]);      
    315342            // set busy if any freebusy in this timeperiod 
    316343            loop1: // since we only need to know if anyone is busy, provide a simple means of breaking from the inner loop 
     
    323350                if (this.attendees[att].freebusy[m].contains(curDateUTC)) { 
    324351                  $(fbCell).addClass("busy"); 
     352                  // change the last added fb in the hash to true 
     353                  this.fb[this.fb.length - 1][1] = true;              
    325354                  break loop1; 
    326355                } 
    327356              } 
     357                           
    328358            } 
    329359            $(fbDisplayTimesRow).append(fbCell); 
     
    495525      } 
    496526       
     527      // populate the freeTime lookup array from the newly created fb array 
     528      this.setFreeTime(); 
    497529       
    498530      // write the table back to the display 
     
    541573            } 
    542574          }); 
     575           
     576          // set the freeTimeIndex to the nearest index for the pickNext/previous buttons 
     577          for (i = 0; i < this.freeTime.length; i++) { 
     578            if (Number(this.freeTime[i]) >= Number(startSelectionMils)) { 
     579              alert(i); 
     580              this.freeTimeIndex = i; 
     581              break; 
     582            } 
     583          } 
    543584   
    544585        } 
     
    612653    } 
    613654     
     655    /*var myString = ""; 
     656    for(i=0; i < this.fb.length; i++) { 
     657      myString += this.fb[i][0]+ " " + this.fb[i][1] +"\n"; 
     658    } 
     659    alert("Fb values:\n" + myString); 
     660    */ 
    614661  } 
    615662}