Author: deepak
Date: Sat Dec 23 06:37:27 2017 New Revision: 1819113 URL: http://svn.apache.org/viewvc?rev=1819113&view=rev Log: Improved: Replace Inline js with External js in makeHyperlinkString macro (OFBIZ-9852) Thanks Aditya Sharma for your contribution Modified: ofbiz/ofbiz-framework/trunk/themes/common/template/macro/HtmlFormMacroLibrary.ftl ofbiz/ofbiz-framework/trunk/themes/common/webapp/common/js/util/OfbizUtil.js Modified: ofbiz/ofbiz-framework/trunk/themes/common/template/macro/HtmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common/template/macro/HtmlFormMacroLibrary.ftl?rev=1819113&r1=1819112&r2=1819113&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/common/template/macro/HtmlFormMacroLibrary.ftl (original) +++ ofbiz/ofbiz-framework/trunk/themes/common/template/macro/HtmlFormMacroLibrary.ftl Sat Dec 23 06:37:27 2017 @@ -851,49 +851,28 @@ Parameter: delegatorName, String, option </#macro> <#macro makeHyperlinkString hiddenFormName imgSrc title alternate linkUrl description linkStyle="" event="" action="" targetParameters="" targetWindow="" confirmation="" uniqueItemName="" height="" width="" id=""> <#if uniqueItemName?has_content> - <div id="${uniqueItemName}"></div> - <a href="javascript:void(0);" id="${uniqueItemName}_link" + <#local params = "{ 'presentation': 'layer'"> + <#if targetParameters?has_content> + <#assign parameterMap = targetParameters?eval> + <#assign parameterKeys = parameterMap?keys> + <#list parameterKeys as key> + <#local params += ",'${key}': '${parameterMap[key]}'"> + </#list> + </#if> + <#local params += " }"> + <a href="javascript:void(0);" id="${uniqueItemName}_link" + data-dialog-params="${params}" + data-dialog-width="${width}" + data-dialog-height="${height}" + data-dialog-url="${linkUrl}" + <#if text?has_content>data-dialog-title="${text}"</#if> <#if linkStyle?has_content>class="${linkStyle}"</#if>> <#if description?has_content>${description}</#if></a> - <script type="text/javascript"> - function ${uniqueItemName}_data () { - var data = { - <#if targetParameters?has_content> - <#assign parameterMap = targetParameters?eval> - <#assign parameterKeys = parameterMap?keys> - <#list parameterKeys as key> - "${key}": "${parameterMap[key]}", - </#list> - </#if> - "presentation": "layer" - }; - return data; - } - jQuery("#${uniqueItemName}_link").click(function () { - jQuery("#${uniqueItemName}").dialog("open"); - }); - jQuery("#${uniqueItemName}").dialog({ - autoOpen: false, - <#if text?has_content>title: "${text}",</#if> - height: ${height}, - width: ${width}, - modal: true, - closeOnEscape: true, - open: function() { - jQuery.ajax({ - url: "${linkUrl}", - type: "POST", - data: ${uniqueItemName}_data(), - success: function(data) {jQuery("#${uniqueItemName}").html(data);} - }); - } - }); - </script> <#else> - <a <#if linkStyle?has_content && (description?has_content || imgSrc?has_content)>class="${linkStyle}"</#if> + <a <#if linkStyle?has_content && (description?has_content || imgSrc?has_content)>class="${linkStyle}"</#if> href="${linkUrl}"<#if targetWindow?has_content> target="${targetWindow}"</#if> <#if action?has_content && event?has_content> ${event}="${action}"</#if> - <#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}')"</#if> + <#if confirmation?has_content> data-confirm-message="${confirmation}"</#if> <#if id?has_content> id="${id}"</#if> <#if imgSrc?length == 0 && title?has_content> title="${title}"</#if>> <#if imgSrc?has_content><img src="${imgSrc}" alt="${alternate}" title="${title}"/></#if>${description}</a> Modified: ofbiz/ofbiz-framework/trunk/themes/common/webapp/common/js/util/OfbizUtil.js URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common/webapp/common/js/util/OfbizUtil.js?rev=1819113&r1=1819112&r2=1819113&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/themes/common/webapp/common/js/util/OfbizUtil.js (original) +++ ofbiz/ofbiz-framework/trunk/themes/common/webapp/common/js/util/OfbizUtil.js Sat Dec 23 06:37:27 2017 @@ -74,6 +74,41 @@ function bindObservers(bind_element) { var params = element.data("inplace-editor-params"); ajaxInPlaceEditDisplayField(id, url, (new Function("return " + params + ";")())); }); + jQuery(bind_element).on("click", "[data-dialog-url]", function(){ + var element = jQuery(this); + var url = element.data("dialog-url"); + var title = element.data("dialog-title"); + var width = element.data("dialog-width"); + var height = element.data("dialog-height"); + var params = element.data("dialog-params"); + var dialogContainer = jQuery('<div/>'); + dialogContainer.dialog({ + autoOpen: false, + title: title, + height: height, + width: width, + modal: true, + closeOnEscape: true, + open: function() { + jQuery.ajax({ + url: url, + type: "POST", + data: params, + success: function(data) { + dialogContainer.html(data); + } + }); + } + }); + dialogContainer.dialog("open"); + }); + jQuery(bind_element).on("click", "[data-confirm-message]", function(e){ + var element = jQuery(this); + var confirmMessage = element.data("confirm-message"); + if (!confirm(confirmMessage)) { + e.preventDefault(); + } + }) } |
Free forum by Nabble | Edit this page |