From: Steve Sutton Date: Mon, 3 Apr 2017 13:26:30 +0000 (-0400) Subject: Fixing the file position X-Git-Tag: v2.9.15^2~15^2~18 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=e1a48a83fae00fd16491891b9ae3b950c4152f7f;p=WP-Plugins%2Fglm-member-db.git Fixing the file position Files can now be ordered correctly. --- diff --git a/classes/data/dataFiles.php b/classes/data/dataFiles.php index eceaf81c..80db532b 100644 --- a/classes/data/dataFiles.php +++ b/classes/data/dataFiles.php @@ -272,14 +272,14 @@ class GlmDataFiles extends GlmDataAbstract * @return boolean True if successful * */ - public function positionOrder($refType, $refID, $orderField) + public function filePositionOrder($refType, $refID, $orderField) { // Check for and retrieve the order field name if (isset($_REQUEST[$orderField]) && trim($_REQUEST[$orderField]) == '') { if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice('dataFiles: positionOrder() unable to find '.$orderField.' data. Perhaps there\'s no files at this time.', 'Process'); + glmMembersAdmin::addNotice('dataFiles: filePositionOrder() unable to find '.$orderField.' data. Perhaps there\'s no files at this time.', 'Process'); } return false; @@ -324,7 +324,7 @@ class GlmDataFiles extends GlmDataAbstract } /* - * Process image gallery titles, descriptions, deletions, and image position ordering. + * Process files titles, descriptions, deletions, and file position ordering. * * @param int $refType Reference Type * @param int $refID Reference entry ID @@ -337,7 +337,7 @@ class GlmDataFiles extends GlmDataAbstract { // Re-order image gallery files - $this->positionOrder($refType, $refID, $orderField); + $this->filePositionOrder($refType, $refID, $orderField); // If any image gallery data is submitted if (isset($_REQUEST['file_caption']) @@ -371,38 +371,19 @@ class GlmDataFiles extends GlmDataAbstract // Get the data for this image $sql = "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files WHERE id = $id;"; - $imgData = $this->wpdb->get_row($sql, ARRAY_A); + $fileData = $this->wpdb->get_row($sql, ARRAY_A); // Do we have data? - if ($imgData != null && trim($imgData['file_name']) != '') { + if ($fileData != null && trim($fileData['file_name']) != '') { // Delete the image from the gallery $sql = "DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files WHERE id = $id;"; $this->wpdb->query($sql); - // Also delete all copies of the image - reset($this->config['imageSizes']); - while (list($k, $v) = each($this->config['imageSizes'])) { - - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice("      Deleting size $k.", 'Process'); - } - - // Check if the image actually exists - May not if we're doing development - if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$k.'/'.$imgData['file_name'])) { - - // Delete each image size - unlink(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$k.'/'.$imgData['file_name']); - - } - - } - // Check if the image actually exists - May not if we're doing development - if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/original/'.$imgData['file_name'])) { + if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$fileData['file_name'])) { - // Also delete the original - unlink(GLM_MEMBERS_PLUGIN_FILES_PATH.'/original/'.$imgData['file_name']); + unlink(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$fileData['file_name']); } } diff --git a/js/imageUpload/imageUpload.js b/js/imageUpload/imageUpload.js index 4b2724bf..d81e92b9 100644 --- a/js/imageUpload/imageUpload.js +++ b/js/imageUpload/imageUpload.js @@ -29,6 +29,7 @@ jQuery(document).ready(function($) { var galleryFiles; var newImageAdded = false; var enableDraggable = true; + var statusArea = false; // Setup Drag and Drop when Add if (window.File && window.FileList && window.FileReader) { @@ -183,7 +184,6 @@ jQuery(document).ready(function($) { // Process only Files processOnlyFiles(); - console.log('Processing ' + numbFiles + ' file '); } /* @@ -224,7 +224,7 @@ jQuery(document).ready(function($) { fd.append('glm_refDest', recordID); // Setup status display area - var status = new createStatusbar(file, thisFile, numbFiles); + var status = new createStatusbar(file, thisFile, numbFiles, false); statusArea.fadeIn( function() { @@ -295,7 +295,7 @@ jQuery(document).ready(function($) { fd.append('glm_refDest', recordID); // Setup status display area - var status = new createStatusbar(file, thisFile, numbFiles); + var status = new createStatusbar(file, thisFile, numbFiles, true); statusArea.fadeIn( function() { @@ -304,7 +304,7 @@ jQuery(document).ready(function($) { alert("This file is too large to process.\nTo use this image, consider resizing it before uploading.\n\nMaximum image size is " + (maxFileSize/1000) + "KB."); statusArea.fadeOut(); - processFile(); + processOnlyFiles(); // Check the image mime type and alert the user if it's not // permitted @@ -312,7 +312,7 @@ jQuery(document).ready(function($) { alert("The file is not an accepted type.\nTo use this file, consider resaving it as a different file type.\n"); statusArea.fadeOut(); - processFile(); + processOnlyFiles(); } else { @@ -328,13 +328,13 @@ jQuery(document).ready(function($) { } else { // Reset expanded image and sortable events - setupExpandedImageEvents(); + setupExpandedFileEvents(); } } - function createStatusbar(file, thisFile, numbFiles) + function createStatusbar(file, thisFile, numbFiles, onlyFile) { var statusDone = false; @@ -346,16 +346,15 @@ jQuery(document).ready(function($) { var lastFile = numbFiles; // Get status area for this drop area - statusArea = drop.siblings('.glm-imageUploadStatus'); + if ( onlyFile ) { + statusArea = fileDrop.siblings('.glm-fileUploadStatus'); + } else { + statusArea = drop.siblings('.glm-imageUploadStatus'); + } // Make status area visible (overlay) and clear contents statusArea.html(''); - // If file is an image -// var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/; - -// if (regex.test(file.name.toLowerCase())) { - // Create HTML5 file reader and load image var reader = new FileReader(); reader.onload = function (e) { @@ -363,7 +362,9 @@ jQuery(document).ready(function($) { // Using a copy of the supplied template, add file information // to statusbar statusbar = uploadStatusTemplate; - statusbar = statusbar.replace('bust-stupid-ngg-image-selection', 'img'); + if ( !( onlyFile ) ) { + statusbar = statusbar.replace('bust-stupid-ngg-image-selection', 'img'); + } statusbar = statusbar.replace('{ thisFile }', curFile); statusbar = statusbar.replace('{ numbFiles }', lastFile); statusbar = statusbar.replace('{ fileImage }', e.target.result); @@ -404,11 +405,19 @@ jQuery(document).ready(function($) { this.setAbort = function(jqxhr) { var sb = this.statusbar; - $('#imageUploadCancel').click(function() - { - jqxhr.abort(); - sb.hide(); - }); + if ( !( onlyFile ) ) { + $('#imageUploadCancel').click(function() + { + jqxhr.abort(); + sb.hide(); + }); + } else { + $('#fileUploadCancel').click(function() + { + jqxhr.abort(); + sb.hide(); + }); + } } } @@ -418,6 +427,7 @@ jQuery(document).ready(function($) { */ function sendFileToServer(fd, status) { + var processingOnlyFiles = false; // Send one (or more) images to the server. Normally only one image here for now. var jqXHR=$.ajax({ xhr: function() { @@ -454,6 +464,7 @@ jQuery(document).ready(function($) { // Check if these are not images (noimage will be true) if ( fileData.noimage ) { + processingOnlyFiles = true; // Add files(s) to files display for ( var i = 0; i < fileData.files.length; i++ ) { // Using a copy of the supplied template, add file information @@ -500,7 +511,11 @@ jQuery(document).ready(function($) { statusArea.fadeOut( function() { // Process the next file, if one exists. - processFile(); + if (processingOnlyFiles) { + processOnlyFiles(); + } else { + processFile(); + } }); @@ -561,5 +576,51 @@ jQuery(document).ready(function($) { }); } } + function setupExpandedFileEvents() { + + var largeFileDisplayed = false; + + // Handle expanded images on hover for image gallery + $('.glm-galleryFile').on("click", function(){ + + // If an image is currently displayed, close it now and reset the flag + if (largeFileDisplayed) { + $('#glm-galleryFileLarger_' + largeFileDisplayed).dialog("close"); + largeFileDisplayed = false; + } + + id = $(this).attr("data-id"); + largeFileDisplayed = id; + + // Display the larger image + var imgTitle = $("#galleryFile_caption_" + id).val(); + $('#glm-galleryFileLarger_' + id).dialog({ + title: imgTitle, + dialogClass: "no-close", + autoOpen: true, + resizable: false, + width: 'auto', + modal: false, + minWidth: 100, + minHeight: 100, + create: function() { + $(this).dialog('option', 'maxHeight', $(window).height() * .9); + $(this).dialog('option', 'maxWidth', $(window).width() * .9); + }, + position: { my: "left+10 top+10", at: "right top", of: $(this) } + }); + }); + + // Make images sortable and store the list of IDs in a hidden input field when order has changed. + if (enableDraggable) { + $('.glm-galleryFiles').sortable({ + update: function(event, ui) { + var sortedIDs = $(this).sortable('toArray'); + $('#filePositionOrder').val(sortedIDs); + } + }); + } + } setupExpandedImageEvents(); + setupExpandedFileEvents(); });