Small fixes in LinkUIDefinition
authorIván Perdomo <ivan.perdomo@openbravo.com>
Sun, 06 Mar 2011 19:53:48 +0100
changeset 11040 329854993f0a
parent 11039 68eedc82708c
child 11041 583db6a6f29c
Small fixes in LinkUIDefinition
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js
modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_UIDEFINITION.xml
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/LinkUIDefinition.java
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js	Fri Mar 04 18:14:10 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js	Sun Mar 06 19:53:48 2011 +0100
@@ -349,8 +349,21 @@
   validateOnExit: true,
   icons: [{
     src : '[SKIN]/../../org.openbravo.client.application/images/form/search_picker.png',
-    click: 'window.open(item.getValue());'
-  }]
+    click: function(form, item) {
+      var url = item.getValue();
+      if(!url || url.indexOf('://') == -1) {
+        return;
+      }
+      window.open(url);
+    }
+  }],
+  validate: function() {
+    var url = this.getValue();
+    if(!url) {
+      return true;
+    }
+    return OB.Utilities.isValidURL(url);
+  }
 });
 
 //== OBFKFilterTextItem ==
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Fri Mar 04 18:14:10 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Sun Mar 06 19:53:48 2011 +0100
@@ -562,3 +562,16 @@
   }
 };
 
+// ** {{{ OB.Utilities.isValidURL}}} **
+// Checks if a String is a valid URL
+//
+// Parameters:
+// * {{{url}}}: String url
+OB.Utilities.isValidURL = function(url) {
+  // Validation based on: http://view.jquery.com/trunk/plugins/validate/jquery.validate.js
+  // Note: http://localhost is not a valid URL, http://localhost.localdomain is a valid one
+  if(!url) {
+    return false;
+  }
+  return (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FDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i).test(url);
+};
\ No newline at end of file
--- a/modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_UIDEFINITION.xml	Fri Mar 04 18:14:10 2011 +0100
+++ b/modules/org.openbravo.client.kernel/src-db/database/sourcedata/OBCLKER_UIDEFINITION.xml	Sun Mar 06 19:53:48 2011 +0100
@@ -66,7 +66,7 @@
 <!--30ABBB2416964B3CB1C4E1608974843B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--30ABBB2416964B3CB1C4E1608974843B-->  <AD_MODULE_ID><![CDATA[4B828F4D03264080AA1D2057B13F613C]]></AD_MODULE_ID>
 <!--30ABBB2416964B3CB1C4E1608974843B-->  <AD_REFERENCE_ID><![CDATA[800101]]></AD_REFERENCE_ID>
-<!--30ABBB2416964B3CB1C4E1608974843B-->  <CLASSNAME><![CDATA[org.openbravo.client.kernel.reference.StringUIDefinition]]></CLASSNAME>
+<!--30ABBB2416964B3CB1C4E1608974843B-->  <CLASSNAME><![CDATA[org.openbravo.client.kernel.reference.LinkUIDefinition]]></CLASSNAME>
 <!--30ABBB2416964B3CB1C4E1608974843B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--30ABBB2416964B3CB1C4E1608974843B--></OBCLKER_UIDEFINITION>
 
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/LinkUIDefinition.java	Fri Mar 04 18:14:10 2011 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/LinkUIDefinition.java	Sun Mar 06 19:53:48 2011 +0100
@@ -4,15 +4,15 @@
  * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
  * Version 1.1  with a permitted attribution clause; you may not  use this
  * file except in compliance with the License. You  may  obtain  a copy of
- * the License at http://www.openbravo.com/legal/license.html 
+ * the License at http://www.openbravo.com/legal/license.html
  * Software distributed under the License  is  distributed  on  an "AS IS"
  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  * License for the specific  language  governing  rights  and  limitations
- * under the License. 
- * The Original Code is Openbravo ERP. 
+ * 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 Openbravo SLU 
- * All Rights Reserved. 
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
@@ -21,7 +21,7 @@
 import org.openbravo.model.ad.ui.Field;
 
 /**
- * Implementation of the Link ui definition.
+ * Implementation of the Link UI definition.
  * 
  */
 public class LinkUIDefinition extends UIDefinition {