Changeset 1447
- Timestamp:
- 2010-03-12 10:35:16 (2 years ago)
- Location:
- trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms
- Files:
-
- 5 edited
-
basic-controls.js (modified) (2 diffs)
-
collection.js (modified) (2 diffs)
-
composite.js (modified) (1 diff)
-
control.js (modified) (16 diffs)
-
form.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-controls.js
r1446 r1447 38 38 $.extend(InputControl.prototype.templates, kf.Control.prototype.templates); 39 39 $.extend(InputControl.prototype.templates, { 40 input:"<input type='text' kauri-role='input'/>"40 control:"<input type='text' kauri-role='input'/>" 41 41 }); 42 42 … … 47 47 InputControl.prototype.initElements = function() { 48 48 49 var $input = this.getElement( );49 var $input = this.getElement("input"); 50 50 51 51 var selector = "input"; 52 52 if(! $input){ 53 53 // does not contain an input element TODO check if this is OK 54 this.setElement("input", $(this.getTemplate(' input')));54 this.setElement("input", $(this.getTemplate('control'))); 55 55 $input = this.getElement(); 56 56 } 57 57 if(! $input.is(selector)){ 58 var $element = $(this.getTemplate('input')); 59 60 $input.each( function() { 61 $.each(this.attributes, function(i, attrib) { 62 var name = attrib.name; 63 var value = attrib.value; 64 if (!$element.attr(name)) { 65 $element.attr(name, value); 66 } 67 }); 68 }); 69 $input.before($element).remove(); 58 var $element = $(this.getTemplate('control')); 59 $element.attr('kauri-idref', $input.attr('kauri-idref')); 60 $input.before($element).remove(); 61 kf.ControlElements.index($element, this.getForm(), true); 62 this.setElement("input", $input); 63 // hier herindexeren 70 64 } 71 65 -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/collection.js
r1446 r1447 62 62 } 63 63 $.extend(CollectionControl.prototype.templates, { 64 layout: "<tr><td ><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/><span kauri-role='delete'/></td></tr>", 65 container: "<table kauri-role='container'></table>", 66 input: "<table kauri-role='input'></table>" 64 layout: "<tr><td ><span kauri-role='label'/><span kauri-role='control'/><span kauri-role='messages'/><span kauri-role='delete'/></td></tr>", 65 control: "<table kauri-role='container'></table>" 67 66 }); 68 67 … … 91 90 92 91 var container = this.getElement(kf.ControlElements.REV_INPUT); 93 var layout = this.getElement(kf.ControlElements.REV_LAYOUT);94 92 95 93 var el, startindex, stopindex; // local variables used in the nested functions -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/composite.js
r1446 r1447 80 80 $.extend(CompositeControl.prototype.templates, kf.AbstractContainerControl.prototype.templates); 81 81 $.extend(CompositeControl.prototype.templates, { 82 input: "<dl kauri-role='input'></dl>",83 layout: "<dt kauri-role='label'/><dd><span kauri-role=' input'/><span kauri-role='messages'/></dd>",84 "kauri-layout": "<dt kauri-role='label'/><dd><span kauri-role='input'/><span kauri-role='messages'/></dd>"82 control: "<dl kauri-role='container'></dl>", 83 layout: "<dt kauri-role='label'/><dd><span kauri-role='control'/><span kauri-role='messages'/></dd>" 84 85 85 }); 86 86 -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js
r1446 r1447 147 147 148 148 149 ControlElements.REV_CONTAINER = "container"; 149 150 /** 150 151 * TODO this one should be removed, it is remplaces by the kauri-layout attribute … … 152 153 * @final 153 154 */ 154 ControlElements.REV_CONTAINER = "container"; 155 ControlElements.REV_CONTROL = "control"; 156 155 157 ControlElements.REV_LAYOUT = "layout"; 156 158 … … 200 202 201 203 var rev = $this.attr(ControlElements.ATTR_REV); 204 $this.attr(ControlElements.ATTR_INDEX, index); 202 205 store.addElementIndex(index, rev, $this); 203 206 … … 205 208 store.addTypeAndControl(index, $this.attr(ControlElements.ATTR_TYPE), $this.attr(ControlElements.ATTR_CONTROL)); 206 209 207 $this.attr(ControlElements.ATTR_INDEX, index);210 208 211 }; 209 212 210 213 // find all kauri-idref and kauri-role marked elements and index them 211 var kauriSelector = "[" + ControlElements.ATTR_IDREF + "] ";214 var kauriSelector = "[" + ControlElements.ATTR_IDREF + "],[" + ControlElements.ATTR_REV + "]"; 212 215 var layoutSelector = "[kauri-layout]"; 213 216 … … 223 226 return (revParents == null || revParents.length==0); 224 227 }); 225 $.unique($(kauriSelector, space)).each(indexor);228 matching.each(indexor); 226 229 227 230 … … 348 351 } 349 352 353 /** 354 * Finds the element assigned to the identified control for a specific kauri-form-relation (functional role), and creates it if 355 * not found. + Sets the element in the control 356 * @param {Control} control 357 * @param {String} relation What relation the element has with the control (input, message, ...) 358 * @param {Boolean} create Flag that indicates if an element should be created if not found 359 * @final 360 * @static 361 */ 362 ControlElements.removeRelationElement = function(control, relation){ 363 364 if (!relation) 365 throw "[ControlElements#lookup] no relation specified."; 366 var form = control.getForm(); 367 var index = control.getAbsoluteId(); 368 369 form.removeElementIndex(index, relation); 370 delete control._elements[relation]; 371 } 372 350 373 351 374 ControlElements.lookupLayout = function(control) { … … 553 576 }, function(i, r){ 554 577 var elms = this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 555 if (elms.meta[r])556 throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r;578 //TODO if (elms.meta[r]) 579 // throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 557 580 558 581 elms.meta[r] = elm; … … 590 613 } 591 614 615 /** 616 * Removes the specified element from the index. 617 * 618 * @param {string} 619 * [index] index to remove 620 * @param {string} 621 * [relation] relation-part to remove 622 */ 623 ControlElements.prototype.removeElementIndex = function(index, relation){ 624 if (index == undefined) 625 return; 626 627 if(! relation){ 628 delete this.elementIndex[index]; 629 } 630 if(this.elementIndex[index] && this.elementIndex[index].meta[relation]){ 631 delete this.elementIndex[index].meta[relation]; 632 } 633 } 634 635 592 636 /** 593 637 * Adds the specified element to the index. … … 879 923 880 924 var $input = ControlElements.lookup(this, ControlElements.REV_INPUT); 881 925 var $control = ControlElements.lookup(this, ControlElements.REV_CONTROL); 926 927 if($control) { 928 var $element = $(this.getTemplate(ControlElements.REV_CONTROL)); 929 $element.attr('kauri-idref', $control.attr('kauri-idref')); 930 $control.before($element).remove(); 931 932 this.setElement(ControlElements.REV_INPUT, $element); 933 ControlElements.removeRelationElement(this, ControlElements.REV_CONTROL); 934 935 ControlElements.index($element, this.getForm(), true); 936 } 937 882 938 // Sets a label in the label element. 883 939 // If no label is found then the control id will be used instead. … … 901 957 902 958 // allow control-specific initialization of containment elements 903 this.initContainerElements( );959 this.initContainerElements(this.getParent() ? this.getParent().getElement() : this.getElement()); 904 960 905 961 //initialize options … … 948 1004 * @see #_initElements(create) 949 1005 */ 950 Control.prototype.initContainerElements = function(c reate){1006 Control.prototype.initContainerElements = function(container, create){ 951 1007 952 1008 } … … 1951 2007 1952 2008 /** 1953 * Initializes typical container elements 2009 * Initializes typical container elements: 2010 * - set the container element on the control (so that children know where to attach) 2011 * - check if there is a 'control' element and if so, replace it by the 'input' template 1954 2012 * @param {Boolean} create If true it will create the container elements if the don't already exist 1955 2013 * @private 1956 2014 */ 1957 AbstractContainerControl.prototype.initContainerElements = function(create){ 1958 var container = ControlElements.lookup(this, ControlElements.REV_INPUT); 2015 AbstractContainerControl.prototype.initContainerElements = function(container, create){ 2016 var id = this.getAbsoluteId(); 2017 2018 // check if there is an container-role element 2019 // if there is not, create one and append where 1959 2020 2021 var $input = ControlElements.lookup(this, ControlElements.REV_INPUT); 2022 var $container = ControlElements.lookup(this, ControlElements.REV_CONTAINER); 1960 2023 1961 // check if there is a layout attached to this element 1962 // if not, switch the apply the input template from the control and append to the input container 1963 var id = this.getAbsoluteId(); 1964 if(!this.getForm().getLayoutIndex(id)){ 1965 var creator = this.getTemplate(ControlElements.REV_INPUT); 2024 if(!$container && !$input) { 2025 var $element = $(this.getTemplate(ControlElements.REV_CONTROL)); 2026 2027 $element.attr('kauri-idref', $input.attr('kauri-idref')); 2028 $input.before($element).remove(); 2029 2030 this.setElement(ControlElements.REV_CONTAINER, $element); 2031 ControlElements.index($input, this.getForm(), true); 2032 } 2033 2034 if (!$container) { 2035 this.setElement(ControlElements.REV_CONTAINER, $input); 2036 } 2037 2038 /*if(!container) { 2039 var creator = this.getTemplate(ControlElements.REV_CONTROL); 1966 2040 if (creator) { 1967 2041 var form = this.getForm(); 1968 var $input = $(creator); 1969 $container = $input.appendTo(container); 1970 this.setElement(ControlElements.REV_INPUT, $input); 1971 } 1972 } 2042 var $control = $(creator); 2043 var parentInput = this.getParent() ? this.getParent().getElement(ControlElements.REV_CONTAINER) : this.getElement(ControlElements.REV_INPUT); 2044 2045 var $container = $control.appendTo(parentInput); 2046 2047 if($container.attr(ControlElements.ATTR_IDREF)) 2048 $container.attr(ControlElements.ATTR_IDREF, $container.attr(ControlElements.ATTR_IDREF) + "/" +id); 2049 else 2050 $container.attr(ControlElements.ATTR_IDREF,id); 2051 this.setElement(ControlElements.REV_CONTAINER, $("[kauri-role="+ControlElements.REV_CONTAINER+"]",$control)); 2052 ControlElements.index($control, this.getForm(), true); 2053 } 2054 }*/ 1973 2055 1974 var $container = $(container); 1975 if (!container) { 1976 1977 } 1978 2056 /* var control = ControlElements.lookup(this, ControlElements.REV_CONTROL); 2057 /* 1979 2058 if (!$container) { // default to complete input space 1980 this.setElement(ControlElements.REV_ INPUT, this.getElement("input"));1981 } 2059 this.setElement(ControlElements.REV_CONTROL, this.getElement("input")); 2060 }*/ 1982 2061 } 1983 2062 … … 2003 2082 * @private 2004 2083 */ 2005 AbstractContainerControl.prototype._createChildElements = function(id, position ) {2084 AbstractContainerControl.prototype._createChildElements = function(id, position, container) { 2006 2085 var absoluteId = this.getAbsoluteId(); 2007 2086 var newIndex = $.concatPath(absoluteId, id); … … 2019 2098 var $layoutGroups = form.getLayoutIndex(groupId); 2020 2099 2021 2022 var copyIdRef = function(idx, elt){2100 var kauriSelector = "[kauri-role],[kauri-id]"; 2101 var setIdRef = function(idx, elt){ 2023 2102 var $elt = $(elt); 2024 if($elt.attr(ControlElements.ATTR_IDREF)) 2025 $elt.attr(ControlElements.ATTR_IDREF, $elt.attr(ControlElements.ATTR_IDREF) + "/" +id); 2026 else 2103 if($elt.is(kauriSelector)){ 2027 2104 $elt.attr(ControlElements.ATTR_IDREF, id); 2105 } 2028 2106 }; 2029 2030 2107 2031 2108 if(!$layoutGroups) { … … 2035 2112 var $layout = $(this.getTemplate("layout")); 2036 2113 2037 $layout.each(copyIdRef); 2038 2039 $.each($("[kauri-role]", $layout), copyIdRef); 2040 2114 $layout.each(setIdRef); 2115 $.each($(kauriSelector, $layout), setIdRef); 2116 2041 2117 newElements = container.append($layout); 2042 2118 ControlElements.index($layout, form, true); … … 2117 2193 this.getAbsoluteId(); 2118 2194 2119 this._createChildElements(id, position ); // ensure the needed html elements for this new child are available.2195 this._createChildElements(id, position, this.getElement()); // ensure the needed html elements for this new child are available. 2120 2196 var me = this; 2121 2197 var form = this.getForm(); -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/form.js
r1446 r1447 346 346 }); 347 347 348 Form.prototype.templates = {}; 349 $.extend(Form.prototype.templates, kf.CompositeControl.prototype.templates); 350 $.extend(Form.prototype.templates, { 351 control: "<fieldset ><dl kauri-role='container'></dl></fieldset>" 352 }); 348 353 349 354 $.extend(kf, {
Note: See TracChangeset
for help on using the changeset viewer.