2007-12-13 23:05:31 +01:00
|
|
|
HasManyFileField = Class.create();
|
|
|
|
HasManyFileField.applyTo('div.hasmanyfile');
|
|
|
|
HasManyFileField.prototype = {
|
|
|
|
initialize: function() {
|
|
|
|
HasManyFileFieldAddButton.applyToChildren(this, 'a.addFile');
|
|
|
|
HasManyFileFieldRemoveButton.applyToChildren(this, 'a.removeFile');
|
|
|
|
HasManyFileFieldUploadButton.applyToChildren(this, 'a.uploadFile');
|
|
|
|
this.tree = document.getElementsByClassName('TreeDropdownField', this)[0];
|
|
|
|
this.list = this.getElementsByTagName('ul')[0];
|
|
|
|
this.uploadFolderID = this.getElementsByTagName('input')[0].value;
|
|
|
|
this.uploadMessage = document.getElementsByClassName('uploadMessage')[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HasManyFileFieldAddButton = Class.create();
|
|
|
|
HasManyFileFieldAddButton.prototype = {
|
|
|
|
onclick: function() {
|
|
|
|
tree = this.parentNode.parentNode.tree;
|
|
|
|
list = this.parentNode.parentNode.list;
|
|
|
|
fieldid = this.parentNode.parentNode.id;
|
|
|
|
fileid = tree.getElementsByTagName('input')[0].value;
|
|
|
|
name = tree.getElementsByTagName('span')[0].innerHTML;
|
|
|
|
|
|
|
|
input = document.createElement('input');
|
|
|
|
input.className = 'hidden';
|
|
|
|
input.type = 'hidden';
|
|
|
|
input.name = fieldid + '[]';
|
|
|
|
input.value = fileid;
|
|
|
|
|
|
|
|
text = document.createTextNode(name);
|
2007-12-20 00:07:42 +01:00
|
|
|
link = document.createElement('a');
|
|
|
|
link.appendChild(text);
|
2007-12-13 23:05:31 +01:00
|
|
|
|
|
|
|
removelink = document.createElement('a');
|
|
|
|
removelink.className = 'removeFile';
|
|
|
|
removelink.innerHTML = 'Remove file';
|
|
|
|
|
|
|
|
li = document.createElement('li');
|
|
|
|
li.appendChild(input);
|
2007-12-20 00:07:42 +01:00
|
|
|
li.appendChild(link);
|
2007-12-13 23:05:31 +01:00
|
|
|
li.appendChild(removelink);
|
|
|
|
list.appendChild(li);
|
|
|
|
|
|
|
|
HasManyFileFieldRemoveButton.applyTo(removelink);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HasManyFileFieldRemoveButton = Class.create();
|
|
|
|
HasManyFileFieldRemoveButton.prototype = {
|
|
|
|
onclick: function() {
|
|
|
|
li = this.parentNode;
|
|
|
|
list = this.parentNode.parentNode;
|
|
|
|
list.removeChild(li);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HasManyFileFieldUploadButton = Class.create();
|
|
|
|
HasManyFileFieldUploadButton.prototype = {
|
|
|
|
initialize: function() {
|
|
|
|
this.upload = new Upload({
|
|
|
|
fileUploadLimit : '6',
|
|
|
|
securityID : $('SecurityID').value,
|
|
|
|
beginUploadOnQueue : true,
|
|
|
|
fileQueued : this.uploadFileQueuedCallback.bind(this),
|
|
|
|
fileComplete : this.uploadFileCompleteCallback.bind(this),
|
|
|
|
queueComplete : this.uploadQueueCompleteCallback.bind(this)
|
|
|
|
});
|
|
|
|
|
|
|
|
this.upload.setFolderID(this.parentNode.parentNode.uploadFolderID);
|
|
|
|
},
|
|
|
|
|
|
|
|
buildUI: function() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onclick: function(event) {
|
|
|
|
Event.stop(event);
|
|
|
|
this.upload.browse();
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileQueuedCallback: function(file,queueLength) {
|
|
|
|
this.parentNode.parentNode.uploadMessage.innerHTML = "Uploading..." + this.upload.getFilesToUpload();
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileCompleteCallback: function(file,serverData) {
|
|
|
|
this.parentNode.parentNode.uploadMessage.innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
|
|
|
|
idregex = /\/\* IDs: ([0-9,]+) \*\//;
|
|
|
|
ids = serverData.match(idregex);
|
|
|
|
fileid = ids[1];
|
|
|
|
|
2007-12-20 00:07:42 +01:00
|
|
|
console.log(serverData);
|
|
|
|
|
|
|
|
nameregex = /\/\* Names: ([^\s]+) \*\//;
|
2007-12-13 23:05:31 +01:00
|
|
|
names = serverData.match(nameregex);
|
|
|
|
name = names[1];
|
|
|
|
|
2007-12-20 00:07:42 +01:00
|
|
|
console.log(name);
|
|
|
|
|
2007-12-13 23:05:31 +01:00
|
|
|
fieldid = this.parentNode.parentNode.id;
|
|
|
|
list = this.parentNode.parentNode.list;
|
|
|
|
|
|
|
|
input = document.createElement('input');
|
|
|
|
input.className = 'hidden';
|
|
|
|
input.type = 'hidden';
|
|
|
|
input.name = fieldid + '[]';
|
|
|
|
input.value = fileid;
|
|
|
|
|
|
|
|
text = document.createTextNode(name);
|
2007-12-20 00:07:42 +01:00
|
|
|
link = document.createElement('a');
|
|
|
|
link.appendChild(text);
|
2007-12-13 23:05:31 +01:00
|
|
|
|
|
|
|
removelink = document.createElement('a');
|
|
|
|
removelink.className = 'removeFile';
|
|
|
|
removelink.innerHTML = 'Remove file';
|
|
|
|
|
|
|
|
li = document.createElement('li');
|
|
|
|
li.appendChild(input);
|
2007-12-20 00:07:42 +01:00
|
|
|
li.appendChild(link);
|
2007-12-13 23:05:31 +01:00
|
|
|
li.appendChild(removelink);
|
|
|
|
list.appendChild(li);
|
|
|
|
|
|
|
|
HasManyFileFieldRemoveButton.applyTo(removelink);
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadQueueCompleteCallback: function() {
|
|
|
|
this.parentNode.parentNode.uploadMessage.innerHTML = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|