private static void WriteModel(DextopJsWriter jw, DextopModel model) { jw.WriteLine("Ext.define('{0}',", model.Meta.ModelName); jw.WriteObject(model); jw.WriteLine(");"); jw.Flush(); }
private void WriteDictRecursively(DextopJsWriter jw, IList<DextopGridColumn> headers) { foreach (var field in headers) { if (field.HasColumns) WriteDictRecursively(jw, field.Columns); jw.Write("dict[\"{0}\"] = ", field.id); jw.WriteObject(field); jw.WriteLine(";"); } }
void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList<System.Reflection.Assembly> assemblies, Stream outputStream, Stream cacheStream) { var typeFilter = TypeFilter ?? ((x, y) => true); using (var w = new StreamWriter(outputStream)) { var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization); foreach (var assembly in assemblies) { var formTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly<DextopFormAttribute>(assembly, false); foreach (var formTypeAttribute in formTypes) if (typeFilter(formTypeAttribute.Key, this)) { var type = formTypeAttribute.Key; var formFields = DextopFormBuilder.BuildForm(type); var name = application.MapTypeName(type, ".form"); jw.Write("Ext.define('{0}', ", name); jw.StartLocalizationScope(); jw.StartBlock(); jw.AddProperty("extend", "Dextop.ItemFactory"); jw.StartFunctionBlock("getDictionary", "options"); jw.WriteLine("options = options || {};"); jw.WriteLine("options.data = options.data || {};"); jw.WriteLine("var dict = Ext.apply({}, options.apply);"); WriteDictRecursively(jw, formFields); jw.WriteLine("return dict;"); jw.CloseBlock(); jw.StartFunctionBlock("buildItems", "dict"); jw.Write("return ["); for (var i = 0; i < formFields.Count; i++) { if (i > 0) jw.Write(", "); if (formFields[i].ItemName != null) jw.Write("dict['{0}']", formFields[i].ItemName); else jw.WriteObject(formFields[i]); } jw.Write("];"); jw.CloseBlock();//function jw.WriteLocalizations(); jw.CloseBlock(); jw.WriteLine(");"); //Ext.define( jw.WriteLine(); jw.Flush(); } } } }
private void WriteDictRecursively(DextopJsWriter jw, IList<DextopFormObject> formFields) { foreach (var field in formFields) { WriteDictRecursively(jw, field.Items); if (field.ItemName != null) { jw.Write("dict[\"{0}\"] = ", field.ItemName); jw.WriteObject(field); jw.WriteLine(";"); } } }
/// <summary> /// Writes the children to the items property. /// </summary> /// <param name="jw">The jw.</param> protected override void WriteItems(DextopJsWriter jw) { if (Items.Count > 0) { jw.WritePropertyName("items"); jw.Write("["); bool first = true; if (PrependItems != null) foreach (var item in PrependItems) { if (first) first = false; else jw.Write(", "); jw.Write("dict['{0}']", item); } for (var i = 0; i < Items.Count; i++) { if (first) first = false; else jw.Write(", "); if (Items[i].ItemName != null) jw.Write("dict['{0}']", Items[i].ItemName); else jw.WriteObject(Items[i]); } if (AppendItems != null) foreach (var item in AppendItems) { if (first) first = false; else jw.Write(", "); jw.Write("dict['{0}']", item); } jw.Write("]"); } }
/// <summary> /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios. /// </summary> /// <param name="jw">The writer.</param> protected override void WriteProperties(DextopJsWriter jw) { if (id != dataIndex) jw.DefaultProperty("id", id); jw.AddLocalizationProperty("text", text, id + "Text"); jw.AddLocalizationProperty("tooltip", tooltip, id + "TooltipText"); jw.DefaultProperty("flex", flex); jw.DefaultProperty("width", width); jw.DefaultProperty("renderer", renderer); jw.DefaultProperty("format", format); jw.DefaultProperty("tpl", tpl); jw.DefaultProperty("align", align); jw.DefaultProperty("hidden", hidden); jw.DefaultProperty("sortable", sortable); if (_columns == null || _columns.Count == 0) { jw.AddProperty("dataIndex", dataIndex); jw.AddProperty("type", type); jw.DefaultProperty("required", required); jw.DefaultProperty("tooltipTpl", tooltipTpl); jw.DefaultProperty("readonly", readOnly); jw.DefaultProperty("menuDisabled", menuDisabled); jw.DefaultProperty("filterable", filterable); jw.DefaultProperty("locked", locked); jw.DefaultProperty("hasHeaderFilter", hasHeaderFilter); } else { jw.WritePropertyName("columns"); jw.Write("["); for (var i = 0; i < _columns.Count; i++) { if (i > 0) jw.Write(", "); if ((jw.Options & DextopJsWriterOptions.ItemFactory) != 0) jw.Write("dict[\"{0}\"]", _columns[i].id); else jw.WriteObject(_columns[i]); } jw.Write("]"); } base.WriteProperties(jw); }