[Rt-commit] rt branch, lcore, updated. 8155012988dde097ad98bd0543d394de867f5af5

clkao at bestpractical.com clkao at bestpractical.com
Thu Oct 1 23:37:25 EDT 2009


The branch, lcore has been updated
       via  8155012988dde097ad98bd0543d394de867f5af5 (commit)
       via  ec15422d1627756e99fd525d0acb0ed1347f75f3 (commit)
       via  c8978062f25da08e11db8fcdc41af1f34a44a59c (commit)
      from  b8eb4f53f57ff1dec5fd4a056711171a3ce0b549 (commit)

Summary of changes:
 share/web/static/js/rulebuilder.js |   55 +++++++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 10 deletions(-)

- Log -----------------------------------------------------------------
commit c8978062f25da08e11db8fcdc41af1f34a44a59c
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Oct 2 10:34:36 2009 +0800

    arraybuilder serialization

diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 596ada9..0599414 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -516,6 +516,10 @@ RuleBuilder.Context.prototype.serialize = function() {
         args.unshift(this.func_name);
         return '('+args.join(' ')+')';
     }
+    else if ( this.arraybuilder ) {
+        var args = jQuery.map(this.children, function(val) { return val.serialize() });
+        return args.join(' ');
+    }
 }
 
 RuleBuilder.Context.prototype.set_expression = function(expression) {

commit ec15422d1627756e99fd525d0acb0ed1347f75f3
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Oct 2 10:59:02 2009 +0800

    correct insert/remove orders for arraybuilder.

diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 0599414..2942613 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -336,7 +336,7 @@ RuleBuilder.Context = function(expected_type, element, parent, rb) {
             .click(function(e) {
                 that.arraybuilder = builder;
                 var child = that.mk_array_item_context(that.inner_type,
-                                                       jQuery('div.array-item-container', builder));
+                                                       jQuery('div.array-item-container', builder), 0);
                 that.children.push(child);
                 builder.show();
                 jQuery(this).remove();
@@ -346,9 +346,21 @@ RuleBuilder.Context = function(expected_type, element, parent, rb) {
     }
 };
 
-RuleBuilder.Context.prototype.mk_array_item_context = function(type, container) {
-    var li = jQuery._div_({'class': 'array-item'})
-        .appendTo(container);
+RuleBuilder.Context.prototype.array_item_idx = function()
+{
+    for (var i in this.parent.children) {
+        if (this.parent.children[i] == this)
+            return i;
+    }
+    return -1;
+}
+
+RuleBuilder.Context.prototype.mk_array_item_context = function(type, container, idx) {
+    var li = jQuery._div_({'class': 'array-item'});
+    if (idx)
+        jQuery("div.array-item:nth-child("+(idx)+")", this.arraybuilder).after(li);
+    else
+        li.appendTo(container);
     var x = jQuery._div_({'class': 'context'})
         .appendTo(li);
     var child = new RuleBuilder.Context(type, x.get(0), this, this.rb);
@@ -357,15 +369,18 @@ RuleBuilder.Context.prototype.mk_array_item_context = function(type, container)
         .text("+")
         .appendTo(li)
         .click(function(e) {
-            var child = that.mk_array_item_context(that.inner_type,
-                                                   jQuery('div.array-item-container', that.arraybuilder));
-            that.children.push(child); // XXX: make correct insert order
+            var idx = child.array_item_idx();
+            var newchild = that.mk_array_item_context(that.inner_type,
+                                                      jQuery('div.array-item-container', that.arraybuilder), idx+1);
+            that.children.splice(idx+1, 0, newchild);
         });
     jQuery._span_({'class': 'delete-icon'})
         .text("-")
         .appendTo(li)
         .click(function(e) {
-             // XXX: make correct splice order
+            var idx = child.array_item_idx();
+            jQuery("div.array-item:nth-child("+(idx+1)+")", that.arraybuilder).remove();
+            that.children.splice(idx, 1);
         });
 
     return child;

commit 8155012988dde097ad98bd0543d394de867f5af5
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Fri Oct 2 11:36:59 2009 +0800

    make transform work with arraybuilder.

diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 2942613..28e85bc 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -339,7 +339,7 @@ RuleBuilder.Context = function(expected_type, element, parent, rb) {
                                                        jQuery('div.array-item-container', builder), 0);
                 that.children.push(child);
                 builder.show();
-                jQuery(this).remove();
+                jQuery(this).hide();
                 that.rb.focus(child);
                 return false;
             });
@@ -404,14 +404,30 @@ RuleBuilder.Context.prototype.transform = function(func_name) {
 
         var parent = new RuleBuilder.Context(this.expected_type,
                                              tc.get(0), null, rb);
-        parent.set_application(func_name, func);
         this.parent = rb.top_context = parent;
 
+        parent.set_application(func_name, func);
+
         jQuery(this.element).unbind('click');
         var first_param = parent.children[0];
         var second_param = parent.children.length > 1 ? parent.children[1] : null;
+
+        if (first_param.inner_type) {
+            parent = first_param;
+            var builder = jQuery('div.arraybuilder', parent.element).show();
+            jQuery("span.arraybuilder-icon", builder).hide();
+            parent.arraybuilder = builder;
+            first_param = parent.mk_array_item_context(parent.inner_type,
+                                                       jQuery('div.array-item-container', builder), 0);
+
+            second_param = parent.mk_array_item_context(parent.inner_type,
+                                                      jQuery('div.array-item-container', parent.arraybuilder), 1);
+            parent.children.push(second_param);
+        }
+
         parent.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);

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


More information about the Rt-commit mailing list