public override void ToJSON(JObject ParentObject) { CswDateTime CswDate = new CswDateTime(_CswNbtResources, DateTimeValue); ParentObject[_DateValueSubField.ToXmlNodeName(true)] = CswDate.ToClientAsDateTimeJObject(); ParentObject["displaymode"] = DisplayMode.ToString(); }
public override void ToJSON(JObject ParentObject) { ParentObject[_ValueSubField.ToXmlNodeName(true)] = Value.ToString(); ParentObject["width"] = Width; ParentObject["height"] = Height; ParentObject["allowmultiple"] = AllowMultiple; ParentObject["imageprefix"] = ImagePrefix; // To preserve order of the displaying/printing of pictorgrams, // this must be an array. JArray OptionsArr = new JArray(); ParentObject["options"] = OptionsArr; foreach (string Key in Options.Keys) { bool isSelected = Value.Contains(Key); if (IsEditModeEditable || isSelected) { JObject Opt = new JObject(); Opt["text"] = Options[Key]; Opt["value"] = Key; Opt["selected"] = isSelected; OptionsArr.Add(Opt); } } } // ToJSON()
// ToXml() public override void ToJSON(JObject ParentObject) { ParentObject[_SelectedUserIdsSubField.ToXmlNodeName()] = SelectedUserIds.ToString(); ParentObject[ElemName_Options] = new JObject(); CswCheckBoxArrayOptions CBAOptions = new CswCheckBoxArrayOptions(); CBAOptions.Columns.Add("Include"); DataTable Data = getUserOptions(); foreach (DataRow Row in Data.Rows) { bool isSelected = SelectedUserIds.Contains(Row[KeyColumn]); if (IsEditModeEditable || isSelected) { CswCheckBoxArrayOptions.Option Option = new CswCheckBoxArrayOptions.Option(); Option.Key = Row[KeyColumn].ToString(); Option.Label = Row[NameColumn].ToString(); Option.Values.Add(CswConvert.ToBoolean(Row[ValueColumn])); CBAOptions.Options.Add(Option); } } CBAOptions.ToJSON((JObject)ParentObject[ElemName_Options]); }
public override void ToJSON(JObject ParentObject) { ParentObject[_CachedValueSubField.ToXmlNodeName(true)] = CachedValue; ParentObject["useSequence"] = UseSequence.ToString(); ParentObject[_SequenceSubField.ToXmlNodeName(true)] = Sequence; ParentObject[_SequenceNumberSubField.ToXmlNodeName(true)] = SequenceNumber; }
public override void ToJSON(JObject ParentObject) { ParentObject[_MolSubField.ToXmlNodeName(true)] = getMol(); ParentObject["column"] = _MolSubField.Column.ToString().ToLower(); ParentObject["href"] = getLink(JctNodePropId, NodeId); ParentObject["placeholder"] = "Images/icons/300/_placeholder.gif"; }
public override void ToJSON( JObject ParentObject ) { ParentObject[_SelectedViewIdsSubField.ToXmlNodeName()] = SelectedViewIds.ToString(); ParentObject["selectmode"] = SelectMode.ToString(); ParentObject[_CachedViewNameSubField.ToXmlNodeName()] = CachedViewNames.ToString(); ParentObject[ElemName_Options] = new JObject(); CswCheckBoxArrayOptions CBAOptions = new CswCheckBoxArrayOptions(); CBAOptions.Columns.Add( "Include" ); DataTable ViewsTable = ViewsForCBA(); foreach( DataRow ViewRow in ViewsTable.Rows ) { bool isSelected = SelectedViewIds.Contains( ViewRow[KeyColumn] ); if( IsEditModeEditable || isSelected ) { CswCheckBoxArrayOptions.Option Option = new CswCheckBoxArrayOptions.Option(); Option.Key = ViewRow[KeyColumn].ToString(); Option.Label = ViewRow[NameColumn].ToString(); Option.Values.Add( CswConvert.ToBoolean( ViewRow[ValueColumn] ) ); CBAOptions.Options.Add( Option ); } } CBAOptions.ToJSON( (JObject) ParentObject[ElemName_Options] ); } // ToJSON()
//private string _ElemName_Value = "Value"; public override void ToJSON(JObject ParentObject) { ParentObject[_TextSubField.ToXmlNodeName(true)] = Text; ParentObject["size"] = Size; ParentObject["maxlength"] = MaxLength; ParentObject["regex"] = RegEx; ParentObject["regexmsg"] = RegExMsg; }
public override void ToJSON(JObject ParentObject) { ParentObject[_NodeIdSubField.ToXmlNodeName(true)] = string.Empty; ParentObject[_NameSubField.ToXmlNodeName(true)] = string.Empty; ParentObject[_PathSubField.ToXmlNodeName(true)] = string.Empty; ParentObject[_BarcodeSubField.ToXmlNodeName(true)] = string.Empty; //ParentObject["search"] = false; CswNbtNode SelectedNode = _CswNbtResources.Nodes[SelectedNodeId]; if (null != SelectedNode) { ParentObject[_NodeIdSubField.ToXmlNodeName(true)] = SelectedNode.NodeId.ToString(); ParentObject[_NameSubField.ToXmlNodeName(true)] = CachedNodeName; ParentObject[_PathSubField.ToXmlNodeName(true)] = CachedPath; ParentObject[_BarcodeSubField.ToXmlNodeName(true)] = CachedBarcode; ParentObject["selectednodelink"] = SelectedNode.NodeLink; } if (IsEditModeEditable) { //Case 30335 - This is required for Allow Inventory to work properly View.SaveToCache(false); ParentObject["viewid"] = View.SessionViewId.ToString(); CswNbtMetaDataObjectClass LocationOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass); ParentObject["locationobjectclassid"] = LocationOC.ObjectClassId.ToString(); JArray LocationNTArray = new JArray(); foreach (CswNbtMetaDataNodeType LocationNT in LocationOC.getNodeTypes()) { LocationNTArray.Add(LocationNT.NodeTypeId); } ParentObject["locationnodetypeids"] = LocationNTArray; //TODO: Remove if David approves Location control always searching // If the # of locations in the system is > than the relationshipoptionlimit, then do a search //int LocationNodeCnt = getNumberOfLocationNodes( _CswNbtResources ); //if( LocationNodeCnt <= _SearchThreshold ) //{ // CswNbtSdLocations Sd = new CswNbtSdLocations( _CswNbtResources ); // JArray Options = new JArray(); // foreach( CswNbtSdLocations.Location location in Sd.GetLocationsList( View.SessionViewId.ToString() ) ) // { // JObject Opt = new JObject(); // Opt["LocationId"] = location.LocationId; // Opt["Name"] = location.Name; // Opt["Path"] = location.Path; // Opt["Disabled"] = location.Disabled; // Options.Add( Opt ); // } // ParentObject["options"] = Options; //} //else //{ // ParentObject["search"] = true; // ParentObject["options"] = ""; //} } }
} // _countProblems() public override void ToJSON(JObject ParentObject) { CswDateTime CswDate = new CswDateTime(_CswNbtResources, StartDateTime); ParentObject.Add(new JProperty(_StartDateTimeSubField.ToXmlNodeName(true), CswDate.ToClientAsDateTimeJObject())); ParentObject[_ValueSubField.ToXmlNodeName(true)] = CachedValue.ToString(); ParentObject[_UnitsSubField.ToXmlNodeName(true)] = Units; }
//private string _ElemName_Rateinterval = "Rateinterval"; public override void ToJSON(JObject ParentObject) { JObject IntervalObj = new JObject(); ParentObject[_IntervalSubField.ToXmlNodeName()] = IntervalObj; ParentObject["allowHourly"] = AllowHourly; //IntervalObj["text"] = RateInterval.ToString(); RateInterval.ToJson(IntervalObj); }
public override void ToJSON(JObject ParentObject) { ParentObject[_RedSubField.ToXmlNodeName(true)] = Red; ParentObject[_YellowSubField.ToXmlNodeName(true)] = Yellow; ParentObject[_BlueSubField.ToXmlNodeName(true)] = Blue; ParentObject[_WhiteSubField.ToXmlNodeName(true)] = White; ParentObject["displaymode"] = DisplayMode.ToString(); ParentObject["hidespecial"] = HideSpecial; }
public override void ToJSON(JObject ParentObject) { ParentObject[_RawFormulaTextSubfield.ToXmlNodeName(true)] = Text; ParentObject["formattedText"] = _parseChemicalFormula(Text); ParentObject["size"] = Size; ParentObject["maxlength"] = MaxLength; ParentObject["regex"] = RegEx; ParentObject["regexmsg"] = RegExMsg; }
public override void ToJSON(JObject ParentObject) { ParentObject[_LowerSubField.ToXmlNodeName(true)] = (!Double.IsNaN(Lower)) ? Lower.ToString() : string.Empty; ParentObject[_TargetSubField.ToXmlNodeName(true)] = (!Double.IsNaN(Target)) ? Target.ToString() : string.Empty; ParentObject[_UpperSubField.ToXmlNodeName(true)] = (!Double.IsNaN(Upper)) ? Upper.ToString() : string.Empty; ParentObject[_LowerInclusiveSubField.ToXmlNodeName(true)] = LowerInclusive; ParentObject[_UpperInclusiveSubField.ToXmlNodeName(true)] = UpperInclusive; ParentObject[_UnitsSubField.ToXmlNodeName(true)] = Units; ParentObject["minvalue"] = MinValue.ToString(); ParentObject["maxvalue"] = MaxValue.ToString(); ParentObject["precision"] = Precision; ParentObject["excludeRangeLimits"] = ExcludeRangeLimits; }
public override void ToJSON(JObject ParentObject) { ParentObject[_TextSubField.ToXmlNodeName(true)] = Text; ParentObject[_ValueSubField.ToXmlNodeName(true)] = Value; ParentObject["search"] = false; if (IsEditModeEditable) { if (Options.Options.Count <= _SearchThreshold) { // Make sure the selected value is in the list of options (originally case 28020) // TODO: When we use WCF, we can just serialize Options directly JArray OptionsArr = new JArray(); bool foundValue = false; foreach (CswNbtNodeTypePropListOption o in Options.Options) { foundValue = foundValue || (o.Value == Value); JObject Opt = new JObject(); Opt["Text"] = o.Text; Opt["Value"] = o.Value; OptionsArr.Add(Opt); } if (false == foundValue) { // We don't want to send an empty option if the property is required if (false == string.IsNullOrEmpty(Value) || false == string.IsNullOrEmpty(Text) || false == _CswNbtMetaDataNodeTypeProp.IsRequired) { JObject Opt = new JObject(); Opt["Text"] = Text; Opt["Value"] = Value; OptionsArr.Add(Opt); } } ParentObject["options"] = OptionsArr; // To search or not to search if ((Options.Options.Count == 1 && (string.IsNullOrEmpty(Options.Options[0].Text) && string.IsNullOrEmpty(Options.Options[0].Value))) || _CswNbtMetaDataNodeTypeProp.IsRequired && Options.Options.Count == 0) { ParentObject["search"] = true; } } else { ParentObject["search"] = true; ParentObject["options"] = ""; } } // if( ForEdit ) } // ToJSON()
public override void ToJSON(JObject ParentObject) { CswNbtView View = _CswNbtResources.ViewSelect.restoreView(ViewId); if (null != View) { ParentObject[_ViewIdSubField.ToXmlNodeName(true)] = ViewId.ToString(); ParentObject["viewmode"] = View.ViewMode.ToString().ToLower(); ParentObject[_CachedViewNameSubField.ToXmlNodeName(true)] = CachedViewName; } else { ParentObject[_ViewIdSubField.ToXmlNodeName(true)] = string.Empty; ParentObject["viewmode"] = string.Empty; ParentObject[_CachedViewNameSubField.ToXmlNodeName(true)] = string.Empty; } }
public override void ToJSON(JObject ParentObject) { ParentObject[_ValueSubField.ToXmlNodeName(true)] = Value.ToString(); if (IsEditModeEditable) { JArray OptionsArray = new JArray(); ParentObject["options"] = OptionsArray; foreach (string Key in Options.Keys) { JObject NewOption = new JObject(); NewOption["text"] = Options[Key]; NewOption["value"] = Key; NewOption["selected"] = Value.Contains(Key).ToString().ToLower(); OptionsArray.Add(NewOption); } } ParentObject["readonlyless"] = CollapsedReadOnlyValue; ParentObject["readonlymore"] = ExpandedReadOnlyValue; } // ToJSON()
public override void ToJSON(JObject ParentObject) { if (false == Double.IsNaN(Base)) { ParentObject[_BaseSubField.ToXmlNodeName(true)] = Base.ToString(); } else { ParentObject[_BaseSubField.ToXmlNodeName(true)] = string.Empty; } if (Int32.MinValue != Exponent) { ParentObject[_ExponentSubField.ToXmlNodeName(true)] = Exponent; } else { ParentObject[_ExponentSubField.ToXmlNodeName(true)] = string.Empty; } ParentObject["minvalue"] = MinValue.ToString(); ParentObject["precision"] = Precision; }
public override void ToJSON(JObject ParentObject) { if (IsEditModeEditable) { ParentObject[_EncryptedPasswordSubField.ToXmlNodeName(true)] = EncryptedPassword; ParentObject["passwordcomplexity"] = PasswordComplexity; ParentObject["passwordlength"] = PasswordLength; ParentObject["newpassword"] = string.Empty; ParentObject["isexpired"] = IsExpired; if (_CswNbtResources.CurrentNbtUser.IsAdministrator()) { ParentObject["expire"] = IsExpired; // case 30227 ParentObject["isadmin"] = true; } else { ParentObject["expire"] = false; ParentObject["isadmin"] = false; } } }
public override void ToJSON(JObject ParentObject) { ParentObject[_AnswerSubField.ToXmlNodeName(true)] = Answer; if (IsEditModeEditable) { ParentObject["allowedanswers"] = "," + AllowedAnswersString; ParentObject["compliantanswers"] = CompliantAnswersString; } ParentObject[_CommentsSubField.ToXmlNodeName(true)] = Comments; ParentObject[_CorrectiveActionSubField.ToXmlNodeName(true)] = CorrectiveAction; ParentObject[_IsCompliantSubField.ToXmlNodeName(true)] = IsCompliant; ParentObject["isactionrequired"] = IsActionRequired; ParentObject["isanswereditable"] = IsAnswerEditable; CswDateTime CswDateAnswered = new CswDateTime(_CswNbtResources, DateAnswered); ParentObject[_DateAnsweredSubField.ToXmlNodeName(true)] = CswDateAnswered.ToClientAsDateTimeJObject(); CswDateTime CswDateCorrected = new CswDateTime(_CswNbtResources, DateCorrected); ParentObject[_DateCorrectedSubField.ToXmlNodeName(true)] = CswDateCorrected.ToClientAsDateTimeJObject(); }
public override void ToJSON(JObject ParentObject) { ParentObject[_ValueSubField.ToXmlNodeName(true)] = (!Double.IsNaN(Value)) ? Value.ToString() : string.Empty; ParentObject["minvalue"] = MinValue.ToString(); ParentObject["maxvalue"] = MaxValue.ToString(); ParentObject["precision"] = Precision; ParentObject["excludeRangeLimits"] = ExcludeRangeLimits; }
public override void ToJSON(JObject ParentObject) { JArray _CommentsJson = CommentsJson; foreach (JObject jr in _CommentsJson) { //converting each output row datetime to local user display format jr["datetime"] = new CswDateTime(_CswNbtResources, CswConvert.ToDateTime(jr["datetime"])).ToClientAsDateTimeString(); } ParentObject[_CommentSubField.ToXmlNodeName(true)] = _CommentsJson; ParentObject["rows"] = Rows.ToString(); ParentObject["columns"] = Columns.ToString(); ParentObject["newmessage"] = ""; }
public override void ToJSON(JObject ParentObject) { ParentObject["selectedvalue"] = SelectedValue; if (IsEditModeEditable) { JArray OptionsArr = new JArray(); JObject foundValue = null; foreach (CswNbtNodeTypePropListOption o in Options.Options) { JObject Opt = new JObject(); Opt["text"] = o.Text; Opt["value"] = o.Value; OptionsArr.Add(Opt); if (o.Value == SelectedValue) { foundValue = Opt; } } // Make sure the selected value is in the list of options (originally case 28020) if (null == foundValue) { JObject Opt = new JObject(); Opt["text"] = Text; Opt["value"] = SelectedValue; OptionsArr.Insert(0, Opt); foundValue = Opt; } ParentObject["options"] = OptionsArr; ParentObject[_TextSubField.ToXmlNodeName(true)] = foundValue["text"]; } else { ParentObject[_TextSubField.ToXmlNodeName(true)] = Text; } } // ToJSON()
public override void ToJSON(JObject ParentObject) { ParentObject[_TextSubField.ToXmlNodeName(true)] = StaticText; ParentObject["rows"] = Rows; ParentObject["columns"] = Columns; }
public override void ToJSON(JObject ParentObject) { ParentObject[_ContentTypeSubField.ToXmlNodeName(true)] = ContentType; ParentObject[_FileNameSubField.ToXmlNodeName(true)] = FileName; ParentObject[CswEnumNbtSubFieldName.Href.ToString().ToLower()] = Href; }
public override void ToJSON(JObject ParentObject) { ParentObject[_TextSubField.ToXmlNodeName(true)] = Text; ParentObject["size"] = Size.ToString(); }
public override void ToJSON(JObject ParentObject) { ParentObject[_SequenceSubField.ToXmlNodeName(true)] = Sequence; ParentObject[_SequenceNumberSubField.ToXmlNodeName(true)] = SequenceNumber; }
public override void ToJSON(JObject ParentObject) { ParentObject[_CachedValueSubField.ToXmlNodeName(true)] = CachedValue; }
public override void ToJSON( JObject ParentObject ) { CswNbtNode RelatedNode = null; if( CswTools.IsPrimaryKey( RelatedNodeId ) ) { //ParentObject[_NodeIDSubField.ToXmlNodeName( true ).ToLower()] = RelatedNodeId.ToString(); RelatedNode = _CswNbtResources.Nodes[RelatedNodeId]; } if( IsEditModeEditable ) { JArray JOptions = (JArray) ( ParentObject["options"] = new JArray() ); bool AllowEdit = _CswNbtResources.Permit.isPropWritable( CswEnumNbtNodeTypePermission.Create, NodeTypeProp, null ); Int32 OptionCount = 0; if( AllowEdit ) { CswPrimaryKey pk = null; if( null != RelatedNode ) { pk = RelatedNode.NodeId; } //Dictionary<CswPrimaryKey, string> Options = _OptionsOverride ?? _getOptions( _CswNbtResources, _CswNbtMetaDataNodeTypeProp.IsRequired, _CswNbtMetaDataNodeTypeProp.FKValue, pk, View ); Dictionary<CswPrimaryKey, string> Options = _OptionsOverride ?? _getOptions( _CswNbtResources, CswConvert.ToBoolean( _CswNbtNodePropData[CswNbtFieldTypeRuleRelationship.AttributeName.Required] ), CswConvert.ToInt32( _CswNbtNodePropData[CswNbtFieldTypeRuleRelationship.AttributeName.Target, CswNbtFieldTypeRuleMetaDataList.SubFieldName.Id] ), pk, View ); if( Options.Count > _SearchThreshold ) { ParentObject["usesearch"] = true; } else { ParentObject["usesearch"] = false; CswPrimaryKey FirstPk = null; foreach( CswPrimaryKey NodePk in Options.Keys ) { if( CswTools.IsPrimaryKey( NodePk ) ) { OptionCount += 1; JObject JOption = new JObject(); FirstPk = FirstPk ?? NodePk; JOption["id"] = NodePk.ToString(); JOption["value"] = Options[NodePk]; JOption["link"] = CswNbtNode.getNodeLink( NodePk, Options[NodePk] ); JOptions.Add( JOption ); } } //If Required, show empty when no value is selected and if there is more than one option to select from bool ShowEmptyOption = Required && false == CswTools.IsPrimaryKey( RelatedNodeId ) && 1 < OptionCount; //If not Required, always show the empty value ShowEmptyOption = ShowEmptyOption || false == Required; if( ShowEmptyOption ) { JObject JOption = new JObject(); JOption["id"] = ""; JOption["value"] = ""; JOptions.AddFirst( JOption ); } else { //Case 30030 if( null == RelatedNode && Required && Options.Count == 1 && CswTools.IsPrimaryKey( FirstPk ) ) { RelatedNode = _CswNbtResources.Nodes[FirstPk]; } } } } ParentObject["nodetypeid"] = 0; ParentObject["objectclassid"] = 0; ParentObject["propertysetid"] = 0; bool AllowAdd = false; bool AllowView = true; if( null != RelatedNodeId ) { CswNbtMetaDataNodeType TargetNodeType = _CswNbtResources.MetaData.getNodeTypeFromNodeId( RelatedNodeId ); AllowAdd = ( null != TargetNodeType && _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.Create, TargetNodeType ) ); AllowView = ( null != TargetNodeType && _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.View, TargetNodeType ) ); } else if( TargetType == CswEnumNbtViewRelatedIdType.NodeTypeId ) { ParentObject["nodetypeid"] = TargetId; CswNbtMetaDataNodeType TargetNodeType = _CswNbtResources.MetaData.getNodeType( TargetId ); AllowAdd = ( null != TargetNodeType && _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.Create, TargetNodeType ) ); AllowView = ( null != TargetNodeType && _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.View, TargetNodeType ) ); } else if( TargetType == CswEnumNbtViewRelatedIdType.ObjectClassId ) { ParentObject["objectclassid"] = TargetId; CswNbtMetaDataObjectClass TargetObjectClass = _CswNbtResources.MetaData.getObjectClass( TargetId ); AllowAdd = ( null != TargetObjectClass && TargetObjectClass.CanAdd && TargetObjectClass.getNodeTypes().Any( nt => _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.Create, nt ) ) ); if( false == AllowAdd ) { AllowView = ( null != TargetObjectClass && TargetObjectClass.getNodeTypes().Any( nt => _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.View, nt ) ) ); } } else if( TargetType == CswEnumNbtViewRelatedIdType.PropertySetId ) { ParentObject["propertysetid"] = TargetId; CswNbtMetaDataPropertySet TargetPropSet = _CswNbtResources.MetaData.getPropertySet( TargetId ); AllowAdd = TargetPropSet.getObjectClasses().Any( oc => null != oc && oc.CanAdd && oc.getNodeTypes().Any( nt => _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.Create, nt ) ) ); if( false == AllowAdd ) { AllowView = TargetPropSet.getObjectClasses().Any( oc => null != oc && oc.getNodeTypes().Any( nt => _CswNbtResources.Permit.canNodeType( CswEnumNbtNodeTypePermission.View, nt ) ) ); } } ParentObject["allowadd"] = AllowAdd; ParentObject["allowview"] = AllowView; if( null != View ) { ParentObject["viewid"] = View.ViewId.ToString(); if( AllowEdit && OptionCount == 0 ) { ParentObject["doGetNodes"] = true; } } } // if( ForEdit ) ParentObject[_NodeIDSubField.ToXmlNodeName( true ).ToLower()] = string.Empty; ParentObject[_NameSubField.ToXmlNodeName( true ).ToLower()] = CachedNodeName; ParentObject["relatednodeid"] = string.Empty; ParentObject["relatednodelink"] = string.Empty; if( null != RelatedNode ) { ParentObject[_NodeIDSubField.ToXmlNodeName( true ).ToLower()] = RelatedNode.NodeId.ToString(); ParentObject[_NameSubField.ToXmlNodeName( true ).ToLower()] = RelatedNode.NodeName; ParentObject["relatednodeid"] = RelatedNode.NodeId.ToString(); ParentObject["relatednodelink"] = RelatedNode.NodeLink; } } // ToJSON()
public override void ToJSON(JObject ParentObject) { ParentObject[_HrefSubField.ToXmlNodeName(true)] = Href; ParentObject[_TextSubField.ToXmlNodeName(true)] = Text; ParentObject["url"] = GetFullURL(Prefix, Href, Suffix); }
public override void ToJSON(JObject ParentObject) { //! the data should be stored this way in the DB and not transformed into it, but we can't do this in Magnolia because of design mode and field type shenanigans /* * data is coming from the server in two dictionaries: a mapping of value to string, and an array of held permissions * Options: { * 'nt_1_Create': 'Role', * 'nt_1_tab_1_View': 'Role, Role', * ... * } * Values: [ * 'nt_1_Create', * 'nt_1_tab_5_Create', * ... * ] * * We need it in the format: Options: [ * { name: 'Role', * Create: true, * Edit: true, * Delete: true, * View: true, * Children: [ * { name: 'Role Tab', * Create: true, * Edit: true, * Delete: true, * View: true, * leaf: true * }] * }, * ... * ] * */ ParentObject[_ValueSubField.ToXmlNodeName(true)] = Value.ToString(); JObject OptionsArray = new JObject(); ParentObject["options"] = OptionsArray; //first build the skeleton of the object we want to return foreach (CswNbtMetaDataNodeType NT in _CswNbtResources.MetaData.getNodeTypes()) { JObject NewNT = new JObject(); NewNT["itemname"] = NT.NodeTypeName; NewNT["create"] = false; NewNT["edit"] = false; NewNT["view"] = false; NewNT["delete"] = false; NewNT["itemid"] = NT.NodeTypeId; JArray Children = new JArray(); foreach (CswNbtMetaDataNodeTypeTab Tab in NT.getNodeTypeTabs()) { JObject NewTab = new JObject(); NewTab["itemname"] = Tab.TabName + " Tab"; NewTab["create"] = false; NewTab["edit"] = false; NewTab["view"] = false; NewTab["delete"] = false; NewTab["itemid"] = Tab.TabId; NewTab["leaf"] = true; Children.Add(NewTab); } NewNT["children"] = Children; OptionsArray[NT.NodeTypeId.ToString()] = NewNT; } //now iterate the values we've stored and assign them to the correct permissions in the skeleton: foreach (string Permission in Value) { string[] PermissionComponents = Permission.Split('_'); bool IsTab = PermissionComponents.Length == 5; string Nodetype = PermissionComponents[1]; string PermissionCategory = PermissionComponents[PermissionComponents.Length - 1].ToLower(); //our permissions data needs a good cleaning... there are invalid nodetypes in the Values dictionary if (ParentObject["options"][Nodetype] != null) { if (false == IsTab) { //if we're not dealing with a tab, we can just set the proper permission ParentObject["options"][Nodetype][PermissionCategory] = true; } else { string TabId = PermissionComponents[3]; //for tabs we have no choice but to iterate to find the correct tab, because of client-side restrictions foreach (JObject Tab in ParentObject["options"][Nodetype]["children"]) { if (Tab["itemid"].ToString() == TabId.ToString()) { Tab[PermissionCategory] = true; } } //for each tab in the returned JObject } //else -- if the permission is a tab } //if this nodetype exists } //for each permission stored in the database } // ToJSON()