- Timestamp:
- 2011-08-09 09:52:26 (10 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js (modified) (10 diffs)
-
modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-collection.js (modified) (2 diffs)
-
modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-form.js (modified) (1 diff)
-
samples/kauri-forms-sample/src/main/kauri/pages/collection-performance.html.xml (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js
r1920 r1927 2097 2097 } 2098 2098 2099 2099 2100 $.inherit(AbstractContainerControl, Control); 2100 2101 … … 2122 2123 }; 2123 2124 2125 var CLEAR = {}; 2126 AbstractContainerControl.prototype.invalidateValueCache = function() { 2127 this.value = CLEAR; 2128 this.cachedWireValue = CLEAR; 2129 }; 2124 2130 2125 2131 /** … … 2225 2231 */ 2226 2232 AbstractContainerControl.prototype.setLoop = function(fn, value, noValidation){ 2227 // ignore childUpdates2228 var restore = this.updateValue;2229 this.updateValue = function(childControl){2230 };2231 2233 2232 2234 var cfn = function(i, child) { … … 2234 2236 fn(i, child, childValue, noValidation); 2235 2237 }; 2236 this.internalSetLoop(cfn, value); 2237 2238 // reset childUpdates 2239 this.updateValue = restore; 2238 2239 var me = this; 2240 2241 this.silenceEventsWhile(function() { // ignore childUpdates 2242 me.internalSetLoop(cfn, value); 2243 }); 2244 2240 2245 // call childUpdates 2241 2246 this.updateValue(noValidation); … … 2283 2288 */ 2284 2289 AbstractContainerControl.prototype.getValue = function(){ 2285 return this.getLoop(AbstractContainerControl.childGetter); 2290 if (this.value == CLEAR){ 2291 this.value = this.getLoop(AbstractContainerControl.childGetter); 2292 } 2293 return this.value; 2286 2294 }; 2287 2295 AbstractContainerControl.childGetter = function(i, child) { … … 2307 2315 */ 2308 2316 AbstractContainerControl.prototype.getWireValue = function(){ 2309 var w = this.getLoop(AbstractContainerControl.childWireGetter); 2310 return this.getType().toWireValue(w); // allow composite-type specific formatting (merge) 2317 if (this.cachedWireValue == CLEAR) { 2318 var w = this.getLoop(AbstractContainerControl.childWireGetter); 2319 this.cachedWireValue = this.getType().toWireValue(w); // allow composite-type specific formatting (merge) 2320 } 2321 return this.cachedWireValue; 2311 2322 }; 2312 2323 AbstractContainerControl.childWireGetter = function(i, child) { … … 2341 2352 Control.reset(me); 2342 2353 } 2354 me.invalidateValueCache(); 2343 2355 }; 2344 2356 … … 2639 2651 2640 2652 childControl.valueChanged(childChanged); 2641 2653 2642 2654 return childControl; 2643 2655 } … … 2651 2663 2652 2664 this._children[id] = childControl; 2653 } 2654 2655 /** 2656 * Deletes a child control in the list of this controls children 2657 * @param {String} id 2658 */ 2659 AbstractContainerControl.prototype.deleteChild = function(id){ 2665 this.updateValue(true, true); // be sure to handle change in value structure 2666 } 2667 2668 /** 2669 * Deletes a child control in the list of this controls children 2670 * @param {String} id 2671 */ 2672 AbstractContainerControl.prototype.deleteChild = function(id){ 2660 2673 2661 delete this._children[id]; 2662 } 2674 delete this._children[id]; 2675 this.updateValue(true, true); // be sure to handle change in value structure 2676 } 2663 2677 2664 2678 … … 2666 2680 * Runs validation on this control and acknowledges a change in value 2667 2681 * @param {Boolean} noValidation perform validation or not 2668 */ 2669 AbstractContainerControl.prototype.updateValue = function(noValidation){ 2670 var value = this.getValue(); 2671 var nvalue = this.normaliseValue(value); 2672 if (!$.valueCompare(value, nvalue)) { // validation & update event only needed if there are actual changes to the normalised valued 2673 var restore = this.updateValue; 2674 this.updateValue = function(noValidation) {} 2675 this.setNormalisedValue(nvalue); 2676 this.updateValue = restore; 2677 } 2678 if(!noValidation) { 2679 this.newValidation(this.getValue(), this.getWireValue()); 2680 } 2681 this.valueChanged(); 2682 * @param {Boolean} noValueAccess avoid accessing the value, just clear cache and notify parent 2683 */ 2684 AbstractContainerControl.prototype.updateValue = function(noValidation, noValueAccess){ 2685 noValueAccess = noValueAccess || false; 2686 this.invalidateValueCache(); // be sure to read children again 2687 if (!noValueAccess) { 2688 var value = this.getValue(); 2689 var nvalue = this.normaliseValue(value); 2690 if (!$.valueCompare(value, nvalue)) { // validation & update event only needed if there are actual changes to the normalised valued 2691 var me = this; 2692 this.silenceEventsWhile(function() { 2693 me.setNormalisedValue(nvalue); 2694 }); 2695 } 2696 if(!noValidation) { 2697 this.newValidation(this.getValue(), this.getWireValue()); 2698 } 2699 } 2700 this.valueChanged(); // and notify parent 2682 2701 } 2702 2703 /** 2704 * 2705 */ 2706 AbstractContainerControl.prototype.silenceEventsWhile = function(action) { 2707 var restoreUpdateFn = this.updateValue; 2708 this.updateValue = function(noValidation) {}; 2709 2710 action(); 2711 2712 this.updateValue = restoreUpdateFn; 2713 } 2683 2714 2684 2715 /** -
trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-collection.js
r1921 r1927 179 179 180 180 // test 181 expect(1 0);181 expect(11); 182 182 183 183 // verify creation of control … … 207 207 equal(c.getElement("messages").html(), $("<p>Length not in range 3 ⩽ Length ⩾ 6.</p>").html(), "validation error set correctly"); 208 208 209 c.addChild().getElement("input").val(okValue + "4").change(); 210 equal(changes, 4, "change detection"); 209 var newRow = c.addChild(); 210 equal(changes, 4, "change detection"); // NOTE: both addchild and the actual value change will trigger an update! 211 newRow.getElement("input").val(okValue + "4").change(); 212 equal(changes, 5, "change detection"); 211 213 212 214 equal(c.getElement("messages").html(), "", "validation error cleared"); -
trunk/modules/kauri-forms/kauri-forms-framework/src/test/kauri.forms/test-form.js
r1908 r1927 711 711 expect(5); 712 712 713 ok($.valueCompare(form.getValue(), {td: "s"}), "checking expected initial value.");713 deepEqual(form.getValue(), {td: "s"}, "checking expected initial value."); 714 714 var tds = form.findControl("tds"); 715 715 tds.getChildByIndex(1); // force creation of children... 716 716 717 ok($.valueCompare(form.getValue(), {td: "s", tds: ["s", "s"]}), "checking expected initial values inside the collection as well.");717 deepEqual(form.getValue(), {td: "s", tds: ["s", "s"]}, "checking expected initial values inside the collection as well."); 718 718 form.delegate("testDelegate", "x"); 719 ok($.valueCompare(form.getValue(), {td: "sx", tds: ["sx", "sx"]}), "checking all modified.");719 deepEqual(form.getValue(), {td: "sx", tds: ["sx", "sx"]}, "checking all modified."); 720 720 form.findControl("tds").delegate("testDelegate", "x"); 721 ok($.valueCompare(form.getValue(), {td: "sx", tds: ["sxx", "sxx"]}), "checking all modified in collection.");721 deepEqual(form.getValue(), {td: "sx", tds: ["sxx", "sxx"]}, "checking all modified in collection."); 722 722 form.findControl("tds/1").delegate("testDelegate", "x"); 723 ok($.valueCompare(form.getValue(), {td: "sx", tds: ["sxx", "sxxx"]}), "checking single modified.");723 deepEqual(form.getValue(), {td: "sx", tds: ["sxx", "sxxx"]}, "checking single modified."); 724 724 725 725 -
trunk/samples/kauri-forms-sample/src/main/kauri/pages/collection-performance.html.xml
r1757 r1927 12 12 var days = ["mo", "tu", "we", "th", "fr", "sa", "su"]; 13 13 14 function getData( ) {14 function getData(size) { 15 15 var data = { 16 16 "performances": [ … … 18 18 } 19 19 20 for (var i = 0; i < 5; i++) {20 for (var i = 0; i < size; i++) { 21 21 data.performances[i] = { "task": "Task " + i}; 22 22 for (var j = 0; j < days.length; j++) { … … 30 30 $(function() { 31 31 var form1 = new $.org.kauriproject.forms.Form("form1", {}); 32 33 var doTimed = function(fn) { 34 var t0 = (new Date()).getTime(); 35 fn(); 36 return (new Date()).getTime() - t0; 37 } 32 38 33 39 $("#loadWireSampleData").click(function() { 34 form1.setWireValue(getData()); 40 var data = getData($("#size").val()); 41 var dt = doTimed(function() { 42 form1.setWireValue(data); 43 }); 44 $("#timing").text(dt); 35 45 }); 36 46 37 $("#loadWireSampleData 100").click(function() {47 $("#loadWireSampleDataRepeat").click(function() { 38 48 var intervalHandle; 39 var tcount = 100;49 var tcount = $("#repeats").val(); 40 50 var t = function() { 41 51 $("#countdown").text(tcount); … … 50 60 51 61 $("#loadNativeSampleData").click(function() { 52 form1.setValue(getData()); 62 var data = getData($("#size").val()); 63 var dt = doTimed(function() { 64 form1.setValue(getData($("#size").val())); 65 }); 66 $("#timing2").text(dt); 53 67 }); 54 68 55 $("#loadNativeSampleData100").click(function() { 56 debugger; 69 $("#loadNativeSampleDataRepeat").click(function() { 57 70 var intervalHandle; 58 var tcount = 100;71 var tcount = $("#repeats").val(); 59 72 var t = function() { 60 73 $("#countdown2").text(tcount); … … 96 109 <p>Press the load sample data button below to test.</p> 97 110 98 <p><button id="loadWireSampleData">Load sample data via setWireValue()</button></p> 99 100 <p><button id="loadWireSampleData100">100 times Load sample data via setWireValue()</button></p> 101 <div id="countdown"/> 102 103 <p><button id="loadNativeSampleData">Load sample data via setValue()</button></p> 104 105 <p><button id="loadNativeSampleData100">100 times Load sample data via setValue()</button></p> 106 <div id="countdown2"/> 111 <p>Load Sample Data: 112 <table style="width: auto; border: 1px solid black;"> 113 <tbody> 114 <tr> 115 <td>containing <input id="size" value="5" size="3"/> rows</td> 116 <td><button id="loadWireSampleData">via setWireValue()</button> <span id="timing">0</span> ms</td> 117 <td><button id="loadNativeSampleData">via setValue()</button> <span id="timing2">0</span> ms</td> 118 </tr> 119 <tr> 120 <td>and repeat that <input id="repeats" value="100" size="3"/> times</td> 121 <td><button id="loadWireSampleDataRepeat">via setWireValue()</button> <span id="countdown">0</span></td> 122 <td><button id="loadNativeSampleDataRepeat">via setValue()</button> <span id="countdown2">0</span></td> 123 </tr> 124 </tbody> 125 </table> 126 </p> 107 127 108 128 <p><button id="addEmptyRows">Add 30 empty rows</button></p>
Note: See TracChangeset
for help on using the changeset viewer.