/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.widget.Repeater"); dojo.require("dojo.widget.HtmlWidget"); dojo.require("dojo.string"); dojo.require("dojo.event.*"); dojo.require("dojo.experimental"); dojo.experimental("dojo.widget.Repeater"); dojo.widget.defineWidget("dojo.widget.Repeater", dojo.widget.HtmlWidget, { /* summary: Makes it easy to add dynamicly new segments to form, ie. add new rows. description: usage:

Name:

or: var myRepeater=dojo.widget.createWidget("Repeater",{pattern: "row.%{index}", useDnd: false}); myRepeater.setRow("

Name:

", {doThis: function(node) { dojo.event.connect(node,"onClick", function() { alert("HERE"); }); } ); */ name: "", rowTemplate: "", // myObject: // Used to bind functionality to rowFunctions myObject: null, // myObject: // defines pattern of the names pattern: "", // useDnd: // if true, you can change position of rows by DnD // you can also remove rows by dragging row away useDnd: false, isContainer: true, initialize: function(args,frag) { var node = this.getFragNodeRef(frag); node.removeAttribute("dojotype"); this.setRow(dojo.string.trim(node.innerHTML), {}); node.innerHTML=""; frag=null; }, postCreate: function(args,frag){ if (this.useDnd) { dojo.require("dojo.dnd.*"); var dnd = new dojo.dnd.HtmlDropTarget(this.domNode, [this.widgetId]); } }, _reIndexRows: function() { for(var i=0,len=this.domNode.childNodes.length; i 0) { return true; } return false; }, getRowCount: function() { return this.domNode.childNodes.length; }, deleteRow: function(/*integer*/idx) { this.domNode.removeChild(this.domNode.childNodes[idx]); this._reIndexRows(); }, _changeRowPosition: function(e) { if (e.dragStatus == "dropFailure") { this.domNode.removeChild(e["dragSource"].domNode); } else if (e.dragStatus == "dropSuccess") { // nothing to do } // else-if this._reIndexRows(); }, setRow: function(/*string*/template, /*object*/myObject) { //template = dojo.string.substituteParams(template, {"index": "0"}); template= template.replace(/\%\{(index)\}/g, "0"); this.rowTemplate=template; this.myObject = myObject; }, getRow: function() { return this.rowTemplate; }, _initRow: function(/*integer or dom node*/node) { if (typeof(node) == "number") { node=this.domNode.childNodes[node]; } // if var elems = ["INPUT", "SELECT", "IMG"]; for (var k=0; k < elems.length; k++) { var list = node.getElementsByTagName(elems[k]); for(var i=0, len=list.length; i