* @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('<b>dataFiles: </b>positionOrder() unable to find '.$orderField.' data. Perhaps there\'s no files at this time.', 'Process');
+ glmMembersAdmin::addNotice('<b>dataFiles: </b>filePositionOrder() unable to find '.$orderField.' data. Perhaps there\'s no files at this time.', 'Process');
}
return false;
}
/*
- * 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
{
// 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'])
// 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']);
}
}
var galleryFiles;
var newImageAdded = false;
var enableDraggable = true;
+ var statusArea = false;
// Setup Drag and Drop when Add
if (window.File && window.FileList && window.FileReader) {
// Process only Files
processOnlyFiles();
- console.log('Processing ' + numbFiles + ' file ');
}
/*
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() {
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() {
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
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 {
} else {
// Reset expanded image and sortable events
- setupExpandedImageEvents();
+ setupExpandedFileEvents();
}
}
- function createStatusbar(file, thisFile, numbFiles)
+ function createStatusbar(file, thisFile, numbFiles, onlyFile)
{
var statusDone = false;
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) {
// 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);
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();
+ });
+ }
}
}
*/
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() {
// 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
statusArea.fadeOut( function() {
// Process the next file, if one exists.
- processFile();
+ if (processingOnlyFiles) {
+ processOnlyFiles();
+ } else {
+ processFile();
+ }
});
});
}
}
+ 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();
});