private void InitRadioButtons(BrandMetadataSelectableSetting selSetting)
        {
            var radiolist = new MetadataRadioButtonList()
            {
                BrandId       = BrandId,
                GroupNumber   = GroupNumber,
                CssClass      = "PanelTxt",
                LinearOutlay  = selSetting.IsLinear,
                SortType      = (SelectableMetadataSortType)selSetting.SortType,
                OrderType     = (SelectableMetadataOrderType)selSetting.OrderType,
                RepeatColumns = selSetting.ColumnCount,
                //adding the ID of the control prevents problems with retrieving the posted back
                //data not being persisted to the meta input underlying controls
                //in a scenario when they are dynamically added to another control
                ID = "MetadataRadioButtonList" + PrepareID()
            };

            radiolist.RefreshFromDataSource();

            if (selSetting.OrderType == (int)SelectableMetadataOrderType.ByColumn)
            {//order by column means the number of rows is limited
                //therefore we need to calculate the number of columns to fit all items
                //in this number of rows
                radiolist.RepeatColumns = radiolist.Items.Count / selSetting.ColumnCount + (radiolist.Items.Count % selSetting.ColumnCount > 0 ? 1 : 0);
                radiolist.DataBind();
            }

            Controls.Add(radiolist);
        }
        public BrandMetadataSelectableSetting RetrieveSetting()
        {
            //var result = BrandMetadataSelectableSetting.New();

            //set the id if we are editing an existing setting as opposed to adding a new one - this will trigger an update at the mapper instance
            //if (BrandMetadataSelectableSettingId > 0) result.BrandMetadataSelectableSettingId = BrandMetadataSelectableSettingId;

            var result = BrandMetadataSelectableSettingId > 0
                             ? BrandMetadataSelectableSetting.Get(BrandMetadataSelectableSettingId)
                             : BrandMetadataSelectableSetting.New();


            result.SelectableType = GetIntOrDefault(TypeDropDownList.SelectedValue);
            result.Depth          = GetIntOrDefault(DepthDropDownList.SelectedValue);
            result.SortType       = GetIntOrDefault(SortTypeRadioButtonList.SelectedValue);
            result.OrderType      = GetIntOrDefault(OrderTypeRadioButtonList.SelectedValue);
            result.ColumnCount    = GetIntOrDefault(ColumnsDropDownList.SelectedValue);

            result.IsLinear      = LinearCheckBox.Checked;
            result.AllowMultiple = AllowMultipleCheckbox.Checked;

            //leave as they are if existing and set the default values if not
            result.FilterGroup          = result.IsNew ? 0 : result.FilterGroup;
            result.FilterSelectableType = result.IsNew ? (int)SelectableMetadataType.DropDown : result.FilterSelectableType;
            result.FilterDepth          = result.IsNew ? 3 : result.FilterDepth;

            return(result);
        }
        /// <summary>
        /// deletes the setting, all stored possible selection values and all selected values for all assets
        /// </summary>
        /// <param name="brandMetadataSettingId">the setting to be deleted</param>
        public static void DeleteSettingAndValues(int brandMetadataSettingId)
        {
            var setting = BrandMetadataSetting.Get(brandMetadataSettingId);

            if (setting == null)
            {
                return;
            }

            var group = setting.GroupNumber;

            var metaValuesFinder = new MetadataFinder()
            {
                GroupNumber = group
            };

            var vals = Metadata.FindMany(metaValuesFinder);

            var assetMetaFinder = new AssetMetadataFinder()
            {
            };

            //iterate through all values, delete existing assetmetadata selection and then delete values themselves as well
            foreach (var metaValue in vals)
            {
                assetMetaFinder.MetadataId = metaValue.MetadataId.GetValueOrDefault();

                var assetMetaSelections = AssetMetadata.FindMany(assetMetaFinder);

                foreach (var assetMeta in assetMetaSelections)
                {
                    AssetMetadata.Delete(assetMeta.AssetMetadataId);
                }

                Metadata.Delete(metaValue.MetadataId);
            }

            //delete selectable setting if one exists
            if (!setting.SelectableSetting.IsNull && !setting.SelectableSetting.IsNew)
            {
                BrandMetadataSelectableSetting.Delete(setting.SelectableSetting.BrandMetadataSelectableSettingId);
            }

            //delete the setting itself
            BrandMetadataSetting.Delete(brandMetadataSettingId);
        }
        private void InitCheckboxes(BrandMetadataSelectableSetting selSetting)
        {
            if (selSetting.IsLinear)
            {//checkbox list required
                var chklist = new MetadataCheckBoxList()
                {
                    BrandId       = BrandId,
                    GroupNumber   = GroupNumber,
                    CssClass      = "PanelTxt",
                    LinearOutlay  = selSetting.IsLinear,
                    SortType      = (SelectableMetadataSortType)selSetting.SortType,
                    OrderType     = (SelectableMetadataOrderType)selSetting.OrderType,
                    RepeatColumns = selSetting.ColumnCount,
                    //adding the ID of the control prevents problems with retrieving the posted back
                    //data not being persisted to the meta input underlying controls
                    //in a scenario when they are dynamically added to another control
                    ID           = "MetadataCheckBoxList" + PrepareID(),
                    AutoPostBack = false,
                };
                chklist.RefreshFromDataSource();
                if (selSetting.OrderType == (int)SelectableMetadataOrderType.ByColumn)
                {//order by column means the number of rows is limited
                    //therefore we need to calculate the number of columns to fit all items
                    //in this number of rows
                    chklist.RepeatColumns = chklist.Items.Count / selSetting.ColumnCount + (chklist.Items.Count % selSetting.ColumnCount > 0 ? 1 : 0);
                    chklist.DataBind();
                }
                Controls.Add(chklist);
            }
            else
            {//hierarchical checkbox treeview required
                var treeview = new MetadataTreeView
                {
                    BrandId        = BrandId,
                    GroupNumber    = GroupNumber,
                    ShowCheckBoxes = TreeNodeTypes.All,
                    SortType       = (SelectableMetadataSortType)selSetting.SortType
                };

                treeview.NodeStyle.CssClass = "PanelTxt";
                treeview.RefreshFromBrandAndSelect(BrandId, new[] { 1 });
                Controls.Add(treeview);
            }
        }
        private void InitComboBox(BrandMetadataSelectableSetting selSetting)
        {
            var dd = new MetadataListBox()
            {
                BrandId       = BrandId,
                GroupNumber   = GroupNumber,
                CssClass      = "formInput W225",
                SelectionMode = ListSelectionMode.Multiple,
                Rows          = selSetting.Depth,
                LinearOutlay  = selSetting.IsLinear,
                //adding the ID of the control prevents problems with retrieving the posted back
                //data not being persisted to the meta input underlying controls
                //in a scenario when they are dynamically added to another control
                ID       = "MetadataListBox" + PrepareID(),
                SortType = (SelectableMetadataSortType)selSetting.SortType
            };

            dd.RefreshFromDataSource();
            Controls.Add(dd);
        }
Exemplo n.º 6
0
        protected void SaveSettingsButton_Click(object sender, EventArgs e)
        {
            var brand      = BrandCache.Instance.GetById(BrandId);
            var setting    = brand.GetCustomMetadataSetting(GroupNumber);
            var selectable = ucEditDetails.RetrieveSetting();
            var updateVals = false;

            if (!setting.IsNew && !setting.IsNull && setting.UiControlType == (int)BrandMetadataUiControlType.Select)
            {//check if the type is not changing which would require updating all metadata vals entries of all assets in the database
                //as that will no longer be reflecting the right values
                updateVals = setting.SelectableSetting.SelectableType != selectable.SelectableType;
            }

            selectable.BrandMetadataSettingId = setting.BrandMetadataSettingId.GetValueOrDefault();

            BrandMetadataSelectableSetting.Update(selectable);

            ucEditDetails.BrandMetadataSelectableSettingId = selectable.BrandMetadataSelectableSettingId.GetValueOrDefault();

            if (updateVals)
            {
                var assets = Asset.FindMany(new AssetFinder()
                {
                    IsDeleted = false
                });
                foreach (var asset in assets)
                {
                    asset.MetadataList.ToString();
                    asset.MetadataTextFieldsList.ToString();
                    asset.MetadataTextAreasList.ToString();

                    Asset.SaveAssetMetadata(asset);
                }
            }

            var msg = "Metadata selection options updated successfully" + (updateVals? ".<br />Asset search metadata updated successfully." : "");

            MessageLabel1.SetSuccessMessage(msg);

            CacheManager.InvalidateCache("BrandMetadata", CacheType.All);
        }
Exemplo n.º 7
0
        protected void ApplyButton_Click(object sender, EventArgs e)
        {
            var selId = GetSelectedSelectableSettingId();

            if (selId <= 0)
            {
                GeneralFeedbackLabel.SetSuccessMessage("no group was selected from the list.");
                return;
            }

            var f = BrandMetadataSelectableSetting.Get(selId);

            f.FilterDepth          = int.Parse(RowsDropDownList.SelectedValue);
            f.FilterSelectableType = Option2RadioButton.Checked
                                             ? (int)SelectableMetadataType.ComboBox
                                             : (int)SelectableMetadataType.DropDown;

            BrandMetadataSelectableSetting.Update(f);

            GeneralFeedbackLabel.SetSuccessMessage("display settings of the selected metadata were updated.");
        }
        private void InitDropDown(BrandMetadataSelectableSetting selSetting)
        {
            var dd = new MetadataDropDownList
            {
                BrandId       = BrandId,
                GroupNumber   = GroupNumber,
                OmitBlankItem = false,
                BlankText     = "Not Specified",
                BlankValue    = "0",
                CssClass      = "formInput W225",
                LinearOutlay  = selSetting.IsLinear,
                //adding the ID of the control prevents problems with retrieving the posted back
                //data not being persisted to the meta input underlying controls
                //in a scenario when they are dynamically added to another control
                ID       = "MetaDropDown" + PrepareID(),
                SortType = (SelectableMetadataSortType)selSetting.SortType
            };

            dd.RefreshFromDataSource();
            Controls.Add(dd);
        }
Exemplo n.º 9
0
        protected void MakeLiveButton_Click(object sender, EventArgs e)
        {
            var saveCandidates = GetInputSettings();

            foreach (var setting in saveCandidates)
            {
                BrandMetadataSelectableSetting.Update(setting.SelectableSetting);
            }

            var b = Brand.Get(BrandId);

            b.FilterMarkup = MarkupTextBox.Text;
            Brand.Update(b);

            MainMultiView.ActiveViewIndex = 0;
            GeneralFeedbackLabel.SetSuccessMessage("changes were saved.");

            GroupSelectableTypeChanges.Clear();
            GroupSelectableRowsCountChanges.Clear();

            LoadPreviewState();
        }
        private void InitPresetTextArea(BrandMetadataSelectableSetting selSetting)
        {
            //=== add dropdown
            var dd = new MetadataDropDownList
            {
                BrandId       = BrandId,
                GroupNumber   = GroupNumber,
                OmitBlankItem = false,
                BlankText     = "Select to populate",
                BlankValue    = "0",
                CssClass      = "presetDropDown formInput W225",
                LinearOutlay  = selSetting.IsLinear,
                //adding the ID of the control prevents problems with retrieving the posted back
                //data not being persisted to the meta input underlying controls
                //in a scenario when they are dynamically added to another control
                ID = "MetadataDropDownList" + PrepareID()
            };

            dd.RefreshFromDataSource();
            Controls.Add(dd);
            //=== add the line break and then the text area
            Controls.Add(new Literal()
            {
                Text = "<br />"
            });

            var ta = new TextArea()
            {
                CssClass = "PanelTxt W225",
                Rows     = 6,
                Columns  = 30,
                //Width = "",
                //adding the ID of the control prevents problems with retrieving the posted back
                //data not being persisted to the meta input underlying controls
                //in a scenario when they are dynamically added to another control
                ID = "MetadataTextArea" + PrepareID()
            };

            Controls.Add(ta);

            //=== add the javascript/jquery logic for the presets selection
            //this is the url the ajax function will be calling to fetch back the respective metadata upon preset change
            var url = SiteUtils.GetWebsiteUrl("~/MetadataGetTextPreset.ashx?metadataId=");

            //ensure there is jquery included on the page
            if (IncludeJqueryReference)
            {
                Page.ClientScript.RegisterClientScriptInclude("jqueryinclude", "/Includes/Javascript/jQuery/jquery-1.4.1.min.js");
            }
            //function gets metadata val upon dropdown change and inserts it into the text area
            var script = String.Format(@"
                $(document).ready(function(){{
                        
                        var url = '{0}';
                        $('.presetDropDown').change(function(){{
                            
                            var metaId = $(this).val();
                            var tarea = $(this).parent().find('textarea');//nextAll('textarea');   
                            $.get(url + metaId, function(data){{
                                
                                $(tarea).val(data);
                            }});
                            
                            return false;
                        }});
                    }}
                 );", url);

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dropdownPresets", script, true);
        }
        public void InitInput(bool resetControls)
        {
            //ensure all is set or that we haven't been here already
            if (initCompleted || Controls.Count > 0)
            {
                return;
            }

            initCompleted = true;

            var setting = BrandMetaSetting;

            if (setting.UiControlType == (int)BrandMetadataUiControlType.Select)
            {
                var selSetting = setting.SelectableSetting;

                try
                {
                    switch ((SelectableMetadataType)selSetting.SelectableType)
                    {
                    case SelectableMetadataType.DropDown: InitDropDown(selSetting); break;

                    case SelectableMetadataType.ComboBox: InitComboBox(selSetting); break;

                    case SelectableMetadataType.RadioButtons: InitRadioButtons(selSetting); break;

                    case SelectableMetadataType.Checkboxes: InitCheckboxes(selSetting); break;

                    case SelectableMetadataType.PresetTextArea: InitPresetTextArea(selSetting); break;

                    default:
                        //if selectable hasn't been initialised yet go with the default setting i.e. a nested dropdown
                        InitDropDown(BrandMetadataSelectableSetting.GetDefault());
                        break;
                    }
                }
                catch (HttpException ex)
                {
                    //the type of underlying control that is being loaded was changed on the fly
                    //in a request before this one. now we are trying to set a control based on the
                    //database held settings and this results in a view state exception - probably
                    //the logic flow will deal with loading the right control after the Init event handler
                    //therefore don't do anything now and only return the control back without doing anything
                    if (ex.Message.ToLower().Contains("failed to load viewstate"))
                    {
                        return;
                    }

                    throw new Exception("An error occurred while loading the metadata input wrapper inner control(s) - check whether the right control is being loaded in the Init event handler.", ex);
                }
            }
            else if (setting.UiControlType == (int)BrandMetadataUiControlType.TextField)
            {
                InitTextField();
            }
            else if (setting.UiControlType == (int)BrandMetadataUiControlType.TextArea)
            {
                InitTextArea();
            }
            else
            {
                //if for some reason the BrandMetaSetting's UiControlType was not initialised go with the
                //default i.e. a nested dropdown
                InitDropDown(BrandMetadataSelectableSetting.GetDefault());
            }
        }