function TableDataItemSource(tableData, columnName) { this.columnName = columnName; this.dataView = new DataSetView(tableData); this.eventChanged = new EventHandlers(this); } TableDataItemSource.prototype = { GetData : function() { if (this.columnName == "") return this.dataView.GetData(); return this.dataView.GetUniqueValues(this.columnName); }, Init: function () { }, CreateSubView : function(value) { if (this.columnName == "") return this.dataView; return this.dataView.CreateView(this.columnName, value); } }; function FilteredTableDataItemSource(filterFieldName, columnName) { this.filterFiledName = filterFieldName; this.columnName = columnName; this.eventChanged = new EventHandlers(this); this.dataView = null; this.initialized = false; } FilteredTableDataItemSource.prototype = { GetData : function() { if (this.dataView == null) return []; else if (this.columnName == "") { return this.dataView.GetData(); } return this.dataView.GetUniqueValues(this.columnName); }, Init : function() { if (this.initialized) return; this.initialized = true; this.filteredField = DocumentForm.GetField(this.filterFiledName); if (this.filteredField == null) return; this.filteredField.itemSource.Init(); this.dataView = this.filteredField.itemSource.CreateSubView(this.filteredField.GetValue()); this.lastFilterValue = this.filteredField.GetValue(); var self = this; var changeHandler = function() { var filterValue = self.filteredField.GetValue(); if (self.lastFilterValue != filterValue) { self.dataView = self.filteredField.itemSource.CreateSubView(filterValue); self.eventChanged.Fire(); self.lastFilterValue = filterValue; } } if (!this.filteredField.AddBlurHandler(changeHandler)) { this.filteredField.AddChangedHandler(changeHandler); } this.eventChanged.Fire(); }, CreateSubView : function(value) { if (this.dataView == null) return this.dataView; return this.dataView.CreateView(this.columnName, value); } }; function ListDataItemSource(data) { this.data = data; this.eventChanged = new EventHandlers(this); } ListDataItemSource.prototype = { Init: function () { }, GetData: function () { return this.data; } } function EmptyItemSource() { this.data = new Array(); this.eventChanged = new EventHandlers(this); } EmptyItemSource.prototype = { Init: function () { }, GetData: function () { return this.data; }, SetData: function (data) { this.data = data; this.eventChanged.Fire(); }, Clear: function() { this.SetData(new Array()); } } function LinkDropDownControlWithItemSource(dropDownID, hintValue, itemSource) { var dropDownControl = document.getElementById(dropDownID); var FillDropDown = function() { dropDownControl.innerHTML = ""; if(hintValue != "") { var option = document.createElement("option"); option.text = hintValue; option.value = ""; dropDownControl.appendChild(option); } var dataValues = itemSource.GetData(); for (var i = 0; i < dataValues.length; i++) { var option = document.createElement("option"); var dataValue = dataValues[i]; if(itemSource.InitOption) { itemSource.InitOption(option, dataValue); } else { option.text = dataValue; option.value = dataValue; } dropDownControl.add(option); } var documentFormField = DocumentForm.GetField(dropDownID); if(documentFormField) { documentFormField.SetValue( documentFormField.lastSetValue ); } // dropDownControl.dispatchEvent(new Event('change')); } dropDownControl.itemsSource = itemSource; itemSource.eventChanged.AddHandler(FillDropDown); FillDropDown(); }