pvollenweider    2005/07/01 15:54:50 CEST

  Modified files:        (Branch: JAHIA-4-1-BRANCH)
    src/view/jsp/include simple_form_generator_definitions.inc 
                         simple_form_generator_display_form.inc 
                         simple_form_generator_process_post.inc 
    src/view/jsp         simple_form_generator.jsp web_css.jsp 
  Log:
  Dore posted values in container list
  
  Revision   Changes    Path
  1.1.2.6    +2 -0      
corporate_portal_templates/src/view/jsp/include/simple_form_generator_definitions.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/simple_form_generator_definitions.inc.diff?r1=1.1.2.5&r2=1.1.2.6&f=h
  1.1.2.5    +70 -12    
corporate_portal_templates/src/view/jsp/include/simple_form_generator_display_form.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/simple_form_generator_display_form.inc.diff?r1=1.1.2.4&r2=1.1.2.5&f=h
  1.1.2.5    +94 -73    
corporate_portal_templates/src/view/jsp/include/simple_form_generator_process_post.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/simple_form_generator_process_post.inc.diff?r1=1.1.2.4&r2=1.1.2.5&f=h
  1.1.2.3    +1 -0      
corporate_portal_templates/src/view/jsp/simple_form_generator.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/simple_form_generator.jsp.diff?r1=1.1.2.2&r2=1.1.2.3&f=h
  1.28.4.15  +9 -0      corporate_portal_templates/src/view/jsp/web_css.jsp
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/web_css.jsp.diff?r1=1.28.4.14&r2=1.28.4.15&f=h
  
  
  
  Index: simple_form_generator_definitions.inc
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/Attic/simple_form_generator_definitions.inc,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- simple_form_generator_definitions.inc     30 Jun 2005 15:20:46 -0000      
1.1.2.5
  +++ simple_form_generator_definitions.inc     1 Jul 2005 13:54:50 -0000       
1.1.2.6
  @@ -10,6 +10,8 @@
           bundleKey="<%=resBundleID%>"/>
       <content:declareField name="subject" title="Subject" type="SmallText"
           titleKey="form.Subject" bundleKey="<%=resBundleID%>"/>
  +    <content:declareField name="storePostedValues" title="Store posted 
values" type="Boolean"
  +        titleKey="form.storePostedValues" bundleKey="<%=resBundleID%>" 
value="false"/>
       <content:declareField name="displayTextAfterPost"
           title="Text to display after a post" type="BigText"
           titleKey="form.displayTextAfterPost" bundleKey="<%=resBundleID%>"
  
  
  
  Index: simple_form_generator_display_form.inc
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/Attic/simple_form_generator_display_form.inc,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- simple_form_generator_display_form.inc    30 Jun 2005 15:16:42 -0000      
1.1.2.4
  +++ simple_form_generator_display_form.inc    1 Jul 2005 13:54:50 -0000       
1.1.2.5
  @@ -1,6 +1,7 @@
   <%
  -JahiaContainerList forms = jData.containers().getContainerList( "forms" );
  -if (forHasBeenPosted) {
  +//JahiaContainerList forms = jData.containers().getContainerList( "forms" );
  +
  +if (forHasBeenPosted & emptyMandatoryFields.isEmpty()) {
       %>
       <%=displayTextAfterPostValue%>
       <%
  @@ -9,7 +10,7 @@
           ContainerListBean formsBean = new ContainerListBean(forms,jParams);
           jData.gui().html().drawBeginActionMenu(formsBean ,
               null, null, true, "", 
"jahiatemplates.Corporate_portal_templates", null, out);
  -        Enumeration formsEnum = forms.getContainers();
  +        formsEnum = forms.getContainers();
           boolean isFormOK = false;
           if (! formsEnum.hasMoreElements()) {
            if ( ! "".equals(jData.gui().html().drawAddContainerLauncher( forms 
)) ) {
  @@ -28,6 +29,7 @@
               String recipients = form.getFieldValue("recipients","Please 
insert a sender");
               String recipientsCC = form.getFieldValue("recipientsCC","");
               String subject = form.getFieldValue("subject","");
  +            storePostedValues = 
"true".equals(form.getFieldValue("storePostedValues","false"));
               JahiaPage pageRedirected = (JahiaPage) 
form.getFieldObject("pageRedirected" );
               isFormOK = ! ("".equals(sender) || "".equals( recipients ));
   
  @@ -60,12 +62,15 @@
                       jData.gui().html().drawBeginActionMenu(fieldsBean , null,
                           null, true, 
"","jahiatemplates.Corporate_portal_templates",
                           null, out);
  +
  +                    Enumeration fieldsEnum = null;
  +
                       %>
                       <form method="post" action="<%=bypassUrl%>"
  -                            name="form_<%=form.getID()%>" 
id="form_<%=form.getID()%>">
  +                            name="submitToContainerList" 
id="form_<%=form.getID()%>">
                       <input type="hidden" name="formId" 
value="<%=form.getID()%>"/>
                       <%
  -                    if (! emptyMandatoryFields.isEmpty()) {
  +                    if (forHasBeenPosted && ! 
emptyMandatoryFields.isEmpty()) {
                           %><strong><span 
style="color:red;"><content:resourceBundle 
resourceBundle="jahiatemplates.Corporate_portal_templates"
                       
resourceName="form.fieldIsMandatory"/></span></strong><br/><br/><%
                       }
  @@ -73,8 +78,7 @@
                       <table>
                       <%
   
  -                    Enumeration fieldsEnum = fields.getContainers();
  -
  +                    fieldsEnum = fields.getContainers();
                       while (fieldsEnum.hasMoreElements()) {
                           JahiaContainer currentField = (JahiaContainer) 
fieldsEnum.nextElement();
                           ContainerBean currentFieldBean = new 
ContainerBean(currentField,jParams);
  @@ -83,14 +87,13 @@
                           boolean isMandatory = "true".equals(isMandatoryStr);
                           String type = currentField.getFieldValue("type","");
                           String defaultValue = 
currentField.getFieldValue("defaultValue","");
  -
                           %>
                           <tr>
                               <td>
                                   <%
                                   if (! 
ResourceBundleMarker.drawMarker(resBundleID,"submitButton","").equals(type)){
                                       %><strong<%
  -                                    if (emptyMandatoryFields.contains(new 
Integer(currentField.getID()))) {
  +                                    if (forHasBeenPosted && 
emptyMandatoryFields.contains(new Integer(currentField.getID()))) {
                                           %> style="color:red;"<%
                                       }
                                       %>><%=fieldTitle%> <%
  @@ -242,17 +245,72 @@
                       </table>
                       </form>
                       <%
  -
                       jData.gui().html().drawEndActionMenu(fieldsBean , null,
                           null, true, 
"","jahiatemplates.Corporate_portal_templates",
                           null, out);
  -                }
  -
  +                    if (storePostedValues) {
  +                        // display tables
  +                        %>
  +                        <table class="forms">
  +                        <tr class="title">
  +                        <%
  +                        fieldsEnum = fields.getContainers();
  +                        Vector fieldNames = new Vector();
  +                        while (fieldsEnum.hasMoreElements()) {
  +                            JahiaContainer currentField = (JahiaContainer) 
fieldsEnum.nextElement();
  +                            String type = 
currentField.getFieldValue("type","");
  +                            if (! 
ResourceBundleMarker.drawMarker(resBundleID,"submitButton","").equals(type)) {
  +                                String fieldTitle = 
currentField.getFieldValue("fieldTitle","");
  +                                fieldNames.add("field_" + 
currentField.getID());
  +                                %>
  +                                <td><%=fieldTitle%></td>
  +                                <%
  +                            }
  +                        }
  +                        %>
  +                        </tr>
  +                        <%
  +                        // get the values
  +                        if (form != null) {
  +                            JahiaContainerList storePostedForm = 
jData.containers().getContainerList( "form_" + form.getID() );
   
  +                            if (storePostedForm != null) {
  +                                Enumeration postedFieldsEnum = 
storePostedForm.getContainers();
  +                                while (postedFieldsEnum.hasMoreElements()) {
  +                                    JahiaContainer postedFieldsContainer = 
(JahiaContainer) postedFieldsEnum.nextElement();
  +                                    ContainerBean postedFieldsContainerBean =
  +                                        new 
ContainerBean(postedFieldsContainer,jParams);
  +                                    Enumeration fieldNamesEnum = 
fieldNames.elements();
  +                                    %>
  +                                    <tr>
  +                                    <%
  +                                    while (fieldNamesEnum.hasMoreElements()) 
{
  +                                        String fieldName = (String) 
fieldNamesEnum.nextElement();
  +                                        String fieldValue = 
postedFieldsContainer.getFieldValue(fieldName,"");
  +                                        logger.debug("fieldName " + 
fieldName + ": " + fieldValue);
  +                                        %><td><%=fieldValue%></td><%
  +                                    }
  +                                    if (jData.gui().isEditMode()) {
  +                                        %><td><%
  +                                        
jData.gui().html().drawBeginActionMenu(postedFieldsContainerBean , null,
  +                                            null, false, 
"","jahiatemplates.Corporate_portal_templates",
  +                                            null, out);
  +                                        %></td><%
  +                                    }
  +                                    %></tr><%
  +                                }
  +                            }
  +                        }
  +                        %>
  +                        </table>
  +                        <%
  +                    }
  +                }
               }
           }
           jData.gui().html().drawEndActionMenu(formsBean ,
               null, null, true, "", 
"jahiatemplates.Corporate_portal_templates", null, out);
       }
   }
  +
   %>
  \ No newline at end of file
  
  
  
  Index: simple_form_generator_process_post.inc
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/Attic/simple_form_generator_process_post.inc,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- simple_form_generator_process_post.inc    30 Jun 2005 15:16:42 -0000      
1.1.2.4
  +++ simple_form_generator_process_post.inc    1 Jul 2005 13:54:50 -0000       
1.1.2.5
  @@ -4,87 +4,108 @@
   String displayTextAfterPostValue = "";
   if (formIdStr != null) {
       logger.debug("Form has been posted");
  -    int formId = -1;
  -    try {
  -        formId = Integer.parseInt(request.getParameter("formId"));
  -        // get the container
  -        ContentContainer formContentContainer = 
ContentContainer.getContainer(formId);
  -        if (formContentContainer != null) {
  -            JahiaContainer form = formContentContainer.
  -                getJahiaContainer(jParams, jParams.getEntryLoadRequest());
  -            String sender = form.getFieldValue("sender","Please insert a 
sender");
  -            String recipients = form.getFieldValue("recipients","Please 
insert a sender");
  -            String recipientsCC = form.getFieldValue("recipientsCC","");
  -            String subject = form.getFieldValue("subject","");
  -            String alertText = form.getFieldValue("alertText","");
  -            displayTextAfterPostValue = 
form.getFieldValue("displayTextAfterPost",
  -                getResourceBundle("form.displayTextAfterPostValue",
  -                    "Thank you. Your form has been sent.",jData));
  -
  -            logger.debug("new form -----------------------------");
  -            logger.debug("sender: " + sender);
  -            logger.debug("recipients: " + recipients);
  -            logger.debug("recipientsCC: " + recipientsCC);
  -            logger.debug("subject: " + subject);
  -            logger.debug("displayTextAfterPostValue: " + 
displayTextAfterPostValue);
  -
  -            StringBuffer mailBody = new StringBuffer();
  -            // get all values posted
  -            JahiaContainerList fields = form.getContainerList( "fields" );
  -            if (fields != null) {
  -                Enumeration fieldsEnum = fields.getContainers();
  -                while (fieldsEnum.hasMoreElements()) {
  -                    JahiaContainer currentField = (JahiaContainer) 
fieldsEnum.nextElement();
  -                    String type = currentField.getFieldValue("type","");
  -                    if (! 
ResourceBundleMarker.drawMarker(resBundleID,"submitButton","").equals(type)) {
  -                        String fieldTitle = 
currentField.getFieldValue("fieldTitle","");
  -                        String isMandatoryStr = 
currentField.getFieldValue("isMandatory","false");
  -                        boolean isMandatory = "true".equals(isMandatoryStr);
  -                        String[] postedValues = 
request.getParameterValues("field_" + currentField.getID());
  -                        StringBuffer postedValuesSB = new StringBuffer("");
  -                        if (postedValues != null) {
  -                            for (int  i = 0; i < postedValues.length; i++){
  -                                if (i > 0){
  -                                    postedValuesSB.append(" - ");
  -                                }
  -                                postedValuesSB.append(postedValues[i]);
  -                            }
  -                        }
  -                        logger.debug("-- " + fieldTitle + ": " + 
postedValuesSB.toString());
  -                        mailBody.append(fieldTitle + " : " + 
postedValuesSB.toString() + "\n");
  -                        if (isMandatory && 
"".equals(postedValuesSB.toString())) {
  -                            logger.debug("Field [" + fieldTitle + "] is 
mandatory");
  -                            emptyMandatoryFields.add(new 
Integer(currentField.getID()));
  +    forHasBeenPosted = true;
  +}
  +JahiaContainerList forms = jData.containers().getContainerList( "forms" );
  +Enumeration formsEnum = forms.getContainers();
  +if (formsEnum.hasMoreElements()) {
  +    JahiaContainer form = (JahiaContainer) formsEnum.nextElement();
  +    String sender = form.getFieldValue("sender","Please insert a sender");
  +    String recipients = form.getFieldValue("recipients","Please insert a 
sender");
  +    String recipientsCC = form.getFieldValue("recipientsCC","");
  +    String subject = form.getFieldValue("subject","");
  +    storePostedValues = 
"true".equals(form.getFieldValue("storePostedValues","false"));
  +    String alertText = form.getFieldValue("alertText","");
  +    displayTextAfterPostValue = form.getFieldValue("displayTextAfterPost",
  +        getResourceBundle("form.displayTextAfterPostValue",
  +            "Thank you. Your form has been sent.",jData));
  +
  +    logger.debug("new form -----------------------------");
  +    logger.debug("sender: " + sender);
  +    logger.debug("recipients: " + recipients);
  +    logger.debug("recipientsCC: " + recipientsCC);
  +    logger.debug("subject: " + subject);
  +    logger.debug("displayTextAfterPostValue: " + displayTextAfterPostValue);
  +
  +
  +
  +    StringBuffer mailBody = new StringBuffer();
  +    // get all values posted
  +    JahiaContainerList fields = form.getContainerList( "fields" );
  +    if (fields != null) {
  +        Vector filesContainerFields = new Vector();
  +        Enumeration fieldsEnum = fields.getContainers();
  +        while (fieldsEnum.hasMoreElements()) {
  +            JahiaContainer currentField = (JahiaContainer) 
fieldsEnum.nextElement();
  +            String type = currentField.getFieldValue("type","");
  +            if (! 
ResourceBundleMarker.drawMarker(resBundleID,"submitButton","").equals(type)) {
  +                String fieldTitle = 
currentField.getFieldValue("fieldTitle","");
  +                if (storePostedValues) {
  +                    jData.containers().declareField( "field_" + 
currentField.getID(), fieldTitle, FieldTypes.BIGTEXT, "" );
  +                    filesContainerFields.add("field_" + 
currentField.getID());
  +                }
  +                String isMandatoryStr = 
currentField.getFieldValue("isMandatory","false");
  +                boolean isMandatory = "true".equals(isMandatoryStr);
  +                String[] postedValues = request.getParameterValues("field_" 
+ currentField.getID());
  +                StringBuffer postedValuesSB = new StringBuffer("");
  +                if (postedValues != null) {
  +                    for (int  i = 0; i < postedValues.length; i++){
  +                        if (i > 0){
  +                            postedValuesSB.append(" - ");
                           }
  +                        postedValuesSB.append(postedValues[i]);
                       }
                   }
  -            }
  -            if (emptyMandatoryFields.isEmpty()) {
  -                //Send the mail
  -                sender = JahiaTools.html2text(sender);
  -                recipients = JahiaTools.html2text(recipients);
  -                recipientsCC = JahiaTools.html2text(recipientsCC);
  -                subject = JahiaTools.html2text(subject);
  -                String body = JahiaTools.html2text(mailBody.toString());
  -                org.jahia.services.mail.MailService mailService =
  -                    ServicesRegistry.getInstance().getMailService();
  -                try {
  -                    mailService.sendMessage (sender, recipients,
  -                        recipientsCC, null, subject, body);
  -                        forHasBeenPosted = true;
  -                } catch (Throwable th) {
  -                    %>Error while sending mail : <%=th.getMessage()%><%
  -
  +                logger.debug("-- " + fieldTitle + ": " + 
postedValuesSB.toString());
  +                mailBody.append(fieldTitle + " : " + 
postedValuesSB.toString() + "\n");
  +                if (isMandatory && "".equals(postedValuesSB.toString())) {
  +                    logger.debug("Field [" + fieldTitle + "] is mandatory");
  +                    emptyMandatoryFields.add(new 
Integer(currentField.getID()));
                   }
  -                logger.debug("Mail sent");
  +            }
  +        }
  +        if (storePostedValues) {
  +            jData.containers().declareContainer( "form_" + form.getID(), 
"Form " + form.getID(), filesContainerFields);
   
  +            // create container list if don't exist
  +            JahiaContainerList storePostedForm = form.getContainerList( 
"form_" + form.getID() );
  +            if ( storePostedForm !=null && storePostedForm.getID()==0 ) {
  +                logger.debug("storePostedForm !=null && 
storePostedForm.getID()==0");
  +                ContainerListBean storePostedFormBean = new 
ContainerListBean(storePostedForm,jParams);
  +                     
org.jahia.registries.ServicesRegistry.getInstance().getJahiaContainersService().
  +                         saveContainerListInfo(storePostedForm, 
jParams.getContentPage().getAclID());
  +                     storePostedForm = 
storePostedFormBean.getJahiaContainerList();
  +            }
  +            ContainerListBean storePostedFormBean = new 
ContainerListBean(storePostedForm,jParams);
  +            
pageContext.setAttribute("storePostedFormBean",storePostedFormBean);
  +            if (forHasBeenPosted & emptyMandatoryFields.isEmpty()) {
  +                %>
  +                <content:formContentMapperHandler 
listName='storePostedFormBean'
  +                    submitMarker="formId" immediatePublication="true"/>
  +                <%
               }
  +
           }
  -    } catch (NumberFormatException nfe) {
  -        logger.error("Could not get formId from post");
       }
  +    if (emptyMandatoryFields.isEmpty()) {
  +        //Send the mail
  +        if (forHasBeenPosted) {
  +            sender = JahiaTools.html2text(sender);
  +            recipients = JahiaTools.html2text(recipients);
  +            recipientsCC = JahiaTools.html2text(recipientsCC);
  +            subject = JahiaTools.html2text(subject);
  +            String body = JahiaTools.html2text(mailBody.toString());
  +            org.jahia.services.mail.MailService mailService =
  +                ServicesRegistry.getInstance().getMailService();
  +            try {
  +                mailService.sendMessage (sender, recipients,
  +                    recipientsCC, null, subject, body);
  +            } catch (Throwable th) {
  +                %>Error while sending mail : <%=th.getMessage()%><%
   
  +            }
  +            logger.debug("Mail sent");
  +        }
  +    }
   }
  -
  -
   %>
  \ No newline at end of file
  
  
  
  Index: simple_form_generator.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/Attic/simple_form_generator.jsp,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- simple_form_generator.jsp 24 Jun 2005 14:13:17 -0000      1.1.2.2
  +++ simple_form_generator.jsp 1 Jul 2005 13:54:50 -0000       1.1.2.3
  @@ -2,6 +2,7 @@
   <%@ include file="include/simple_form_generator_definitions.inc"%>
   <%
   Vector emptyMandatoryFields = new Vector();
  +boolean storePostedValues = false;
   %>
   <%@ include file="include/simple_form_generator_process_post.inc"%>
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
  
  
  
  Index: web_css.jsp
  ===================================================================
  RCS file: 
/home/cvs/repository/corporate_portal_templates/src/view/jsp/web_css.jsp,v
  retrieving revision 1.28.4.14
  retrieving revision 1.28.4.15
  diff -u -r1.28.4.14 -r1.28.4.15
  --- web_css.jsp       24 May 2005 12:24:10 -0000      1.28.4.14
  +++ web_css.jsp       1 Jul 2005 13:54:50 -0000       1.28.4.15
  @@ -953,4 +953,13 @@
   }
   span.hl {
       background: #FFFF66;
  +}
  +table.forms td {
  +    padding: 0 5px 0 5px;
  +    background: #e9e9e9;
  +}
  +table.forms tr.title td {
  +    background: #000000;
  +    font-weight: bold;
  +    color: #ffffff;
   }
  \ No newline at end of file
  

Reply via email to