protected override void OnLoad(EventArgs e)
        {
            try
            {
                base.OnLoad(e);

                if (IsPostBack) return;

                switch (SettingsRepository.GetMode(ModuleId))
                {
                    case DigitalAssestsMode.Group:
                        int groupId;
                        if (string.IsNullOrEmpty(Request["groupId"]) || !int.TryParse(Request["groupId"], out groupId))
                        {
                            Skin.AddModuleMessage(this, Localization.GetString("InvalidGroup.Error", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return;
                        }

                        var groupFolder = controller.GetGroupFolder(groupId, PortalSettings);
                        if (groupFolder == null)
                        {
                            Skin.AddModuleMessage(this, Localization.GetString("InvalidGroup.Error", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return;
                        }

                        this.RootFolderViewModel = groupFolder;
                        break;

                    case DigitalAssestsMode.User:
                        if (PortalSettings.UserId == Null.NullInteger)
                        {
                            Skin.AddModuleMessage(this, Localization.GetString("InvalidUser.Error", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            return;
                        }
                  
                        this.RootFolderViewModel = this.controller.GetUserFolder(this.PortalSettings.UserInfo);     
                        break;

                    default:
                        //handle upgrades where FilterCondition didn't exist
                        SettingsRepository.SetDefaultFilterCondition(ModuleId);
                        this.RootFolderViewModel = this.controller.GetRootFolder(ModuleId);
                        break;
                }
                
                var initialPath = "";
                int folderId;
                if (int.TryParse(Request["folderId"] ?? DAMState["folderId"], out folderId))
                {
                    var folder = FolderManager.Instance.GetFolder(folderId);
                    if (folder != null && folder.FolderPath.StartsWith(RootFolderViewModel.FolderPath))
                    {
                        initialPath = PathUtils.Instance.RemoveTrailingSlash(folder.FolderPath.Substring(RootFolderViewModel.FolderPath.Length));
                    }
                }

                PageSize = Request["pageSize"] ?? DAMState["pageSize"] ?? "10";
                ActiveView = Request["view"] ?? DAMState["view"] ?? "gridview";

                Page.DataBind();
                InitializeTreeViews(initialPath);
                InitializeSearchBox();
                InitializeFolderType();
                InitializeGridContextMenu();
                InitializeEmptySpaceContextMenu();

                FolderNameRegExValidator.ErrorMessage = controller.GetInvalidCharsErrorText();
                FolderNameRegExValidator.ValidationExpression = "^([^" + Regex.Escape(controller.GetInvalidChars()) + "]+)$";
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected virtual FolderViewModel GetFolderViewModel(IFolderInfo folder)
        {
            var folderName = string.IsNullOrEmpty(folder.FolderName)
                ? LocalizationHelper.GetString("RootFolder.Text")
                : folder.FolderName;

            var folderViewModel = new FolderViewModel
            {
                FolderID = folder.FolderID,
                FolderMappingID = folder.FolderMappingID,
                FolderName = folderName,
                FolderPath = folder.FolderPath,
                PortalID = folder.PortalID,
                LastModifiedOnDate = folder.LastModifiedOnDate.ToString("g"),
                IconUrl = GetFolderIconUrl(folder.PortalID, folder.FolderMappingID),
                Permissions = GetPermissionViewModelCollection(folder),
                HasChildren = folder.HasChildren
            };
            folderViewModel.Attributes.Add(new KeyValuePair<string, object>("UnlinkAllowedStatus", GetUnlinkAllowedStatus(folder)));
            return folderViewModel;
        }
 private void SetupNodeAttributes(DnnTreeNode node, IEnumerable<PermissionViewModel> permissions, FolderViewModel folder)
 {
     node.Attributes.Add("permissions", permissions.ToJson());
     foreach (var attribute in folder.Attributes)
     {
         node.Attributes.Add(attribute.Key, attribute.Value.ToJson());
     }
 }
 private DnnTreeNode CreateNodeFromFolder(FolderViewModel folder)
 {
     var node = new DnnTreeNode
     {
         Text = folder.FolderName,
         ImageUrl = folder.IconUrl,
         Value = folder.FolderID.ToString(CultureInfo.InvariantCulture),
         Category = folder.FolderMappingID.ToString(CultureInfo.InvariantCulture),
     };
     this.SetExpandable(node, folder.HasChildren && HasViewPermissions(folder.Permissions));
     return node;
 }
        protected override void OnInit(EventArgs e)
        {
            try
            {
                base.OnInit(e);

                JavaScript.RequestRegistration(CommonJs.DnnPlugins);

                var folderId = Convert.ToInt32(Request.Params["FolderId"]);
                Folder = FolderManager.Instance.GetFolder(folderId);
                HasFullControl = UserInfo.IsSuperUser || FolderPermissionController.HasFolderPermission(Folder.FolderPermissions, "FULLCONTROL");

                FolderViewModel rootFolder;
                switch (SettingsRepository.GetMode(ModuleId))
                {
                    case DigitalAssestsMode.Group:
                        var groupId = Convert.ToInt32(Request.Params["GroupId"]);
                        rootFolder = controller.GetGroupFolder(groupId, PortalSettings);
                        if (rootFolder == null)
                        {
                            throw new Exception("Invalid group folder");
                        }
                        break;

                    case DigitalAssestsMode.User:
                        rootFolder = controller.GetUserFolder(PortalSettings.UserInfo);
                        break;

                    default:
                        rootFolder = controller.GetRootFolder(ModuleId);
                        break;
                }

                isRootFolder = rootFolder.FolderID == folderId;
                folderViewModel = isRootFolder ? rootFolder : controller.GetFolder(folderId);
                
                // Setup controls
                CancelButton.Click += OnCancelClick;
                SaveButton.Click += OnSaveClick;
                PrepareFolderPreviewInfo();
                cmdCopyPerm.Click += cmdCopyPerm_Click;

                var mef = new ExtensionPointManager();
                var folderFieldsExtension = mef.GetUserControlExtensionPointFirstByPriority("DigitalAssets", "FolderFieldsControlExtensionPoint");
                if (folderFieldsExtension != null)
                {
                    folderFieldsControl = Page.LoadControl(folderFieldsExtension.UserControlSrc);
                    folderFieldsControl.ID = folderFieldsControl.GetType().BaseType.Name;
                    FolderDynamicFieldsContainer.Controls.Add(folderFieldsControl);
                    var fieldsControl = folderFieldsControl as IFieldsControl;
                    if (fieldsControl != null)
                    {
                        fieldsControl.SetController(controller);
                        fieldsControl.SetItemViewModel(new ItemViewModel
                        {
                            ItemID = folderViewModel.FolderID,
                            IsFolder = true,
                            PortalID = folderViewModel.PortalID,
                            ItemName = folderViewModel.FolderName
                        });
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            try
            {
                base.OnInit(e);

                jQuery.RequestDnnPluginsRegistration();

                var folderId = Convert.ToInt32(Request.Params["FolderId"]);
                Folder = FolderManager.Instance.GetFolder(folderId);
                if (string.IsNullOrEmpty(Folder.FolderPath))
                {
                    folderViewModel = controller.GetRootFolder();
                    isRootFolder = true;
                }
                else
                {
                    folderViewModel = controller.GetFolder(folderId);
                }

                // Setup controls
                CancelButton.Click += OnCancelClick;
                SaveButton.Click += OnSaveClick;
                PrepareFolderPreviewInfo();
                cmdCopyPerm.Click += cmdCopyPerm_Click;

                var mef = new ExtensionPointManager();
                var folderFieldsExtension = mef.GetUserControlExtensionPointFirstByPriority("DigitalAssets", "FolderFieldsControlExtensionPoint");
                if (folderFieldsExtension != null)
                {
                    folderFieldsControl = Page.LoadControl(folderFieldsExtension.UserControlSrc);
                    folderFieldsControl.ID = folderFieldsControl.GetType().BaseType.Name;
                    FolderDynamicFieldsContainer.Controls.Add(folderFieldsControl);
                    var fieldsControl = folderFieldsControl as IFieldsControl;
                    if (fieldsControl != null)
                    {
                        fieldsControl.SetController(controller);
                        fieldsControl.SetItemViewModel(new ItemViewModel()
                        {
                            ItemID = folderViewModel.FolderID,
                            IsFolder = true,
                            PortalID = folderViewModel.PortalID,
                            ItemName = folderViewModel.FolderName
                        });
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Beispiel #7
0
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                base.OnLoad(e);

                if (IsPostBack) return;

                if (SettingsRepository.IsGroupMode(ModuleId))
                {
                    int groupId;
                    if (string.IsNullOrEmpty(Request["groupId"]) || !int.TryParse(Request["groupId"], out groupId))
                    {
                        Skin.AddModuleMessage(this, Localization.GetString("InvalidGroup.Error", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    var groupFolder = controller.GetGroupFolder(groupId, PortalSettings);
                    if (groupFolder == null)
                    {
                        Skin.AddModuleMessage(this, Localization.GetString("InvalidGroup.Error", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    this.RootFolderViewModel = groupFolder;
                }
                else
                {
                    var rootFolderId = SettingsRepository.GetRootFolderId(ModuleId);
                    this.RootFolderViewModel = rootFolderId.HasValue ? this.controller.GetFolder(rootFolderId.Value) : this.controller.GetRootFolder();
                }

                var stateCookie = Request.Cookies["damState-" + UserId];
                var state = HttpUtility.ParseQueryString(Uri.UnescapeDataString(stateCookie != null ? stateCookie.Value : ""));

                var initialPath = "";
                int folderId;
                if (int.TryParse(Request["folderId"] ?? state["folderId"], out folderId))
                {
                    var folder = FolderManager.Instance.GetFolder(folderId);
                    if (folder != null && folder.FolderPath.StartsWith(RootFolderViewModel.FolderPath))
                    {
                        initialPath = PathUtils.Instance.RemoveTrailingSlash(folder.FolderPath.Substring(RootFolderViewModel.FolderPath.Length));
                    }
                }

                PageSize = Request["pageSize"] ?? state["pageSize"] ?? "10";
                ActiveView = Request["view"] ?? state["view"] ?? "gridview";

                InitializeTreeViews(initialPath);
                InitializeSearchBox();
                InitializeFolderType();
                InitializeGridContextMenu();
                InitializeEmptySpaceContextMenu();

                FolderNameRegExValidator.ErrorMessage = controller.GetInvalidCharsErrorText();
                FolderNameRegExValidator.ValidationExpression = "^([^" + Regex.Escape(controller.GetInvalidChars()) + "]+)$";
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }