blob: 9b3ce11d8cda60be77b45f83621a016602775743 (
plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// $Header: /cvsroot/bitweaver/_bit_util/javascript/libs/multifile.js,v 1.5 2007/07/09 18:29:25 squareing Exp $
// please modify this file and leave plenty of comments. This file will be
// compressed automatically. Please make sure you only use comments beginning
// with '//' and put comments on separate lines otherwise the packer will choke
// Multiple file selector by Stickman -- http://www.the-stickman.com
function MultiSelector( list_target, max ){
this.list_target = list_target;
this.count = 0;
this.id = 0;
if( max ){
this.max = max;
} else {
this.max = -1;
};
// BitMod allow us to know what the maximum for each named item is.
this.max_elements = Array();
// BitMod allow us to add elements that are disabled and enabled in unison
this.disable_array = Array();
// BitMod Added setType to allow us to add something besides a div.
this.type = 'file';
this.addDisableElement = function(element) {
this.disable_array[element] = element;
};
this.setType = function(type) {
this.type = type;
};
// BitMod Added to allow us to include a title textbox
this.includeText = 0;
this.setIncludeText = function(include) {
this.includeText = include;
};
// BitMod Added to allow us to set the new item dragable
this.makeDragable = 0;
this.setMakeDragable = function(drag) {
this.makeDragable = drag;
};
// BitMod Added addNamedElement function to allow us to name these.
// Thus we can have multiple on the same form
this.addNamedElement = function(element, name) {
// BitMod We need a way to tell where the end is to avoid an infinite
// loop when processing the uploads because ones in the middle may get removed
// so we can't reliably tell when we hit the end without some magic
if(name in this.max_elements) {
this.max_elements[name].value = this.id;
}
else {
var max_element = document.createElement('input');
max_element.type = 'hidden';
max_element.name = name + '_max';
max_element.value = this.count;
this.max_elements[name] = max_element;
this.list_target.appendChild(max_element);
};
if( element.tagName == 'INPUT' && element.type == 'file' ){
element.base_name = name;
element.name = name + '_' + this.id++;
element.multi_selector = this;
element.onchange = function(){
var new_element = document.createElement( 'input' );
new_element.type = 'file';
this.parentNode.insertBefore( new_element, this );
this.multi_selector.addNamedElement( new_element, element.base_name);
this.multi_selector.addListRow( this , element.name);
this.style.position = 'absolute';
this.style.left = '-1000px';
};
if( this.max != -1 && this.count >= this.max ){
element.disabled = true;
for (var item in this.disable_array) {
var elem = document.getElementById(item);
if (elem) {
elem.disabled = true;
}
}
};
this.count++;
this.current_element = element;
} else {
alert( 'Error: not a file input element' );
};
};
this.addElement = function( element ){
this.addNamedElement(element, 'file');
};
this.addListRow = function( element , name){
// BitMod create by type and set id so we can use it
// in a drag and drop li.
var new_row = document.createElement( this.type );
if (this.makeDragable) {
DragDrop.makeItemDragable(new_row);
};
new_row.id = name;
var new_row_button = document.createElement( 'input' );
new_row_button.type = 'button';
new_row_button.value = 'Remove';
new_row.element = element;
new_row_button.onclick= function(){
this.parentNode.element.parentNode.removeChild( this.parentNode.element );
this.parentNode.parentNode.removeChild( this.parentNode );
this.parentNode.element.multi_selector.count--;
this.parentNode.element.multi_selector.current_element.disabled = false;
for (var item in this.parentNode.element.multi_selector.disable_array) {
var elem = document.getElementById(item);
if (elem) {
elem.disabled = false;
};
};
return false;
};
new_row.innerHTML = '<span>'+element.value+'</span>';
// BitMod to allow us to add a text box
if (this.includeText) {
new_row.innerHTML += "<br />";
var new_row_text = document.createElement( 'input' );
new_row_text.type = 'text';
new_row_text.name = name + '_text';
new_row.appendChild(new_row_text);
};
new_row.appendChild( new_row_button );
this.list_target.appendChild( new_row );
};
};
|