MINOR Fixed merge error from r99117 (from r101076)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@111634 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-04 06:06:44 +00:00
parent 8ea6dddba5
commit 10081b2911

View File

@ -43,6 +43,26 @@
// Modified by: Silverstripe Ltd. (changed naming of file-input-elements)
function ObservableObject() {
this.functions = [];
}
ObservableObject.prototype = {
subscribe : function(evt, fn) {
this.functions.push([evt, fn]);
},
unsubscribe : function(evt, fn) {
this.functions = this.fns.filter(function(el) {if (el !== [evt, fn]) return el;});
},
fire : function(evt, data, scope) {
scope = scope || window
this.functions.forEach(function(el) {
if (el[0] == evt) el[1].call(scope, data);
});
}
};
var MultiSelectorObserver = new ObservableObject();
function MultiSelector( list_target, max, upload_button ){
this.upload_button = upload_button;
@ -130,6 +150,7 @@ function MultiSelector( list_target, max, upload_button ){
* Add a new row to the list of files
*/
this.addListRow = function( element ){
var fileId = this.id -1;
// Modified 2006-11-06 by Silverstripe Ltd.
var filenameMatches = element.value.match(/([^\/\\]+)$/);
@ -137,6 +158,7 @@ function MultiSelector( list_target, max, upload_button ){
// Row div
var new_row = document.createElement('div');
new_row.className = 'fileBox';
// Delete button
var new_row_button = document.createElement('input');
@ -175,15 +197,29 @@ function MultiSelector( list_target, max, upload_button ){
// Modified 2006-11-06 by Silverstripe Ltd.
new_row.innerHTML = filename;
MultiSelectorObserver.fire('onBeforeCreateRow', [fileId, new_row], this);
// Add button
new_row.appendChild( new_row_button );
// Add it to the list
this.list_target.appendChild( new_row );
MultiSelectorObserver.fire('onAfterCreateRow', [fileId, new_row], this);
// Modified 2006-11-06 by Silverstripe Ltd.
if(typeof(window.ontabschanged) != 'undefined') window.ontabschanged();
};
};
MultiSelectorObserver.subscribe('onBeforeCreateRow', function(data) {
if (jQuery('#metadataFormTemplate')) {
var parameters = jQuery('#metadataFormTemplate').clone(true);
parameters.get(0).id = '';
parameters.find(":input[name!='']").each(function(i) { this.name = this.name.replace(/__X__/g, data[0]); });
parameters.find(":input[id!='']").each(function(i) { this.id = this.id.replace(/__X__/g, data[0]); });
data[1].innerHTML = data[1].innerHTML + '<div id="MetadataFor-'+data[0]+'">'+parameters.html()+'</div>';
}
});