// SubsDraggable adapted from http://dev.rubyonrails.org/ticket/5771 // extentions for scriptaculous dragdrop.js Object.extend(Class, { superrise: function(obj, names){ names.each( function(n){ obj['super_' + n] = obj[n] } ) return obj; } }) // Draggable that allows substitution of draggable element var SubsDraggable = Class.create(); SubsDraggable.prototype = Object.extend({}, Draggable.prototype); Class.superrise(SubsDraggable.prototype, ['initialize', 'startDrag', 'finishDrag']) Object.extend( SubsDraggable.prototype , { initialize: function(event) { this.super_initialize.apply(this, arguments); if( typeof(this.options.dragelement) == 'undefined' ) this.options.dragelement = false; }, startDrag: function(event) { if( this.options.dragelement ) { this._originalElement = this.element; // Get the id of the file being dragged var beingDraggedId = this.element.id.replace('drag-Files-',''); this.element = this.options.dragelement(this.element); Position.absolutize(this.element); Position.clone(this._originalElement, this.element); // Add # files being moved message this.element.className = 'dragfile DraggedHandle'; // We are at least moving the 1 file being dragged var numMoved = 1; var i, checkboxes = $('Form_EditForm').elements['Files[]']; if(!checkboxes) checkboxes = []; if(!checkboxes.length) checkboxes = [ checkboxes ]; for(i=0;i would give a recordID of 6 if(this.id && this.id.match(/-([^-]+)$/)) this.recordID = RegExp.$1; this.droppable = Droppables.add(this.id, {accept:'dragfile', hoverclass:'filefolderhover', onDrop:function(droppedElement) { // Get this.recordID from the last "-" separated chunk of the id HTML attribute // eg:
  • would give a recordID of 6 if(this.element.id && this.element.id.match(/-([^-]+)$/)) this.recordID = RegExp.$1; $('Form_EditForm').elements['DestFolderID'].value = this.recordID; // Add the dropped file to the list of files to move var list = droppedElement.getElementsByTagName('img')[0].id.replace('drag-img-Files-',''); var i, checkboxes = $('Form_EditForm').elements['Files[]']; if(!checkboxes) checkboxes = []; if(!checkboxes.length) checkboxes = [ checkboxes ]; // Add each checked file to the list of ones to move for(i=0;i