[Rt-commit] rt branch, lcore, updated. 1660b512047eeaaedb885c2d93ea0f30dfc5c89e

clkao at bestpractical.com clkao at bestpractical.com
Thu Sep 10 05:46:29 EDT 2009


The branch, lcore has been updated
       via  1660b512047eeaaedb885c2d93ea0f30dfc5c89e (commit)
      from  eadd2084b72c9abeb12ba60a63f184f7c102b3a8 (commit)

Summary of changes:
 lib/RT/Lorzy.pm                    |    4 +++-
 share/web/static/js/rulebuilder.js |   34 +++++++++++++++++++++++++++-------
 2 files changed, 30 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 1660b512047eeaaedb885c2d93ea0f30dfc5c89e
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Thu Sep 10 18:42:20 2009 +0900

    support 2nd level attribute menu.

diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index 4c4e02a..88ab33b 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -76,9 +76,11 @@ sub install_model_accessors {
     my $modelname = lc($model);
     $modelname =~ s/.*://;
     for my $column ($model->columns) {
+        next if $column->virtual;
         my $name = $column->name;
         my $type = $column->type;
-        $type = $type =~ m/^varchar/ ? 'Str'
+        $type = $column->refers_to   ? $column->refers_to
+              : $type =~ m/^varchar/ ? 'Str'
               : $type eq 'timestamp' ? 'DateTime'
               : $type eq 'boolean'   ? 'Bool'
               : $type eq 'smallint'  ? 'Bool'
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 2d3421c..c203540 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -139,6 +139,8 @@ RuleBuilder.prototype.update_expressions = function() {
                     .appendTo(expressions_div);
                 });
 
+    this.model_accessors = {};
+    this.build_accessor_menu('RT::Model::Queue');
     this.build_accessor_menu('RT::Model::Ticket');
     this.build_accessor_menu('RT::Model::Transaction');
 }
@@ -159,7 +161,6 @@ RuleBuilder.prototype.build_accessor_menu = function(model) {
         hideDelay: 500 };
 
     var re = new RegExp('^'+model+'\.');
-
     jQuery.get('/rulebuilder/getfunctions.json',
                { parameters: [model] },
                function(response, status) {
@@ -168,6 +169,7 @@ RuleBuilder.prototype.build_accessor_menu = function(model) {
                        if (re.match(name))
                            entries.push(name);
                    }
+                   that.model_accessors[model] = entries;
                    jQuery('.ret_'+e_sel(model), that.ebuilder)
                    .each(function() {
                        var expression = jQuery('span.expression-text',this).text();
@@ -176,17 +178,35 @@ RuleBuilder.prototype.build_accessor_menu = function(model) {
                        .menu(options,
                              jQuery.map(entries,
                                         function(val) {
-                                            var attribute = val.replace(re, '');
-                                            var type = that.functions[val].return_type;
-                                            attribute += ' <span class="return-type">'+type+'</span>';
-                                            // XXX: submenu here for known types
-                                            return {src: attribute, data: { type: type, expression: expression, func: val } }}
-                                       ));
+                                            return that.map_accessor_menu_entry(model, val, expression, true);
+                                        }
+                                       ))
                    });
                },
                'json');
 };
 
+RuleBuilder.prototype.map_accessor_menu_entry = function (model, func_name, expression, want_submenu) {
+    var re = new RegExp('^'+model+'\.');
+    var attribute = func_name.replace(re, '');
+    var type = this.functions[func_name].return_type;
+    var submenu = null;
+    attribute += ' <span class="return-type">'+type+'</span>';
+
+    var that = this;
+    if (want_submenu && that.model_accessors[type]) {
+        submenu = jQuery.map(that.model_accessors[type],
+                             function(val) {
+                                 return that.map_accessor_menu_entry(type, val,
+                                                                     "("+func_name+" "+expression+")" );
+                             });
+    }
+
+    return {src: attribute,
+            subMenu: submenu,
+            data: { type: type, expression: expression, func: func_name } };
+};
+
 
 RuleBuilder.prototype.update_application = function () {
     /* might be an expression too */

-----------------------------------------------------------------------


More information about the Rt-commit mailing list