1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/********************************************************************************************
* BlueShoes Framework; This file is part of the php application framework.
* NOTE: This code is stripped (obfuscated). To get the clean documented code goto
* www.blueshoes.org and register for the free open source *DEVELOPER* version or
* buy the commercial version.
*
* In case you've already got the developer version, then this is one of the few
* packages/classes that is only available to *PAYING* customers.
* To get it go to www.blueshoes.org and buy a commercial version.
*
* @copyright www.blueshoes.org
* @author Samuel Blume <sam at blueshoes dot org>
* @author Andrej Arn <andrej at blueshoes dot org>
*/
function Bs_FormFieldSelect() {
this.hasValue = function(val) {
val = val + '';for (var i=0; i<this.length; i++) {
var t = this.options[i].value + '';if (t == val) return true;}
return false;}
this.getValue = function() {
var selIndex = this.selectedIndex;if ((selIndex != 'undefined') && (selIndex > -1)) {
if (typeof(this.options[selIndex].value) != 'undefined') return this.options[selIndex].value;if (typeof(this.options[selIndex].text) != 'undefined') return this.options[selIndex].text;}
return 'undefined';}
this.getValueOrText = function(selIndex) {
if (typeof(selIndex) == 'undefined') selIndex = this.selectedIndex;if ((selIndex != 'undefined') && (selIndex > -1)) {
if (typeof(this.options[selIndex].value) != 'undefined') {
if (typeof(this.options[selIndex].outerHTML) == 'string') {
if (this.options[selIndex].outerHTML.toLowerCase().indexOf('value=') != -1) {
return this.options[selIndex].value;}
} else {
if (this.options[selIndex].value != '') return this.options[selIndex].value;}
}
if (typeof(this.options[selIndex].text) != 'undefined') return this.options[selIndex].text;}
return false;}
this.getTextForValue = function(value) {
for (var i=0; i<this.options.length; i++) {
if (this.options[i].value == value) {
return this.options[i].text;}
}
return false;}
this.setTo = function(compare, type) {
if (typeof(type) == 'undefined') type = 'text';for (var i=0; i<this.length; i++) {
if (this.options[i][type] == compare) {
this.selectedIndex = i;return true;}
}
return false;}
this.moveSelectedTo = function(toField, keepSelected) {
if (typeof(toField) == 'string') toField = document.getElementById(toField);if (bs_isNull(toField)) return false;var unsetArray = new Array();for (var i=0; i<this.length; i++) {
if (this.options[i].selected) {
var newOpt = new Option(this.options[i].text, this.options[i].value, false, false);toField.options[toField.length] = newOpt;unsetArray[unsetArray.length] = i;}
}
unsetArray.reverse();for (var i=0; i<unsetArray.length; i++) {
this.options[unsetArray[i]] = null;}
return true;}
this.moveAllTo = function(toField) {
if (typeof(toField) == 'string') toField = document.getElementById(toField);if (bs_isNull(toField)) return false;var unsetArray = new Array();for (var i=0; i<this.length; i++) {
var newOpt = new Option(this.options[i].text, this.options[i].value, false, false);toField.options[toField.length] = newOpt;unsetArray[unsetArray.length] = i;}
unsetArray.reverse();for (var i=0; i<unsetArray.length; i++) {
this.options[unsetArray[i]] = null;}
return true;}
this.moveTo = function(toField, optionValue) {
if (typeof(toField) == 'string') toField = document.getElementById(toField);if (bs_isNull(toField)) return false;var unsetArray = new Array();for (var i=0; i<this.options.length; i++) {
if (this.options[i].value == optionValue) {
var newOpt = new Option(this.options[i].text, this.options[i].value, false, false);toField.options[toField.length] = newOpt;unsetArray[unsetArray.length] = i;break;}
}
unsetArray.reverse();for (var i=0; i<unsetArray.length; i++) {
this.options[unsetArray[i]] = null;}
return true;}
this.moveHashTo = function(toField, hash) {
if (typeof(toField) == 'string') toField = document.getElementById(toField);if (bs_isNull(toField)) return false;var unsetArray = new Array();for (var i=0; i<this.length; i++) {
if (typeof(hash[this.options[i].value]) != 'undefined') {
var newOpt = new Option(this.options[i].text, this.options[i].value, false, false);toField.options[toField.length] = newOpt;unsetArray[unsetArray.length] = i;}
}
unsetArray.reverse();for (var i=0; i<unsetArray.length; i++) {
this.options[unsetArray[i]] = null;}
return true;}
this.getAllKeys = function() {
var ret = new Array();for (var i=0; i<this.options.length; i++) {
ret[i] = this.options[i].value;}
return ret;}
this.getAllOptions = function() {
var ret = new Array();for (var i=0; i<this.options.length; i++) {
var key = this.getValueOrText(i);ret[key] = this.options[i].text;}
return ret;}
this.prune = function() {
this.options.length = 0;}
this.addElementsByHash = function(dataHash) {
var i = 0;for (var key in dataHash) {
var newOpt = new Option(dataHash[key], key, false, false);this.options[this.options.length] = newOpt;i++;}
return i;}
this.sortByText = function(desc, natural) {
var sortArr = new Array;for (var i=0; i<this.length; i++) {
if (this.options[i].value == 'undefined') this.options[i].value = this.options[i].text;sortArr[i] = this.options[i].text + '__BS_SORT__' + this.options[i].value;}
sortArr.sort();if (desc) sortArr.reverse();this.prune();var key = '';var txt = '';for (var i=0; i<sortArr.length; i++) {
var pos = sortArr[i].lastIndexOf('__BS_SORT__');txt = sortArr[i].substr(0, pos);key = sortArr[i].substr(pos + '__BS_SORT__'.length);var newOpt = new Option(txt, key, false, false);this.options[this.options.length] = newOpt;}
}
this.sortByKey = function() {
}
this.setText = function(value, text) {
for (var i=0; i<this.length; i++) {
if (this.options[i].value == value) {
this.options[i].text = text
return true;}
}
return false;}
this.removeElement = function(value) {
for (var i=0; i<this.length; i++) {
if (this.options[i].value == value) {
this.options[i] = null;return true;}
}
return false;}
this.init = function(formField) {
if (formField == null) return;for (var name in this) {
if (name == 'init') continue;formField[name] = this[name];}
}
}
|