Exemplo n.º 1
0
        /// <summary>
        /// 将UserPrefs组织成Table表现形式
        /// </summary>
        /// <param name="defaultUserPrefs">默认设置</param>
        /// <param name="personalUserPrefs">用户的个性化设置</param>
        /// <returns></returns>
        public static string GetUserPrefsTable(UserPrefCollection <UserPref> defaultUserPrefs, UserPrefsSaved personalUserPrefs)
        {
            StringBuilder sb = new StringBuilder("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\">");

            bool scriptAdded = false;

            for (int i = 0; i < defaultUserPrefs.Count; i++)
            {
                string value = personalUserPrefs.GetValueByName(defaultUserPrefs[i].Name);

                //此处不需要进行判断value的差异是因为当value为string.empty时ToHtml方法会自动按默认值输出
                sb.Append(defaultUserPrefs[i].ToHtml(value).Replace("__ITEM_INDEX__", i.ToString()));

                if (!scriptAdded && defaultUserPrefs[i].DataType == UserPrefDataType.ListType)
                {
                    scriptAdded = true;
                    sb.Insert(0, "<script>var listcontrol___MODULE_ID__ = new Array();function checklist___MODULE_ID__() {for (var i = 0; i < listcontrol___MODULE_ID__.length; i ++) {var inputFld = listcontrol___MODULE_ID__[i][0];var checkFunc = listcontrol___MODULE_ID__[i][1];if (inputFld.value &&inputFld.value.length > 0) {if(!checkFunc || checkFunc()) {inputFld.listApp.add();} else {inputFld.focus();inputFld.select();return false;}}}return true;};var checklist_submit___MODULE_ID__ = function(event) {if (!checklist___MODULE_ID__()) {return false;}return this.prev_submit(event);};var reset_list___MODULE_ID__ = function() {this.prev_reset();for (var i = 0; i < this.elements.length; i ++) {if (this.elements[i].listApp) {this.elements[i].listApp.reset();}}};_gel(\"m___MODULE_ID___form\").prev_reset = _gel(\"m___MODULE_ID___form\").reset;_gel(\"m___MODULE_ID___form\").reset = reset_list___MODULE_ID__;if (!_gel(\"m___MODULE_ID___form\").prev_submit) {_gel(\"m___MODULE_ID___form\").prev_submit = _gel(\"m___MODULE_ID___form\").onsubmit;_gel(\"m___MODULE_ID___form\").onsubmit = checklist_submit___MODULE_ID__;}</script>");
                }
            }
            if (defaultUserPrefs.ShowRequired)
            {
                sb.Append("<tr><td colspan=\"3\" align=\"left\"><font color=\"red\">* 为必填项</font></td></tr>");
            }
            sb.Append("</table>");
            return(sb.ToString());
        }
Exemplo n.º 2
0
        public ifr()
        {
            HttpContext.Current.Response.ContentType = "text/html";
//			if (ForumUtils.IsCrossSitePost(DNTRequest.GetUrlReferrer(), DNTRequest.GetHost()))
//				return;

//			if (userid < 1)
//				return;
            string     url        = DNTRequest.GetQueryString("url");
            int        mid        = DNTRequest.GetQueryInt("mid", 0);
            int        uid        = DNTRequest.GetQueryInt("uid", 0);
            ModuleInfo moduleinfo = Spaces.GetModuleById(mid, uid);

            if (moduleinfo == null)
            {
                return;
            }
            if (url != moduleinfo.ModuleUrl)
            {
                return;
            }
            UserPrefsSaved ups = new UserPrefsSaved(moduleinfo.UserPref);

            string        path           = BaseConfigs.GetForumPath + "space/modules/" + url;
            string        modulefilepath = Utils.GetMapPath(path);
            ModulePref    mp             = ModuleXmlHelper.LoadModulePref(modulefilepath);
            ModuleContent mc             = ModuleXmlHelper.LoadContent(modulefilepath);

#if NET1
            UserPrefCollection upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#else
            UserPrefCollection <UserPref> upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#endif

            StringBuilder registScript = new StringBuilder("<script type=\"text/javascript\">");
            foreach (UserPref up in upc)
            {
                string userprefvalue = ups.GetValueByName(up.Name);
                userprefvalue = userprefvalue == string.Empty ? up.DefaultValue : userprefvalue;
                registScript.AppendFormat(PREF_SCRIPT_FORMAT, mid, up.Name, userprefvalue);
            }
            registScript.Append(ModuleXmlHelper.GetModuleRequireScript(mp, mc.Type == ModuleContentType.HtmlInline));
            registScript.Append("</script>");
            string html = string.Format(IFRAME_HTML, registScript.ToString(), mc.ContentHtml, BaseConfigs.GetForumPath);
            html = html.Replace("__MODULE_ID__", mid.ToString()).Replace("_IG_", "_DS_");


            HttpContext.Current.Response.Write(html);
            HttpContext.Current.Response.End();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds the contents of another <see cref="UserPrefCollection">UserPrefCollection</see> to the end of the collection.
 /// </summary>
 /// <param name="value">A <see cref="UserPrefCollection">UserPrefCollection</see> containing the Components to add to the collection. </param>
 public void AddRange(UserPrefCollection value)
 {
     for (int i = 0; (i < value.Count); i = (i + 1))
     {
         if (((UserPref)value.List[i]).DataType != UserPrefDataType.HiddenType)
         {
             this._visibleItemCount++;
         }
         if (((UserPref)value.List[i]).Required)
         {
             this._showRequired = true;
         }
         this.Add((UserPref)value.List[i]);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 返回指定文件中的UserPref集合
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <returns></returns>
        public static UserPrefCollection <UserPref> LoadUserPrefs(string filename)
        {
            XmlDocument xmlfile = LoadXmlFile(filename);

            if (xmlfile == null)
            {
                return(null);
            }
            XmlNodeList xmlnodelist = xmlfile.SelectNodes("/Module/UserPref");

            if (xmlnodelist == null)
            {
                return(null);
            }

            UserPrefCollection <UserPref> upc = new UserPrefCollection <UserPref>();

            foreach (XmlNode xmlnode in xmlnodelist)
            {
                UserPref up = new UserPref();
                up.Name        = xmlnode.Attributes["name"] == null ? "" : xmlnode.Attributes["name"].Value;
                up.DisplayName = xmlnode.Attributes["display_name"] == null ? "" : xmlnode.Attributes["display_name"].Value;
                up.UrlParam    = xmlnode.Attributes["urlparam"] == null ? "" : xmlnode.Attributes["urlparam"].Value;
                up.DataType    = xmlnode.Attributes["datatype"] == null ? UserPrefDataType.StringType : ParseUserPrefDataType(xmlnode.Attributes["datatype"].Value);

                if (up.DataType == UserPrefDataType.EnumType)
                {
                    up.EnumValues = new Discuz.Common.Generic.List <EnumValue>();
                    XmlNodeList enumlist = xmlnode.SelectNodes("EnumValue");
                    foreach (XmlNode enumnode in enumlist)
                    {
                        EnumValue ev = new EnumValue();
                        ev.Value        = enumnode.Attributes["value"] == null ? "" : enumnode.Attributes["value"].Value;
                        ev.DisplayValue = enumnode.Attributes["display_value"] == null ? "" : enumnode.Attributes["display_value"].Value;
                        up.EnumValues.Add(ev);
                    }
                }

                up.Required     = xmlnode.Attributes["required"] == null ? false : Utils.StrToBool(xmlnode.Attributes["required"].Value, false);
                up.DefaultValue = xmlnode.Attributes["default_value"] == null ? "" : xmlnode.Attributes["default_value"].Value;
                upc.Add(up);
            }
            return(upc);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserPrefCollectionEnumerator">UserPrefCollectionEnumerator</see> class referencing the specified <see cref="UserPrefCollection">UserPrefCollection</see> object.
 /// </summary>
 /// <param name="mappings">The <see cref="UserPrefCollection">UserPrefCollection</see> to enumerate.</param>
 public UserPrefCollectionEnumerator(UserPrefCollection mappings)
 {
     _temp       = ((IEnumerable)(mappings));
     _enumerator = _temp.GetEnumerator();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserPrefCollection">UserPrefCollection</see> class containing the elements of the specified source collection.
 /// </summary>
 /// <param name="value">A <see cref="UserPrefCollection">UserPrefCollection</see> with which to initialize the collection.</param>
 public UserPrefCollection(UserPrefCollection value)
 {
     this.AddRange(value);
 }