Changeset 3137

Show
Ignore:
Timestamp:
01/18/11 14:11:23
Author:
johnsa
Message:

personal client: send json formatted attendee list when scheduling a group

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/deployment/webuser/webapp/resources/demoskins/themes/bedeworkTheme/javascript/bedeworkScheduling.js

    r3133 r3137  
    312312  }; 
    313313   
     314  // add a group of attendees returned from the CardDAV server 
     315  // uids - an array of uids to add 
     316  this.addGroupOfAttendees = function(uids) { 
     317    // display the processing message 
     318    $("#bwSchedProcessingMsg").show(); 
     319     
     320    // the json string we'll send to the server 
     321    var attendees = ""; 
     322    var isFirst = true; 
     323     
     324    for (var i = 0; i<uids.length; i++) { 
     325      var attendeeIsNew = true; 
     326      var uid = uids[i]; 
     327       
     328      // check to see if attendee already exists 
     329      for (var j=0; j < bwGrid.attendees.length; j++) { 
     330        if (uid.indexOf("mailto:") == -1) { 
     331           uid = "mailto:" + uid;  
     332        } 
     333        if (uid == bwGrid.attendees[j].uid) { 
     334          attendeeIsNew = false; 
     335          break; 
     336        }  
     337      } 
     338       
     339      if (attendeeIsNew) { 
     340         if (!isFirst) attendees += "&";  
     341         attendees += 'attjson={"uri":"' + uid + '"}'; 
     342         isFirst = false; 
     343      } 
     344    } 
     345     
     346    // send the json string to the server: 
     347    $.ajax({ 
     348      type: "POST", 
     349      url: bwGrid.attUrlPrefix, 
     350      data: attendees + "&attendee=true&submit=add&list=yes&skinName=widget", 
     351      dataType: "json", 
     352      success: function(responseData){ 
     353 
     354        // the local array is overwritten with attendee data returned from the ajax call 
     355        if (responseData.attendees != undefined && responseData.attendees.length) { 
     356          bwGrid.attendees.length = 0; 
     357          for (var k=0; k < responseData.attendees.length; k++) { 
     358            var att = responseData.attendees[k]; 
     359            // strip off mailto: from uids to store locally 
     360            var attUri = att.uid; 
     361            if (attUri.indexOf("mailto:") != -1) { 
     362              attUri = attUri.substr(7);  
     363            } 
     364            var newAttendee = new bwAttendee(att.name, attUri, att.role, att.status, att.type); 
     365            bwGrid.attendees.push(newAttendee);  
     366          } 
     367          bwGrid.requestFreeBusy(); 
     368        } else { // no attendees were returned 
     369          alert(bwErrorAttendees); 
     370        } 
     371         
     372        // got attendees??  set the param that will trigger a 
     373        // scheduling request. For now, just set this every time 
     374        // (we'll trim back later) 
     375        if (bwGrid.attendees.length) { 
     376          $("input.bwEventFormSubmit").each(function(k) { 
     377             $(this).attr("name","submitAndSend"); 
     378             $(this).val(bwEventSubmitMeetingDisp); 
     379          }); 
     380        } 
     381      }, 
     382      error: function(msg) { 
     383        // there was a problem 
     384        alert("Error: " + msg.statusText); 
     385      } 
     386    }); 
     387     
     388    // hide the processing message 
     389    $("#bwSchedProcessingMsg").hide(); 
     390  } 
     391   
    314392  this.addAttendeeFromGrid = function() { 
    315393    var uid = $("#bwAddAttendee").val(); 
     
    319397    if (uid.indexOf(",") != -1) { 
    320398      // we have a list of uids from a group 
    321       alert("can't add a group yet, but soon...");  
     399      // alert("can't add a group yet, but soon..."); 
     400      var uids = uid.split(","); 
     401      bwGrid.addGroupOfAttendees(uids); 
    322402    } else { 
    323403      // we have a single uid