# HG changeset patch
# User Asier Lostalé <asier.lostale@openbravo.com>
# Date 1328259600 -3600
# Node ID b913dc4d115f16f746ad09e1ff3533e6ce8099df
# Parent  4ab1f1545d84ac2bddbba82ca5f1929e6a1a62e6
fixed bug 19579: to print a pdf , the popup is not closed automatically

diff -r 4ab1f1545d84 -r b913dc4d115f modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Thu Feb 02 12:14:56 2012 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Fri Feb 03 10:00:00 2012 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2012 Openbravo SLU 
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -714,7 +714,7 @@
 
       type = "print";
       action = "OB.ToolbarUtils.print(this.view, '" + processUrl + "', " + process.isDirectPrint()
-          + ");";
+          + ", " + !hasEmail + ");";
       label = Utility.messageBD(new DalConnectionProvider(false), "Print", OBContext.getOBContext()
           .getLanguage().getLanguage());
     }
diff -r 4ab1f1545d84 -r b913dc4d115f modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Thu Feb 02 12:14:56 2012 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Fri Feb 03 10:00:00 2012 +0100
@@ -1508,10 +1508,12 @@
 
 OB.ToolbarUtils = {};
 
-OB.ToolbarUtils.print = function(view, url, directPrint){
+OB.ToolbarUtils.print = function(view, url, directPrint, download){
   var selectedRecords = view.viewGrid.getSelectedRecords(),
     length = selectedRecords.length;
 
+  download=false;
+  
   if (length === 0) {
     view.messageBar.setMessage(isc.OBMessageBar.TYPE_WARNING, '', OB.I18N.getLabel('OBUIAPP_PrintNoRecordSelected'));
     return;
@@ -1524,7 +1526,8 @@
     Command: 'DEFAULT',
     inppdfpath: url,
     inphiddenkey: view.standardProperties.inpKeyName,
-    inpdirectprint: (directPrint ? 'Y' : 'N')
+    inpdirectprint: (directPrint ? 'Y' : 'N'),
+    inpdownload: (download ? 'Y' : 'N')
   };
 
   for (param in allProperties) {
@@ -1546,9 +1549,9 @@
 
   popupParams.inphiddenvalue = selectedIds;
 
-  view.setContextInfo(sessionProperties, function(){
-    OB.Layout.ClassicOBCompatibility.Popup.open('print', 0, 0, OB.Application.contextUrl + 'businessUtility/PrinterReports.html', '', window, false, false, true, popupParams);
-  });
+  view.setContextInfo(sessionProperties, function () {
+      OB.Utilities.postThroughHiddenForm(OB.Application.contextUrl + 'businessUtility/PrinterReports.html', popupParams);
+    });
 };
 
 OB.ToolbarUtils.showAuditTrail = function(view){
diff -r 4ab1f1545d84 -r b913dc4d115f modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDefaultFilterActionHandler.java
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDefaultFilterActionHandler.java	Thu Feb 02 12:14:56 2012 +0100
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDefaultFilterActionHandler.java	Fri Feb 03 10:00:00 2012 +0100
@@ -79,7 +79,8 @@
       for (SelectorField f : obc.list()) {
         try {
           exprResult = engine.eval(f.getDefaultExpression());
-
+engine.eval("!OB.isSalesTransaction()")
+          
           if (sel.isCustomQuery()) {
             result.put(f.getDisplayColumnAlias(), exprResult);
           } else {
diff -r 4ab1f1545d84 -r b913dc4d115f src/org/openbravo/erpCommon/businessUtility/PrinterReports.html
--- a/src/org/openbravo/erpCommon/businessUtility/PrinterReports.html	Thu Feb 02 12:14:56 2012 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/PrinterReports.html	Fri Feb 03 10:00:00 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -26,15 +26,20 @@
 <script language="JavaScript" src="../../../../../web/js/messages.js" type="text/javascript"></script>
 <script language="JavaScript" type="text/javascript" id="paramLanguage">    defaultLang = "en_US";</script>
 <script language="JavaScript" type="text/javascript" id="isPrintPreview">
-function printReport(pagina) {
+function printReport(url) {
     if (isWindowInMDIContext) {
+     // debugger;
       var LayoutMDI = getFrame('LayoutMDI');
-      if (pagina.indexOf('../') === 0) {
-        pagina = pagina.substring(3, pagina.length);
+      if (url.indexOf('../') === 0) {
+        url = url.substring(3, url.length);
       }
-      LayoutMDI.OB.Layout.ClassicOBCompatibility.Popup.open('printpdf', 600, 300, LayoutMDI.OB.Application.contextUrl + pagina + "?Commnad=PDF", '', window, false, false, true);
+      if (download){ 
+        LayoutMDI.OB.Utilities.postThroughHiddenForm(LayoutMDI.OB.Application.contextUrl + url);
+      } else {
+        LayoutMDI.OB.Layout.ClassicOBCompatibility.Popup.open('printpdf', 600, 300, LayoutMDI.OB.Application.contextUrl + url, '', window, false, false, true);
+      }
     } else {
-      openPDF(pagina, 'PDF');
+      openPDF(url, 'PDF');
     }
     closePage();
     return true;
@@ -49,7 +54,7 @@
   </OBJECT></EMBED>
 </div>
 <script language="javascript" type="text/javascript" id="isDirectPrint">
-function printReport(pagina) {
+function printReport(url) {
     Pdf1.printWithDialog();
 }
 </script>
diff -r 4ab1f1545d84 -r b913dc4d115f src/org/openbravo/erpCommon/businessUtility/PrinterReports.java
--- a/src/org/openbravo/erpCommon/businessUtility/PrinterReports.java	Thu Feb 02 12:14:56 2012 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/PrinterReports.java	Fri Feb 03 10:00:00 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -52,14 +52,16 @@
       String inptabId = vars.getStringParameter("inpTabId");
       String strHiddenValue = vars.getGlobalVariable("inphiddenvalue", strWindowId + "|"
           + strKeyColumnId);
-      printPage(response, vars, strDirectPrint, strPDFPath, strHiddenKey, strHiddenValue, inptabId);
+      boolean download = "Y".equals(vars.getStringParameter("inpdownload"));
+      printPage(response, vars, strDirectPrint, strPDFPath, strHiddenKey, strHiddenValue, inptabId,
+          download);
     } else
       pageError(response);
   }
 
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
       String strDirectPrint, String strPDFPath, String strHiddenKey, String strHiddenValue,
-      String inptabId) throws IOException, ServletException {
+      String inptabId, boolean download) throws IOException, ServletException {
     if (log4j.isDebugEnabled())
       log4j.debug("Output: dataSheet");
     String[] discard = { "isPrintPreview" };
@@ -75,7 +77,8 @@
     } else
       mapping = PrinterReportsData.selectMapping(this, strPDFPath);
 
-    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
+    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith
+        + "/\", download=" + download + ";\n");
     xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("pdfPath", mapping);
     xmlDocument.setParameter("directPrint", strDirectPrint);
