public JsonResult SaveWebPart(string PageId, string WebPartObjectID, string WebPartID, string WebPartPost, string PublicValue, string PrivateValue) { return(this.ExecuteFunctionRun(() => { PageId = this.GetPageId(PageId); ActionResult result = new ActionResult(true); SiteWebPartInstance siteWebPaerInst = this.Engine.SiteManager.GetWebPartInst(WebPartObjectID); if (siteWebPaerInst != null) { this.InstId = siteWebPaerInst.ObjectID; } else { //添加插件到页面,初始化 this.AddWebPartToPage(WebPartID, PageId, WebPartPost, ""); } Dictionary <string, object> PublicParams = this.GetValue(PublicValue); Dictionary <string, object> PrivateParams = this.GetValue(PrivateValue); this.SavePublic(PublicParams); this.SavePrivate(PrivateParams); return Json(result, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 添加插件到页面,保存时 /// </summary> /// <param name="webpartId">部件id,唯一部件</param> /// <param name="pageId">00000000-0000-0000-0000-000000000000 Guid.NewGuid().ToString()</param> /// <param name="part">部件显示区域</param> /// <param name="webpartname"></param> public Dictionary <string, string> AddWebPartToPage(string webpartId, string pageId, string part, string webpartname) { Dictionary <string, string> result = new Dictionary <string, string>(); OThinker.H3.Site.SitePage page = this.Engine.SiteManager.GetPage(pageId); if (page == null || page == default(OThinker.H3.Site.SitePage)) { result.Add("Error", "页面不存在"); return(result); } SiteWebPartInstance inst = new SiteWebPartInstance(); int recordCount = 0; int pageCount = 0; SiteWebPartInstance[] webparts = this.Engine.SiteManager.GetAllWebPartInsts(); if (webparts != null && webparts.Length > 0) { int i = 0; foreach (SiteWebPartInstance webpart in webparts) { if (webpart.PagePart == part && webpart.PageId == pageId) { i++; } } recordCount = i; pageCount = recordCount % 1 > 0 ? recordCount / 1 + 1 : recordCount / 1; } inst.CreatedTime = DateTime.Now; inst.CreatedBy = UserValidatorFactory.CurrentUser.UserID; inst.PageId = pageId; inst.PagePart = part; inst.SortKey = recordCount + 1; inst.WebPartId = webpartId; List <SiteWebPartInstanceValue> source = new List <SiteWebPartInstanceValue>(); OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = "Title"; obj.AttributeType = AttributeType.PublicAttribute; obj.AttributeValue = webpartname; obj.InstanceId = webpartId; obj.ParentIndex = 1; source.Add(obj); inst.Attributes = source.ToArray(); this.Engine.SiteManager.AddWebPartInst(inst); result.Add("Success", inst.ObjectID); this.InstId = inst.ObjectID; return(result); }
/// <summary> /// 拖拽插件到其他位置 /// </summary> /// <param name="WebPartIDs">该位置的所有插件</param> /// <param name="PartID">位置id</param> /// <returns></returns> public JsonResult PageWebPartSort(string[] WebPartIDs, string PartID) { bool result = false; if (WebPartIDs == null || WebPartIDs.Length == 0) { } else { for (int i = 0; i < WebPartIDs.Length; i++) { SiteWebPartInstance webPart = this.Engine.SiteManager.GetWebPartInst(WebPartIDs[i]); if (webPart != null) { webPart.SortKey = i; webPart.PagePart = PartID; this.Engine.SiteManager.UpdateWebPartInst(webPart); } } result = true; } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取当前实例下plugin的所有私有属性 /// </summary> /// <returns></returns> protected List <OThinker.H3.Site.SiteWebPartPrivateAttribute> GetPrivateAttributes() { if (string.IsNullOrEmpty(this.InstId)) { return(new List <OThinker.H3.Site.SiteWebPartPrivateAttribute>()); } SiteWebPartInstance instance = Engine.SiteManager.GetWebPartInst(this.InstId); SiteWebPart[] parts = Engine.SiteManager.GetAllWebParts(); var attrs = parts.ToList().Where(e => e.ObjectID == instance.WebPartId).FirstOrDefault().PrivateAttributes; //替换本地语言 if (attrs != null) { foreach (var attr in attrs) { //attr.AttributeTitle = GetPrivateLanguageText(attr.AttributeName, attr.AttributeTitle); } return(attrs.ToList()); } return(null); }
/// <summary> /// 获取编辑部件的属性信息 /// </summary> /// <param name="InstanceID"></param> /// <returns></returns> public JsonResult GetWebPartInstEditValue(string InstanceID) { if (string.IsNullOrEmpty(InstanceID)) { return(Json("缺少参数[实例ID]", JsonRequestBehavior.AllowGet)); } SiteWebPartInstance webpart = this.Engine.SiteManager.GetWebPartInst(InstanceID); if (webpart == null) { return(Json("部件实例不存在", JsonRequestBehavior.AllowGet)); } List <ListItem> Item = new List <ListItem>(); SiteWebPartInstanceValue[] InstanceValue = webpart.Attributes; foreach (SiteWebPartInstanceValue item in InstanceValue) { string name = item.AttributeName; string value = item.AttributeValue; Item.Add(new ListItem(name, value)); } return(Json(Item, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 返回控件属性值 /// </summary> /// <param name="webpart"></param> /// <param name="AttrName"></param> /// <returns></returns> public string GetWebPartAttrValue(SiteWebPartInstance webpart, string AttrName) { string value = webpart.Attributes.ToList().Where(e => e.AttributeName == AttrName).Count() == 0 ? "" : webpart.Attributes.ToList().Where(e => e.AttributeName == AttrName).FirstOrDefault().AttributeValue; return(value); }
/// <summary> /// 统一保存配置 /// </summary> /// <param name="dict"></param> private void SaveConfigs(Dictionary <string, object> dict, AttributeType AttrType) { string instId = this.InstId; if (string.IsNullOrEmpty(instId)) { return; } //先找到PluginInstVal 对象,先删除再重新添加 SiteWebPartInstance instance = Engine.SiteManager.GetWebPartInst(instId); if (instance != null) { List <SiteWebPartInstanceValue> source = new List <SiteWebPartInstanceValue>(); if (instance.Attributes != null) { source = instance.Attributes.ToList(); var values = source.Where(e => e.AttributeType == AttrType).ToList(); if (values != null) { foreach (var value in values) { source.Remove((SiteWebPartInstanceValue)value); } } } //移除缓存,如果有的话 //PortalCache<string, string, string>.Instance.FindItem(PortalConst.CacheName_WebPartInstContent).Remove(instId); List <string> attrinfo = null; foreach (var pv in dict) { //如果不存在,就不保存了,确保属性一定要定义 if (!IsAttribteExists(pv.Key, AttrType)) { continue; } attrinfo = GetAttributeTypeAndFormat(pv.Key, AttrType); //多值状态,一个属性多个值,用List<string>传进来,其余的都用string if (pv.Value is List <string> ) { List <string> multiattrs = pv.Value as List <string>; int ix = 1;//给多值保存一个顺序 foreach (string str in multiattrs) { OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = pv.Key; obj.AttributeType = AttrType; obj.AttributeValue = str; // obj.BindType = attrinfo[0]; obj.Format = attrinfo[1]; obj.InstanceId = instId; obj.ParentIndex = ix; ix++; source.Add(obj); } } else { OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = pv.Key; obj.AttributeType = AttrType; obj.AttributeValue = pv.Value.ToString(); // obj.BindType = attrinfo[0]; obj.Format = attrinfo[1]; obj.InstanceId = instId; source.Add(obj); } } instance.Attributes = source.ToArray(); Engine.SiteManager.UpdateWebPartInst(instance); } }