Esempio n. 1
0
        private Dictionary <string, string> GetFieldValues(object sender)
        {
            iLayer layer      = (iLayer)sender;
            var    parameters = new Dictionary <string, string>(layer.ActionParameters);

            foreach (Fieldset fieldset in layer.Items.OfType <Fieldset>())
            {
                System.Console.WriteLine(fieldset.Header);

                foreach (Field field in fieldset.Fields)
                {
                    System.Console.WriteLine(field.Label);

                    if (field is SelectListField)
                    {
                        SelectListField listField = (SelectListField)field;
                        for (int i = 0; i < listField.Items.Count; i++)
                        {
                            System.Console.WriteLine((i + 1) + ".  " + listField.Items[i].Value);
                        }
                        var item = listField.Items[Convert.ToInt32(System.Console.ReadLine()) - 1];
                        parameters[listField.ID + ".Key"] = item.Key;
                        parameters[listField.ID]          = item.Value;
                    }
                    else
                    {
                        parameters[field.ID] = System.Console.ReadLine();
                    }
                }
            }

            return(parameters);
        }
        public void Start()
        {
            ConfigField = configField as SelectListField;
            if (ConfigField == null)
            {
                return;
            }

            options          = ConfigField.GetOptions().ToDictionary(el => el.Key, el => el.Value);
            dropdown.Options = options.Select(el => new SearchableDropdown.OptionData(el.Key, el.Value)).ToList();
            (dropdown.OnItemSelected ?? (dropdown.OnItemSelected = new SearchableDropdown.DropdownEvent())).AddListener(AddNewItem);

            if (tooltipProvider)
            {
                tooltipProvider.SetContent(ConfigField.Tooltip);
            }

            if (fieldText)
            {
                fieldText.text = ConfigField.DisplayName;
            }

            var value = ConfigField.GetValue();

            foreach (var item in value)
            {
                AddNewItem(item, true);
            }
        }
Esempio n. 3
0
        private SelectListField <string> GetElementTypeSelectListField(long pageZoneElementId, Guid?elementTypeId, Dictionary <Guid, ElementType> allElementTypesById, IEnumerable <ElementType> availableElementTypes)
        {
            SelectListField <string> selectListField = new SelectListField <string>
            {
                Name                 = string.Format("element_{0}_elementType", pageZoneElementId),
                Label                = PageResource.PageZoneElementTypeLabel,
                Required             = true,
                RequiredErrorMessage = PageResource.PageZoneElementTypeRequiredMessage,
                Items                = new List <ListFieldItem <string> >()
            };

            if (elementTypeId.HasValue)
            {
                selectListField.Items.Add(new ListFieldItem <string> {
                    Name = allElementTypesById[elementTypeId.Value].Name, Value = elementTypeId.ToString()
                });
                selectListField.Value = elementTypeId.Value.ToString();
            }
            else if (availableElementTypes.Count() > 0)
            {
                foreach (ElementType elementType in availableElementTypes)
                {
                    selectListField.Items.Add(new ListFieldItem <string> {
                        Name = elementType.Name, Value = elementType.ElementTypeId.ToString()
                    });
                }
                selectListField.Value = availableElementTypes.First().ElementTypeId.ToString();
            }
            return(selectListField);
        }
        private SelectListField <string> GetPageSelectListField(long navBarTabId, long pageId, IEnumerable <Page> foldersAndDocuments)
        {
            SelectListField <string> selectListField = new SelectListField <string>
            {
                Name                 = string.Format("tab_{0}_page", navBarTabId),
                Label                = ElementResource.NavBarPageLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.NavBarTabPageRequiredMessage,
                Value                = pageId.ToString(),
                Items                = new List <ListFieldItem <string> >()
            };

            foreach (Page page in foldersAndDocuments)
            {
                selectListField.Items.Add(new ListFieldItem <string> {
                    Name = page.Name, Value = page.PageId.ToString()
                });
            }
            return(selectListField);
        }
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[0]);
            long     elementId = Convert.ToInt64(parts[1]);

            // Get current code snippet settings
            Guid elementTypeId = FormId;
            IAdvancedElementService elementService      = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
            CodeSnippetSettings     codeSnippetSettings = (CodeSnippetSettings)elementService.New(_authenticationService.TenantId);

            codeSnippetSettings.ElementId = elementId;
            elementService.Read(codeSnippetSettings);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };

            form.Fields.Add("code", new MultiLineTextField
            {
                Name                 = "code",
                Label                = ElementResource.CodeSnippetCodeLabel,
                Value                = codeSnippetSettings.Code,
                Rows                 = 10,
                Required             = true,
                RequiredErrorMessage = ElementResource.CodeSnippetCodeRequiredMessage
            });

            form.Fields.Add("language", new SelectListField <string>
            {
                Name  = "language",
                Label = ElementResource.CodeSnippetLanguageLabel,
                Value = Convert.ToString((int)codeSnippetSettings.Language),
                Items = new List <ListFieldItem <string> >()
            });
            SelectListField <string> selectListField = (SelectListField <string>)form.Fields["language"];

            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Apache), Value = Convert.ToString((int)Language.Apache)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Bash), Value = Convert.ToString((int)Language.Bash)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.CoffeeScript), Value = Convert.ToString((int)Language.CoffeeScript)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.CPlusPlus), Value = Convert.ToString((int)Language.CPlusPlus)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.CSharp), Value = Convert.ToString((int)Language.CSharp)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Css), Value = Convert.ToString((int)Language.Css)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Diff), Value = Convert.ToString((int)Language.Diff)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Html), Value = Convert.ToString((int)Language.Html)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Http), Value = Convert.ToString((int)Language.Http)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Ini), Value = Convert.ToString((int)Language.Ini)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Java), Value = Convert.ToString((int)Language.Java)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.JavaScript), Value = Convert.ToString((int)Language.JavaScript)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Json), Value = Convert.ToString((int)Language.Json)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Makefile), Value = Convert.ToString((int)Language.Makefile)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Markdown), Value = Convert.ToString((int)Language.Markdown)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Nginx), Value = Convert.ToString((int)Language.Nginx)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.ObjectiveC), Value = Convert.ToString((int)Language.ObjectiveC)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Perl), Value = Convert.ToString((int)Language.Perl)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Php), Value = Convert.ToString((int)Language.Php)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Python), Value = Convert.ToString((int)Language.Python)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Ruby), Value = Convert.ToString((int)Language.Ruby)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Sql), Value = Convert.ToString((int)Language.Sql)
            });
            selectListField.Items.Add(new ListFieldItem <string> {
                Name = _dataAnnotationsService.GetEnumDisplayName <Language>(Language.Xml), Value = Convert.ToString((int)Language.Xml)
            });
            form.SubmitLabel = ElementResource.CodeSnippetButtonLabel;

            // Return result
            return(form);
        }