',
@@ -646,12 +643,6 @@ function _upload_form($node) {
if (user_access('upload files')) {
$limits = _upload_file_limits($user);
-
- // This div is hidden when the user uploads through JS.
- $form['new'] = array(
- '#prefix' => '
',
- '#suffix' => '
',
- );
$form['new']['upload'] = array(
'#type' => 'file',
'#title' => t('Attach new file'),
@@ -662,14 +653,13 @@ function _upload_form($node) {
'#type' => 'submit',
'#value' => t('Attach'),
'#name' => 'attach',
- '#id' => 'attach-button',
+ '#ahah_path' => 'upload/js',
+ '#ahah_wrapper' => 'attach-wrapper',
'#submit' => array(),
);
- // The class triggers the js upload behaviour.
- $form['attach-url'] = array('#type' => 'hidden', '#value' => url('upload/js', array('absolute' => TRUE)), '#attributes' => array('class' => 'upload'));
}
- // Needed for JS.
+ // This value is used in upload_js().
$form['current']['vid'] = array('#type' => 'hidden', '#value' => isset($node->vid) ? $node->vid : 0);
return $form;
}
@@ -721,6 +711,7 @@ function upload_load($node) {
function upload_js() {
// We only do the upload.module part of the node validation process.
$node = (object)$_POST;
+ $files = isset($_POST['files']) ? $_POST['files'] : array();
// Load existing node files.
$node->files = upload_load($node);
@@ -738,8 +729,13 @@ function upload_js() {
drupal_alter('form', $form, array(), 'upload_js');
$form_state = array('submitted' => FALSE);
$form = form_builder('upload_js', $form, $form_state);
- // @todo: Put status messages inside wrapper, instead of above so they do not
- // persist across ajax reloads.
+
+ // Maintain the list and delete checkboxes values.
+ foreach ($files as $fid => $file) {
+ $form['files'][$fid]['list']['#value'] = isset($file['list']) ? 1 : 0;
+ $form['files'][$fid]['remove']['#value'] = isset($file['remove']) ? 1 : 0;
+ }
+
$output = theme('status_messages') . drupal_render($form);
// We send the updated file attachments form.
Index: misc/upload.js
===================================================================
RCS file: misc/upload.js
diff -N misc/upload.js
--- misc/upload.js 8 Jun 2007 12:51:59 -0000 1.13
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,116 +0,0 @@
-// $Id: upload.js,v 1.13 2007/06/08 12:51:59 goba Exp $
-
-/**
- * Attaches the upload behaviour to the upload form.
- */
-Drupal.uploadAutoAttach = function() {
- $('input.upload').each(function () {
- var uri = this.value;
- // Extract the base name from the id (edit-attach-url -> attach).
- var base = this.id.substring(5, this.id.length - 4);
- var button = base + '-button';
- var wrapper = base + '-wrapper';
- var hide = base + '-hide';
- var upload = new Drupal.jsUpload(uri, button, wrapper, hide);
- });
-};
-
-/**
- * JS upload object.
- */
-Drupal.jsUpload = function(uri, button, wrapper, hide) {
- // Note: these elements are replaced after an upload, so we re-select them
- // everytime they are needed.
- this.button = '#'+ button;
- this.wrapper = '#'+ wrapper;
- this.hide = '#'+ hide;
- Drupal.redirectFormButton(uri, $(this.button).get(0), this);
-};
-
-/**
- * Handler for the form redirection submission.
- */
-Drupal.jsUpload.prototype.onsubmit = function () {
- // Insert progressbar and stretch to take the same space.
- this.progress = new Drupal.progressBar('uploadprogress');
- this.progress.setProgress(-1, Drupal.t('Uploading file'));
-
- var hide = this.hide;
- var el = this.progress.element;
- var offset = $(hide).get(0).offsetHeight;
- $(el).css({
- width: '28em',
- height: offset +'px',
- paddingTop: '10px',
- display: 'none'
- });
- $(hide).css('position', 'absolute');
-
- $(hide).after(el);
- $(el).fadeIn('slow');
- $(hide).fadeOut('slow');
-};
-
-/**
- * Handler for the form redirection completion.
- */
-Drupal.jsUpload.prototype.oncomplete = function (data) {
- // Remove old form
- Drupal.freezeHeight(); // Avoid unnecessary scrolling
- $(this.wrapper).html('');
-
- // Place HTML into temporary div
- var div = document.createElement('div');
- $(div).html(data);
-
- // If uploading the first attachment fade in everything
- if ($('tr', div).size() == 2) {
- // Replace form and re-attach behaviour
- $(div).hide();
- $(this.wrapper).append(div);
- $(div).fadeIn('slow');
- Drupal.uploadAutoAttach();
- }
- // Else fade in only the last table row
- else {
- // Hide form and last table row
- $('table tr:last-of-type td', div).hide();
-
- // Note: workaround because jQuery's #id selector does not work outside of 'document'
- // Should be: $(this.hide, div).hide();
- var hide = this.hide;
- $('div', div).each(function() {
- if (('#'+ this.id) == hide) {
- this.style.display = 'none';
- }
- });
-
- // Replace form, fade in items and re-attach behaviour
- $(this.wrapper).append(div);
- $('table tr:last-of-type td', div).fadeIn('slow');
- $(this.hide, div).fadeIn('slow');
- Drupal.uploadAutoAttach();
- }
- Drupal.unfreezeHeight();
-};
-
-/**
- * Handler for the form redirection error.
- */
-Drupal.jsUpload.prototype.onerror = function (error) {
- alert(Drupal.t('An error occurred:\n\n@error', { '@error': error }));
- // Remove progressbar
- $(this.progress.element).remove();
- this.progress = null;
- // Undo hide
- $(this.hide).css({
- position: 'static',
- left: '0px'
- });
-};
-
-
-// Global killswitch
-if (Drupal.jsEnabled) {
- $(document).ready(Drupal.uploadAutoAttach);
-}
Index: misc/ahah.js
===================================================================
RCS file: misc/ahah.js
diff -N misc/ahah.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ misc/ahah.js 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+// $Id: $
+
+/**
+ * Attaches the ahah behaviour to each ahah form element.
+ */
+Drupal.ahahAutoAttach = function() {
+ for (var base in Drupal.settings.ahah) {
+ var element = Drupal.settings.ahah[base];
+ var ahah = new Drupal.ahah(base, element);
+ }
+};
+
+/**
+ * AHAH object.
+ */
+Drupal.ahah = function(base, element) {
+ // Set the properties for this object.
+ this.id = '#' + base;
+ this.event = element.event;
+ this.uri = element.uri;
+ this.wrapper = '#'+ element.wrapper;
+ this.effect = element.effect;
+ this.method = element.method;
+ if (this.effect == 'none') {
+ this.showEffect = 'show';
+ this.hideEffect = 'hide';
+ }
+ else if (this.effect == 'fade') {
+ this.showEffect = 'fadeIn';
+ this.hideEffect = 'fadeOut';
+ }
+ else {
+ this.showEffect = this.effect + 'Toggle';
+ this.hideEffect = this.effect + 'Toggle';
+ }
+ Drupal.redirectFormButton(this.uri, $(this.id).get(0), this);
+};
+
+/**
+ * Handler for the form redirection submission.
+ */
+Drupal.ahah.prototype.onsubmit = function () {
+ // Insert progressbar and stretch to take the same space.
+ this.progress = new Drupal.progressBar('ahah_progress');
+ this.progress.setProgress(-1, Drupal.t('Please wait...'));
+
+ var $wrapper = $(this.wrapper);
+ var $button = $(this.id);
+ var $progress_element = $(this.progress.element);
+
+ $progress_element.css({
+ display: 'none',
+ width: '10em',
+ margin: '0 0 0 20px',
+ float: 'left'
+ });
+ $button.css('float', 'left').attr('disabled', true).after($progress_element);
+ $progress_element.eval(this.showEffect + "()");
+};
+
+/**
+ * Handler for the form redirection completion.
+ */
+Drupal.ahah.prototype.oncomplete = function (data) {
+ var $wrapper = $(this.wrapper);
+ var $button = $(this.id);
+ var $progress_element = $(this.progress.element);
+
+ Drupal.freezeHeight();
+
+ // Remove the progress element.
+ $progress_element.remove();
+
+ // Add the form and re-attach behavior.
+ if (this.method == 'replace') {
+ $wrapper.empty();
+ this.method = 'append';
+ }
+ $wrapper.eval(this.method + '(data)').eval(this.showEffect + '()');
+ $button.css('float', 'none').attr('disabled', false);
+
+ Drupal.ahahAutoAttach();
+ Drupal.unfreezeHeight();
+};
+
+/**
+ * Handler for the form redirection error.
+ */
+Drupal.ahah.prototype.onerror = function (error) {
+ alert(Drupal.t('An error occurred:\n\n@error', { '@error': error }));
+ // Remove progressbar
+ $(this.progress.element).remove();
+ this.progress = null;
+ // Undo hide
+ $(this.wrapper).show();
+};
+
+
+// Global killswitch
+if (Drupal.jsEnabled) {
+ $(document).ready(Drupal.ahahAutoAttach);
+}