Changeset 7499


Ignore:
Timestamp:
Aug 6, 2018, 2:46:45 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2126: Add extension points to the Preferences and Contact information dialogs

The dialogs should now have TabAction extension points with id:

  • net.sf.basedb.clients.web.tabcontrol.edit.user-preferences
  • net.sf.basedb.clients.web.tabcontrol.edit.user-information


and OnSaveAction extension points with id:

  • net.sf.basedb.clients.web.onsave.user-preferences
  • net.sf.basedb.clients.web.onsave.user-information
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/edit/EditUtil.java

    r7407 r7499  
    157157    RethrowErrorHandlerFactory ehf = new RethrowErrorHandlerFactory();
    158158   
     159    // Special dialogs
     160    registerEditTab(registry, EP_PREFIX_EDIT + "user-preferences", "Tab-control in the 'BASE » Preferences' dialog.");
     161    registerEditTab(registry, EP_PREFIX_EDIT + "user-information", "Tab-control in the 'BASE » Contact information' dialog.");
     162    registerOnSave(registry, EP_PREFIX_SAVE + "user-preferences", "On-save callback for the 'BASE » Preferences' dialog.", ehf);
     163    registerOnSave(registry, EP_PREFIX_SAVE + "user-information", "On-save callback for the 'BASE » Contact information' dialog.", ehf);
     164   
     165    // Regular edit-item dialogs
    159166    registerEditTab(registry, EP_PREFIX_EDIT + "all", "Tab-control in all edit dialogs");
    160167    registerEditTab(registry, EP_PREFIX_EDIT + "ownable", "Tab-control in edit dialogs for items that are owned by a user");
  • trunk/www/my_base/user/preferences.jsp

    r7295 r7499  
    5757  import="net.sf.basedb.clients.web.extensions.JspContext"
    5858  import="net.sf.basedb.clients.web.extensions.startpage.StartPageAction"
     59  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
     60  import="net.sf.basedb.clients.web.extensions.tabcontrol.TabAction"
    5961  import="net.sf.basedb.util.Values"
    6062  import="java.util.Collections"
     
    124126  JspContext context = ExtensionsControl.createContext(dc, pageContext, null, user);
    125127  ExtensionsInvoker<StartPageAction> invoker = (ExtensionsInvoker<StartPageAction>)ExtensionsControl.useExtensions(context, "net.sf.basedb.clients.web.start-page");
     128  ExtensionsInvoker<TabAction> tabsInvoker = (ExtensionsInvoker<TabAction>)ExtensionsControl.useExtensions(context, EditUtil.EP_PREFIX_EDIT+"user-preferences");
    126129  %>
    127130  <base:page type="popup" title="<%="Preferences for "+HTML.encodeTags(user.getName())%>" id="preferences">
     
    145148      id="settings"
    146149      subclass="content dialogtabcontrol"
    147       active="<%=activePage%>" remember="<%=activePage == null%>"   
     150      active="<%=activePage%>" remember="<%=activePage == null%>"
     151      extensions="<%=tabsInvoker%>"
    148152      position="bottom">
    149153      <t:tab
  • trunk/www/my_base/user/settings.jsp

    r7495 r7499  
    4444  import="net.sf.basedb.util.json.JsonUtil"
    4545  import="net.sf.basedb.util.json.JsonConverter"
     46  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    4647  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
    4748  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
     49  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
     50  import="net.sf.basedb.clients.web.extensions.tabcontrol.TabAction"
     51  import="net.sf.basedb.clients.web.extensions.JspContext"
     52  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
    4853  import="org.json.simple.JSONObject"
    4954  import="org.json.simple.JSONArray"
     
    9398  String jsDateTimeFormat = HTML.javaScriptEncode(dateTimeFormat);
    9499  String htmlDateTimeFormat = HTML.encodeTags(dateTimeFormat);
     100  JspContext context = ExtensionsControl.createContext(dc, pageContext, null, user);
     101  ExtensionsInvoker<TabAction> tabsInvoker = (ExtensionsInvoker<TabAction>)ExtensionsControl.useExtensions(context, EditUtil.EP_PREFIX_EDIT+"user-information");
    95102%>
    96103  <base:page type="popup" title="<%=title%>">
     
    111118      subclass="content dialogtabcontrol"
    112119      active="<%=activePage%>" id="settings"
     120      extensions="<%=tabsInvoker%>"
    113121      position="bottom" remember="false">
    114122 
  • trunk/www/my_base/user/submit_user.jsp

    r7498 r7499  
    4545  import="net.sf.basedb.util.Values"
    4646  import="net.sf.basedb.util.formatter.Formatter"
     47  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    4748  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
    4849  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     50  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
     51  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
     52  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
     53  import="net.sf.basedb.clients.web.extensions.JspContext"
    4954  import="java.util.Arrays"
    5055  import="java.util.Collections"
     
    7782    dc.reattachItem(user, false);
    7883
    79     // Contact information tab
    80     user.setEmail(email);
    81     boolean useDeviceVerification = Values.getBoolean(request.getParameter("useDeviceVerification"));
    82     if (!useDeviceVerification) user.disableDeviceVerification();
    83     if (EmailUtil.isEnabled())
    84     {
    85       user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
    86       if (useDeviceVerification && !user.getUseDeviceVerification())
    87       {
    88         // Send a verification code for verifying the email address
    89         forward = "verify_email.jsp?ID="+ID;
    90       }
    91     }
    92     user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
    93     user.setAddress(Values.getStringOrNull(request.getParameter("address")));
    94     user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
    95     user.setFax(Values.getStringOrNull(request.getParameter("fax")));
    96     user.setUrl(Values.getStringOrNull(request.getParameter("url")));
    97 
    98     // Password tab
    99     String password = Values.getStringOrNull(request.getParameter("password"));
    100     if (password != null) user.setPassword(password);
    101 
    102     // Other settings tab
    103     user.setDescription(Values.getStringOrNull(request.getParameter("description")));
    104 
    105     // Extended properties
    106     List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true);
    107     if (extendedProperties != null)
    108     {
    109       Map<String, String[]> parameters = request.getParameterMap();
    110       for (ExtendedProperty ep : extendedProperties)
    111       {
    112         if (ep.isRestrictedEdit()) continue;
    113         String name = ep.getName();
    114         if (parameters.containsKey("ep."+name))
     84    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user);
     85    ExtensionsInvoker invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information");
     86    try
     87    {
     88      // Contact information tab
     89      user.setEmail(email);
     90      boolean useDeviceVerification = Values.getBoolean(request.getParameter("useDeviceVerification"));
     91      if (!useDeviceVerification) user.disableDeviceVerification();
     92      if (EmailUtil.isEnabled())
     93      {
     94        user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
     95        if (useDeviceVerification && !user.getUseDeviceVerification())
    11596        {
    116           Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
    117           Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
    118           user.setExtended(name, value);
     97          // Send a verification code for verifying the email address
     98          forward = "verify_email.jsp?ID="+ID;
    11999        }
    120100      }
    121     }
    122 
    123     dc.commit();
    124     sc.setSessionSetting("user", null);
    125     message = "Information saved";
     101      user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
     102      user.setAddress(Values.getStringOrNull(request.getParameter("address")));
     103      user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
     104      user.setFax(Values.getStringOrNull(request.getParameter("fax")));
     105      user.setUrl(Values.getStringOrNull(request.getParameter("url")));
     106 
     107      // Password tab
     108      String password = Values.getStringOrNull(request.getParameter("password"));
     109      if (password != null) user.setPassword(password);
     110 
     111      // Other settings tab
     112      user.setDescription(Values.getStringOrNull(request.getParameter("description")));
     113 
     114      // Extended properties
     115      List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true);
     116      if (extendedProperties != null)
     117      {
     118        Map<String, String[]> parameters = request.getParameterMap();
     119        for (ExtendedProperty ep : extendedProperties)
     120        {
     121          if (ep.isRestrictedEdit()) continue;
     122          String name = ep.getName();
     123          if (parameters.containsKey("ep."+name))
     124          {
     125            Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
     126            Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
     127            user.setExtended(name, value);
     128          }
     129        }
     130      }
     131     
     132      // OnSave extensions
     133      invoker.render(OnSaveRenderer.ON_SAVE);
     134      dc.commit();
     135      invoker.render(OnSaveRenderer.ON_COMMIT);
     136      message = "Information saved";
     137    }
     138    catch (Exception ex)
     139    {
     140      invoker.render(OnSaveRenderer.onRollback(ex));
     141      throw ex;
     142    }
     143    finally
     144    {
     145      sc.setSessionSetting("user", null);
     146    }
    126147  }
    127148  else if ("VerifyEmail".equals(cmd))
     
    136157  else if ("SavePreferences".equals(cmd))
    137158  {
    138     int newScale = Values.getInt(request.getParameter("scale"), 100);
    139     sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
    140     sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
    141     sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
    142     sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
    143     ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
    144     int maxRecent = Base.getMaxRecent(sc);
    145  
    146     String toolbar = request.getParameter("toolbar");
    147     boolean hasImages = true;
    148     boolean hasText = true;
    149     if ("text".equals(toolbar))
    150     {
    151       hasImages = false;
    152     }
    153     else if ("images".equals(toolbar))
    154     {
    155       hasText = false;
    156     }
    157     sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
    158     sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
    159     String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
    160     String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
    161     String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
    162     sc.setUserClientSetting("ratiocolor.min", minColor);
    163     sc.setUserClientSetting("ratiocolor.mid", midColor);
    164     sc.setUserClientSetting("ratiocolor.max", maxColor);
    165     cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
     159    User user = User.getById(dc, sc.getLoggedInUserId());
     160    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user);
     161    ExtensionsInvoker invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information");
     162    try
     163    {
     164      int newScale = Values.getInt(request.getParameter("scale"), 100);
     165      sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
     166      sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
     167      sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
     168      sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
     169      ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
     170      int maxRecent = Base.getMaxRecent(sc);
    166171   
    167     String dateFormat = request.getParameter("date_format");
    168     String dateTimeFormat = request.getParameter("datetime_format");
    169     FormatterSettings.setDateFormat(sc, dateFormat);
    170     FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
    171     cc.setRecent("dateFormats", dateFormat, maxRecent);
    172     cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
    173 
    174     int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
    175     FormatterSettings.setNumDecimals(sc, numDecimals);
    176    
    177     sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
    178    
    179     sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page")));
    180    
    181     // Plugins tab
    182     sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
    183     sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
    184     sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
    185    
    186     // Recent items tab
    187     int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
    188     sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
    189     sc.setSessionSetting("appearance.recent", newMaxUsed);
    190     int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
    191     sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
    192     sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
    193 
    194     String[] stickyItems = request.getParameterValues("sticky_items");
    195     sc.setUserClientSetting("menu.mostRecent",
    196       stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
    197    
    198     // Roles tab
    199     String[] inactiveRoles = request.getParameterValues("inactiveRoles");
    200     sc.setUserClientSetting("inactiveRoles", inactiveRoles == null ? null : Values.getString(Arrays.asList(inactiveRoles), ":", true));
    201    
    202     message = "Preferences saved";
     172      String toolbar = request.getParameter("toolbar");
     173      boolean hasImages = true;
     174      boolean hasText = true;
     175      if ("text".equals(toolbar))
     176      {
     177        hasImages = false;
     178      }
     179      else if ("images".equals(toolbar))
     180      {
     181        hasText = false;
     182      }
     183      sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
     184      sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
     185      String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
     186      String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
     187      String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
     188      sc.setUserClientSetting("ratiocolor.min", minColor);
     189      sc.setUserClientSetting("ratiocolor.mid", midColor);
     190      sc.setUserClientSetting("ratiocolor.max", maxColor);
     191      cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
     192     
     193      String dateFormat = request.getParameter("date_format");
     194      String dateTimeFormat = request.getParameter("datetime_format");
     195      FormatterSettings.setDateFormat(sc, dateFormat);
     196      FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
     197      cc.setRecent("dateFormats", dateFormat, maxRecent);
     198      cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
     199 
     200      int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
     201      FormatterSettings.setNumDecimals(sc, numDecimals);
     202     
     203      sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
     204     
     205      sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page")));
     206     
     207      // Plugins tab
     208      sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
     209      sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
     210      sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
     211     
     212      // Recent items tab
     213      int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
     214      sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
     215      sc.setSessionSetting("appearance.recent", newMaxUsed);
     216      int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
     217      sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
     218      sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
     219 
     220      String[] stickyItems = request.getParameterValues("sticky_items");
     221      sc.setUserClientSetting("menu.mostRecent",
     222        stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
     223     
     224      // Roles tab
     225      String[] inactiveRoles = request.getParameterValues("inactiveRoles");
     226      sc.setUserClientSetting("inactiveRoles", inactiveRoles == null ? null : Values.getString(Arrays.asList(inactiveRoles), ":", true));
     227     
     228      // OnSave extensions
     229      invoker.render(OnSaveRenderer.ON_SAVE);
     230      dc.commit();
     231      invoker.render(OnSaveRenderer.ON_COMMIT);
     232      message = "Preferences saved";
     233    }
     234    catch (Exception ex)
     235    {
     236      invoker.render(OnSaveRenderer.onRollback(ex));
     237      throw ex;
     238    }
    203239  }
    204240  else if ("ReloadPermissions".equals(cmd))
Note: See TracChangeset for help on using the changeset viewer.