Click here to Skip to main content
15,897,518 members
Articles / Web Development / HTML

Gallery Server Pro - An ASP.NET Gallery for Sharing Photos, Video, Audio and Other Media

Rate me:
Please Sign up or sign in to vote.
4.86/5 (131 votes)
18 Oct 2013GPL331 min read 830.3K   539  
Gallery Server Pro is a complete, stable ASP.NET gallery for sharing photos, video, audio and other media. This article presents the overall architecture and major features.
<%@ Page Language="C#" MasterPageFile="~/master/taskMstr.master" AutoEventWireup="true"
	CodeBehind="rearrange.aspx.cs" Inherits="GalleryServerPro.Web.task.rearrange" %>

<%@ MasterType TypeName="GalleryServerPro.Web.Master.taskMstr" %>
<%@ Import Namespace="GalleryServerPro.Business.Interfaces" %>
<asp:Content ID="ct1" ContentPlaceHolderID="c3" runat="server">

	<script type="text/javascript">
	
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(rearrange_PageLoad);

function rearrange_PageLoad(sender, args)
{
	if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) hideScrollDivsFromIE6();
}
	
function SwapSnaps(sender, eventArgs) 
{
	// User has dragged a thumbnail and is hovering over another thumbnail. The snap control automatically inserts
	// the dragged thumbnail into the destination, but we need to pull out the existing thumbnail and and shift
	// all thumbnails between the source and destination by one.
	var destPanel; // Panel user is hovering over
	var swapToPanel; // Panel to receive thumbnail from left or right sibling
	var swapFromPanel; // Panel with two thumbnails where we need to extract one and assign it to its left or right sibling
	var n; var j;
	if (eventArgs.get_elementId() == null || eventArgs.get_index() < 0) return; // Ignore
     
	var destPanelId = parseInt(eventArgs.get_elementId().substring(2));

	for(curPanelId = 0; curPanelId < _snapDockIds.length; curPanelId++)
	{
		var curPanel = document.getElementById("sd"+curPanelId);
		if((curPanel.childNodes.length == 0) || ((curPanel.childNodes.length == 1) && (curPanel.childNodes[0].nodeType == 3)))
		{
			if (curPanelId > destPanelId)
			{
				// User is moving a thumbnail closer to the beginning
				for (j = curPanelId; j > destPanelId; j--)
				{
					swapToPanel = document.getElementById("sd"+j);
					swapFromPanel = document.getElementById("sd"+(j-1));
					// Grab the last node that is an element and move it to the next panel
					for(n = swapFromPanel.lastChild; n != null; n = n.previousSibling)
					{
						if (n.nodeType == 1) { swapToPanel.appendChild(n); break; }
					}
				}
			}
			else
			{
				// User is moving a thumbnail closer to the end
				for (j = curPanelId; j < destPanelId; j++)
				{
					swapToPanel = document.getElementById("sd"+j);
					swapFromPanel = document.getElementById("sd"+(j+1));
					// Grab the last node that is an element and move it to the previous panel
					for(n = swapFromPanel.lastChild; n != null; n = n.previousSibling)
					{
						if (n.nodeType == 1) { swapToPanel.appendChild(n); break; }
					}
				}
			}
			break;
		} 
	}
}

var _intervalId;
var _dy;

function beginScroll(dy)
{
	if (_intervalId != null)
		return;
	_dy = dy;
	scroll();
	_intervalId = window.setInterval(scroll, 10);
}

function endScroll()
{
	window.clearInterval(_intervalId);
	_intervalId = null;
}

function scroll()
{
	window.scrollBy(0, _dy);
}

function retrieveOrder()
{
	// Determine the current order of the thumbnails and write it to the hidden field 'goIds' as a comma-delimited
	// string. This field is used by the server script to indicate the sequence.
	var divTags = document.getElementsByTagName("div");
	var goIds = new Array();
	for(var i = 0; i < divTags.length; i++)
	{
		if (Sys.UI.DomElement.containsCssClass(divTags[i], "snapDock"))
		{
			// Get reference to the hidden input in this node
			var n = findNode(divTags[i], "hdId");
			if (n != null)
				Array.add(goIds, n.value);
		}
	}
	
	$get('goIds').value = goIds.join();
}

function findNode(n, startsWith)
{
	// Get reference to the child node whose id starts with the specified value
	for (var m = n.firstChild; m != null; m = m.nextSibling)
	{
		if ((m.id) && (m.id.startsWith(startsWith)))
			return m;
		else
		{
			var foundNode = findNode(m, startsWith);
			if (foundNode != null) return foundNode;
		}
	}
	return null;
}

function hideScrollDivsFromIE6()
{
	// IE 6 and earlier do not support position:fixed, so remove these divs. These users won't be able to drag and scroll.
	var n = $get('divScrollUp');
	if (n != null) n.parentNode.removeChild(n);
	n = null;
	n = $get('divScrollDown');
	if (n != null) n.parentNode.removeChild(n);
}

	</script>

	<div id="divScrollUp" class="scrollBox" onmouseover="beginScroll(-10);" onmouseout="endScroll();">
		<asp:Literal runat="server" Text="<%$ Resources:GalleryServerPro, Task_Rearrange_Objects_Scroll_Up_Div_Text %>" />
	</div>
	<div id="divScrollDown" class="scrollBox" onmouseover="beginScroll(10);" onmouseout="endScroll();">
		<asp:Literal runat="server" Text="<%$ Resources:GalleryServerPro, Task_Rearrange_Objects_Scroll_Down_Div_Text %>" />
	</div>
	<asp:Repeater ID="rprDock" runat="server">
		<ItemTemplate>
			<div id="<%# GetSnapDockId() %>" class="snapDock">
			</div>
		</ItemTemplate>
	</asp:Repeater>
	<asp:Repeater ID="rprSnap" runat="server" OnItemDataBound="rprSnap_ItemDataBound">
		<ItemTemplate>
			<CA:Snap ID="sp" DockingContainers="<%# SnapDockIds %>" CurrentDockingContainer="<%# GetSnapDockingContainerId() %>"
				CurrentDockingIndex="0" DraggingStyle="Original" DockingStyle="Original" MustBeDocked="True"
				IsCollapsed="false" runat="server">
				<ClientEvents>
					<SnapDock EventHandler="SwapSnaps" />
				</ClientEvents>
				<Content>
					<%# GetHiddenInputIdTag((IGalleryObject)((RepeaterItem)Container.Parent).DataItem) %>
					<div class="<%# GetThumbnailCssClass(((RepeaterItem)Container.Parent).DataItem.GetType()) %>"
						onmousedown="<%# Container.ClientID %>.startDragging(event);">
						<%# GetAlbumText(((IGalleryObject)((RepeaterItem)Container.Parent).DataItem).Title, ((RepeaterItem)Container.Parent).DataItem.GetType())%>
						<div class="op0" style="width: <%# (Convert.ToInt32(DataBinder.Eval(((RepeaterItem)Container.Parent).DataItem, "Thumbnail.Width")) + 15).ToString() %>px;
							height: <%# (Convert.ToInt32(DataBinder.Eval(((RepeaterItem)Container.Parent).DataItem, "Thumbnail.Height")) + 10).ToString() %>px;">
							<div class="op1">
								<div class="op2">
									<div class="sb">
										<div class="ib">
											<%# GetThumbnailImageTag((IGalleryObject)((RepeaterItem)Container.Parent).DataItem) %>
										</div>
									</div>
								</div>
							</div>
						</div>
						<%# GetMediaObjectText(Eval("Title").ToString(), ((RepeaterItem)Container.Parent).DataItem.GetType())%>
					</div>
				</Content>
			</CA:Snap>
		</ItemTemplate>
	</asp:Repeater>
	<input id="goIds" name="goIds" type="hidden" />
	<hr style="clear: left; visibility: hidden;" />
</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Tech Info Systems
United States United States
I have nearly 20 years of industry experience in software development, architecture, and Microsoft Office products. My company Tech Info Systems provides custom software development services for corporations, governments, and other organizations. Tech Info Systems is a registered member of the Microsoft Partner Program and I am a Microsoft Certified Professional Developer (MCPD).

I am the creator and lead developer of Gallery Server Pro, a free, open source ASP.NET gallery for sharing photos, video, audio, documents, and other files over the web. It has been developed over several years and has involved thousands of hours. The end result is a robust, configurable, and professional grade gallery that can be integrated into your web site, whether you are a large corporation, small business, professional photographer, or a local church.

Comments and Discussions