Changeset 2077

Show
Ignore:
Timestamp:
02/26/09 17:50:04
Author:
johnsa
Message:

refactoring access control widget: more to be done yet.

Files:

Legend:

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

    r2076 r2077  
    402402      <script type="text/javascript" src="{$resourcesRoot}/resources/bedeworkPrefs.js">&#160;</script> 
    403403    </xsl:if> 
    404     <xsl:if test="/bedework/page='modCalendar'"> 
     404    <xsl:if test="/bedework/page='modCalendar' or 
     405                  /bedework/page='modSchedulingPrefs'"> 
    405406      <script type="text/javascript" src="{$resourcesRoot}/resources/bedeworkAccess.js">&#160;</script> 
    406407      <!-- initialize calendar acls, if present --> 
     
    77677768  <xsl:template name="entityAccessForm"> 
    77687769    <xsl:param name="type"/><!-- optional: currently used for inbox and outbox to conditionally display scheduling access --> 
    7769     <xsl:param name="method">2</xsl:param><!-- optional: 
    7770       there are two methods of setting access 
    7771       - method 1, the older method, uses a single request/response per principal 
    7772       - method 2 constructs a javascript object that commits the entire ACL 
    7773         structure in a single request 
    7774       Both methods are currently supported.  Method two is now the default. --> 
    7775     <xsl:param name="acl"/><!-- nodeset of entity acls used to initialize 
    7776       javascript object. Required for method two. --> 
     7770    <xsl:param name="acl"/><!-- required: nodeset of entity acls used to initialize javascript object. --> 
     7771    <xsl:param name="outputId"/><!-- required: id of the current access block display to update --> 
    77777772 
    77787773    <table cellpadding="0" id="shareFormTable" class="common"> 
     
    77947789              <input type="radio" value="all" name="whoType"/> all users 
    77957790            </p> 
    7796             <xsl:choose> 
    7797               <xsl:when test="$method = '2'"> 
    7798                 <input type="button" name="updateACLs" value="add entry" onclick="bwAcl.update(this.form)"/> 
    7799               </xsl:when> 
    7800               <xsl:otherwise> 
    7801                 <input type="submit" name="submit" value="update access"/> 
    7802               </xsl:otherwise> 
    7803             </xsl:choose> 
     7791            <input type="button" name="updateACLs" value="add entry" onclick="bwAcl.update(this.form,${id})"/> 
    78047792          </div> 
    78057793        </td> 
     
    80308018 
    80318019  <xsl:template match="acl" mode="currentAccess"> 
    8032     <xsl:param name="action"/> <!-- required --> 
    8033     <xsl:param name="calPathEncoded"/> <!-- optional (for entities) --> 
    8034     <xsl:param name="guid"/> <!-- optional (for entities) --> 
    8035     <xsl:param name="recurrenceId"/> <!-- optional (for entities) --> 
    8036     <xsl:param name="what"/> <!-- optional (for scheduling only) --> 
    8037     <xsl:param name="method">2</xsl:param> <!-- which method of access control 
    8038       are we using: 1 (one request per pricipal) or 2 (set all with 
    8039       javascript and send entire ACL to server) --> 
    80408020    <h3>Current Access:</h3> 
    8041     <table class="common scheduling" id="bwCurrentAccess"> 
    8042       <thead> 
    8043         <tr> 
    8044           <th>Entry</th> 
    8045           <th>Access</th> 
    8046           <th>Inherited from</th> 
    8047           <th></th> 
    8048         </tr> 
    8049       </thead> 
    8050       <tbody> 
    8051         <xsl:for-each select="ace"> 
    8052           <xsl:variable name="who"> 
    8053             <xsl:choose> 
    8054               <xsl:when test="invert"> 
    8055                 <xsl:choose> 
    8056                   <xsl:when test="invert/principal/href"><xsl:value-of select="normalize-space(invert/principal/href)"/></xsl:when> 
    8057                   <xsl:when test="invert/principal/property"><xsl:value-of select="name(invert/principal/property/*)"/></xsl:when> 
    8058                   <xsl:otherwise><xsl:value-of select="name(invert/principal/*)"/></xsl:otherwise> 
    8059                 </xsl:choose> 
    8060               </xsl:when> 
    8061               <xsl:otherwise> 
    8062                 <xsl:choose> 
    8063                   <xsl:when test="principal/href"><xsl:value-of select="normalize-space(principal/href)"/></xsl:when> 
    8064                   <xsl:when test="principal/property"><xsl:value-of select="name(principal/property/*)"/></xsl:when> 
    8065                   <xsl:otherwise><xsl:value-of select="name(principal/*)"/></xsl:otherwise> 
    8066                 </xsl:choose> 
    8067               </xsl:otherwise> 
    8068             </xsl:choose> 
    8069           </xsl:variable> 
    8070           <xsl:variable name="whoType"> 
    8071             <xsl:choose> 
    8072               <xsl:when test="contains($who,/bedework/syspars/userPrincipalRoot)">user</xsl:when> 
    8073               <xsl:when test="contains($who,/bedework/syspars/groupPrincipalRoot)">group</xsl:when> 
    8074               <xsl:when test="$who='authenticated'">auth</xsl:when> 
    8075               <xsl:when test="$who='unauthenticated'">unauth</xsl:when> 
    8076               <xsl:when test="$who='all'">all</xsl:when> 
    8077               <xsl:when test="invert/principal/property/owner">other</xsl:when> 
    8078               <xsl:when test="principal/property"><xsl:value-of select="name(principal/property/*)"/></xsl:when> 
    8079               <xsl:when test="invert/principal/property"><xsl:value-of select="name(invert/principal/property/*)"/></xsl:when> 
    8080               <xsl:otherwise></xsl:otherwise> 
    8081             </xsl:choose> 
    8082           </xsl:variable> 
    8083           <xsl:variable name="shortWho"> 
    8084             <xsl:choose> 
    8085               <xsl:when test="$whoType='user'"><xsl:value-of select="substring-after(substring-after($who,normalize-space(/bedework/syspars/userPrincipalRoot)),'/')"/></xsl:when> 
    8086               <xsl:when test="$whoType='group'"><xsl:value-of select="substring-after(substring-after($who,normalize-space(/bedework/syspars/groupPrincipalRoot)),'/')"/></xsl:when> 
    8087               <xsl:otherwise></xsl:otherwise> <!-- if not user or group, send no who --> 
    8088             </xsl:choose> 
    8089           </xsl:variable> 
    8090           <tr> 
    8091             <td> 
    8092               <xsl:choose> 
    8093                 <xsl:when test="$whoType = 'user' or ($who = 'owner' and $whoType != 'other')"> 
    8094                   <img src="{$resourcesRoot}/resources/userIcon.gif" width="13" height="13" border="0" alt="user"/> 
    8095                 </xsl:when> 
    8096                 <xsl:otherwise> 
    8097                   <img src="{$resourcesRoot}/resources/groupIcon.gif" width="13" height="13" border="0" alt="group"/> 
    8098                 </xsl:otherwise> 
    8099               </xsl:choose> 
    8100               <xsl:text> </xsl:text> 
    8101               <xsl:choose> 
    8102                 <xsl:when test="$whoType = 'other'"> 
    8103                   anyone (other) 
    8104                 </xsl:when> 
    8105                 <xsl:when test="$shortWho != ''"> 
    8106                   <xsl:value-of select="$shortWho"/> 
    8107                 </xsl:when> 
    8108                 <xsl:otherwise> 
    8109                   <xsl:value-of select="$who"/> 
    8110                 </xsl:otherwise> 
    8111               </xsl:choose> 
    8112             </td> 
    8113             <td class="acls"> 
    8114               <xsl:if test="grant"> 
    8115                 <span class="grant"> 
    8116                   <xsl:for-each select="grant/privilege/*"> 
    8117                     <xsl:value-of select="name(.)"/> 
    8118                     <xsl:if test="position() != last()">, </xsl:if> 
    8119                   </xsl:for-each> 
    8120                 </span><br/> 
    8121               </xsl:if> 
    8122               <xsl:if test="deny"> 
    8123                 <span class="deny"> 
    8124                   <xsl:for-each select="deny/privilege/*"> 
    8125                     not-<xsl:value-of select="name(.)"/> 
    8126                     <xsl:if test="position() != last()">, </xsl:if> 
    8127                   </xsl:for-each> 
    8128                 </span> 
    8129               </xsl:if> 
    8130             </td> 
    8131             <td> 
    8132               <xsl:choose> 
    8133                 <xsl:when test="inherited"> 
    8134                   <xsl:value-of select="inherited/href"/> 
    8135                 </xsl:when> 
    8136                 <xsl:otherwise> 
    8137                   Not inherited 
    8138                 </xsl:otherwise> 
    8139               </xsl:choose> 
    8140             </td> 
    8141             <td> 
    8142               <xsl:if test="not(inherited)"> 
    8143                 <xsl:choose> 
    8144                   <xsl:when test="$method = '2'"> 
    8145                     <!-- we are using javascript to update the form --> 
    8146                     <xsl:variable name="rowPos" select="position()-1"/> 
    8147                     <a href="javascript:bwAcl.deleteAce({$rowPos})" title="reset to default"> 
    8148                       <img src="{$resourcesRoot}/resources/trashIcon.gif" width="13" height="13" border="0" alt="reset to default"/> 
    8149                     </a> 
    8150                   </xsl:when> 
    8151                   <xsl:otherwise> 
    8152                     <a href="{$action}&amp;how=default&amp;what={$what}&amp;who={$shortWho}&amp;whoType={$whoType}&amp;calPath={$calPathEncoded}&amp;guid={$guid}&amp;recurrenceId={$recurrenceId}" title="reset to default"> 
    8153                       <img src="{$resourcesRoot}/resources/trashIcon.gif" width="13" height="13" border="0" alt="reset to default"/> 
    8154                     </a> 
    8155                   </xsl:otherwise> 
    8156                 </xsl:choose> 
    8157               </xsl:if> 
    8158             </td> 
    8159           </tr> 
    8160         </xsl:for-each> 
    8161       </tbody> 
    8162     </table> 
     8021    <div id="bwCurrentAccessWidget">&#160;</div> 
     8022    <script type="text/javascript"> 
     8023      bwAcl.display("bwCurrentAccessWidget"); // display acls in the table 
     8024    </script> 
    81638025  </xsl:template> 
    81648026 
     
    84028264  </xsl:template> 
    84038265 
    8404   <!-- return string values to be loaded into javascript for access control 
    8405        forms, method 2 --> 
     8266  <!-- return string values to be loaded into javascript for access control forms --> 
    84068267  <xsl:template match="ace" mode="initJS"><!-- 
    84078268  --><xsl:variable name="who"><!-- 
  • trunk/deployment/webuser/webapp/resources/demoskins/resources/bedeworkAccess.js

    r2076 r2077  
    5555var allStr = "all"; 
    5656 
    57 var deleteStr = "remove"; 
     57var bwAclWidgetDeleteStr = "remove"; 
     58var bwAclWidgetEntryStr = "Entry"; 
     59var bwAclWidgetAccessStr = "Access"; 
     60var bwAclWidgetInheritedStr = "Inherited from"; 
    5861 
    5962// note that resourcesRoot is passed in from the html head section defined in the xslt 
     
    258261} 
    259262 
    260 // Gather up the how values on access form submission and set the how field 
    261 // (method 1) or return the value (method 2). 
     263// Gather up the how values on access form submission and return the value. 
    262264// If in "basic" mode: 
    263265//   Set the value of how to the value of the basicHowItem radio button. 
     
    267269//   The allow/deny flag contains the final values to be returned with 
    268270//   the "-" switch if we set the value to deny (e.g. "A" or "-A", "R" or "-R"). 
    269 // Method: there are two methods used with this function; method one sets 
    270 //   the "how" field in the form used to update a single principal.  Method 
    271 //   two returns the assembled how string to the calling function. 
    272 function setAccessHow(formObj,method) { 
     271function setAccessHow(formObj) { 
    273272  var howString = ""; 
    274273  if (formObj.setappvar[0].checked == true) { // "basic" mode is selected 
     
    290289    } 
    291290  } 
    292   if (method == 2) { 
    293     return howString; 
    294   } else { 
    295     formObj.how.value = howString; 
    296   } 
     291  return howString; 
    297292} 
    298293 
     
    435430 
    436431  this.equals = function(pr) { 
    437     //alert("this=" + this.toString() + " pr=" + pr.toString()); 
    438  
    439432    if (this.whoType != pr.whoType) { 
    440433      return false; 
    441434    } 
    442  
    443435    return this.who == pr.who; 
    444436  } 
    445437} 
    446438 
    447 /* METHOD TWO FUNCTIONS*/ 
    448 // Access Control Entry (ACE) object 
    449  
     439/* Access Control Entry (ACE) object 
     440 */ 
    450441function bwAce(who, whoType, how, inherited, invert) { 
    451442  this.principal = new bwPrincipal(who, whoType); 
     
    555546  // row: current row in table 
    556547  // aceI: index of the ace 
    557   this.toFormRow = function(row, aceI) { 
     548  // id: id of widget output block in the html 
     549  this.toFormRow = function(row, aceI, id) { 
    558550    var td_0 = row.insertCell(0); 
    559551    td_0.innerHTML = this.principal.format(); 
     
    563555    var td_3 = row.insertCell(3); 
    564556    if (this.inherited == "") { 
    565       td_3.innerHTML = "<a href=\"javascript:bwAcl.deleteAce('" + aceI + "')\">" + trashIcon + " " + deleteStr + "</a>"; 
     557      td_3.innerHTML = "<a href=\"javascript:bwAcl.deleteAce('" + aceI + "','" + id + "')\">" + trashIcon + " " + bwAclWidgetDeleteStr + "</a>"; 
    566558    } 
    567559  } 
     
    603595 
    604596  // Update the list - expects the browser form object 
    605   this.update = function(formObj) { 
     597  this.update = function(formObj,id) { 
    606598    // get the type of ace being set 
    607599    var type; 
     
    620612 
    621613    // get the how string from the form 
    622     var how = setAccessHow(formObj, 2); 
     614    var how = setAccessHow(formObj); 
    623615 
    624616    //alert("About to update who=" + formObj.who.value + 
     
    633625 
    634626    // redraw the display 
    635     this.display(); 
    636   } 
    637  
    638   this.deleteAce = function(index) { 
     627    this.display(id); 
     628  } 
     629 
     630  this.deleteAce = function(index,id) { 
    639631    var ace = aces[index]; 
    640632    var replace = false; 
     
    659651 
    660652    // redraw the display 
    661     this.display(); 
    662   } 
    663  
    664   // update the ACL table displayed on screen 
    665   this.display = function() { 
     653    this.display(id); 
     654  } 
     655 
     656  // build the ACL widget displayed on screen in the given id 
     657  this.display = function(id) { 
    666658    try { 
     659 
     660      var aclWidget = document.getElementById(id); 
     661      aclWidget.innerHTML = ""; 
     662 
     663      var bwCurrentAccess = document.createElement("table"); 
     664      bwCurrentAccess.className = "common scheduling"; 
     665      bwCurrentAccess.id = "bwCurrentAccess"; 
     666      bwCurrentAccess.createTHead(); 
     667      bwCurrAccessHead = bwCurrentAccess.tHead.insertRow(0); 
     668      bwCurrAccessHead.innerHTML = '<th>' + bwAclWidgetEntryStr + '</th>' +  '<th>' + bwAclWidgetAccessStr + '</th>' + '<th>' + bwAclWidgetInheritedStr + '</th><th></th>'; 
     669      var bwCurrAccessTBody = document.createElement("tbody"); 
     670      bwCurrentAccess.appendChild(bwCurrAccessTBody); 
     671 
     672      // finally, write the table back to the display 
     673      aclWidget.appendChild(bwCurrentAccess); 
     674 
    667675      // get the table body 
    668676      var aclTableBody = document.getElementById("bwCurrentAccess").tBodies[0]; 
    669677 
    670678      // remove existing rows 
    671       for (i = aclTableBody.rows.length - 1; i >= 0; i--) { 
    672         aclTableBody.deleteRow(i); 
    673      
    674  
    675       // recreate the table rows 
     679      //for (i = aclTableBody.rows.length - 1; i >= 0; i--) { 
     680      //  aclTableBody.deleteRow(i); 
     681      //
     682 
     683      // create the table rows 
    676684      for (var j = 0; j < aces.length; j++) { 
    677685        var curAce = aces[j]; 
    678686        var tr = aclTableBody.insertRow(j); 
    679687 
    680         curAce.toFormRow(tr, j); 
    681       } 
     688        curAce.toFormRow(tr, j, id); 
     689      } 
     690 
    682691    } catch (e) { 
    683692      alert(e); 
  • trunk/deployment/webuser/webapp/resources/demoskins/resources/bedeworkEventForm.js

    r2061 r2077  
    243243  } // else we are editing an instance of a recurrence 
    244244  setBedeworkXProperties(formObj,submitter); 
    245   setAccessHow(formObj,1); 
     245  setAccessHow(formObj); 
    246246  //setAccessAcl(formObj); 
    247247}