예제 #1
0
        /// <summary>
        /// Gets the controller from a control collection recursively.
        /// </summary>
        /// <param name="cc">Control collection.</param>
        /// <returns>Controller or null if not found.</returns>
        public static DJUploadController GetControllerFromControls(ControlCollection cc)
        {
            DJUploadController res = null;

            foreach (object o in cc)
            {
                res = o as DJUploadController;

                if (res != null)
                {
                    break;
                }

                Control c = o as Control;

                if (c != null && c.HasControls())
                {
                    res = GetControllerFromControls(c.Controls);

                    if (res != null)
                    {
                        break;
                    }
                }
            }

            return(res);
        }
예제 #2
0
        /// <summary>
        /// Gets the upload controller.
        /// </summary>
        /// <param name="page">The page to check.</param>
        /// <returns>The upload controller.</returns>
        public static DJUploadController GetController(Page page)
        {
            DJUploadController res = null;

            res = GetControllerFromControls(page.Controls);

            if (res == null)
            {
                throw new Exception("An instance of the DJUploadController control must be placed at the beginning of the page before other controls.");
            }

            return(res);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            DJUploadController controller;

            controller = DJUploadController.GetController(Page);

            if (controller != null)
            {
                _frame.Attributes["src"] = _progressURL + "?DJUploadStatus=" + controller.UploadID;

                if (controller.ShowProgressBar)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), ID, "up_killProgress('" + ClientID + "')", true);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use
        /// composition-based implementation to create any child controls they contain
        /// in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _controller     = DJUploadController.GetController(Page);
            _uploadControls = new List <System.Web.UI.WebControls.FileUpload>();

            // Create the parameter field
            _parameters = new HiddenField();
            Controls.Add(_parameters);

            // Create the container
            Panel outerContainer = new Panel();

            outerContainer.CssClass = "upUploadBox";
            Controls.Add(outerContainer);

            // Create the file uploads
            Panel fuContainer = new Panel();

            for (int i = 0; i < MaxFileUploads; i++)
            {
                if (ApplyStyles)
                {
                    fuContainer.CssClass = "upFileInputs";
                }
                else
                {
                    fuContainer.CssClass = "upContainerNormal";
                }

                outerContainer.Controls.Add(fuContainer);

                System.Web.UI.WebControls.FileUpload fu = new System.Web.UI.WebControls.FileUpload();
                fu.CssClass = "upFileNormal";
                if (System.Web.HttpContext.Current.Request.Browser.Browser.IndexOf("IE") >= 0)
                {
                    fu.CssClass = "upFileNormal_IE";
                }
                _uploadControls.Add(fu);
                fuContainer.Controls.Add(fu);

                //if (ApplyStyles)
                //{
                //    ImageButton btnRemove = new ImageButton();
                //    fuContainer.Controls.Add(btnRemove);
                //    btnRemove.AlternateText = "Remove upload";
                //    btnRemove.ImageUrl = _controller.ImagePath + "removebutton.gif";
                //    btnRemove.OnClientClick = "up_RemoveUpload(this); return false;";
                //    btnRemove.CssClass = "upRemoveButton upShowDynamic";
                //}
                //else
                //{
                //    Button btnRemove = new Button();
                //    fuContainer.Controls.Add(btnRemove);
                //    btnRemove.OnClientClick = "up_RemoveUpload(this); return false;";
                //    btnRemove.Text = "Remove";
                //    btnRemove.CssClass = "upButtonNormal upShowDynamic";
                //}

                if (i >= InitialFileUploads)
                {
                    fuContainer.CssClass += " upHiddenDynamic";
                }
            }

            // Create the buttons
            if (ApplyStyles)
            {
                ImageButton btnGo = new ImageButton();
                fuContainer.Controls.Add(btnGo);
                btnGo.AlternateText    = "Upload now";
                btnGo.ImageUrl         = _controller.ImagePath + "uploadbutton.gif";
                btnGo.Visible          = ShowUploadButton;
                btnGo.CausesValidation = true;
                btnGo.CssClass         = "upGoButton";
            }
            else
            {
                Button btnGo = new Button();
                fuContainer.Controls.Add(btnGo);
                btnGo.Text             = "Upload";
                btnGo.Visible          = ShowUploadButton;
                btnGo.CausesValidation = true;
                btnGo.CssClass         = "upButtonNormal";
                btnGo.Attributes.Add("ajaxcall", "none");
            }

            if (ApplyStyles)
            {
                ImageButton btnAdd = new ImageButton();
                fuContainer.Controls.Add(btnAdd);
                btnAdd.AlternateText = "Add a new upload";
                btnAdd.ImageUrl      = _controller.ImagePath + "addbutton.gif";
                btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
                btnAdd.Visible       = ShowAddButton;
                btnAdd.CssClass      = "upAddButton upShowDynamic";
            }
            else
            {
                Button btnAdd = new Button();
                fuContainer.Controls.Add(btnAdd);
                btnAdd.Text          = "Add";
                btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
                btnAdd.Visible       = ShowAddButton;
                btnAdd.CssClass      = "upButtonNormal upShowDynamic";
            }



            //Panel buttonContainer = new Panel();
            //buttonContainer.CssClass = "upButtons";

            //// Create the buttons
            //if (ApplyStyles)
            //{
            //    ImageButton btnGo = new ImageButton();
            //    buttonContainer.Controls.Add(btnGo);
            //    btnGo.AlternateText = "Upload now";
            //    btnGo.ImageUrl = _controller.ImagePath + "uploadbutton.gif";
            //    btnGo.Visible = ShowUploadButton;
            //    btnGo.CausesValidation = true;
            //    btnGo.CssClass = "upGoButton";
            //}
            //else
            //{
            //    Button btnGo = new Button();
            //    buttonContainer.Controls.Add(btnGo);
            //    btnGo.Text = "Upload";
            //    btnGo.Visible = ShowUploadButton;
            //    btnGo.CausesValidation = true;
            //    btnGo.CssClass = "upButtonNormal";
            //    btnGo.Attributes.Add("ajaxcall", "none");
            //}

            //if (ApplyStyles)
            //{
            //    ImageButton btnAdd = new ImageButton();
            //    buttonContainer.Controls.Add(btnAdd);
            //    btnAdd.AlternateText = "Add a new upload";
            //    btnAdd.ImageUrl = _controller.ImagePath + "addbutton.gif";
            //    btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
            //    btnAdd.Visible = ShowAddButton;
            //    btnAdd.CssClass = "upAddButton upShowDynamic";
            //}
            //else
            //{
            //    Button btnAdd = new Button();
            //    buttonContainer.Controls.Add(btnAdd);
            //    btnAdd.Text = "Add";
            //    btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
            //    btnAdd.Visible = ShowAddButton;
            //    btnAdd.CssClass = "upButtonNormal upShowDynamic";
            //}

            //outerContainer.Controls.Add(buttonContainer);

            CustomValidator val = new CustomValidator();

            val.ServerValidate          += new ServerValidateEventHandler(val_ServerValidate);
            val.ClientValidationFunction = "up_ValidateUpload";
            val.ErrorMessage             = RequiredMessage;
            val.Enabled = val.EnableClientScript = RequiredField;
            val.Display = ValidatorDisplay.Dynamic;
            Controls.Add(val);

            HiddenField extensions = new HiddenField();

            extensions.Value = AllowedFileExtensions;
            Controls.Add(extensions);

            CustomValidator valExtensions = new CustomValidator();

            valExtensions.ClientValidationFunction = "up_ValidateUploadExtensions";
            valExtensions.ErrorMessage             = InvalidExtensionMessage;
            valExtensions.EnableClientScript       = valExtensions.EnableClientScript = (AllowedFileExtensions != null);
            valExtensions.Display = ValidatorDisplay.Dynamic;
            Controls.Add(valExtensions);

            // Create the end marker
            _endMarker = new HiddenField();
            Controls.Add(_endMarker);
        }
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use 
        /// composition-based implementation to create any child controls they contain 
        /// in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _controller = DJUploadController.GetController(Page);
            _uploadControls = new List<System.Web.UI.WebControls.FileUpload>();

            // Create the parameter field
            _parameters = new HiddenField();
            Controls.Add(_parameters);

            // Create the container
            Panel outerContainer = new Panel();
            outerContainer.CssClass = "upUploadBox";
            Controls.Add(outerContainer);

            // Create the file uploads
            Panel fuContainer = new Panel();
            for (int i = 0; i < MaxFileUploads; i++)
            {
                if (ApplyStyles)
                {
                    fuContainer.CssClass = "upFileInputs";
                }
                else
                {
                    fuContainer.CssClass = "upContainerNormal";
                }

                outerContainer.Controls.Add(fuContainer);

                System.Web.UI.WebControls.FileUpload fu = new System.Web.UI.WebControls.FileUpload();
                fu.CssClass = "upFileNormal";
                if ( System.Web.HttpContext.Current.Request.Browser.Browser.IndexOf("IE") >= 0 )
                    fu.CssClass = "upFileNormal_IE";
                 _uploadControls.Add(fu);
                fuContainer.Controls.Add(fu);

                //if (ApplyStyles)
                //{
                //    ImageButton btnRemove = new ImageButton();
                //    fuContainer.Controls.Add(btnRemove);
                //    btnRemove.AlternateText = "Remove upload";
                //    btnRemove.ImageUrl = _controller.ImagePath + "removebutton.gif";
                //    btnRemove.OnClientClick = "up_RemoveUpload(this); return false;";
                //    btnRemove.CssClass = "upRemoveButton upShowDynamic";
                //}
                //else
                //{
                //    Button btnRemove = new Button();
                //    fuContainer.Controls.Add(btnRemove);
                //    btnRemove.OnClientClick = "up_RemoveUpload(this); return false;";
                //    btnRemove.Text = "Remove";
                //    btnRemove.CssClass = "upButtonNormal upShowDynamic";
                //}

                if (i >= InitialFileUploads)
                {
                    fuContainer.CssClass += " upHiddenDynamic";
                }
            }

            // Create the buttons
            if (ApplyStyles)
            {
                ImageButton btnGo = new ImageButton();
                fuContainer.Controls.Add(btnGo);
                btnGo.AlternateText = "Upload now";
                btnGo.ImageUrl = _controller.ImagePath + "uploadbutton.gif";
                btnGo.Visible = ShowUploadButton;
                btnGo.CausesValidation = true;
                btnGo.CssClass = "upGoButton";
            }
            else
            {
                Button btnGo = new Button();
                fuContainer.Controls.Add(btnGo);
                btnGo.Text = "Upload";
                btnGo.Visible = ShowUploadButton;
                btnGo.CausesValidation = true;
                btnGo.CssClass = "upButtonNormal";
                btnGo.Attributes.Add("ajaxcall", "none");
            }

            if (ApplyStyles)
            {
                ImageButton btnAdd = new ImageButton();
                fuContainer.Controls.Add(btnAdd);
                btnAdd.AlternateText = "Add a new upload";
                btnAdd.ImageUrl = _controller.ImagePath + "addbutton.gif";
                btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
                btnAdd.Visible = ShowAddButton;
                btnAdd.CssClass = "upAddButton upShowDynamic";
            }
            else
            {
                Button btnAdd = new Button();
                fuContainer.Controls.Add(btnAdd);
                btnAdd.Text = "Add";
                btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
                btnAdd.Visible = ShowAddButton;
                btnAdd.CssClass = "upButtonNormal upShowDynamic";
            }

            //Panel buttonContainer = new Panel();
            //buttonContainer.CssClass = "upButtons";

            //// Create the buttons
            //if (ApplyStyles)
            //{
            //    ImageButton btnGo = new ImageButton();
            //    buttonContainer.Controls.Add(btnGo);
            //    btnGo.AlternateText = "Upload now";
            //    btnGo.ImageUrl = _controller.ImagePath + "uploadbutton.gif";
            //    btnGo.Visible = ShowUploadButton;
            //    btnGo.CausesValidation = true;
            //    btnGo.CssClass = "upGoButton";
            //}
            //else
            //{
            //    Button btnGo = new Button();
            //    buttonContainer.Controls.Add(btnGo);
            //    btnGo.Text = "Upload";
            //    btnGo.Visible = ShowUploadButton;
            //    btnGo.CausesValidation = true;
            //    btnGo.CssClass = "upButtonNormal";
            //    btnGo.Attributes.Add("ajaxcall", "none");
            //}

            //if (ApplyStyles)
            //{
            //    ImageButton btnAdd = new ImageButton();
            //    buttonContainer.Controls.Add(btnAdd);
            //    btnAdd.AlternateText = "Add a new upload";
            //    btnAdd.ImageUrl = _controller.ImagePath + "addbutton.gif";
            //    btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
            //    btnAdd.Visible = ShowAddButton;
            //    btnAdd.CssClass = "upAddButton upShowDynamic";
            //}
            //else
            //{
            //    Button btnAdd = new Button();
            //    buttonContainer.Controls.Add(btnAdd);
            //    btnAdd.Text = "Add";
            //    btnAdd.OnClientClick = "up_AddUpload('" + ClientID + "'); return false;";
            //    btnAdd.Visible = ShowAddButton;
            //    btnAdd.CssClass = "upButtonNormal upShowDynamic";
            //}

            //outerContainer.Controls.Add(buttonContainer);

            CustomValidator val = new CustomValidator();
            val.ServerValidate += new ServerValidateEventHandler(val_ServerValidate);
            val.ClientValidationFunction = "up_ValidateUpload";
            val.ErrorMessage = RequiredMessage;
            val.Enabled = val.EnableClientScript = RequiredField;
            val.Display = ValidatorDisplay.Dynamic;
            Controls.Add(val);

            HiddenField extensions = new HiddenField();
            extensions.Value = AllowedFileExtensions;
            Controls.Add(extensions);

            CustomValidator valExtensions = new CustomValidator();
            valExtensions.ClientValidationFunction = "up_ValidateUploadExtensions";
            valExtensions.ErrorMessage = InvalidExtensionMessage;
            valExtensions.EnableClientScript = valExtensions.EnableClientScript = (AllowedFileExtensions != null);
            valExtensions.Display = ValidatorDisplay.Dynamic;
            Controls.Add(valExtensions);

            // Create the end marker
            _endMarker = new HiddenField();
            Controls.Add(_endMarker);
        }
        private void add_upload_controls(PlaceHolder placeHolder, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("New_Group_And_Item_MySobekViewer.add_upload_controls", String.Empty);

            StringBuilder filesBuilder = new StringBuilder(2000);
            filesBuilder.AppendLine("<script src=\"" + currentMode.Base_URL + "default/scripts/sobekcm_metadata.js\" type=\"text/javascript\"></script>");

            if ((template.Upload_Types == Template.Template_Upload_Types.File) || (template.Upload_Types == Template.Template_Upload_Types.File_or_URL))
            {
                filesBuilder.AppendLine("Add a new item for this package:");
                filesBuilder.AppendLine("<blockquote>");

                LiteralControl filesLiteral2 = new LiteralControl(filesBuilder.ToString());
                placeHolder.Controls.Add(filesLiteral2);
                filesBuilder.Remove(0, filesBuilder.Length);

                DJUploadController1 = new DJUploadController
                                          {
                                              CSSPath = currentMode.Base_URL + "default/scripts/upload_styles",
                                              ImagePath = currentMode.Base_URL + "default/scripts/upload_images",
                                              ScriptPath = currentMode.Base_URL + "default/scripts/upload_scripts"
                                          };
                placeHolder.Controls.Add(DJUploadController1);

                DJAccessibleProgrssBar1 = new DJAccessibleProgressBar();
                placeHolder.Controls.Add(DJAccessibleProgrssBar1);

                DJFileUpload1 = new DJFileUpload {ShowAddButton = false, ShowUploadButton = true, MaxFileUploads = 1};
                placeHolder.Controls.Add(DJFileUpload1);

                // Set the default processor
                FileSystemProcessor fs = new FileSystemProcessor {OutputPath = userInProcessDirectory};
                DJUploadController1.DefaultFileProcessor = fs;

                // Change the file processor and set it's properties.
                FieldTestProcessor fsd = new FieldTestProcessor {OutputPath = userInProcessDirectory};
                DJFileUpload1.FileProcessor = fsd;

                filesBuilder.AppendLine("</blockquote><br />");
            }

            LiteralControl literal1 = new LiteralControl(filesBuilder.ToString());
            placeHolder.Controls.Add(literal1);
        }