auto create form from record definition
authorCornelius Weiß <c.weiss@metaways.de>
Tue, 5 Jul 2016 11:47:21 +0000 (13:47 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 5 Jul 2016 13:24:40 +0000 (15:24 +0200)
Change-Id: Iea00a4181abf8eb5b34d8c81203e6ea2ba083d4c
Reviewed-on: http://gerrit.tine20.com/customers/3306
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Tinebase.jsb2
tine20/Tinebase/js/widgets/dialog/EditDialog.js
tine20/Tinebase/js/widgets/form/RecordForm.js [new file with mode: 0644]

index eefb8ac..7f21a6c 100644 (file)
           "path": "js/widgets/form/"
         },
         {
+          "text": "RecordForm.js",
+          "path": "js/widgets/form/"
+        },
+        {
           "text": "Model.js",
           "path": "js/widgets/persistentfilter/"
         },
index 0d57682..e7f4820 100644 (file)
@@ -387,7 +387,7 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
                     border: false,
                     frame: true,
                     layout: 'border',
-                    items: [{
+                    items: [Ext.applyIf(this.getRecordFormItems(), {
                         region: 'center',
                         xtype: 'columnform',
                         labelAlign: 'top',
@@ -397,8 +397,7 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
                             labelSeparator: '',
                             columnWidth: 1/2
                         },
-                        items: this.getRecordFormItems()
-                    }].concat(this.getEastPanel())
+                    })].concat(this.getEastPanel())
                 }, new Tine.widgets.activities.ActivitiesTabPanel({
                     app: this.appName,
                     record_id: this.record.id,
@@ -456,29 +455,9 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
     },
 
     getRecordFormItems: function() {
-        // @TODO move to Tine.widgets.form.RecordForm to cope with group and sort
-        var items = [],
-            fieldNames = this.recordClass.getFieldNames(),
-            modelConfig = this.recordClass.getModelConfiguration(),
-            fieldsToExclude = ['description', 'tags', 'notes', 'attachments', 'relations', 'customfields'];
-
-        Ext.each(Tine.Tinebase.Model.genericFields, function(field) {fieldsToExclude.push(field.name)});
-        fieldsToExclude.push(this.recordClass.getMeta('idProperty'));
-
-        Ext.each(fieldNames, function(fieldName) {
-            var fieldDefinition = modelConfig.fields[fieldName];
-            // exclude: genericFields, idProperty, wellKnown(description, tags, customfields, relations, attachments, notes)
-            if (fieldsToExclude.indexOf(fieldDefinition.fieldName) < 0 && ! fieldDefinition.shy) {
-                var field = Tine.widgets.form.FieldManager.get(this.app, this.recordClass, fieldDefinition.fieldName);
-                if (field) {
-                    // apply basic layout
-                    field.columnWidth = 1;
-                    items.push([field]);
-                }
-            }
-        }, this);
-
-        return items;
+        return new Tine.widgets.form.RecordForm({
+            recordClass: this.recordClass
+        });
     },
 
     /**
diff --git a/tine20/Tinebase/js/widgets/form/RecordForm.js b/tine20/Tinebase/js/widgets/form/RecordForm.js
new file mode 100644 (file)
index 0000000..3447496
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Tine 2.0
+ *
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Cornelius Weiss <c.weiss@metaways.de>
+ * @copyright   Copyright (c) 2016 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+Ext.ns('Tine.widgets.form');
+
+/**
+ * Generic 'Edit Record' form
+ *
+ * @namespace   Tine.widgets.form
+ * @class       Tine.widgets.form.RecordForm
+ * @extends     Ext.ux.form.ColumnFormPanel
+ * @author      Cornelius Weiss <c.weiss@metaways.de>
+ * @constructor
+ * @param {Object} config The configuration options.
+ */
+
+Tine.widgets.form.RecordForm = Ext.extend(Ext.ux.form.ColumnFormPanel, {
+    /**
+     * record definition class  (required)
+     * @cfg {Ext.data.Record} recordClass
+     */
+    recordClass: null,
+
+    initComponent: function() {
+        var appName = this.recordClass.getAppName(),
+            app = Tine.Tinebase.appMgr.get(appName),
+            fieldNames = this.recordClass.getFieldNames(),
+            modelConfig = this.recordClass.getModelConfiguration(),
+            fieldsToExclude = ['description', 'tags', 'notes', 'attachments', 'relations', 'customfields'];
+
+        Ext.each(Tine.Tinebase.Model.genericFields, function(field) {fieldsToExclude.push(field.name)});
+        fieldsToExclude.push(this.recordClass.getMeta('idProperty'));
+
+        this.items = [];
+        Ext.each(fieldNames, function(fieldName) {
+            var fieldDefinition = modelConfig.fields[fieldName];
+            // exclude: genericFields, idProperty, wellKnown(description, tags, customfields, relations, attachments, notes)
+            if (fieldsToExclude.indexOf(fieldDefinition.fieldName) < 0 && ! fieldDefinition.shy) {
+                var field = Tine.widgets.form.FieldManager.get(app, this.recordClass, fieldDefinition.fieldName);
+                if (field) {
+                    // apply basic layout
+                    field.columnWidth = 1;
+                    this.items.push([field]);
+                }
+            }
+        }, this);
+
+        Tine.widgets.form.RecordForm.superclass.initComponent.call(this);
+    }
+
+});
+
+Ext.reg('recordform', Tine.widgets.form.RecordForm);
\ No newline at end of file