[elvystrac] r1675 - List of layouts upgraded - when LD-window is closed, list of layouts is refreshed (if it is on background)

  • From: elvys@xxxxxxxxxxxxxxxxxxxxxx
  • To: elvystrac@xxxxxxxxxxxxx
  • Date: Fri, 5 Feb 2010 01:59:17 +0100

Author: DavidK
Date: 2010-02-05 01:59:17 +0100 (Fri, 05 Feb 2010)
New Revision: 1675

Added:
   trunk/server/webServer2/WebContent/images/clearpixel.gif
   trunk/server/webServer2/WebContent/js/layoutrel/
   trunk/server/webServer2/WebContent/js/layoutrel/layoutEdit.js
Modified:
   trunk/server/elvysCommons/src/cz/elvys/commons/utils/HibUtils.java
   trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBL.java
   trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLImpl.java
   trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLTest.java
   trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java
   
trunk/server/webServer2/JavaSource/cz/elvys/webServer/component/layoutrel/LayoutListComponentBean.java
   
trunk/server/webServer2/SpringSource/cz/elvys/webServer/bl/api/elvysrel/PlanDocumentBL.java
   trunk/server/webServer2/WebContent/js/elvys-template.js
   
trunk/server/webServer2/WebContent/secured/components/layoutListComponent.xhtml
   trunk/server/webServer2/WebContent/secured/layoutrel/layoutEdit.xhtml
   trunk/server/webServer2/WebContent/template/elvys-template.xhtml
Log:
List of layouts upgraded - when LD-window is closed, list of layouts is 
refreshed (if it is on background)

Modified: trunk/server/elvysCommons/src/cz/elvys/commons/utils/HibUtils.java
===================================================================
--- trunk/server/elvysCommons/src/cz/elvys/commons/utils/HibUtils.java  
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/elvysCommons/src/cz/elvys/commons/utils/HibUtils.java  
2010-02-05 00:59:17 UTC (rev 1675)
@@ -50,6 +50,7 @@
         *              nullable - if null or empty array, no additional nodes 
will be loaded
         * @return object ref or null if not found
         * @throws Exception some HIB exception
+        * @deprecated use type-specific DAO access (from type specific BL) 
instead
         */
        public static Object findByID(Class<?> hibClass, Integer ID, String ... 
fetches) throws Exception {
                // init transaction

Modified: trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBL.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBL.java       
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBL.java       
2010-02-05 00:59:17 UTC (rev 1675)
@@ -18,13 +18,15 @@
        public Layout getPresentLayout(Integer elvysID, boolean isDay) throws 
ExecuteException;
        
        /**
-        * Gets list of layouts belonging to certain company
+        * Gets list of layouts belonging to certain company <br/>
+        * Fetches: company
+        * Orders by: date of create (ID) TODO zmenit to na date of create
         * @param companyId id of company
-        * @param excludedLayoutsIds ids of layouts which will be excluded
+        * @param excludedLayoutsIds ids of layouts which will be excluded
         * @throws ExecuteException 
         * @return
         */
-       public List<Layout> getLayoutsOfCompany(Integer companyId, Integer... 
excludedLayoutsIds) throws ExecuteException;
+       public List<Layout> listLayoutsOfCompany(Integer companyId, Integer... 
excludedLayoutsIds) throws ExecuteException;
        
        
        /**

Modified: 
trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLImpl.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLImpl.java   
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLImpl.java   
2010-02-05 00:59:17 UTC (rev 1675)
@@ -1,5 +1,7 @@
 package elvys.server.bl.layoutrel;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -145,30 +147,52 @@
        
 
 
-       /* (non-Javadoc)
-        * @see 
cz.elvys.webServer.bl.api.layoutrel.LayoutBL#getLayoutsOfCompany(java.lang.Integer,
 java.lang.Integer[])
-        */
-       public List<Layout> getLayoutsOfCompany(Integer companyId, Integer... 
excludedLayoutsIds) throws ExecuteException {
-               if (companyId == null) {
-                       throw new ExecuteException("companyId is null!!");
-               }
+       @Override
+       public List<Layout> listLayoutsOfCompany(Integer companyId, Integer... 
excludedLayoutsIds) throws ExecuteException {
+               if (companyId == null) throw new ExecuteException("companyId is 
null!!");
+               
+               
                Session sess = 
InitSessionFactory.getInstance().getCurrentSession();
                Transaction tx = HibUtils.startTx(sess);
                List<Layout> layouts = null;
                try {
-                       Criteria crit = 
sess.createCriteria(Layout.class).add(Restrictions.eq("disabled", false))
-                               .add(Restrictions.eq("company.id", 
companyId)).setFetchMode("company", FetchMode.JOIN);
-                       if (excludedLayoutsIds != null && 
excludedLayoutsIds.length > 0) {
-                               crit = 
crit.add(Restrictions.not(Restrictions.in("id", excludedLayoutsIds)));
-                       }
-                       layouts = crit.list();
+                       Query query = sess.createQuery("select layout from 
Layout layout " +
+                                       "inner join fetch layout.company comp " 
+
+                                       "where layout.disabled = false " +
+                                       "  and comp.disabled = false " +
+                                       "   and comp.id=:companyId " +
+                                       "order by layout.id"); 
+                       query.setInteger("companyId", companyId);
+                       layouts = query.list();
                        tx.commit();
                } catch (Exception e) {
                        tx.rollback();
                        String message = UNABLE_LOAD_LAYOUTS + companyId;
                        throw new ExecuteException(message, e);
                }
-               return layouts;
+               
+               // remove not wanted
+               if (excludedLayoutsIds == null || excludedLayoutsIds.length == 
0) {
+                       // nothing to exclude
+                       return layouts;
+               } else {
+                       // filter that list
+                       Set<Integer> notWanted =  new HashSet<Integer>();
+                       for (int i=0; i<excludedLayoutsIds.length; i++) {
+                               notWanted.add(excludedLayoutsIds[i]);
+                       }
+                       List<Layout> result = new ArrayList<Layout>();
+                       for (Layout layout : layouts) {
+                               if (notWanted.contains(layout.getId())){
+                                       // not wanted, do nothing
+                               } else {
+                                       // add into the result
+                                       result.add(layout);
+                               }
+                       }
+                       return result;
+               }
+               
        }
        
        

Modified: 
trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLTest.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLTest.java   
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/elvysCommons/src/elvys/server/bl/layoutrel/LayoutBLTest.java   
2010-02-05 00:59:17 UTC (rev 1675)
@@ -38,9 +38,20 @@
        }
        
        @Test
-       public void testGetLayoutsOfCompany() throws Exception {
-               // TODO
-               throw new RuntimeException("not prepared yet..");
+       public void testListLayoutsOfCompany() throws Exception {
+               
+               // get list of all
+               List<Layout> layouts = lbl.listLayoutsOfCompany(companyId);
+               assertLayouts(layouts);
+               
+               // reduce list by id
+               assertTrue(layouts.size() >= 3);
+               Integer notWantedId = layouts.get(0).getId();
+               Integer notWantedId2 = layouts.get(1).getId();
+               List<Layout> layoutsFiltered = lbl.listLayoutsOfCompany(
+                       companyId, new Integer[] {notWantedId, notWantedId2});
+               assertLayouts(layoutsFiltered);
+               assertTrue(layouts.size() == 2+ layoutsFiltered.size());
        }
        
        
@@ -82,5 +93,40 @@
                // TODO
                throw new RuntimeException("not prepared yet..");
        }
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       
+       // auxiliary method
+       private void assertLayouts(List<Layout> layouts) {
+               assertNotNull(layouts);
+               assertTrue(layouts.size() != 0);
+               // assert all nodes
+               for (Layout layout : layouts) {
+                       assertLayout(layout);
+               }
+       }
+       
+       // auxiliary method 
+       private void assertLayout(Layout layout) {
+               assertTrue(layout != null);
+               assertTrue(layout.getId() != null);
+               assertTrue(layout.getName() != null);
+               assertTrue(layout.getSectCount() >0 );
+       }
 }
 

Modified: 
trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java  
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/elvysCommons/src/elvys/server/bl/planning/PlanningBLTest.java  
2010-02-05 00:59:17 UTC (rev 1675)
@@ -206,7 +206,7 @@
                
                
                // layouts
-               List<Layout> layouts = lbl.getLayoutsOfCompany(companyId);
+               List<Layout> layouts = lbl.listLayoutsOfCompany(companyId);
                for(Layout layout:layouts) {
                        int highestPos = layout.getSectCount();
                        

Modified: 
trunk/server/webServer2/JavaSource/cz/elvys/webServer/component/layoutrel/LayoutListComponentBean.java
===================================================================
--- 
trunk/server/webServer2/JavaSource/cz/elvys/webServer/component/layoutrel/LayoutListComponentBean.java
      2010-02-05 00:57:07 UTC (rev 1674)
+++ 
trunk/server/webServer2/JavaSource/cz/elvys/webServer/component/layoutrel/LayoutListComponentBean.java
      2010-02-05 00:59:17 UTC (rev 1675)
@@ -3,9 +3,7 @@
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.ActionListener;
 import java.io.Serializable;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.StringTokenizer;
 
 import javax.faces.event.ActionEvent;
 
@@ -114,7 +112,19 @@
                this.chooseListener2 = chooseListener2;
        }
 
+       
+       
        /**
+        * Reloads list of layouts
+        * @param aev
+        */
+       public void reload(ActionEvent aev) {
+               // as it is request scoped and list is loaded each time, it is 
enought to
+               //   rerender part of .xhtml containing the list
+               //initLayoutList();
+       }
+       
+       /**
         * Initializes list of layouts.
         */
        private List<Layout> initLayoutList() {
@@ -123,7 +133,7 @@
                        LayoutBL worker = Factory.getLayoutBL();
                        Integer[] ids = parseIDs(notSelectIDs);
                        companyId = BeanManager.getUser().getCompany().getId();
-                       List<Layout> layouts = 
worker.getLayoutsOfCompany(companyId, ids);
+                       List<Layout> layouts = 
worker.listLayoutsOfCompany(companyId, ids);
                        return layouts;
                } catch(Exception e) {
                        String message = 
CommonUtils.prepareErrorMessage(CANNOT_INITIALIZE, 

Modified: 
trunk/server/webServer2/SpringSource/cz/elvys/webServer/bl/api/elvysrel/PlanDocumentBL.java
===================================================================
--- 
trunk/server/webServer2/SpringSource/cz/elvys/webServer/bl/api/elvysrel/PlanDocumentBL.java
 2010-02-05 00:57:07 UTC (rev 1674)
+++ 
trunk/server/webServer2/SpringSource/cz/elvys/webServer/bl/api/elvysrel/PlanDocumentBL.java
 2010-02-05 00:59:17 UTC (rev 1675)
@@ -4,7 +4,6 @@
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 
-import cz.elvys.webServer.HIBgen.ContentType;
 import cz.elvys.webServer.HIBgen.Timeline;
 import cz.elvys.webServer.toSpring.elvysrel.LabeledRectangle;
 import cz.elvys.webServer.toSpring.elvysrel.Rectangle;

Added: trunk/server/webServer2/WebContent/images/clearpixel.gif
===================================================================
(Binary files differ)


Property changes on: trunk/server/webServer2/WebContent/images/clearpixel.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/server/webServer2/WebContent/js/elvys-template.js
===================================================================
--- trunk/server/webServer2/WebContent/js/elvys-template.js     2010-02-05 
00:57:07 UTC (rev 1674)
+++ trunk/server/webServer2/WebContent/js/elvys-template.js     2010-02-05 
00:59:17 UTC (rev 1675)
@@ -1,4 +1,9 @@
-function showLayoutEditor() {
-       
features="height=700,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
                   
+// opens window with LayoutDesigner
+function showLayoutEditor(action) {
+       // formId=action.form.id;
+       
features="height=700,width=1000,status=no,toolbar=no,menubar=no,location=no,dependent=yes,scrollbars=no,resizable=no";
+       var winId;
        
winId=window.open('/webServer2/secured/layoutrel/layoutEdit.jsf','NOVEOKNO',features);
 // open an empty window
+       winId.opener=this;
+       
 }
\ No newline at end of file

Added: trunk/server/webServer2/WebContent/js/layoutrel/layoutEdit.js
===================================================================
--- trunk/server/webServer2/WebContent/js/layoutrel/layoutEdit.js               
                (rev 0)
+++ trunk/server/webServer2/WebContent/js/layoutrel/layoutEdit.js       
2010-02-05 00:59:17 UTC (rev 1675)
@@ -0,0 +1,7 @@
+// "onbeforeunload" function on the child window
+function refreshListOfLayoutsBeforeUnload() {
+       var hiddenlink = 
this.opener.document.getElementById('LayoutListForm:LayoutListComponentRefreshHiddenLink');
+       if (hiddenlink != null) {
+               hiddenlink.click();
+       }
+};
\ No newline at end of file

Modified: 
trunk/server/webServer2/WebContent/secured/components/layoutListComponent.xhtml
===================================================================
--- 
trunk/server/webServer2/WebContent/secured/components/layoutListComponent.xhtml 
    2010-02-05 00:57:07 UTC (rev 1674)
+++ 
trunk/server/webServer2/WebContent/secured/components/layoutListComponent.xhtml 
    2010-02-05 00:59:17 UTC (rev 1675)
@@ -62,65 +62,8 @@
                companyID="#{companyID}" 
                notSelectLayouts="#{notSelectLayouts}"
                chooseListener1="#{chooseListener1}"
-               chooseListener2="#{chooseListener2}"/>
+               chooseListener2="#{chooseListener2}"/>  
 
-       <script language="javascript">
-
-               var formId; // reference to the main form
-               var winId;      // reference to the popup window
-
-
-               // This function calls the popup window.
-               //
-               function showLayoutEditor(action, form, target) {
-                       // formId=action.form.id;
-                       
features="height=700,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
                   
-                       
winId=window.open('/webServer2/secured/layoutrel/layoutEdit.jsf','NOVEOKNO',features);
 // open an empty window
-
-                       //hform=document.forms[form]; // reference to the 
hidden form
-                         
-                       //This is an emulation of the action link being clicked.
-                       
//document.getElementById(form+':'+target).value=form+':'+target;
-
-                       // Copy the current country variable value
-                       // to the corresponding field of the hidden form.
-                       // 
document.getElementById(form+':'+'layoutToEdit').value = 'ahoj';
-
-                       // Submit the hidden form. The output will be sent to 
the just opened window.
-                       //hform.submit();
-               }
-               
-               
-               // This function is called from the popup window 
-               // when a user clicks on a state or province from the list.
-               // The selected value is copied to a "place" text field
-               // in the main form.
-               // 
-               function updatePlace(place) {
-                                       form=document.forms[formId];
-                                       form[formId+":place"].value=place;
-                                       winId.close();
-               }
-               
-               
-               // This function returns the selected value 
-               // from the drop down list.
-               //
-               function getCountry (form) {
-                       field = form[form.id+":country"];
-                       return field.value;
-               }
-       
-               // This function cleans up the "place" text field.
-               //  
-               function resetTextField(form, field) {
-                       fieldName=form.id+":"+field;
-                       form[fieldName].value="";
-               }
-
-       </script>
-               
-
        <h:form id="LayoutListForm" style="overflow:auto">
                <h:panelGroup style="border: solid 1px black; padding: 0px; 
display: block; overflow: auto; float: left;">
                        <rich:dataTable id="#{id}"
@@ -189,7 +132,7 @@
                                        <f:facet 
name="header">#{lbl['layout.list.editlayout']}</f:facet>
                                        <a4j:commandButton id="EditLayoutButton"
                                                image="/images/icons/edit.png"
-                                               
oncomplete="showLayoutEditor(this,'LayoutDesignerHiddenForm','show')"
+                                               
oncomplete="showLayoutEditor(this)"
                                                reRender="#{id}">
                                                <f:setPropertyActionListener 
value="#{layout}"
                                                        
target="#{layoutEditBean.layoutToEdit}" />
@@ -229,7 +172,7 @@
                        <!-- CREATE NEW LAYOUT -->
                        <a4j:commandButton id="CreateLayoutButton"
                                        image="/images/icons/create.png"
-                                       
oncomplete="showLayoutEditor2(this,'LayoutDesignerHiddenForm','show')"
+                                       oncomplete="showLayoutEditor(this)"
                                        reRender="#{id}">
                                        <f:setPropertyActionListener 
value="#{null}"
                                                
target="#{layoutEditBean.layoutToEdit}" />
@@ -240,23 +183,16 @@
                        </rich:toolTip>
                </h:panelGroup>
                
+               <!-- hidden refresh link -->
+               <h:commandButton id="LayoutListComponentRefreshHiddenLink" 
+                       image="/images/clearpixel.gif" 
+                       actionListener="#{layoutEditBean.reload}"
+                       style="border: 0px;"
+                       alt="refresh"
+                       reRender="LayoutListForm" />
        </h:form>
        
        
-       <!-- hidden form for launching popup layout designer window -->
-       <h:form id="LayoutDesignerHiddenForm" target="NOVEOKNO">
-                       <!--
-                               The command_link below is used to navigate to a 
page
-                               that shows LayoutDesigner applet
-                       -->
-                       <a id="LayoutDesignerHiddenForm:show" 
onclick="document.forms['LayoutDesignerHiddenForm']['LayoutDesignerHiddenForm:show'].value='LayoutDesignerHiddenForm:show';
 document.forms['LayoutDesignerHiddenForm'].submit(); return false;" href="#"/>
-                       
-                       <h:commandLink type="hidden" id="show_old" 
action="layoutCreate" value="">
-                               <f:verbatim></f:verbatim>
-                       </h:commandLink>
-
-       </h:form>
-       
        <elvys:layoutPreviewModal
                modalWinId="ModalShowLayoutImg"
                contentId="ModalShowLayoutImgContent"

Modified: trunk/server/webServer2/WebContent/secured/layoutrel/layoutEdit.xhtml
===================================================================
--- trunk/server/webServer2/WebContent/secured/layoutrel/layoutEdit.xhtml       
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/webServer2/WebContent/secured/layoutrel/layoutEdit.xhtml       
2010-02-05 00:59:17 UTC (rev 1675)
@@ -8,9 +8,15 @@
        xmlns:elvys="http://www.elvys.farm.particle.cz";>
 
 
-<head> <title>#{lbl['layout.edit.header']}</title> </head>
+<head> 
+       <title>#{lbl['layout.edit.header']}</title>
+       <script 
+               type="text/javascript" 
+               language="javascript" 
+               src="/webServer2/js/layoutrel/layoutEdit.js"/>  
+</head>
 
-<body>
+<body onbeforeunload="refreshListOfLayoutsBeforeUnload()">
   <f:view locale="#{user.locale}">
        <rich:panel id="EditLayout">
                <f:facet name="header">

Modified: trunk/server/webServer2/WebContent/template/elvys-template.xhtml
===================================================================
--- trunk/server/webServer2/WebContent/template/elvys-template.xhtml    
2010-02-05 00:57:07 UTC (rev 1674)
+++ trunk/server/webServer2/WebContent/template/elvys-template.xhtml    
2010-02-05 00:59:17 UTC (rev 1675)
@@ -61,7 +61,7 @@
                                                        <rich:menuItem 
id="LayoutCreateMenuItem"
                                                                
value="#{lbl['template.menu.layout.create']}"
                                                                
submitMode="ajax"
-                                                               
oncomplete="showLayoutEditor();">
+                                                               
oncomplete="showLayoutEditor(this);">
                                                                
<f:setPropertyActionListener value="#{null}"
                                                                        
target="#{layoutEditBean.layoutToEdit}" />
                                                                
<f:actionListener 
type="cz.elvys.webServer.beans.layoutrel.LayoutEditBean$StartCreatingLayoutListener"/>


Other related posts:

  • » [elvystrac] r1675 - List of layouts upgraded - when LD-window is closed, list of layouts is refreshed (if it is on background) - elvys