PageRenderTime 3596ms CodeModel.GetById 22ms RepoModel.GetById 6ms app.codeStats 0ms

/Trunk/Content/Community/Modules/DigitalAssets/FileProperties.ascx.cs

#
C# | 248 lines | 201 code | 28 blank | 19 comment | 9 complexity | bed52f78e3c364543ec798c53f077b01 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0
  1. #region Copyright
  2. //
  3. // DotNetNuke® - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2013
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. using System;
  22. using System.Collections.Generic;
  23. using System.IO;
  24. using System.Linq;
  25. using System.Threading;
  26. using System.Web.UI;
  27. using System.Web.UI.HtmlControls;
  28. using DotNetNuke.Entities.Modules;
  29. using DotNetNuke.ExtensionPoints;
  30. using DotNetNuke.Framework;
  31. using DotNetNuke.Modules.DigitalAssets.Components.Controllers;
  32. using DotNetNuke.Modules.DigitalAssets.Components.Controllers.Models;
  33. using DotNetNuke.Modules.DigitalAssets.Components.ExtensionPoint;
  34. using DotNetNuke.Modules.DigitalAssets.Services;
  35. using DotNetNuke.Security.Permissions;
  36. using DotNetNuke.Services.Exceptions;
  37. using DotNetNuke.Services.FileSystem;
  38. using DotNetNuke.UI.Skins.Controls;
  39. using DotNetNuke.Web.UI;
  40. namespace DotNetNuke.Modules.DigitalAssets
  41. {
  42. public partial class FileProperties : PortalModuleBase
  43. {
  44. private readonly IDigitalAssetsController controller = (new Factory()).DigitalAssetsController;
  45. private IFileInfo file;
  46. private IFolderInfo folder;
  47. private ItemViewModel fileItem;
  48. private Control previewPanelControl;
  49. private Control fileFieldsControl;
  50. private IEnumerable<PropertiesTabContentControl> tabContentControls;
  51. protected string DialogTitle
  52. {
  53. get
  54. {
  55. return fileItem.ItemName;
  56. }
  57. }
  58. protected bool CanManageFolder
  59. {
  60. get
  61. {
  62. return UserInfo.IsSuperUser || FolderPermissionController.CanManageFolder((FolderInfo)folder);
  63. }
  64. }
  65. protected override void OnInit(EventArgs e)
  66. {
  67. try
  68. {
  69. base.OnInit(e);
  70. jQuery.RequestDnnPluginsRegistration();
  71. var fileId = Convert.ToInt32(Request.Params["FileId"]);
  72. file = FileManager.Instance.GetFile(fileId, true);
  73. fileItem = controller.GetFile(fileId);
  74. folder = FolderManager.Instance.GetFolder(file.FolderId);
  75. SaveButton.Click += OnSaveClick;
  76. CancelButton.Click += OnCancelClick;
  77. if (FolderPermissionController.CanViewFolder((FolderInfo)folder))
  78. {
  79. var mef = new ExtensionPointManager();
  80. var preViewPanelExtension = mef.GetUserControlExtensionPointFirstByPriority("DigitalAssets", "PreviewInfoPanelExtensionPoint");
  81. previewPanelControl = Page.LoadControl(preViewPanelExtension.UserControlSrc);
  82. PreviewPanelContainer.Controls.Add(previewPanelControl);
  83. var fileFieldsExtension = mef.GetUserControlExtensionPointFirstByPriority("DigitalAssets", "FileFieldsControlExtensionPoint");
  84. fileFieldsControl = Page.LoadControl(fileFieldsExtension.UserControlSrc);
  85. fileFieldsControl.ID = fileFieldsControl.GetType().BaseType.Name;
  86. FileFieldsContainer.Controls.Add(fileFieldsControl);
  87. PrepareFilePreviewInfoControl();
  88. PrepareFileFieldsControl();
  89. // Tab Extension Point
  90. var tabContentControlsInstances = new List<PropertiesTabContentControl>();
  91. foreach (var extension in mef.GetEditPageTabExtensionPoints("DigitalAssets", "FilePropertiesTab"))
  92. {
  93. if (FolderPermissionController.HasFolderPermission(folder.FolderPermissions, extension.Permission))
  94. {
  95. var liElement = new HtmlGenericControl("li") { InnerHtml = "<a href=\"#" + extension.EditPageTabId + "\">" + extension.Text + "</a>", };
  96. liElement.Attributes.Add("class", extension.CssClass);
  97. liElement.Attributes.Add("id", extension.EditPageTabId + "_tab");
  98. Tabs.Controls.Add(liElement);
  99. var container = new PanelTabExtensionControl { PanelId = extension.EditPageTabId };
  100. var control = (PortalModuleBase)Page.LoadControl(extension.UserControlSrc);
  101. control.ID = Path.GetFileNameWithoutExtension(extension.UserControlSrc);
  102. control.ModuleConfiguration = ModuleConfiguration;
  103. var contentControl = control as PropertiesTabContentControl;
  104. if (contentControl != null)
  105. {
  106. contentControl.OnItemUpdated += OnItemUpdated;
  107. tabContentControlsInstances.Add(contentControl);
  108. }
  109. container.Controls.Add(control);
  110. TabsPanel.Controls.Add(container);
  111. }
  112. }
  113. tabContentControls = tabContentControlsInstances.ToList();
  114. }
  115. }
  116. catch (Exception ex)
  117. {
  118. Exceptions.ProcessModuleLoadException(this, ex);
  119. }
  120. }
  121. protected override void OnLoad(EventArgs e)
  122. {
  123. try
  124. {
  125. if (!Page.IsPostBack)
  126. {
  127. SetPropertiesAvailability(CanManageFolder);
  128. }
  129. if (!FolderPermissionController.CanViewFolder((FolderInfo)folder))
  130. {
  131. SaveButton.Visible = false;
  132. SetPropertiesVisibility(false);
  133. UI.Skins.Skin.AddModuleMessage(this, LocalizeString("UserCannotReadFileError"), ModuleMessage.ModuleMessageType.RedError);
  134. }
  135. else
  136. {
  137. SetFilePreviewInfo();
  138. SaveButton.Visible = FolderPermissionController.CanViewFolder((FolderInfo)folder) && FolderPermissionController.CanManageFolder((FolderInfo)folder);
  139. }
  140. }
  141. catch (DotNetNukeException dnnex)
  142. {
  143. UI.Skins.Skin.AddModuleMessage(this, dnnex.Message, ModuleMessage.ModuleMessageType.RedError);
  144. }
  145. catch (Exception exc)
  146. {
  147. Exceptions.ProcessModuleLoadException(this, exc);
  148. }
  149. }
  150. private void CloseClientDialog(bool refresh)
  151. {
  152. var script = "parent.window.dnnModule.digitalAssets.closeDialog(" + (refresh ? "true" : "false") + ");";
  153. Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseDialogScript", script, true);
  154. }
  155. private void OnItemUpdated()
  156. {
  157. SetFilePreviewInfo();
  158. foreach (var propertiesTabContentControl in tabContentControls)
  159. {
  160. propertiesTabContentControl.DataBindItem();
  161. }
  162. }
  163. private void OnSaveClick(object sender, EventArgs e)
  164. {
  165. if (!Page.IsValid)
  166. {
  167. return;
  168. }
  169. try
  170. {
  171. SaveFileProperties();
  172. CloseClientDialog(true);
  173. }
  174. catch (ThreadAbortException) { }
  175. catch (DotNetNukeException dnnex)
  176. {
  177. UI.Skins.Skin.AddModuleMessage(this, dnnex.Message, ModuleMessage.ModuleMessageType.RedError);
  178. }
  179. catch (Exception ex)
  180. {
  181. Exceptions.LogException(ex);
  182. UI.Skins.Skin.AddModuleMessage(this, ex.Message, ModuleMessage.ModuleMessageType.RedError);
  183. }
  184. }
  185. private void OnCancelClick(object sender, EventArgs e)
  186. {
  187. CloseClientDialog(false);
  188. }
  189. private void SaveFileProperties()
  190. {
  191. file = (IFileInfo)((FileFieldsControl)fileFieldsControl).SaveProperties();
  192. }
  193. private void SetPropertiesVisibility(bool visibility)
  194. {
  195. ((FileFieldsControl)fileFieldsControl).SetPropertiesVisibility(visibility);
  196. }
  197. private void SetPropertiesAvailability(bool availability)
  198. {
  199. ((FileFieldsControl)fileFieldsControl).SetPropertiesAvailability(availability);
  200. }
  201. private void SetFilePreviewInfo()
  202. {
  203. var previewPanelInstance = (PreviewPanelControl)previewPanelControl;
  204. previewPanelInstance.SetPreviewInfo(controller.GetFilePreviewInfo(file, fileItem));
  205. }
  206. private void PrepareFilePreviewInfoControl()
  207. {
  208. var previewPanelInstance = (PreviewPanelControl)previewPanelControl;
  209. previewPanelInstance.SetController(controller);
  210. previewPanelInstance.SetModuleConfiguration(ModuleConfiguration);
  211. }
  212. private void PrepareFileFieldsControl()
  213. {
  214. var fileFieldsIntance = (FileFieldsControl)fileFieldsControl;
  215. fileFieldsIntance.SetController(controller);
  216. fileFieldsIntance.SetItemViewModel(fileItem);
  217. fileFieldsIntance.SetFileInfo(file);
  218. }
  219. }
  220. }