Ignore:
Timestamp:
2004-12-02T16:20:11+13:00 (19 years ago)
Author:
schweer
Message:

wizard for creating subscriptions: saving state works

Location:
trunk/greenstone3-extensions/gsdl-as
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java

    r8717 r8724  
    1414import java.util.*;
    1515
     16import javax.mail.Session;
    1617import javax.servlet.http.*;
    1718
     
    3839        actions.add("login");
    3940        actions.add("register");
     41        actions.add("logout");
    4042    }
    4143   
     
    99101            return "login.vm";
    100102        }
    101         // TODO handle wizard-style stuff
    102         // if "finish"
    103         ProfileStore.getInstance().createSubscription(arguments);
    104         return listSubscriptions(arguments, context);
    105         // else show next page
     103        if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) {
     104            ProfileStore.getInstance().createSubscription(arguments);
     105            return listSubscriptions(arguments, context);
     106        } else {
     107            return showSubscriptionWizardPage(arguments, context, true);
     108        }
    106109    }
    107110
     
    117120    }
    118121   
    119     public String editSubscription(Map arguments, Context context) {
     122    public String editSubscription(Map arguments, Context context) throws Exception {
    120123        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
    121124        if (!UserManager.getInstance().isLoggedIn(session)) {
     
    123126            return "login.vm";
    124127        }
    125         // TODO handle wizard-style stuff
    126         // if "finish"
    127         ProfileStore.getInstance().changeSubscription(arguments, session);
    128         return listSubscriptions(arguments, context);
    129         // else show next page
     128        if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) {
     129            ProfileStore.getInstance().changeSubscription(arguments, session);
     130            return listSubscriptions(arguments, context);
     131        } else {
     132            return showSubscriptionWizardPage(arguments, context, false);
     133        }
    130134    }
    131135   
     
    156160        UserManager.getInstance().createUser(arguments, session);
    157161        return login(arguments, context);
     162    }
     163   
     164    public String logout(Map arguments, Context context) {
     165        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
     166        Enumeration atts = session.getAttributeNames();
     167        while (atts.hasMoreElements()) {
     168            session.removeAttribute((String) atts.nextElement());
     169        }
     170        session.invalidate();
     171        return "general.vm";
    158172    }
    159173   
     
    211225        return null;
    212226    }
     227
     228    /**
     229     * @param arguments
     230     * @param context
     231     * @param create
     232     * @return
     233     * @throws Exception
     234     */
     235    private String showSubscriptionWizardPage(Map arguments, Context context, boolean create) throws Exception {
     236        if (create) {
     237            context.put("action", "createSubscription");
     238        } else {
     239            context.put("action", "editSubscription");
     240        }
     241        if (!arguments.containsKey("current_page")) {
     242            return "sub_type-details.vm";
     243        }
     244       
     245        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
     246        String currentPage = (String) arguments.get("current_page");
     247        String direction = (String) arguments.get("next_page");
     248       
     249        // save page arguments
     250        savePageArgsToSession(currentPage, arguments, session);
     251       
     252        String nextPage = getNextPage(currentPage, direction);
     253
     254        // fill prefill
     255        context.put("prefill", getPageArgsFromSession(nextPage, session));
     256       
     257        // fill preview
     258        context.put("preview", getPagePreview(nextPage, session));
     259       
     260        // get page-specific stuff
     261        if (nextPage.equals("host")) {
     262           
     263        } else if (nextPage.equals("collection")) {
     264           
     265        }
     266       
     267        return "sub_" + nextPage + ".vm";
     268    }
     269
     270    /**
     271     * @param nextPage
     272     * @param session
     273     * @return
     274     */
     275    private Map getPagePreview(String nextPage, HttpSession session) {
     276        Map preview = new TreeMap();
     277        if (nextPage.equals("type-details")) {
     278            return preview;
     279        }
     280        preview.putAll(getPageArgsFromSession("type-details", session));
     281        if (nextPage.equals("host")) {
     282            return preview;
     283        }
     284        preview.putAll(getPageArgsFromSession("host", session));
     285        if (nextPage.equals("collection")) {
     286            return preview;
     287        }
     288        preview.putAll(getPageArgsFromSession("collection", session));
     289        return preview;
     290    }
     291
     292    /**
     293     * @param currentPage
     294     * @param direction
     295     * @return
     296     * @throws Exception
     297     */
     298    private String getNextPage(String currentPage, String direction) throws Exception {
     299        String nextPage;
     300        if (currentPage.equals("host") && direction.equals("back")) {
     301            nextPage = "type-details";
     302        } else if (currentPage.equals("type-details") || (currentPage.equals("collection") && direction.equals("back"))) {
     303            nextPage = "host";
     304        } else if (currentPage.equals("host") || (currentPage.equals("notification") && direction.equals("back"))) {
     305            nextPage = "collection";
     306        } else if (currentPage.equals("collection")) {
     307            nextPage = "notification";
     308        } else {
     309            throw new Exception("unknown combination of currentPage=" + currentPage + " and nextPage=" + direction);
     310        }
     311        return nextPage;
     312    }
     313
     314    /**
     315     * @param page
     316     * @param session
     317     * @return TODO
     318     */
     319    private Map getPageArgsFromSession(String page, HttpSession session) {
     320        Map pageArgs = (Map) session.getAttribute("page_args");
     321        if (pageArgs == null || !pageArgs.containsKey(page))
     322            return new TreeMap();
     323        return (Map) pageArgs.get(page);
     324    }
     325
     326    /**
     327     * @param page
     328     * @param arguments
     329     * @param session
     330     */
     331    private void savePageArgsToSession(String page, Map arguments, HttpSession session) {
     332        Map pageArgs = (Map) session.getAttribute("page_args");
     333        if (pageArgs == null) {
     334            pageArgs = new TreeMap();
     335        }
     336        pageArgs.put(page, arguments);
     337        session.setAttribute("page_args", pageArgs);
     338    }
    213339}
  • trunk/greenstone3-extensions/gsdl-as/web/default.css

    r8720 r8724  
    5151    color: #666633;
    5252}
    53 
    54 img.help {
    55     cursor: help;
    56 }
  • trunk/greenstone3-extensions/gsdl-as/web/form.css

    r8720 r8724  
    1111}
    1212
     13td, th {
     14    padding: 0px 5px;
     15}
     16
     17thead tr {
     18    background-color: #CCCCCC;
     19}
     20
     21tr.even {
     22    background-color: #CCCCCC;
     23}
     24
     25.explanation {
     26    font-size: small;
     27}
     28
     29#progress {
     30    font-size: x-small;
     31    border: 0px solid black;
     32    width: 80%;
     33    margin: 5px auto;
     34}
     35
     36#progress td {
     37    width: 25%;
     38    vertical-align: top;
     39    text-align: center;
     40    color: #555;
     41    border-top: 10px solid #CCC;
     42}
     43
     44#progress td.completed {
     45    border-top-color: #9CBE9C;
     46    color: #000;
     47}
     48
     49#progress td.current {
     50    background-color: #F0E68C;
     51    font-style: italic;
     52    color: #000;
     53}
     54
     55table.subscription {
     56    font-size: small;
     57}
     58
     59.rssbutton {
     60    background: #ff6600;
     61    color: #ffffff;
     62    border-left:   1px solid #cc9966;
     63    border-top:    1px solid #ccaa99;
     64    border-right:  1px solid #993300;
     65    border-bottom: 1px solid #331100;
     66    padding: 0px 0.5em 0px 0.5em;
     67    font-family: helvetica, arial, sans-serif;
     68    font-weight: bold;
     69    font-size: xx-small;
     70    margin-top: 1em;
     71}
     72
  • trunk/greenstone3-extensions/gsdl-as/web/subscribe.html

    r8720 r8724  
    1717            You can subscribe to be notified of events about these elements:
    1818            <ul>
    19                 <li><a href="sub_document.html">documents</a> (new, modified or deleted documents)</li>
     19                <li><a href="/alerting/service?action=createSubscription">documents</a> (new, modified or deleted documents)</li>
    2020                <li><a href="sub_docparts.html">parts of documents</a> (new, modified or deleted parts of documents)</li>
    2121                <li><a href="sub_metadata.html">document metadata</a> (new, modified or deleted metadata of documents)</li>
Note: See TracChangeset for help on using the changeset viewer.