mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Added HasManyFileField
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46792 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4056408d73
commit
7c0e6add9b
11
css/HasManyFileField.css
Normal file
11
css/HasManyFileField.css
Normal file
@ -0,0 +1,11 @@
|
||||
#right form .hasmanyfile a.addFile,
|
||||
#right form .hasmanyfile a.uploadFile,
|
||||
#right form .hasmanyfile li {
|
||||
font-size: 1.2em;
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
#right form .hasmanyfile a.removeFile {
|
||||
padding-left: 3px;
|
||||
font-size: 0.8em;
|
||||
}
|
125
javascript/HasManyFileField.js
Normal file
125
javascript/HasManyFileField.js
Normal file
@ -0,0 +1,125 @@
|
||||
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);
|
||||
|
||||
removelink = document.createElement('a');
|
||||
removelink.className = 'removeFile';
|
||||
removelink.innerHTML = 'Remove file';
|
||||
|
||||
li = document.createElement('li');
|
||||
li.appendChild(input);
|
||||
li.appendChild(text);
|
||||
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];
|
||||
|
||||
nameregex = /\/\* Names: ([A-Za-z0-9_. -]+) \*\//;
|
||||
names = serverData.match(nameregex);
|
||||
name = names[1];
|
||||
|
||||
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);
|
||||
|
||||
removelink = document.createElement('a');
|
||||
removelink.className = 'removeFile';
|
||||
removelink.innerHTML = 'Remove file';
|
||||
|
||||
li = document.createElement('li');
|
||||
li.appendChild(input);
|
||||
li.appendChild(text);
|
||||
li.appendChild(removelink);
|
||||
list.appendChild(li);
|
||||
|
||||
HasManyFileFieldRemoveButton.applyTo(removelink);
|
||||
},
|
||||
|
||||
uploadQueueCompleteCallback: function() {
|
||||
this.parentNode.parentNode.uploadMessage.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user