Changeset 2887
- Timestamp:
- 04/28/10 17:06:14
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/deployment/webuser/webapp/resources/demoskins/fbMockup/bedeworkFb.js
r2886 r2887 176 176 this.attendees = new Array(); // array of bwAttendee objects 177 177 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 178 186 // initialize any incoming attendees on first load 179 187 for (i = 0; i < attendees.length; i++) { … … 207 215 } 208 216 209 this.pickNext = function( gridObj) {217 this.pickNext = function() { 210 218 // clear highlighting 211 219 $("#bwScheduleTable .fbcell").removeClass("highlight"); 212 220 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 //} 229 230 }); 230 231 } … … 234 235 $("#bwScheduleTable .fbcell").removeClass("highlight"); 235 236 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) { 245 244 $(this).addClass("highlight"); 246 }245 //} 247 246 }); 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 } 248 269 } 249 270 … … 295 316 } 296 317 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 298 322 fbDisplayTimesRow = fbDisplay.insertRow(fbDisplay.rows.length); 299 323 $(fbDisplayTimesRow).addClass("allAttendees"); … … 307 331 for (k = 0; k < this.hourDivision; k++) { 308 332 var fbCell = document.createElement("td"); 309 fbCell.id = curDate.getTime() + "-AllAttendees"; 333 var timeClass = curDate.getTime().toString(); 334 fbCell.id = timeClass + "-AllAttendees"; 310 335 $(fbCell).addClass("fbcell"); 311 $(fbCell).addClass(curDate.getTime().toString());336 $(fbCell).addClass(timeClass); 312 337 if (curDate.getMinutes() == 0 && j != 0) { 313 338 $(fbCell).addClass("hourBoundry"); 314 339 } 340 // create a hash of the freebusy time/busy state, default to false 341 this.fb.push([timeClass,false]); 315 342 // set busy if any freebusy in this timeperiod 316 343 loop1: // since we only need to know if anyone is busy, provide a simple means of breaking from the inner loop … … 323 350 if (this.attendees[att].freebusy[m].contains(curDateUTC)) { 324 351 $(fbCell).addClass("busy"); 352 // change the last added fb in the hash to true 353 this.fb[this.fb.length - 1][1] = true; 325 354 break loop1; 326 355 } 327 356 } 357 328 358 } 329 359 $(fbDisplayTimesRow).append(fbCell); … … 495 525 } 496 526 527 // populate the freeTime lookup array from the newly created fb array 528 this.setFreeTime(); 497 529 498 530 // write the table back to the display … … 541 573 } 542 574 }); 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 } 543 584 544 585 } … … 612 653 } 613 654 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 */ 614 661 } 615 662 }
