コード例 #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        /// <exception cref="T:System.InvalidOperationException">
        /// The <see cref="P:System.Web.UI.UpdatePanel.ContentTemplate"/> property is being defined when the <see cref="P:System.Web.UI.UpdatePanel.ContentTemplateContainer"/> property has already been created.
        /// </exception>
        /// <remarks>
        /// Draws the controls, only gets called for the first drawing of the page, not for each postback
        /// </remarks>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string editLink = string.Format(@"
                        function {0}_relatedLinkEdit() {{
                            var idx = document.getElementById('{0}links').selectedIndex;
                            if (idx != -1) {{
                                var link = document.getElementById('{0}links')[idx].value;
                                var text = document.getElementById('{0}links')[idx].text;
                                if (link.length > 2) {{
                                    var linkType = link.substring(0,1);
                                    var linkNewWind = link.substring(1,2);
                                    var linkLink = link.substring(2);

                                    {0}_closeLinkContainer();

                                    document.getElementById('{0}linktitle').value = text;
                                    if (linkNewWind == 'n') {{
                                        document.getElementById('{0}checkNewWindow').checked = true;
                                    }}
                                    else {{
                                        document.getElementById('{0}checkNewWindow').checked = false;
                                    }}
                                    switch (linkType)
                                    {{
                                        case 'i':
                                            var e = {{ outVal: linkLink }};
                                            mc_{0}pagePicker.SaveSelection(e);
                                            document.getElementById('{0}_addInternalLinkPanel').style.display='block';
                                            document.getElementById('{0}_editInternalLinkButton').style.display='block';
                                            break;

                                        case 'm':
                                            var e = {{ outVal: linkLink }};
                                            mc_{0}mediaChooser.SaveSelection(e);
                                            document.getElementById('{0}_addMediaLinkPanel').style.display='block';
                                            document.getElementById('{0}_editMediaLinkButton').style.display='block';
                                            break;

                                        case 'e':
                                            document.getElementById('{0}exturl').value = linkLink;
                                            document.getElementById('{0}_addExternalLinkPanel').style.display='block';
                                            document.getElementById('{0}_editExternalLinkButton').style.display='block';
                                            break;
                                    }}
                                    document.getElementById('{0}_addLinkContainer').style.display='block';
                                }}
                            }}
                        }}

                        function {0}_addInternalLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            //{0}pagePicker_clear();
                            mc_{0}pagePicker.ClearSelection();

                            document.getElementById('{0}_addInternalLinkPanel').style.display='block';
                            document.getElementById('{0}_addInternalLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_addMediaLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            //{0}mediaChooser_clear();
                            mc_{0}mediaChooser.ClearSelection();

                            document.getElementById('{0}_addMediaLinkPanel').style.display='block';
                            document.getElementById('{0}_addMediaLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_addExternalLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            document.getElementById('{0}exturl').value = 'http://';

                            document.getElementById('{0}_addExternalLinkPanel').style.display='block';
                            document.getElementById('{0}_addExternalLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_closeLinkContainer() {{
                            document.getElementById('{0}_addInternalLinkPanel').style.display='none';
                            document.getElementById('{0}_addInternalLinkButton').style.display='none';
                            document.getElementById('{0}_editInternalLinkButton').style.display='none';

                            document.getElementById('{0}_addMediaLinkPanel').style.display='none';
                            document.getElementById('{0}_addMediaLinkButton').style.display='none';
                            document.getElementById('{0}_editMediaLinkButton').style.display='none';

                            document.getElementById('{0}_addExternalLinkPanel').style.display='none';
                            document.getElementById('{0}_addExternalLinkButton').style.display='none';
                            document.getElementById('{0}_editExternalLinkButton').style.display='none';

                            document.getElementById('{0}_addLinkContainer').style.display='none';
                        }}
                        ", this.ClientID);
            Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "_editLink", editLink, true);

            try
            {
                _xml = new XmlDocument();
                _xml.LoadXml(_data.Value.ToString());

            }
            catch
            {
                _xml = createBaseXmlDocument();
            }

            _listboxLinks = new ListBox();
            _listboxLinks.ID = base.ID + "links";
            _listboxLinks.Attributes.Add("onClick", ClientID + "_closeLinkContainer();");
            _listboxLinks.Width = 400;
            _listboxLinks.Height = 140;
            foreach (XmlNode node in _xml.DocumentElement.ChildNodes)
            {
                string text = node.Attributes["title"].Value.ToString();
                string type;
                if (node.Attributes["type"].Value.ToString().Equals("internal"))
                    type = "i";
                else if (node.Attributes["type"].Value.ToString().Equals("media"))
                    type = "m";
                else
                    type = "e";

                string value = type
                    + (node.Attributes["newwindow"].Value.ToString().Equals("1") ? "n" : "o")
                    + node.Attributes["link"].Value.ToString();
                _listboxLinks.Items.Add(new ListItem(text, value));
            }

            _buttonUp = new Button();
            _buttonUp.ID = base.ID + "btnUp";
            _buttonUp.Text = umbraco.ui.GetText("relatedlinks", "modeUp");
            _buttonUp.Width = 80;
            _buttonUp.Click += new EventHandler(this.buttonUp_Click);

            _buttonDown = new Button();
            _buttonDown.ID = base.ID + "btnDown";
            _buttonDown.Attributes.Add("style", "margin-top: 5px;");
            _buttonDown.Text = umbraco.ui.GetText("relatedlinks", "modeDown");
            _buttonDown.Width = 80;
            _buttonDown.Click += new EventHandler(this.buttonDown_Click);

            _buttonEdit = new Button();
            _buttonEdit.ID = base.ID + "btnEdit";
            _buttonEdit.Text = GetTextWithDefault("relatedlinks", "editLink", "Edit link");
            _buttonEdit.Width = 80;
            _buttonEdit.OnClientClick = this.ClientID + "_relatedLinkEdit(); return false;";

            _buttonDelete = new Button();
            _buttonDelete.ID = base.ID + "btnDel";
            _buttonDelete.Text = umbraco.ui.GetText("relatedlinks", "removeLink");
            _buttonDelete.Width = 80;
            _buttonDelete.Click += new EventHandler(this.buttonDel_Click);

            _textboxLinkTitle = new TextBox();
            _textboxLinkTitle.Width = 400;
            _textboxLinkTitle.ID = base.ID + "linktitle";

            _checkNewWindow = new CheckBox();
            _checkNewWindow.ID = base.ID + "checkNewWindow";
            _checkNewWindow.Checked = false;
            _checkNewWindow.Text = umbraco.ui.GetText("relatedlinks", "newWindow");

            _textBoxExtUrl = new TextBox();
            _textBoxExtUrl.Width = 400;
            _textBoxExtUrl.ID = base.ID + "exturl";

            _buttonAddExtUrl = new Button();
            _buttonAddExtUrl.ID = base.ID + "btnAddExtUrl";
            _buttonAddExtUrl.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddExtUrl.Width = 80;
            _buttonAddExtUrl.Click += new EventHandler(this.buttonAddExt_Click);

            _buttonAddIntUrlCP = new Button();
            _buttonAddIntUrlCP.ID = base.ID + "btnAddIntUrl";
            _buttonAddIntUrlCP.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddIntUrlCP.Width = 80;
            _buttonAddIntUrlCP.Click += new EventHandler(this.buttonAddIntCP_Click);

            _buttonAddMediaCP = new Button();
            _buttonAddMediaCP.ID = base.ID + "btnAddMedia";
            _buttonAddMediaCP.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddMediaCP.Width = 80;
            _buttonAddMediaCP.Click += new EventHandler(this.buttonAddMediaCP_Click);

            _buttonEditExtUrl = new Button();
            _buttonEditExtUrl.ID = base.ID + "btnEditExtUrl";
            _buttonEditExtUrl.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditExtUrl.Width = 80;
            _buttonEditExtUrl.Click += new EventHandler(this.buttonEditExt_Click);

            _buttonEditIntUrlCP = new Button();
            _buttonEditIntUrlCP.ID = base.ID + "btnEditIntUrl";
            _buttonEditIntUrlCP.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditIntUrlCP.Width = 80;
            _buttonEditIntUrlCP.Click += new EventHandler(this.buttonEditIntCP_Click);

            _buttonEditMediaCP = new Button();
            _buttonEditMediaCP.ID = base.ID + "btnEditMedia";
            _buttonEditMediaCP.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditMediaCP.Width = 80;
            _buttonEditMediaCP.Click += new EventHandler(this.buttonEditMediaCP_Click);

            _pagePickerExtractor = new PagePickerwMediaDataExtractor();
            _pagePicker = new pagePicker(_pagePickerExtractor);
            _pagePicker.ID = base.ID + "pagePicker";

            _mediaChooserExtractor = new PagePickerwMediaDataExtractor();
            _mediaChooser = new mediaChooser(_mediaChooserExtractor);
            _mediaChooser.ID = base.ID + "mediaChooser";

            ContentTemplateContainer.Controls.Add(new LiteralControl("<div class=\"relatedlinksdatatype\" style=\"text-align: left;  padding: 5px;\"><table><tr><td rowspan=\"2\">"));
            ContentTemplateContainer.Controls.Add(_listboxLinks);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td><td style=\"vertical-align: top\">"));
            ContentTemplateContainer.Controls.Add(_buttonUp);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(_buttonDown);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr><tr><td style=\"vertical-align: bottom\">"));
            ContentTemplateContainer.Controls.Add(_buttonEdit);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(_buttonDelete);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr></table>"));

            // Add related links container: for each link type, we add a link that displays the
            // corresponding div and hides the others
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<a href=\"javascript:;\" onClick=\"{0}_addInternalLink();\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addInternal"))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format(" | <a href=\"javascript:;\" onClick=\"{0}_addMediaLink();\"><strong>{1}</strong></a>", ClientID, GetTextWithDefault("relatedlinks", "addMedia", "Add media link"))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format(" | <a href=\"javascript:;\" onClick=\"{0}_addExternalLink();\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addExternal"))));

            // All urls containers
            // Main contaniner: {ClienID}_addLinkContainer
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addLinkContainer\" style=\"display: none; padding: 4px; border: 1px solid #ccc; margin-top: 5px;margin-right:10px;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<a href=\"javascript:;\" onClick=\"{0}_closeLinkContainer();\" style=\"border: none;\"><img src=\"{1}/images/close.png\" style=\"float: right\" /></a>", ClientID, IOHelper.ResolveUrl(SystemDirectories.Umbraco))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "caption"))));
            ContentTemplateContainer.Controls.Add(_textboxLinkTitle);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));

            // External Url container: {CliendID}_addExternalLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addExternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "linkurl"))));
            ContentTemplateContainer.Controls.Add(_textBoxExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Internal Link container: {CliendID}_addInternalLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addInternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "internalPage"))));
            ContentTemplateContainer.Controls.Add(_pagePicker);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Media Link container: {CliendID}_addMediaLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addMediaLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", GetTextWithDefault("relatedlinks", "media", "Media"))));
            ContentTemplateContainer.Controls.Add(_mediaChooser);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Checkbox for new window container
            ContentTemplateContainer.Controls.Add(new LiteralControl("<div style=\"margin: 5px 0\">"));
            ContentTemplateContainer.Controls.Add(_checkNewWindow);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Internal Link button: {ClientID}_addInternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addInternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddIntUrlCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // Internal Link button: {ClientID}_editInternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editInternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditIntUrlCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Media Link button: {ClientID}_addMediaLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addMediaLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddMediaCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // Media Link button: {ClientID}_editMediaLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editMediaLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditMediaCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // External Url button: {ClientID}_addExternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addExternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // External Url button: {ClientID}_editExternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editExternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            resetInputMedia();
        }
コード例 #2
0
        public void mediapicker(HtmlGenericControl widgetElementsDiv, WidgetElement schemaElement, XmlNode widgetNode)
        {
            //deserialize element prevalues
            MediaPickerOptions prevalues = jsonSerializer.Deserialize<MediaPickerOptions>(schemaElement.prevalues);

            HtmlGenericControl controlWrapper = buildControlWrapper(widgetElementsDiv, prevalues.elementName, prevalues.title, prevalues.description, schemaElement, widgetNode);

            //include media picker JS
            string mediaPickerJS = string.Format("<script src=\"{0}\" ></script>", "/umbraco/controls/Images/ImageViewer.js");
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Widget_Builder_DataEditor), "WidgetBuilderMediaPicker", mediaPickerJS, false);

            DataInterface dataExtractor = new DataInterface();

            //get the value from the XML
            try
            {
                XmlNode element = widgetNode.SelectSingleNode(prevalues.elementName);
                dataExtractor.Value = element.InnerText;
            }
            catch (Exception e) {
                dataExtractor.Value = "";
            }
            mediaChooser mediaChooser = new mediaChooser(dataExtractor, true, true);

            HtmlGenericControl mediaWrapper = new HtmlGenericControl();
            mediaWrapper.Controls.Add(mediaChooser);
            mediaWrapper.TagName = "div";
            mediaWrapper.Attributes["class"] = "widgetMediaPicker " + prevalues.className;

            controlWrapper.Controls.Add(mediaChooser);
        }
コード例 #3
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();

            try
            {
                // Custom Font Path
                CustomFontPathTextBox = new TextBox {ID = "txtCustomFont", CssClass = "umbEditorTextField"};

                // Fonts DropDownList
                FontNameDropDownList = new DropDownList {ID = "ddlFontName", CssClass = "umbEditorDropDownList"};
                FontNameDropDownList.Items.AddRange(DropDownItems.Fonts);

                // Font Size TextBox
                FontSizeTextBox = new TextBox {ID = "txtFontSize", CssClass = "umbEditorNumberField"};

                // Font Style CheckBoxList
                FontStyleCheckBoxList = new CheckBoxList
                                            {ID = "cblFontStyle", RepeatColumns = 2, CssClass = "umbEditorDropDownList"};
                FontStyleCheckBoxList.Items.AddRange(DropDownItems.FontStyles);

                // Fore Color Picker
                ForegroundColorPicker = new HtmlInputText {ID = "cpForeColor"};
                ForegroundColorPicker.Attributes.Add("type", "color");
                ForegroundColorPicker.Attributes.Add("data-hex", "true");

                // Back Color Picker
                BackgroundColorPicker = new HtmlInputText {ID = "cpBackColor"};
                BackgroundColorPicker.Attributes.Add("type", "color");
                BackgroundColorPicker.Attributes.Add("data-hex", "true");

                // Shadow Color Picker
                ShadowColorPicker = new HtmlInputText {ID = "cpShadowColor"};
                ShadowColorPicker.Attributes.Add("type", "color");
                ShadowColorPicker.Attributes.Add("data-hex", "true");

                // Horizontal Alignment DropDownList
                HorizontalAlignmentDropDownList = new DropDownList
                                                      {ID = "ddlAlignHorizontal", CssClass = "umbEditorDropDownList"};
                HorizontalAlignmentDropDownList.Items.AddRange(DropDownItems.HAlignments);

                // Vertical Alignment DropDownList
                VerticalAlignmentDropDownList = new DropDownList
                                                    {ID = "ddlAlignVertical", CssClass = "umbEditorDropDownList"};
                VerticalAlignmentDropDownList.Items.AddRange(DropDownItems.VAlignments);

                // Area Height TextBox
                ImageHeightTextBox = new TextBox {ID = "txtImageHeight", CssClass = "umbEditorNumberField"};

                // Area Width TextBox
                ImageWidthTextBox = new TextBox {ID = "txtImageWidth", CssClass = "umbEditorNumberField"};

                // Background picker
                _dataExtractor = new DataExtractor {Value = BackgroundMediaId};
                BackgroundMediaChooser = new mediaChooser(_dataExtractor, true, true) {ID = "backgroundMedia"};

                // Image Format Picker
                ImageFormatDropDownList = new DropDownList {ID = "ddlImageFormat", CssClass = "umbEditorDropDownList"};
                ImageFormatDropDownList.Items.AddRange(DropDownItems.OutputFormats);

                // Preview Image
                ImagePreview = new Image
                                   {BorderColor = Color.LightGray, BorderStyle = BorderStyle.Dashed, BorderWidth = 1};

                // Add Controls to Editor
                Controls.Add(FontNameDropDownList);
                Controls.Add(CustomFontPathTextBox);
                Controls.Add(FontSizeTextBox);
                Controls.Add(FontStyleCheckBoxList);
                Controls.Add(ForegroundColorPicker);
                Controls.Add(BackgroundColorPicker);
                Controls.Add(ShadowColorPicker);
                Controls.Add(HorizontalAlignmentDropDownList);
                Controls.Add(VerticalAlignmentDropDownList);
                Controls.Add(ImageHeightTextBox);
                Controls.Add(ImageWidthTextBox);
                Controls.Add(BackgroundMediaChooser);
                Controls.Add(ImageFormatDropDownList);
                Controls.Add(ImagePreview);
            }
            catch (Exception exception)
            {
                SetErrorMessage(exception);
            }
        }