Esempio n. 1
0
		public Popup(Controller controller, string title, Room room, HtmlItem[] items)
		{
			Title = title;
			RoomGuid = room.Guid;
			Removed = false;
			RoomGuidForClickAction = room.Guid;
			//RoomGuidForClickAction = item.GetRoomGuidForChatClickAction();


			#region //Holder
			Holder = (DivElement)Document.CreateElement("div");
			Holder.ClassName = "ChatClientPopup";
			Holder.Style.Width = PopupArea.PopupWidth.ToString() + "px";
			Holder.Style.Height = PopupArea.PopupHeight.ToString() + "px";
			
			#region //HeaderDiv
			DOMElement header = (DOMElement)Document.CreateElement("div");
			header.ClassName = "ChatClientPopupHeader";
			header.Style.Overflow = "hidden";

			{
				#region //Close button
				DivElement div = (DivElement)Document.CreateElement("div");
				div.ClassName = "ChatClientPopupCloseLinkHolder";

				{
					AnchorElement link = (AnchorElement)Document.CreateElement("a");
					link.InnerHTML = "Close";
					link.Href = "";
					DomEvent.AddHandler(link, "click", new DomEventHandler(closeButtonClick));
					div.AppendChild(link);
				}
				header.AppendChild(div);
				#endregion
			}

			{
				#region //TitleDiv
				DivElement div = (DivElement)Document.CreateElement("div");
				div.ClassName = "ChatClientPopupTitle";
				div.InnerHTML = Title;
				header.AppendChild(div);
				#endregion
			}

			Holder.AppendChild(header);
			
			#endregion

			#region //ItemsDiv
			{
				if (items != null)
				{
					ItemsList = (DivElement)Document.CreateElement("div");
					ItemsList.ClassName = "ChatClientPopupItemsList";

					DomEvent.AddHandler(ItemsList, "click", new DomEventHandler(holderClick));
					DomEvent.AddHandler(ItemsList, "mouseover", new DomEventHandler(holderMouseOver));
					DomEvent.AddHandler(ItemsList, "mouseout", new DomEventHandler(holderMouseOut));

					bool hasMultipleRelevantItems = false;
					for (int i = 0; i < items.Length; i++)
					{
						HtmlItem item = (HtmlItem)items[i];

						#region // if the item is posted by the current user, we never want to show a popup
						if (item is IHasPostingUsr)
						{
							if (((IHasPostingUsr)item).PostingUsrK == controller.UsrK)
								continue;
						}
						#endregion

						if (HasRelevantItems)
						{
							hasMultipleRelevantItems = true;
							break;
						}

						HasRelevantItems = true;
					}
					if (HasRelevantItems)
					{
						for (int i = 0; i < items.Length; i++)
						{
							HtmlItem item = (HtmlItem)items[i];

							#region // if the item is posted by the current user, we never want to show a popup
							if (item is IHasPostingUsr)
							{
								if (((IHasPostingUsr)item).PostingUsrK == controller.UsrK)
									continue;
							}
							#endregion

							if (!hasMultipleRelevantItems)
								RoomGuidForClickAction = item.GetRoomGuidForChatClickAction();

							#region //bodge it so it displays correctly - remember to save all things we change
							int previousInstance = item.Instance;
							bool previousNewStatus = false;
							if (item is Newable)
							{
								previousNewStatus = ((Newable)item).IsInNewSection;
								((Newable)item).IsInNewSection = false;
							}
							item.Instance = 2;

							bool previousShowChatButton = false;
							if (!hasMultipleRelevantItems && item is Message) // we only hide the chat button if there's only one item shown. for multi-item popups we want to leave the chat buttons as they were.
							{
								previousShowChatButton = ((Message)item).ShowChatButton;
								((Message)item).ShowChatButton = false;
							}
							#endregion

							DOMElement itemNode = Document.CreateElement("span");
							itemNode.InnerHTML = item.ToHtml();

							if (ItemsList.HasChildNodes())
								ItemsList.InsertBefore(itemNode, ItemsList.ChildNodes[0]);
							else
								ItemsList.AppendChild(itemNode);

							#region //restore all the things we bodged

							item.Instance = previousInstance;

							if (item is Newable)
								((Newable)item).IsInNewSection = previousNewStatus;
							
							if (!hasMultipleRelevantItems && item is Message) // we only hide the chat button if there's only one item shown. for multi-item popups we want to leave the chat buttons as they were.
								((Message)item).ShowChatButton = previousShowChatButton;

							#endregion

						}
						Holder.AppendChild(ItemsList);
					}
				}
			}
			#endregion

			#endregion

			Id = Math.Random().ToString();
			jHolder = JQueryAPI.JQuery(Holder);
		}