Example #1
0
        public static HtmlString GetMagicSelect(int projectId, bool showCharacters, ShowImplicitGroups showGroups,
                                                MagicControlStrategy strategy, string propertyName, IEnumerable <string> elements, bool showSpecial)
        {
            var implicitGroupsString = GetImplicitGroupString(showGroups);

            var strategyString = GetStrategyString(strategy);

            //TODO: convert to verbatim
            var magicSelectFor = new HtmlString(string.Format(@"
      <div id=""{0}_control_{6}"" style=""max-width: 700px;width:100%""></div>
      <script type=""text/javascript"">
              $(function() {{
              var options = 
                {{
                  url: '/' + {1} + '/roles/{7}',
                  multiselect: true,
                  showcharacters: {2},
                  hiddenselect: {{ id: '{0}', name: '{0}' }},
                  implicitgroups: {3},
                  strategy: {{
                    type: '{4}',
                    elements: [{5}]
                  }},
                }};
            $('#{0}_control_{6}').multicontrol(options);
          }});
      </script>", propertyName, projectId, showCharacters ? "true" : "false", implicitGroupsString,
                                                              strategyString, elements.JoinStrings(", "), Random.Next(), showSpecial ? "json_full" : "json_real"));

            return(magicSelectFor);
        }
        private static string GetStrategyString(MagicControlStrategy strategy)
        {
            switch (strategy)
            {
            case MagicControlStrategy.Changer:
                return("changer");

            case MagicControlStrategy.NonChanger:
                return("nonchanger");

            default:
                throw new ArgumentOutOfRangeException(nameof(strategy), strategy, null);
            }
        }