[Rt-commit] rt branch, lcore, updated. eadd2084b72c9abeb12ba60a63f184f7c102b3a8

clkao at bestpractical.com clkao at bestpractical.com
Thu Sep 10 03:50:16 EDT 2009


The branch, lcore has been updated
       via  eadd2084b72c9abeb12ba60a63f184f7c102b3a8 (commit)
       via  ffae044a273c84f8cf676c87222be1a0cdd43d70 (commit)
      from  16a214eaff54dce4af902225a2113fac0b2e797a (commit)

Summary of changes:
 share/web/static/css/rulebuilder.css |    7 ++-
 share/web/static/js/rulebuilder.js   |  125 ++++++++++++++++++++++++++++++++--
 2 files changed, 123 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit ffae044a273c84f8cf676c87222be1a0cdd43d70
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Thu Sep 10 16:20:15 2009 +0900

    transform for toplevel expression.

diff --git a/share/web/static/css/rulebuilder.css b/share/web/static/css/rulebuilder.css
index 34f6448..dfe2982 100644
--- a/share/web/static/css/rulebuilder.css
+++ b/share/web/static/css/rulebuilder.css
@@ -4,8 +4,9 @@ div.context span.return-type,
 div.expression span.return-type,
 div.parameter .type,
 div.menu-item span.return-type {
-  color:#555555;
-  font-style:italic;
+    color:#555555;
+    font-style:italic;
+    padding-right:0.5em;
 }
 
 .signature .parameter {
@@ -29,6 +30,8 @@ div.top-context {
 
 div.context {
     border: 1px dashed;
+    margin: 0.5em;
+    padding: 0.5em;
     min-height: 1.5em;
 }
 
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 74e8e58..ff71a24 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -249,9 +249,94 @@ RuleBuilder.Context = function(expected_type, element, parent, rb) {
     jQuery._span_({ 'class': 'return-type'})
           .text(expected_type)
           .appendTo(this.element);
+    jQuery._span_({ 'class': 'transform' })
+          .text("♨")
+          .click(function(e) {
+              that.transformMenu(this);
+              return false;
+          })
+          .hide()
+          .appendTo(this.element);
+    if (expected_type == 'Str' || expected_type == 'Num') { // self-evaluating
+        jQuery._span_({ 'class': 'enter-value' })
+          .text("Enter a value")
+          .click(function(e) {
+              jQuery(this).html('').unbind('click');
+              jQuery._input_({ 'type': 'text', class: 'enter-value'})
+                  .appendTo(this).trigger('focus');
+              return true;
+          })
+          .appendTo(this.element);
+    }
 };
 
+
+RuleBuilder.Context.prototype.transform = function(func_name) {
+    if (this.parent) {
+        alert('not yet');
+    }
+    else {
+        var rb = this.rb;
+        var func = rb.functions[func_name];
+        jQuery(rb.top_context.element).removeClass('top-context').remove();
+        var tc = jQuery._div_({'class': 'context top-context'})
+            .prependTo(this.rb.ebuilder);
+
+        rb.top_context = new RuleBuilder.Context(this.expected_type,
+                                                 tc.get(0), null, rb);
+        rb.top_context.set_application(func_name, func);
+        this.parent = rb.top_context;
+
+        jQuery(this.element).unbind('click');
+        var first_param = rb.top_context.children[0];
+        rb.top_context.children[0] = this;
+        this.expected_type = first_param.expected_type;
+        jQuery('span.return-type:first', this.element)
+            .text(first_param.expected_type);
+        jQuery(first_param.element).replaceWith(this.element);
+        var that = this;
+        jQuery(this.element).click(function(e) { rb.focus(that); return false });
+
+        this.update_return_type(this.return_type);
+    }
+}
+
+RuleBuilder.Context.prototype.transformMenu = function(el) {
+    // this.return_type -> this.expected_type
+    var that = this;
+    var options = {
+        onClick: function(e,item) {
+            that.transform(item.src);
+            jQuery.Menu.closeAll();
+            return false;
+        },
+        minWidth: 120,
+        arrowSrc: '/images/arrow_right.gif',
+        hoverOpenDelay: 500,
+        hideDelay: 500 };
+
+    jQuery.get('/rulebuilder/getfunctions.json',
+               { parameters: [ this.return_type ],
+                 return_type: this.expected_type },
+               function(response, status) {
+                   var entries = [];
+                   for (var name in response) {
+                       entries.push(name);
+                   }
+
+                   jQuery(el)
+                   .menu(options,
+                         jQuery.map(entries,
+                                    function(val) {
+                                        return {src: val, data: {  } }}
+                                       ));
+               },
+               'json');
+
+}
+
 RuleBuilder.Context.prototype.update_return_type = function(type) {
+    this.return_type = type;
     if (this.expected_type == type) {
         jQuery("span.return-type", this.element).removeClass("unmatched").addClass("matched");
     }
@@ -263,12 +348,15 @@ RuleBuilder.Context.prototype.update_return_type = function(type) {
 RuleBuilder.Context.prototype.clear = function() {
     jQuery('div.application', this.element).remove();
     jQuery('span.expression', this.element).remove();
+    jQuery('span.transform', this.element).hide();
+    jQuery('span.enter-value', this.element).hide();
 }
 
 RuleBuilder.Context.prototype.set_expression = function(expression) {
     this.clear();
     this.expression = expression.expression;
     this.update_return_type(expression.type);
+    jQuery('span.transform', this.element).show();
 
     jQuery._span_({ 'class': 'expression'})
           .text(this.expression)
@@ -282,13 +370,13 @@ RuleBuilder.Context.prototype.set_application = function(func_name, func) {
     this.func = func;
     this.children = [];
     this.update_return_type(func.return_type);
+    jQuery('span.transform', this.element).show();
     jQuery._div({'class': 'application'})
             ._div_({'class': 'application-function function'})
            ._div_({'class': 'application-params signature'})
           .div_()
         .appendTo(this.element);
 
-//    jQuery(this.sel+' div.application-function').html(this.current_application);
     jQuery('div.application-function',this.element).html(func_name);
     jQuery('div.application', this.element).show();
     jQuery('div.application-params', this.element).html('');
@@ -307,10 +395,6 @@ RuleBuilder.Context.prototype.set_application = function(func_name, func) {
     }
 };
 
-RuleBuilder.Context.prototype.init = function() {
-
-};
-
 jQuery.fn.sort = function() {
     return this.pushStack( [].sort.apply( this, arguments ), []);
 };

commit eadd2084b72c9abeb12ba60a63f184f7c102b3a8
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Thu Sep 10 16:50:04 2009 +0900

    serialize.

diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index ff71a24..2d3421c 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -29,7 +29,7 @@ RuleBuilder.prototype.init = function () {
     var that = this;
 
     this.ebuilder = ebuilder;
-    
+
     jQuery._div_({'class': 'context top-context'})
         .appendTo(ebuilder);
 
@@ -77,6 +77,12 @@ RuleBuilder.prototype.init = function () {
 	}
 
     this.focus(this.top_context);
+
+    jQuery._div_({'class': 'ohai'})
+        .text("OH HAI")
+        .click(function(e){ alert(that.top_context.serialize())})
+        .prependTo(ebuilder);
+
 };
 
 RuleBuilder.prototype.push_application = function(func_name) {
@@ -264,6 +270,7 @@ RuleBuilder.Context = function(expected_type, element, parent, rb) {
               jQuery(this).html('').unbind('click');
               jQuery._input_({ 'type': 'text', class: 'enter-value'})
                   .appendTo(this).trigger('focus');
+              that.self_eval = true;
               return true;
           })
           .appendTo(this.element);
@@ -352,6 +359,26 @@ RuleBuilder.Context.prototype.clear = function() {
     jQuery('span.enter-value', this.element).hide();
 }
 
+RuleBuilder.Context.prototype.serialize = function() {
+    if( this.self_eval ) {
+        var val = jQuery('input.enter-value', this.element).val();
+        if (this.expected_type == 'Str') {
+            return '"'+val+'"';
+        }
+        else {
+            return val;
+        }
+    }
+    else if ( this.expression ) {
+        return this.expression;
+    }
+    else if ( this.func_name ) {
+        var args = jQuery.map(this.children, function(val) { return val.serialize() });
+        args.unshift(this.func_name);
+        return '('+args.join(' ')+')';
+    }
+}
+
 RuleBuilder.Context.prototype.set_expression = function(expression) {
     this.clear();
     this.expression = expression.expression;
@@ -367,7 +394,7 @@ RuleBuilder.Context.prototype.set_expression = function(expression) {
 
 RuleBuilder.Context.prototype.set_application = function(func_name, func) {
     this.clear();
-    this.func = func;
+    this.func_name = func_name;
     this.children = [];
     this.update_return_type(func.return_type);
     jQuery('span.transform', this.element).show();

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


More information about the Rt-commit mailing list