changeset 310:aeeb0f534411

Added Base model class
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 09 Aug 2013 15:37:48 +0200
parents 51897f9a6bbb
children d80bb62b7fd4
files app/model/Base.js
diffstat 1 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/model/Base.js	Fri Aug 09 15:37:48 2013 +0200
@@ -0,0 +1,46 @@
+/**
+ * Base class for models
+ */
+Ext.define('Lada.model.Base', {
+    extend: 'Ext.data.Model',
+    requires: ['Lada.lib.Helpers'],
+    /**
+     * Define fields in the model
+     */
+    fields: [],
+    /**
+     * Define the property which is used as unique attribute in the model.
+     * This might cause problems whith combined PK in the database. See
+     * https://roundup-intern.intevation.de/bfs/issue30
+     */
+    idProperty: null,
+    /**
+     * Define the URL of the (REST) ressource where to query for this model
+     */
+    proxyUrl: null,
+    /**
+     * The Proxy used for this model. Defaults to a REST proxy which returns
+     * JSON. The payload is expected to be in a "data" node. The url of the
+     * proxy is configured in the proxyUrl attribute.
+     */
+    proxy: {
+        type: 'rest',
+        appendId: true, //default
+        url: this.proxyUrl,
+        reader: {
+            type: 'json',
+            root: 'data'
+        }
+    },
+    /**
+     * Helper function to build an ID which is used in the proxy calls. This
+     * function is a workaround for
+     * https://roundup-intern.intevation.de/bfs/issue30
+     * as some items can not be identified with a singe id.
+     */
+    getEidi: function() {
+        var kid =  this.get('kId');
+        var probeId = this.get('probeId');
+        return "/" + kid + "/" + probeId;
+    }
+});

http://lada.wald.intevation.org