Module: nagvis
Branch: master
Commit: e917e28e189ebb189fdac2b27c9fb4da5d3b9838
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=e917e28e189ebb189fdac2b27c9fb4da5d3b9838

Author: Lars Michelsen <[email protected]>
Date:   Sun Oct 31 19:50:35 2010 +0100

Centralized the child hover code fetching

---

 share/frontend/nagvis-js/js/NagVisObject.js |    2 +-
 share/frontend/nagvis-js/js/frontend.js     |   28 ++++++++++++++++++++-
 share/frontend/nagvis-js/js/hover.js        |   34 +++++++-------------------
 3 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/share/frontend/nagvis-js/js/NagVisObject.js 
b/share/frontend/nagvis-js/js/NagVisObject.js
index 28b63b3..9681bff 100644
--- a/share/frontend/nagvis-js/js/NagVisObject.js
+++ b/share/frontend/nagvis-js/js/NagVisObject.js
@@ -259,7 +259,7 @@ var NagVisObject = Base.extend({
                                this.getHoverTemplateCode();
                        
                        // Replace dynamic (state dependent) macros
-                       sTemplateCode = replaceHoverTemplateDynamicMacros(this, 
this.hover_template_code);
+                       sTemplateCode = replaceHoverTemplateDynamicMacros(this);
                }
                
                var doc = document;
diff --git a/share/frontend/nagvis-js/js/frontend.js 
b/share/frontend/nagvis-js/js/frontend.js
index 987a318..ea7996d 100644
--- a/share/frontend/nagvis-js/js/frontend.js
+++ b/share/frontend/nagvis-js/js/frontend.js
@@ -30,6 +30,7 @@
  * Definition of needed variables
  */
 var oHoverTemplates = {};
+var oHoverTemplatesChild = {};
 var oHoverUrls = {};
 var oContextTemplates = {};
 var oAutomapParams = {};
@@ -351,6 +352,26 @@ function parseHoverMenus(aObjs) {
 }
 
 /**
+ * getHoverTemplateChildCode()
+ *
+ * Extracts the childs code from the hover templates
+ *
+ * @param   String   The whole template code
+ * @return  String   The child part template code
+ * @author     Lars Michelsen <[email protected]>
+ */
+function getHoverTemplateChildCode(sTemplateCode) {
+       var regex = getRegEx('loopChild', 
"<!--\\sBEGIN\\sloop_child\\s-->(.+?)<!--\\sEND\\sloop_child\\s-->");
+       var results = regex.exec(sTemplateCode);
+       regex = null;
+       
+       if(results !== null) 
+               return results[1];
+       else
+               return '';
+}
+
+/**
  * getHoverTemplates()
  *
  * Gets the code for needed hover templates and saves it for later use in icons
@@ -388,12 +409,15 @@ function getHoverTemplates(aObjs) {
        }
        
        // Get the needed templates via bulk request
-       aTemplateObjects = 
getBulkRequest(oGeneralProperties.path_server+'?mod=General&act=getHoverTemplate',
 aUrlParts, oWorkerProperties.worker_request_max_length, true);
+       aTemplateObjects = 
getBulkRequest(oGeneralProperties.path_server+'?mod=General&act=getHoverTemplate',
+                                         aUrlParts, 
oWorkerProperties.worker_request_max_length, true);
        
        // Set the code to global object oHoverTemplates
        if(aTemplateObjects.length > 0)
-               for(var i = 0, len = aTemplateObjects.length; i < len; i++)
+               for(var i = 0, len = aTemplateObjects.length; i < len; i++) {
                        oHoverTemplates[aTemplateObjects[i].name] = 
aTemplateObjects[i].code;
+                       oHoverTemplatesChild[aTemplateObjects[i].name] = 
getHoverTemplateChildCode(aTemplateObjects[i].code);
+               }
 }
 
 /**
diff --git a/share/frontend/nagvis-js/js/hover.js 
b/share/frontend/nagvis-js/js/hover.js
index 5946044..a718962 100644
--- a/share/frontend/nagvis-js/js/hover.js
+++ b/share/frontend/nagvis-js/js/hover.js
@@ -31,28 +31,15 @@
  * @author     Lars Michelsen <[email protected]>
  */
 
-function getHoverTemplateChildCode(sTemplateCode) {
-       var regex = getRegEx('loopChild', 
"<!--\\sBEGIN\\sloop_child\\s-->(.+?)<!--\\sEND\\sloop_child\\s-->");
-       var results = regex.exec(sTemplateCode);
-       regex = null;
-       
-       if(results !== null) 
-               return results[1];
-       else
-               return '';
-}
-
 function replaceHoverTemplateChildMacros(oObj, sTemplateCode) {
        var mapName = '';
        var childsHtmlCode = '';
        
-       if(typeof(oPageProperties) != 'undefined' && oPageProperties != null) {
+       if(typeof(oPageProperties) != 'undefined' && oPageProperties != null)
                mapName = oPageProperties.map_name;
-       }
        
-       var rowHtmlCode = getHoverTemplateChildCode(sTemplateCode);
-       
-       if(rowHtmlCode != '' && oObj.members && oObj.members.length > 0) {
+       var rowHtmlCode = oHoverTemplatesChild[oObj.conf.hover_template];
+       if(typeof(rowHtmlCode) != 'undefined' && rowHtmlCode != '' && 
oObj.members && oObj.members.length > 0) {
                // Loop all child objects until all looped or the child limit 
is reached
                for(var i = 0, len1 = oObj.conf.hover_childs_limit, len2 = 
oObj.members.length;
                    (len1 == -1 || (len1 >= 0 && i <= len1)) && i < len2; i++) {
@@ -134,7 +121,7 @@ function replaceHoverTemplateMacrosChild(oObj, 
sTemplateCode) {
        return sTemplateCode;
 }
 
-function replaceHoverTemplateDynamicMacros(oObj, sTemplateCode) {
+function replaceHoverTemplateDynamicMacros(oObj) {
        var oMacros = {};
 
        if(typeof(oPageProperties) != 'undefined' && oPageProperties != null 
@@ -177,6 +164,8 @@ function replaceHoverTemplateDynamicMacros(oObj, 
sTemplateCode) {
                oMacros.obj_state_duration = oObj.conf.state_duration;
                oMacros.obj_perfdata = oObj.conf.perfdata;
        }
+
+       var sTemplateCode = oObj.hover_template_code;
        
        // On a update the image url replacement is easier. Just replace the old
        // timestamp with the current
@@ -296,22 +285,17 @@ function replaceHoverTemplateStaticMacros(oObj, 
sTemplateCode) {
        }
        oSectionMacros = null;
        
-       // Get loop child code for later replacing
-       // FIXME: This is workaround is needed cause the obj_name macro is 
replaced
-       // by the parent objects macro in current progress
-       var sChildCode = getHoverTemplateChildCode(sTemplateCode);
-       
        // Loop and replace all normal macros
        sTemplateCode = sTemplateCode.replace(/\[(\w*)\]/g, function(){ return 
oMacros[ arguments[1] ] || '['+arguments[1]+']';});
        
        oMacros = null;
        
        // Re-add the clean child code
+       // This workaround is needed cause the obj_name macro is replaced
+       // by the parent objects macro in current progress
        var regex = getRegEx('loopChild', 
"<!--\\sBEGIN\\sloop_child\\s-->(.+?)<!--\\sEND\\sloop_child\\s-->");
-       
        if(sTemplateCode.search(regex) !== -1)
-               sTemplateCode = sTemplateCode.replace(regex, '<!-- BEGIN 
loop_child -->'+sChildCode+'<!-- END loop_child -->');
-       
+               sTemplateCode = sTemplateCode.replace(regex, '<!-- BEGIN 
loop_child -->'+oHoverTemplatesChild[oObj.hover_template]+'<!-- END loop_child 
-->');
        regex = null;
        
        // Search for images and append current timestamp to src (prevent 
caching of


------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to