Changeset 2917


Ignore:
Timestamp:
Nov 15, 2006, 11:28:36 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #348: Take ownership of items

Implemented on all biomaterial pages

Location:
trunk/www/biomaterials
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/biomaterials/extracts/index.jsp

    r2811 r2917  
    4343  import="net.sf.basedb.util.RemovableUtil"
    4444  import="net.sf.basedb.util.ShareableUtil"
     45  import="net.sf.basedb.util.OwnableUtil"
    4546  import="net.sf.basedb.clients.web.Base"
    4647  import="net.sf.basedb.clients.web.WebException"
     
    272273    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
    273274  }
     275  else if ("TakeOwnershipOfItem".equals(cmd))
     276  {
     277    // Take ownership a single item and then return to the view page
     278    dc = sc.newDbControl();
     279    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     280    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
     281    dc.commit();
     282    redirect = viewPage;
     283  }
     284  else if ("TakeOwnershipOfItems".equals(cmd))
     285  {
     286    // Take ownership all selected items on the list page
     287    dc = sc.newDbControl();
     288    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     289    int numTotal = cc.getSelected().size();
     290    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
     291    dc.commit();
     292    if (numTotal != numOwned)
     293    {
     294      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
     295    }
     296    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     297  }
    274298  else if ("ExportItems".equals(cmd))
    275299  {
  • trunk/www/biomaterials/extracts/list_extracts.jsp

    r2893 r2917  
    151151      frm.submit();
    152152    }
     153    function takeOwnership()
     154    {
     155      var frm = document.forms[formId];
     156      if (Forms.numChecked(frm) == 0)
     157      {
     158        alert('Please select at least one item in the list');
     159        return;
     160      }
     161      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
     162      {
     163        frm.action = submitPage;
     164        frm.cmd.value = 'TakeOwnershipOfItems';
     165        frm.submit();
     166      }
     167    }
    153168    function shareItem(itemId)
    154169    {
     
    378393          title="Share…"
    379394          tooltip="Share the selected items"
     395        />
     396        <tbl:button
     397          image="take_ownership.png"
     398          onclick="takeOwnership()"
     399          title="Take ownership&hellip;"
     400          tooltip="Take ownership of the selected items"
    380401        />
    381402        <tbl:button
  • trunk/www/biomaterials/extracts/view_extract.jsp

    r2875 r2917  
    8787  final boolean sharePermission = extract.hasPermission(Permission.SET_PERMISSION);
    8888  final boolean usePermission = extract.hasPermission(Permission.USE);
    89  
     89  final boolean setOwnerPermission = extract.hasPermission(Permission.SET_OWNER);
     90  final boolean isOwner = extract.isOwner(); 
    9091  %>
    9192
     
    108109    {
    109110      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
     111    }
     112    function takeOwnership()
     113    {
     114      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
     115      {
     116        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
     117      }
    110118    }
    111119    function runPlugin(cmd)
     
    175183        title="Share&hellip;"
    176184        tooltip="<%=sharePermission ? "Share this extract to other user, groups and projects" : "You do not have permission to share this extract"%>"
     185      />
     186      <tbl:button
     187        disabled="<%=setOwnerPermission ? false : true%>"
     188        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
     189        onclick="takeOwnership()"
     190        title="Take ownership&hellip;"
     191        visible="<%=!isOwner%>"
     192        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
    177193      />
    178194      <tbl:button
  • trunk/www/biomaterials/labeledextracts/index.jsp

    r2811 r2917  
    4444  import="net.sf.basedb.util.RemovableUtil"
    4545  import="net.sf.basedb.util.ShareableUtil"
     46  import="net.sf.basedb.util.OwnableUtil"
    4647  import="net.sf.basedb.clients.web.Base"
    4748  import="net.sf.basedb.clients.web.WebException"
     
    286287    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
    287288  }
     289  else if ("TakeOwnershipOfItem".equals(cmd))
     290  {
     291    // Take ownership a single item and then return to the view page
     292    dc = sc.newDbControl();
     293    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     294    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
     295    dc.commit();
     296    redirect = viewPage;
     297  }
     298  else if ("TakeOwnershipOfItems".equals(cmd))
     299  {
     300    // Take ownership all selected items on the list page
     301    dc = sc.newDbControl();
     302    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     303    int numTotal = cc.getSelected().size();
     304    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
     305    dc.commit();
     306    if (numTotal != numOwned)
     307    {
     308      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
     309    }
     310    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     311  }
    288312  else if ("ExportItems".equals(cmd))
    289313  {
  • trunk/www/biomaterials/labeledextracts/list_labeledextracts.jsp

    r2893 r2917  
    147147      frm.submit();
    148148    }
     149    function takeOwnership()
     150    {
     151      var frm = document.forms[formId];
     152      if (Forms.numChecked(frm) == 0)
     153      {
     154        alert('Please select at least one item in the list');
     155        return;
     156      }
     157      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
     158      {
     159        frm.action = submitPage;
     160        frm.cmd.value = 'TakeOwnershipOfItems';
     161        frm.submit();
     162      }
     163    }
    149164    function shareItem(itemId)
    150165    {
     
    393408          title="Share&hellip;"
    394409          tooltip="Share the selected items"
     410        />
     411        <tbl:button
     412          image="take_ownership.png"
     413          onclick="takeOwnership()"
     414          title="Take ownership&hellip;"
     415          tooltip="Take ownership of the selected items"
    395416        />
    396417        <tbl:button
  • trunk/www/biomaterials/labeledextracts/view_labeledextract.jsp

    r2875 r2917  
    8585  final boolean sharePermission = extract.hasPermission(Permission.SET_PERMISSION);
    8686  final boolean usePermission = extract.hasPermission(Permission.USE);
    87  
     87  final boolean setOwnerPermission = extract.hasPermission(Permission.SET_OWNER);
     88  final boolean isOwner = extract.isOwner();
    8889  %>
    8990
     
    106107    {
    107108      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
     109    }
     110    function takeOwnership()
     111    {
     112      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
     113      {
     114        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
     115      }
    108116    }
    109117    function runPlugin(cmd)
     
    173181        title="Share&hellip;"
    174182        tooltip="<%=sharePermission ? "Share this labeled extract to other user, groups and projects" : "You do not have permission to share this labeled extract"%>"
     183      />
     184      <tbl:button
     185        disabled="<%=setOwnerPermission ? false : true%>"
     186        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
     187        onclick="takeOwnership()"
     188        title="Take ownership&hellip;"
     189        visible="<%=!isOwner%>"
     190        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
    175191      />
    176192      <tbl:button
  • trunk/www/biomaterials/labels/index.jsp

    r2811 r2917  
    4040  import="net.sf.basedb.util.RemovableUtil"
    4141  import="net.sf.basedb.util.ShareableUtil"
     42  import="net.sf.basedb.util.OwnableUtil"
    4243  import="net.sf.basedb.clients.web.Base"
    4344  import="net.sf.basedb.clients.web.WebException"
     
    210211    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
    211212  }
     213  else if ("TakeOwnershipOfItem".equals(cmd))
     214  {
     215    // Take ownership a single item and then return to the view page
     216    dc = sc.newDbControl();
     217    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     218    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
     219    dc.commit();
     220    redirect = viewPage;
     221  }
     222  else if ("TakeOwnershipOfItems".equals(cmd))
     223  {
     224    // Take ownership all selected items on the list page
     225    dc = sc.newDbControl();
     226    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     227    int numTotal = cc.getSelected().size();
     228    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
     229    dc.commit();
     230    if (numTotal != numOwned)
     231    {
     232      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
     233    }
     234    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     235  }
    212236  else if ("ExportItems".equals(cmd))
    213237  {
  • trunk/www/biomaterials/labels/list_labels.jsp

    r2753 r2917  
    125125      frm.submit();
    126126    }
     127    function takeOwnership()
     128    {
     129      var frm = document.forms[formId];
     130      if (Forms.numChecked(frm) == 0)
     131      {
     132        alert('Please select at least one item in the list');
     133        return;
     134      }
     135      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
     136      {
     137        frm.action = submitPage;
     138        frm.cmd.value = 'TakeOwnershipOfItems';
     139        frm.submit();
     140      }
     141    }
    127142    function shareItem(itemId)
    128143    {
     
    246261          title="Share&hellip;"
    247262          tooltip="Share the selected items"
     263        />
     264        <tbl:button
     265          image="take_ownership.png"
     266          onclick="takeOwnership()"
     267          title="Take ownership&hellip;"
     268          tooltip="Take ownership of the selected items"
    248269        />
    249270        <tbl:button
  • trunk/www/biomaterials/labels/view_label.jsp

    r2753 r2917  
    7676  final boolean sharePermission = label.hasPermission(Permission.SET_PERMISSION);
    7777  final boolean usePermission = label.hasPermission(Permission.USE);
    78  
    79   boolean readCurrentOwner = true;
    80   User currentOwner = null;
    81   try
    82   {
    83     currentOwner = label.getOwner();
    84   }
    85   catch (PermissionDeniedException ex)
    86   {
    87     readCurrentOwner = false;
    88   }
    89  
     78  final boolean setOwnerPermission = label.hasPermission(Permission.SET_OWNER);
     79  final boolean isOwner = label.isOwner();
    9080  %>
    91 
    9281  <base:page title="<%=title%>">
    9382  <base:head scripts="tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
     
    10897    {
    10998      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
     99    }
     100    function takeOwnership()
     101    {
     102      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
     103      {
     104        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
     105      }
    110106    }
    111107    function runPlugin(cmd)
     
    159155        title="Share&hellip;"
    160156        tooltip="<%=sharePermission ? "Share this label to other user, groups and projects" : "You do not have permission to share this label"%>"
     157      />
     158      <tbl:button
     159        disabled="<%=setOwnerPermission ? false : true%>"
     160        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
     161        onclick="takeOwnership()"
     162        title="Take ownership&hellip;"
     163        visible="<%=!isOwner%>"
     164        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
    161165      />
    162166      <tbl:button
  • trunk/www/biomaterials/samples/index.jsp

    r2811 r2917  
    4343  import="net.sf.basedb.util.RemovableUtil"
    4444  import="net.sf.basedb.util.ShareableUtil"
     45  import="net.sf.basedb.util.OwnableUtil"
    4546  import="net.sf.basedb.clients.web.Base"
    4647  import="net.sf.basedb.clients.web.WebException"
     
    272273    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
    273274  }
     275  else if ("TakeOwnershipOfItem".equals(cmd))
     276  {
     277    // Take ownership a single item and then return to the view page
     278    dc = sc.newDbControl();
     279    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     280    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
     281    dc.commit();
     282    redirect = viewPage;
     283  }
     284  else if ("TakeOwnershipOfItems".equals(cmd))
     285  {
     286    // Take ownership all selected items on the list page
     287    dc = sc.newDbControl();
     288    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     289    int numTotal = cc.getSelected().size();
     290    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
     291    dc.commit();
     292    if (numTotal != numOwned)
     293    {
     294      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
     295    }
     296    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     297  }
    274298  else if ("ExportItems".equals(cmd))
    275299  {
  • trunk/www/biomaterials/samples/list_samples.jsp

    r2893 r2917  
    152152      frm.submit();
    153153    }
     154    function takeOwnership()
     155    {
     156      var frm = document.forms[formId];
     157      if (Forms.numChecked(frm) == 0)
     158      {
     159        alert('Please select at least one item in the list');
     160        return;
     161      }
     162      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
     163      {
     164        frm.action = submitPage;
     165        frm.cmd.value = 'TakeOwnershipOfItems';
     166        frm.submit();
     167      }
     168    }
    154169    function shareItem(itemId)
    155170    {
     
    379394          title="Share&hellip;"
    380395          tooltip="Share the selected items"
     396        />
     397        <tbl:button
     398          image="take_ownership.png"
     399          onclick="takeOwnership()"
     400          title="Take ownership&hellip;"
     401          tooltip="Take ownership of the selected items"
    381402        />
    382403        <tbl:button
  • trunk/www/biomaterials/samples/view_sample.jsp

    r2875 r2917  
    8484  final boolean deletePermission = sample.hasPermission(Permission.DELETE);
    8585  final boolean sharePermission = sample.hasPermission(Permission.SET_PERMISSION);
    86  
     86  final boolean setOwnerPermission = sample.hasPermission(Permission.SET_OWNER);
     87  final boolean isOwner = sample.isOwner();
    8788  %>
    8889
     
    109110    {
    110111      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
     112    }
     113    function takeOwnership()
     114    {
     115      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
     116      {
     117        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
     118      }
    111119    }
    112120    function runPlugin(cmd)
     
    172180        title="Share&hellip;"
    173181        tooltip="<%=sharePermission ? "Share this sample to other user, groups and projects" : "You do not have permission to share this sample"%>"
     182      />
     183      <tbl:button
     184        disabled="<%=setOwnerPermission ? false : true%>"
     185        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
     186        onclick="takeOwnership()"
     187        title="Take ownership&hellip;"
     188        visible="<%=!isOwner%>"
     189        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
    174190      />
    175191      <tbl:button
Note: See TracChangeset for help on using the changeset viewer.