Esempio n. 1
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string result = ValidateForm();

        if (String.IsNullOrEmpty(result))
        {
            if (ElementID == 0)
            {
                // Create new UI element info
                elemInfo = new UIElementInfo();
                elemInfo.ElementResourceID  = ResourceID;
                elemInfo.ElementParentID    = ParentID;
                elemInfo.ElementFromVersion = string.Empty;
                elemInfo.ElementOrder       = UIElementInfoProvider.GetLastElementOrder(ParentID) + 1;
            }
            else
            {
                // If parent changed set last order
                if (elemSelector.ElementID != elemInfo.ElementParentID)
                {
                    elemInfo.ElementOrder = UIElementInfoProvider.GetLastElementOrder(elemSelector.ElementID) + 1;
                }
                elemInfo.ElementParentID = this.elemSelector.ElementID;
            }
            elemInfo.ElementDisplayName = this.txtDisplayName.Text.Trim();
            elemInfo.ElementName        = this.txtName.Text.Trim();
            elemInfo.ElementIsCustom    = this.chkCustom.Checked;
            elemInfo.ElementCaption     = this.txtCaption.Text.Trim();
            elemInfo.ElementDisplayName = this.txtDisplayName.Text.Trim();
            elemInfo.ElementTargetURL   = this.txtTargetURL.Text.Trim();
            elemInfo.ElementIconPath    = this.txtIconPath.Text.Trim();
            elemInfo.ElementDescription = this.txtDescription.Text.Trim();
            elemInfo.ElementSize        = (this.radRegular.Checked ? UIElementSizeEnum.Regular : UIElementSizeEnum.Large);
            if (plcCMSVersion.Visible)
            {
                elemInfo.ElementFromVersion = this.versionSelector.Value.ToString();
            }

            // Set UI element info
            UIElementInfoProvider.SetUIElementInfo(elemInfo);

            // Get updated element info (ElementIDPath was changed in DB)
            elemInfo = UIElementInfoProvider.GetUIElementInfo(elemInfo.ElementID);

            // Reload header and content after save
            StringBuilder sb = new StringBuilder();
            sb.Append("if (window.parent != null) {");
            if (ElementID == 0)
            {
                sb.Append("if (window.parent.parent.frames['uicontent'] != null) {");
                sb.Append("window.parent.parent.frames['uicontent'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_EditFrameset.aspx") + "?moduleID=" + ResourceID + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "&saved=1';");
                sb.Append("}");
                sb.Append("if (window.parent.frames['uicontent'] != null) {");
                sb.Append("window.parent.frames['uicontent'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_EditFrameset.aspx") + "?moduleID=" + ResourceID + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "&saved=1';");
                sb.Append("}");
            }
            else
            {
                sb.Append("if (window.parent.parent.frames['header'] != null) {");
                sb.Append("window.parent.parent.frames['header'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_Header.aspx") + "?moduleID=" + ResourceID + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "';");
                sb.Append("}");
                sb.Append("if (window.parent.frames['header'] != null) {");
                sb.Append("window.parent.frames['header'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_Header.aspx") + "?moduleID=" + ResourceID + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "';");
                sb.Append("}");
            }
            sb.Append("if (window.parent.parent.frames['tree'] != null) {");
            sb.Append("window.parent.parent.frames['tree'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_Tree.aspx") + "?moduleID=" + ResourceID + "&path=" + elemInfo.ElementIDPath + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "';");
            sb.Append("}");
            sb.Append("if (window.parent.frames['tree'] != null) {");
            sb.Append("window.parent.frames['tree'].location = '" + ResolveUrl("~/CMSModules/Modules/Pages/Development/Module_UI_Tree.aspx") + "?moduleID=" + ResourceID + "&path=" + elemInfo.ElementIDPath + "&elementId=" + elemInfo.ElementID + "&parentId=" + elemInfo.ElementParentID + "';");
            sb.Append("}");
            sb.Append("}");

            this.lblInfo.ResourceString = "general.changessaved";
            this.lblInfo.Visible        = true;

            this.ltlScript.Text = ScriptHelper.GetScript(sb.ToString());
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = result;
        }
    }
    void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        elementInfo = (UIElementInfo)EditForm.EditedObject;

        // Clear icon field based on icon type
        int type = EditForm.FieldControls["ElementIconType"].Value.ToInteger(0);

        if (type == 0)
        {
            elementInfo.ElementIconClass = "";
        }
        else
        {
            elementInfo.ElementIconPath = "";
        }

        // Check unique code name
        UIElementInfo testUI = UIElementInfoProvider.GetUIElementInfo(elementInfo.ElementResourceID, elementInfo.ElementName);

        if ((testUI != null) && (testUI.ElementID != elementInfo.ElementID))
        {
            ShowError(GetString("ui.element.alreadyexists"));
            EditForm.StopProcessing = true;
            return;
        }

        UIElementInfo oldItem = UIContext.EditedObject as UIElementInfo;

        // If new element or display name has changed or parent changed, refresh tree and recalculate order
        if ((oldItem != null) && ((oldItem.ElementParentID != elementInfo.ElementParentID) || (oldItem.ElementDisplayName != elementInfo.ElementDisplayName)) || (ElementID == 0))
        {
            // If element is new or changed parent, put him in the end of the order, otherwise it stays on it's place
            if ((ElementID == 0) || (oldItem.ElementParentID != elementInfo.ElementParentID))
            {
                elementInfo.ElementOrder = UIElementInfoProvider.GetLastElementOrder(elementInfo.ElementParentID) + 1;
            }
            refreshTree = true;
        }

        // Clear target URL for page template type
        if (elementInfo.ElementType == UIElementTypeEnum.PageTemplate)
        {
            elementInfo.ElementTargetURL = null;
        }
        else
        {
            // Empty Page Template ID for non page template type
            elementInfo.ElementPageTemplateID = 0;
        }

        // Add javascript prefix for TargetURL if javascript type is selected
        if ((elementInfo.ElementType == UIElementTypeEnum.Javascript) && !elementInfo.ElementTargetURL.StartsWithCSafe("javascript", true))
        {
            elementInfo.ElementTargetURL = "javascript:" + elementInfo.ElementTargetURL;
        }

        if (isNew)
        {
            elementInfo.ElementIsCustom = !SystemContext.DevelopmentMode;
        }

        // For new elements or when template is changed, create new element's properties based on default values
        bool templateChanged = ValidationHelper.GetBoolean(EditForm.FieldControls["ElementPageTemplateID"].GetValue("TemplateChanged"), false);

        if (isNew || templateChanged)
        {
            // Get page template if any template is selected
            PageTemplateInfo pti = (elementInfo.ElementPageTemplateID > 0) ? PageTemplateInfoProvider.GetPageTemplateInfo(elementInfo.ElementPageTemplateID) : null;

            // Create form info based on either template combined with default general data (XML file) or default general data only (if no template is selected)
            FormInfo fi = (pti != null) ? pti.PageTemplatePropertiesForm : PortalFormHelper.GetUIElementDefaultPropertiesForm(UIElementPropertiesPosition.Both);

            // Create XMLData collection for current element (this make sense only for template change).
            XmlData data = new XmlData();
            data.LoadData(elementInfo.ElementProperties);

            // Apply default data to element's properties, but only if has not it's own data (based by column name)
            foreach (FormFieldInfo ffi in fi.GetFields(true, true))
            {
                if (!data.ColumnNames.Contains(ffi.Name) && !String.IsNullOrEmpty(ffi.DefaultValue))
                {
                    data[ffi.Name] = ffi.DefaultValue;
                }
            }

            elementInfo.ElementProperties = data.GetData();
        }
    }