Source/NFX.Wave/Client/RecordModelGenerator.cs
/// <summary>
/// Generates JSON object suitable for passing into WV.RecordModel.Record(...) constructor on the client.
/// Pass target to select attributes targeted to ANY target or to the specified one, for example
///  may get attributes for client data entry screen that sees field metadata differently, in which case target will reflect the name
///   of the screen
/// </summary>
Generates JSON object suitable for passing into WV.RecordModel.Record(...) constructor on the client.
Pass target to select attributes targeted to ANY target or to the specified one, for example
may get attributes for client data entry screen that sees field metadata differently, in which case target will reflect the name
of the screen
Generates JSON object suitable for passing into WV . RecordModel . Record ( ... ) constructor on the client . Pass target to select attributes targeted to ANY target or to the specified one for example may get attributes for client data entry screen that sees field metadata differently in which case target will reflect the name of the screen
public virtual JSONDataMap RowToRecordInitJSON(Row row,
                                                     Exception validationError,
                                                     string recID = null,
                                                     string target = null,
                                                     string isoLang = null,
                                                     ModelFieldValueListLookupFunc valueListLookup = null)
      {
        var result = new JSONDataMap();
        if (row==null) return result;
        if (recID.IsNullOrWhiteSpace()) recID = Guid.NewGuid().ToString();
        result["OK"] = true;
        result["ID"] = recID;
        if (isoLang.IsNotNullOrWhiteSpace())
          result["ISOLang"] = isoLang;
        var form = row as FormModel;
        if (form != null)
        {
          result[FormModel.JSON_MODE_PROPERTY] = form.FormMode;
          result[FormModel.JSON_CSRF_PROPERTY] = form.CSRFToken;
          if (form.HasRoundtripBag)
            result[FormModel.JSON_ROUNDTRIP_PROPERTY] = form.RoundtripBag.ToJSON(JSONWritingOptions.CompactASCII);
        }
        var fields = new JSONDataArray();
        result["fields"] = fields;
        var schemaName = row.Schema.Name;
        if (row.Schema.TypedRowType!=null) schemaName = row.Schema.TypedRowType.FullName;
        foreach(var sfdef in row.Schema.FieldDefs.Where(fd=>!fd.NonUI))
        {
          var fdef = row.GetClientFieldDef(this, sfdef, target, isoLang);
          if (fdef==null || fdef.NonUI) continue;
          var fld = new JSONDataMap();
          fields.Add(fld);
          fld["def"] = FieldDefToJSON(row, schemaName, fdef, target, isoLang, valueListLookup);
          var val = row.GetClientFieldValue(this, sfdef, target, isoLang);
          if (val is GDID && ((GDID)val).IsZero) val = null;
          fld["val"] = val;
          var ferr = validationError as CRUDFieldValidationException;
          if (ferr!= null && ferr.FieldName==fdef.Name)
          {
            fld["error"] = ferr.ToMessageWithType();
            fld["errorText"] = OnLocalizeString(schemaName, "errorText", ferr.ClientMessage, isoLang);
          }
        }
        if (validationError!=null && !(validationError is CRUDFieldValidationException))
        {
          result["error"] = validationError.ToMessageWithType();
          result["errorText"] = OnLocalizeString(schemaName, "errorText", validationError.Message, isoLang);
        }
        return result;
      }
public virtual JSONDataMap RowToRecordInitJSON ( Row row , Exception validationError , string recID = null , string target = null , string isoLang = null , ModelFieldValueListLookupFunc valueListLookup = null ) { var result = new JSONDataMap ( ) ; if ( row == null ) return result ; if ( recID . IsNullOrWhiteSpace ( ) ) recID = Guid . NewGuid ( ) . ToString ( ) ; result [ " " ] = true ; result [ " " ] = recID ; if ( isoLang . IsNotNullOrWhiteSpace ( ) ) result [ " " ] = isoLang ; var form = row as FormModel ; if ( form != null ) { result [ FormModel . JSON_MODE_PROPERTY ] = form . FormMode ; result [ FormModel . JSON_CSRF_PROPERTY ] = form . CSRFToken ; if ( form . HasRoundtripBag ) result [ FormModel . JSON_ROUNDTRIP_PROPERTY ] = form . RoundtripBag . ToJSON ( JSONWritingOptions . CompactASCII ) ; } var fields = new JSONDataArray ( ) ; result [ " " ] = fields ; var schemaName = row . Schema . Name ; if ( row . Schema . TypedRowType != null ) schemaName = row . Schema . TypedRowType . FullName ; foreach ( var sfdef in row . Schema . FieldDefs . Where ( fd => ! fd . NonUI ) ) { var fdef = row . GetClientFieldDef ( this , sfdef , target , isoLang ) ; if ( fdef == null || fdef . NonUI ) continue ; var fld = new JSONDataMap ( ) ; fields . Add ( fld ) ; fld [ " " ] = FieldDefToJSON ( row , schemaName , fdef , target , isoLang , valueListLookup ) ; var val = row . GetClientFieldValue ( this , sfdef , target , isoLang ) ; if ( val is GDID && ( ( GDID ) val ) . IsZero ) val = null ; fld [ " " ] = val ; var ferr = validationError as CRUDFieldValidationException ; if ( ferr != null && ferr . FieldName == fdef . Name ) { fld [ " " ] = ferr . ToMessageWithType ( ) ; fld [ " " ] = OnLocalizeString ( schemaName , " " , ferr . ClientMessage , isoLang ) ; } } if ( validationError != null && ! ( validationError is CRUDFieldValidationException ) ) { result [ " " ] = validationError . ToMessageWithType ( ) ; result [ " " ] = OnLocalizeString ( schemaName , " " , validationError . Message , isoLang ) ; } return result ; }
Generates JSON object suitable for passing into WV.RecordModel.Record(...) constructor on the client.
Generates JSON object suitable for passing into WV . RecordModel . Record ( ... ) constructor on the client .
//20140914 DKh //20160123 DKh //field level exception //record level
row
Row
validationError
Exception
recID
string
target
string
isoLang
string
valueListLookup
ModelFieldValueListLookupFunc