Changeset 1446

Show
Ignore:
Timestamp:
06/28/07 23:58:46
Author:
douglm
Message:

More work on access handling javascript

Files:

Legend:

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

    r1445 r1446  
    11/* Bedework Access control form functions 
    22 
    3    Bedework uses to methods to set access control.  The first and older method  
    4    is to send a single access control string per principal in one  
    5    request/response cycle.  The second and more current method (which is  
    6    required in the event form) is to build a javascript object representing  
     3   Bedework uses to methods to set access control.  The first and older method 
     4   is to send a single access control string per principal in one 
     5   request/response cycle.  The second and more current method (which is 
     6   required in the event form) is to build a javascript object representing 
    77   the acls on an item (e.g. an event), manipulate the object with the GUI, and send 
    88   all the acls in a single request parameter.  Both methods are currently used. 
     
    5252var grantStr = "grant"; 
    5353 
     54var howAllVal = "all"; 
     55 
     56var howReadVal = "read"; 
     57var howReadAclVal = "read-acl"; 
     58var howReadCurPrivSetVal = "read-curprivset"; 
     59var howReadFreebusyVal = "read-freebusy "; 
     60 
     61var howWriteVal = "write"; 
     62var howWriteAclVal = "write-acl"; 
     63var howWritePropertiesVal = "write-properties"; 
     64var howWriteContentVal = "write-content"; 
     65 
     66var howBindVal = "create"; 
     67var howScheduleVal = "schedule"; 
     68var howScheduleRequestVal = "schedule-request"; 
     69var howScheduleReplyVal = "schedule-reply"; 
     70var howScheduleFreebusyVal = "schedule-freebusy"; 
     71 
     72var howUnbindVal = "delete"; 
     73 
     74var howUnlockVal = "unlock"; 
     75 
     76var howNoneVal = "none"; 
     77 
    5478// ======================================================================== 
    5579// ======================================================================== 
    5680 
    57  
    58  
    59  
    60 function setupAccessForm(chkBoxObj,formObj) { 
    61   switch (chkBoxObj.value) { 
    62     case "A": // All 
    63       if (chkBoxObj.checked) { 
    64         for (i = 0; i < formObj.howItem.length; i++) { 
    65           if (formObj.howItem[i].value != "A") { 
    66             formObj.howItem[i].checked = false; 
    67             formObj.howItem[i].disabled = true; 
    68             // now iterate over corresponding radio buttons for each howItem 
    69             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    70               formObj[formObj.howItem[i].value][j].disabled = true; 
    71             } 
    72           } 
     81/* Define how values, first par is the how, 
     82   second the contained hows 
     83   third the display name */ 
     84function howVals(h, cont, dv) { 
     85  var how; 
     86  var contains; 
     87  var dispVal; 
     88 
     89  this.how = h; 
     90  this.contains = cont; 
     91  this.dispVal = dv; 
     92 
     93  /* return true if ch is contained in this access */ 
     94  this.doesContain = function(ch) { 
     95    return this.contains.match(ch) != null; 
     96  } 
     97
     98 
     99var hows = new function() { 
     100  var hv = new Array(); 
     101 
     102  hv.push(new howVals("A", "RrPFWapcbStysuN", howAllVal)); 
     103 
     104  hv.push(new howVals("R", "rPF", howReadVal)); 
     105  hv.push(new howVals("r", "", howReadAclVal)); 
     106  hv.push(new howVals("P", "", howReadCurPrivSetVal)); 
     107  hv.push(new howVals("F", "", howReadFreebusyVal)); 
     108 
     109  hv.push(new howVals("W", "apcbStysuN", howWriteVal)); 
     110  hv.push(new howVals("a", "", howWriteAclVal)); 
     111  hv.push(new howVals("p", "", howWritePropertiesVal)); 
     112  hv.push(new howVals("c", "", howWriteContentVal)); 
     113 
     114  hv.push(new howVals("b", "Stys", howBindVal)); 
     115  hv.push(new howVals("S", "tys", howScheduleVal)); 
     116  hv.push(new howVals("t", "", howScheduleRequestVal)); 
     117  hv.push(new howVals("y", "", howScheduleReplyVal)); 
     118  hv.push(new howVals("s", "", howScheduleFreebusyVal)); 
     119 
     120  hv.push(new howVals("u", "", howUnbindVal)); 
     121 
     122  hv.push(new howVals("U", "", howUnlockVal)); 
     123 
     124  hv.push(new howVals("N", "rPFapcbStysu", howNoneVal)); 
     125 
     126  this. getHows = function(ch) { 
     127    for (var i = 0; i < hv.length; i++) { 
     128      if (hv[i].how == ch) { 
     129        return hv[i]; 
     130      } 
     131    } 
     132 
     133    return null; 
     134  } 
     135
     136 
     137function setupAccessForm(chkBoxObj, formObj) { 
     138  var hvs;  // howVals 
     139 
     140  /* If we checked/unchecked a value that contains other values we need 
     141     to uncheck and disable the contained boxes. */ 
     142 
     143  hvs = hows.getHows(chkBoxObj.value); 
     144 
     145  if (hvs.contains == "") { 
     146    // Doesn't contain anything 
     147    return; 
     148  } 
     149 
     150  for (i = 0; i < formObj.howItem.length; i++) { 
     151    if (hvs.doesContain(formObj.howItem[i].value)) { 
     152      if (chkBoxObj.checked == true) { 
     153        formObj.howItem[i].checked = false; 
     154        formObj.howItem[i].disabled = true; 
     155        // now iterate over corresponding radio buttons for each howItem 
     156        for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
     157          formObj[formObj.howItem[i].value][j].disabled = true; 
    73158        } 
    74159      } else { 
    75         for (i = 0; i < formObj.howItem.length; i++) { 
    76           formObj.howItem[i].disabled = false; 
    77         } 
    78       } 
    79       break; 
    80     case "R": // Read 
    81       if (chkBoxObj.checked) { 
    82         for (i = 0; i < formObj.howItem.length; i++) { 
    83           if (formObj.howItem[i].value == "r" || 
    84               formObj.howItem[i].value == "P" || 
    85               formObj.howItem[i].value == "F") { 
    86             formObj.howItem[i].checked = false; 
    87             formObj.howItem[i].disabled = true; 
    88             // now iterate over corresponding radio buttons for each howItem 
    89             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    90               formObj[formObj.howItem[i].value][j].disabled = true; 
    91             } 
    92           } 
    93         } 
    94       } else { 
    95         for (i = 0; i < formObj.howItem.length; i++) { 
    96           if (formObj.howItem[i].value == "r" || 
    97               formObj.howItem[i].value == "P" || 
    98               formObj.howItem[i].value == "F") { 
    99             formObj.howItem[i].disabled = false; 
    100           } 
    101         } 
    102       } 
    103       break; 
    104     case "W": // Write 
    105       if (chkBoxObj.checked == true) { 
    106         for (i = 0; i < formObj.howItem.length; i++) { 
    107           if (formObj.howItem[i].value == "a" || 
    108               formObj.howItem[i].value == "p" || 
    109               formObj.howItem[i].value == "c" || 
    110               formObj.howItem[i].value == "b" || 
    111               formObj.howItem[i].value == "S" || 
    112               formObj.howItem[i].value == "t" || 
    113               formObj.howItem[i].value == "y" || 
    114               formObj.howItem[i].value == "s" || 
    115               formObj.howItem[i].value == "u") { 
    116             formObj.howItem[i].checked = false; 
    117             formObj.howItem[i].disabled = true; 
    118             // now iterate over corresponding radio buttons for each howItem 
    119             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    120               formObj[formObj.howItem[i].value][j].disabled = true; 
    121             } 
    122           } 
    123         } 
    124       } else { 
    125         for (i = 0; i < formObj.howItem.length; i++) { 
    126           if (formObj.howItem[i].value == "a" || 
    127               formObj.howItem[i].value == "p" || 
    128               formObj.howItem[i].value == "c" || 
    129               formObj.howItem[i].value == "b" || 
    130               formObj.howItem[i].value == "S" || 
    131               formObj.howItem[i].value == "t" || 
    132               formObj.howItem[i].value == "y" || 
    133               formObj.howItem[i].value == "s" || 
    134               formObj.howItem[i].value == "u") { 
    135             formObj.howItem[i].disabled = false; 
    136           } 
    137         } 
    138       } 
    139       break; 
    140     case "b": // Bind (create) 
    141       if (chkBoxObj.checked == true) { 
    142         for (i = 0; i < formObj.howItem.length; i++) { 
    143           if (formObj.howItem[i].value == "S" || 
    144               formObj.howItem[i].value == "t" || 
    145               formObj.howItem[i].value == "y" || 
    146               formObj.howItem[i].value == "s") { 
    147             formObj.howItem[i].checked = false; 
    148             formObj.howItem[i].disabled = true; 
    149             // now iterate over corresponding radio buttons for each howItem 
    150             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    151               formObj[formObj.howItem[i].value][j].disabled = true; 
    152             } 
    153           } 
    154         } 
    155       } else { 
    156         for (i = 0; i < formObj.howItem.length; i++) { 
    157           if (formObj.howItem[i].value == "S" || 
    158               formObj.howItem[i].value == "t" || 
    159               formObj.howItem[i].value == "y" || 
    160               formObj.howItem[i].value == "s") { 
    161             formObj.howItem[i].disabled = false; 
    162           } 
    163         } 
    164       } 
    165       break; 
    166     case "S": // Schedule 
    167       if (chkBoxObj.checked == true) { 
    168         for (i = 0; i < formObj.howItem.length; i++) { 
    169           if (formObj.howItem[i].value == "t" || 
    170               formObj.howItem[i].value == "y" || 
    171               formObj.howItem[i].value == "s") { 
    172             formObj.howItem[i].checked = false; 
    173             formObj.howItem[i].disabled = true; 
    174             // now iterate over corresponding radio buttons for each howItem 
    175             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    176               formObj[formObj.howItem[i].value][j].disabled = true; 
    177             } 
    178           } 
    179         } 
    180       } else { 
    181         for (i = 0; i < formObj.howItem.length; i++) { 
    182           if (formObj.howItem[i].value == "t" || 
    183               formObj.howItem[i].value == "y" || 
    184               formObj.howItem[i].value == "s") { 
    185             formObj.howItem[i].disabled = false; 
    186           } 
    187         } 
    188       } 
    189       break; 
    190     case "N": // None 
    191       if (chkBoxObj.checked == true) { 
    192         for (i = 0; i < formObj.howItem.length; i++) { 
    193           if (formObj.howItem[i].value != "N") { 
    194             formObj.howItem[i].checked = false; 
    195             formObj.howItem[i].disabled = true; 
    196             // now iterate over corresponding radio buttons for each howItem 
    197             for (j = 0; j < formObj[formObj.howItem[i].value].length; j++) { 
    198               formObj[formObj.howItem[i].value][j].disabled = true; 
    199             } 
    200           } 
    201         } 
    202       } else { 
    203         for (i = 0; i < formObj.howItem.length; i++) { 
    204           formObj.howItem[i].disabled = false; 
    205         } 
    206       } 
    207       break; 
    208   } 
    209 
     160        formObj.howItem[i].disabled = false; 
     161      } 
     162    } 
     163  } 
     164
     165 
    210166// enable and disable corresponding allow/deny flags when a howItem checkbox is 
    211167// clicked 
     
    217173  } 
    218174} 
     175 
    219176// iterate over the allow/deny radio buttons and set them to true or false 
    220177function activateAllowDenyFlag(val,formObj,disabledFlag) { 
     
    223180  } 
    224181} 
    225 // Gather up the how values on access form submission and set the how field  
     182// Gather up the how values on access form submission and set the how field 
    226183// (method 1) or return the value (method 2). 
    227184// If in "basic" mode: 
     
    232189//   The allow/deny flag contains the final values to be returned with 
    233190//   the "-" switch if we set the value to deny (e.g. "A" or "-A", "R" or "-R"). 
    234 // Method: there are two methods used with this function; method one sets  
    235 //   the "how" field in the form used to update a single principal.  Method  
     191// Method: there are two methods used with this function; method one sets 
     192//   the "how" field in the form used to update a single principal.  Method 
    236193//   two returns the assembled how string to the calling function. 
    237194function setAccessHow(formObj,method) { 
     
    273230  this.inherited = inherited; 
    274231  this.invert = invert; // boolean 
    275    
     232 
    276233  this.equals = function(ace) { 
    277234    if (this.whoType != ace.whoType) { 
    278235      return false; 
    279236    } 
    280      
     237 
    281238    return (this.formatWho() == ace.formatWho()); 
    282239  } 
    283    
     240 
    284241  // format the who string for on-screen display 
    285242  this.formatWho = function() { 
     
    287244      return who; 
    288245    } 
    289      
     246 
    290247    if (whoType == "auth") { 
    291248      return authenticatedStr; 
    292249    } 
    293      
     250 
    294251    if (whoType == "unauth") { 
    295252      return unauthenticatedStr; 
    296253    } 
    297      
     254 
    298255    if (whoType == "owner") { 
    299256      return ownerStr; 
    300257    } 
    301      
     258 
    302259    if (whoType == "other") { 
    303260      return otherStr; 
    304261    } 
    305      
     262 
    306263    return "***************" + whoType; 
    307264  } 
    308    
     265 
    309266  this.toXml = function() { 
    310267    var res = "<ace><principal>\n"; 
    311      
     268 
    312269    if (whoType == "user" || whoType == "group") { 
    313270      res += "<href>" + who + "</href>"; 
     
    325282    res += "<read/>"; 
    326283    res += "</grant>"; 
    327      
     284 
    328285    if (this.inherited != '') { 
    329286      res += "<inherited><href>" + this.inherited + "</href></inherited>"; 
    330287    } 
    331      
     288 
    332289    return res + "</ace>"; 
     290  } 
     291 
     292  // format the how string for on-screen display 
     293  this.formatHow = function() { 
     294    var formattedHow = ""; 
     295 
     296    for (i = 0; i < how.length; i++) { 
     297      var h = how[i]; 
     298      if (h == "-") { 
     299        formattedHow += "not-"; 
     300      } else { 
     301        var hvs = hows.getHows(h); 
     302 
     303        formattedHow += hvs.dispVal + " "; 
     304      } 
     305    } 
     306 
     307    return formattedHow; 
    333308  } 
    334309} 
     
    338313var bwAcl = new function() { 
    339314  var aces = new Array(); 
    340    
     315 
    341316  // Initialize the list. 
    342   // The function expects a comma-separated list of arguments grouped  
     317  // The function expects a comma-separated list of arguments grouped 
    343318  // into the five ACE properties. 
    344319  this.init = function(who,whoType,how,inherited,invert) { 
    345320    aces.push(new bwAce(who,whoType,how,inherited,invert)); 
    346321  } 
    347    
     322 
    348323  // Add or update an ace 
    349324  this.addAce = function(newAce) { 
     
    354329        aces[i] = newAce; 
    355330        return; 
    356       }  
     331      } 
    357332    } 
    358333    // not found: add ace to end of array 
    359334    aces.push(newAce); 
    360335  } 
    361    
     336 
    362337  // Update the list - expects the browser form object 
    363338  this.update = function(formObj) { 
     
    377352    // return the how string from the form 
    378353    var how = setAccessHow(formObj,2); 
    379     // update the bwAcl  
     354    // update the bwAcl 
    380355    bwAcl.addAce(new bwAce(formObj.who.value,type,how,"local",false)); 
    381      
     356 
    382357    // update the acl form field 
    383358    formObj.acl = this.toXml(); 
    384      
     359 
    385360    // redraw the display 
    386361    this.display(); 
    387362  } 
    388    
     363 
    389364  this.deleteAce = function(index) { 
    390365    bwAcl.aces.splice(index, 1); 
    391      
     366 
    392367    // redraw the display 
    393368    this.display(); 
    394369  } 
    395    
     370 
    396371  // update the ACL table displayed on screen 
    397372  this.display = function() { 
     
    399374      // get the table body 
    400375      var aclTableBody = document.getElementById("bwCurrentAccess").tBodies[0]; 
    401        
     376 
    402377      // remove existing rows 
    403378      for (i = aclTableBody.rows.length - 1; i >= 0; i--) { 
    404379        aclTableBody.deleteRow(i); 
    405       }   
    406        
     380      } 
     381 
    407382      // recreate the table rows 
    408383      for (var j = 0; j < aces.length; j++) { 
    409384        var formattedWho = aces[j].formatWho(); 
    410         var formattedHow = this.formatHow(aces[j].how); 
     385        var formattedHow = aces[j].formatHow(); 
    411386        var tr = aclTableBody.insertRow(j); 
     387 
    412388        tr.insertCell(0).appendChild(document.createTextNode(formattedWho)); 
    413         var td_1 = tr.insertCell(1); 
    414         td_1.appendChild(document.createTextNode(formattedHow)); 
    415         var td_2 = tr.insertCell(2); 
    416         td_2.appendChild(document.createTextNode(aces[j].inherited)); 
     389        tr.insertCell(1).appendChild(document.createTextNode(formattedHow)); 
     390        tr.insertCell(2).appendChild(document.createTextNode(aces[j].inherited)); 
    417391        var td_3 = tr.insertCell(3); 
    418392        td_3.appendChild(document.createTextNode('')); 
    419393        //<a href="javascript:bwAcl.delete(' + j +')">' + deleteStr + '</a> 
    420       }         
     394      } 
    421395    } catch (e) { 
    422396      alert(e); 
    423397    } 
    424398  } 
    425    
    426   // format the how string for on-screen display 
    427   this.formatHow = function(how) { 
    428     var formattedHow = ""; 
    429      
    430     for (i = 0; i < how.length; i++) { 
    431       switch (how[i]) { 
    432         case "-":  
    433           formattedHow += "not-"; 
    434           break;           
    435         case "A": 
    436           formattedHow += "all "; 
    437           break;           
    438         case "R": 
    439           formattedHow += "read "; 
    440           break;          
    441         case "r": 
    442           formattedHow += "read-acl "; 
    443           break;          
    444         case "P": 
    445           formattedHow += "read-privSet "; 
    446           break;          
    447         case "F": 
    448           formattedHow += "read-freebusy "; 
    449           break;          
    450         case "W": 
    451           formattedHow += "write "; 
    452           break;          
    453         case "a": 
    454           formattedHow += "write-acl "; 
    455           break;          
    456         case "p": 
    457           formattedHow += "write-properties "; 
    458           break;          
    459         case "c": 
    460           formattedHow += "write-content "; 
    461           break;         
    462         case "b": 
    463           formattedHow += "create "; 
    464           break;         
    465         case "S": 
    466           formattedHow += "schedule "; 
    467           break;         
    468         case "t": 
    469           formattedHow += "schedule-request "; 
    470           break;         
    471         case "y": 
    472           formattedHow += "schedule-reply "; 
    473           break;         
    474         case "s": 
    475           formattedHow += "schedule-freebusy "; 
    476           break;         
    477         case "u": 
    478           formattedHow += "delete "; 
    479           break;         
    480         case "U": 
    481           formattedHow += "unlock "; 
    482           break;         
    483         case "N": 
    484           formattedHow += "none "; 
    485           break; 
    486       }  
    487     } 
    488     return formattedHow; 
    489   } 
    490    
    491  /*   'A',     // privAll 
    492  
    493     'R',     // privRead 
    494     'r',     // privReadAcl 
    495     'P',     // privReadCurrentUserPrivilegeSet 
    496     'F',     // privReadFreeBusy 
    497  
    498     'W',     // privWrite 
    499     'a',     // privWriteAcl 
    500     'p',     // privWriteProperties 
    501     'c',     // privWriteContent 
    502     'b',     // privBind 
    503  
    504     'S',     // privSchedule 
    505     't',     // privScheduleRequest 
    506     'y',     // privScheduleReply 
    507     's',     // privScheduleFreeBusy 
    508  
    509     'u',     // privUnbind 
    510              // unbind and bind usually correspond to create and destroy 
    511  
    512     'U',     // privUnlock 
    513              // not implemented 
    514  
    515     'N',     // privNone 
    516   */ 
     399 
    517400  // generate webDAV ACl XML output 
    518401  this.toXml = function() { 
    519402    var res = "<acl>\n"; 
    520      
     403 
    521404    for (var j = 0; j < aces.length; j++) { 
    522405      res += aces[j].toXml(); 
    523406    } 
    524      
     407 
    525408    return res + "</acl>"; 
    526409  }