From 0dea78ab2e8f432c4029b5a30d5c2cc7f521aec2 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 31 Aug 2011 16:00:45 +0000 Subject: [PATCH] - Pull application name from template ID for image - Use label as tooltip - Apply CSS classes to image --- etemplate/js/et2_core_widget.js | 20 +++++++++++++++++ etemplate/js/et2_widget_image.js | 23 ++++++++++++++++++-- etemplate/js/test/et2_test_basic_widgets.xet | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_core_widget.js b/etemplate/js/et2_core_widget.js index 8837fca440..8738ca446b 100644 --- a/etemplate/js/et2_core_widget.js +++ b/etemplate/js/et2_core_widget.js @@ -745,6 +745,26 @@ var et2_widget = Class.extend({ return this._parent.getInstanceManager(); } + return null; + }, + + /** + * Returns the application for the template the widget is in. + * If a sub-template is used, this may be different from the current app. + */ + getTemplateApp: function() { + if(this._template_application) + { + return this._template_application; + } + else if(this._type == 'template' && this.id) + { + var parts = this.id.split(".",2); + return parts[0]; + } else if (this.getParent()) { + this._template_application = this.getParent().getTemplateApp(); + return this._template_application; + } return null; } }); diff --git a/etemplate/js/et2_widget_image.js b/etemplate/js/et2_widget_image.js index 11dfde90c7..af578bb641 100644 --- a/etemplate/js/et2_widget_image.js +++ b/etemplate/js/et2_widget_image.js @@ -50,6 +50,10 @@ var et2_image = et2_baseWidget.extend({ this.node = $j(document.createElement("a")); this.image.appendTo(this.node); } + if(this.options.class) + { + this.node.addClass(this.options.class); + } this.setDOMNode(this.node[0]); }, @@ -58,12 +62,27 @@ var et2_image = et2_baseWidget.extend({ this.options.label = _value; // label is NOT the alt attribute in eTemplate, but the title/tooltip this.image.attr("alt", _value); + this.image.set_statustext(_value); }, set_src: function(_value) { + if(!this.isInTree()) + { + console.warn(this.image[0], " not in tree"); + return; + } this.options.src = _value; - // using current app (default) is not exactly right, it should be the app of the template, eg. "addressbook" for "addressbook.edit" - this.image.attr("src", egw.image(_value, egw_appName) || _value); + // Get application to use from template ID + var appname = this.getTemplateApp(); + var src = egw.image(_value,appname || "phpgwapi"); + if(src ) + { + this.image.attr("src", src).show(); + } + else + { + this.image.css("display","none"); + } } }); diff --git a/etemplate/js/test/et2_test_basic_widgets.xet b/etemplate/js/test/et2_test_basic_widgets.xet index 2ce05320b5..c2d7ccd1aa 100644 --- a/etemplate/js/test/et2_test_basic_widgets.xet +++ b/etemplate/js/test/et2_test_basic_widgets.xet @@ -12,7 +12,7 @@ - +