Move to new model standard
authorMichael Spahn <m.spahn@metaways.de>
Wed, 22 Aug 2012 08:10:07 +0000 (10:10 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Thu, 4 Oct 2012 13:54:56 +0000 (15:54 +0200)
Define $_defaultModel for Inventory
Add default model to controller

Remove unneeded JS files and remove from jsb file

Migrate to new modelling system

Change-Id: I5e0ec3d3d2d5b06572aafa09ad3a9d8a3272cd4a
Reviewed-on: https://gerrit.tine20.org/tine20/962
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: jenkins user
tine20/Inventory/Controller.php
tine20/Inventory/Frontend/Json.php
tine20/Inventory/Inventory.jsb2
tine20/Inventory/Model/InventoryItem.php
tine20/Inventory/js/Inventory.js [deleted file]
tine20/Inventory/js/InventoryItemEditDialog.js
tine20/Inventory/js/InventoryItemGridPanel.js [deleted file]
tine20/Inventory/js/Model.js [deleted file]

index c1ff713..c2afccf 100644 (file)
@@ -81,7 +81,8 @@ class Inventory_Controller extends Tinebase_Controller_Event implements Tinebase
             'type'              => Tinebase_Model_Container::TYPE_PERSONAL,
             'owner_id'          => $_accountId,
             'backend'           => 'Sql',
-            'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Inventory')->getId() 
+            'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Inventory')->getId(),
+            'model'             => static::$_defaultModel
         ));
         
         $personalContainer = Tinebase_Container::getInstance()->addContainer($newContainer);
index 1e3763f..b56872c 100644 (file)
@@ -26,6 +26,12 @@ class Inventory_Frontend_Json extends Tinebase_Frontend_Json_Abstract
     protected $_controller = NULL;
     
     /**
+     * the models handled by this frontend
+     * @var array
+     */
+    protected $_models = array('InventoryItem');
+    
+    /**
      * user fields (created_by, ...) to resolve in _multipleRecordsToJson and _recordToJson
      *
      * @var array
index 271e0aa..20bb8af 100644 (file)
       "isDebug": true,
       "fileIncludes": [
         {
-          "text": "Model.js",
-          "path": "js/"
-        },
-        {
-          "text": "Inventory.js",
-          "path": "js/"
-        },
-        {
-          "text": "InventoryItemGridPanel.js",
-          "path": "js/"
-        },
-        {
           "text": "InventoryItemEditDialog.js",
           "path": "js/"
         }
index 538b346..c30b77f 100644 (file)
@@ -40,43 +40,111 @@ class Inventory_Model_InventoryItem extends Tinebase_Record_Abstract
      *
      * @var array
      */
-    protected $_validators = array(
-        'id'                    => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'name'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'type'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'container_id'          => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
-    // @todo add more fields
-        'inventory_id'          => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'description'           => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'location'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'add_time'              => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'total_number'          => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'active_number'         => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+    protected static $_meta = array(
+        'id'                    => 'id',
+        'name'                  => 'name',
+        'type'                  => 'type',
+        'container_id'          => 'container_id',
+
+        'recordName'            => 'inventory record', // _('inventory record')
+        'recordsName'           => 'inventory records', // _('inventory records')
+        'containerProperty'     => 'container_id',
+        'containerName'         => 'inventory record list', // _('inventory record list')
+        'containersName'        => 'inventory record lists', // _('inventory record lists')
+
     // modlog information
-        'created_by'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'creation_time'         => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'last_modified_by'      => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'last_modified_time'    => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'is_deleted'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'deleted_time'          => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'deleted_by'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'created_by'            => 'created_by',
+        'creation_time'         => 'creation_time',
+        'last_modified_by'      => 'last_modified_by',
+        'last_modified_time'    => 'last_modified_time',
+        'is_deleted'            => 'is_deleted',
+        'deleted_time'          => 'deleted_time',
+        'deleted_by'            => 'deleted_by',
     // relations (linked Inventory_Model_InventoryItem records) and other metadata
-        'relations'             => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => NULL),
-        'tags'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'notes'                 => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'hasRelations'      => true,
+        'hasCustomFields'   => true,
+        'hasNotes'          => true,
+        'hasTags'           => true,
+        'useModlog'         => true
     );
 
     /**
-     * name of fields containing datetime or an array of datetime information
-     *
-     * @var array list of datetime fields
-     */    
-    protected $_datetimeFields = array(
-        'creation_time',
-        'last_modified_time',
-        'deleted_time',
-        'add_time'
-    );
+     * fields for auto start
+     * @var array
+     */
+    protected static $_fields = array(
+            'id'                => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'name'              => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence' => 'required'),
+                    'label'      => NULL,
+            ),
+            'type'              => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence' => 'required'),
+                    'label'      => NULL,
+            ),
+            'container_id'      => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence' => 'required'),
+                    'label'      => NULL
+            ),
+            'inventory_id'      => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'description'       => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+                   
+            ),
+            'location'          => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true, 'presence' => 'required'),
+                    'label'      => NULL
+            ),
+            'add_time'          => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence' => 'required'),
+                    'label'      => NULL
+            ),
+            'total_number'      => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+                    
+            ),
+            'active_number'     => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            // modlog information
+            'created_by'        => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'creation_time'     => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'last_modified_by'  => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'last_modified_time'=> array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),    
+            'is_deleted'        => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'deleted_time'      => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            ),
+            'deleted_by'        => array(
+                    'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+                    'label'      => NULL
+            )
+     );
     
     /**
      * overwrite constructor to add more filters
@@ -88,68 +156,13 @@ class Inventory_Model_InventoryItem extends Tinebase_Record_Abstract
      */
     public function __construct($_data = NULL, $_bypassFilters = false, $_convertDates = true)
     {
-        // do something here if you like (add default empty values, ...)
-        
-        return parent::__construct($_data, $_bypassFilters, $_convertDates);
-    }
     
-    /**
-     * (non-PHPdoc)
-     * @see Tinebase/Record/Tinebase_Record_Abstract::isValid()
-     */
-    public function isValid($_throwExceptionOnInvalidData = false)
-    {
-        //$isValid = parent::isValid($_throwExceptionOnInvalidData);
-        
-        $isValid = (int) $this->active_number > (int) $this->total_number;
-        
-        if ($isValid && $_throwExceptionOnInvalidData) {
-            $e = new Tinebase_Exception_Record_Validation('active number must be equal or less than total number');
-            Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ":\n" .
-               print_r($this->_validationErrors,true). $e);
-            throw $e;
+        foreach (array("total_number", "active_number") AS $val)
+        {
+            $this->_filters[$val] = new Zend_Filter_Empty(NULL);
         }
-        return $isValid;
-    }
-    
-    /**
-     * (non-PHPdoc)
-     * @see Tinebase/Record/Tinebase_Record_Abstract::setFromArray()
-     */
-    /*
-    public function setFromArray(array $_data)
-    {
-    
-        if (isset($_data['total_number']) && ! is_int($_data['total_number'])) {
-            unset($_data['total_number']);
-        }
-        
-        if (isset($_data['active_number']) && ! is_int($_data['active_number'])) {
-            unset($_data['active_number']);
-        }
-        
-        return parent::setFromArray($_data);
+        print_r($this->_filters,true);
+        return parent::__construct($_data, $_bypassFilters, $_convertDates);
     }
-    */
-    /**
-     * fills a record from json data
-     *
-     * @param string $_data json encoded data
-     * @return void
-     */
-    public function setFromJson($_data)
-    {
     
-        if (isset($_data['total_number']) && ! is_int($_data['total_number'])) {
-            unset($_data['total_number']);
-        }
-        
-        if (isset($_data['active_number']) && ! is_int($_data['active_number'])) {
-            unset($_data['active_number']);
-        }
-        
-       return parent::setFromJson($_data);
-        
-        // do something here if you like
-    }
 }
diff --git a/tine20/Inventory/js/Inventory.js b/tine20/Inventory/js/Inventory.js
deleted file mode 100644 (file)
index 7e3a4d6..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Tine 2.0
- * 
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Stefanie Stamer <s.stamer@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
- */
-Ext.ns('Tine.Inventory');
-
-/**
- * @namespace   Tine.Inventory
- * @class       Tine.Inventory.Application
- * @extends     Tine.Tinebase.Application
- * 
- * @author      Cornelius Weiss <c.weiss@metaways.de>
- */
-Tine.Inventory.Application = Ext.extend(Tine.Tinebase.Application, {
-    /**
-     * Get translated application title of the calendar application
-     * 
-     * @return {String}
-     */
-    getTitle: function() {
-        return this.i18n.gettext('Inventory');
-    }
-});
-
-/**
- * @namespace   Tine.Inventory
- * @class       Tine.Inventory.MainScreen
- * @extends     Tine.widgets.MainScreen
- * 
- * @author      Cornelius Weiss <c.weiss@metaways.de>
- */
-Tine.Inventory.MainScreen = Ext.extend(Tine.widgets.MainScreen, {
-    activeContentType: 'InventoryItem'
-});
-    
-/**
- * @namespace   Tine.Inventory
- * @class       Tine.Inventory.TreePanel
- * @extends     Tine.widgets.container.TreePanel
- * 
- * @author      Cornelius Weiss <c.weiss@metaways.de>
- */
-Tine.Inventory.InventoryItemTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
-    id: 'Inventory_Tree',
-    filterMode: 'filterToolbar',
-    recordClass: Tine.Inventory.Model.InventoryItem
-});
-
-/**
- * favorites panel
- * 
- * @class       Tine.Inventory.FilterPanel
- * @extends     Tine.widgets.persistentfilter.PickerPanel
- *  
- * @param {Object} config
- */
-Tine.Inventory.FilterPanel = function(config) {
-    Ext.apply(this, config);
-    Tine.Inventory.FilterPanel.superclass.constructor.call(this);
-};
-Ext.extend(Tine.Inventory.FilterPanel, Tine.widgets.persistentfilter.PickerPanel, {
-    filter: [{field: 'model', operator: 'equals', value: 'Inventory_Model_InventoryItemFilter'}]
-});
index 97d4026..96a2f6a 100644 (file)
@@ -29,21 +29,18 @@ Tine.Inventory.InventoryItemEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
      * @private
      */
     windowNamePrefix: 'InventoryItemEditWindow_',
+    
     appName: 'Inventory',
-    recordClass: Tine.Inventory.Model.InventoryItem,
-    recordProxy: Tine.Inventory.recordBackend,
+    modelName: 'InventoryItem',
+    
+    windowHeight: 470,
+    windowWidth: 800,
+
     loadRecord: false,
     tbarItems: [{xtype: 'widget-activitiesaddbutton'}],
     evalGrants: true,
     showContainerSelector: true,
     
-    /**
-     * overwrite update toolbars function (we don t have record grants yet)
-     * @private
-     */
-    updateToolbars: function() {
-
-    },
     
     /**
      * executed after record got updated from proxy
@@ -52,7 +49,6 @@ Tine.Inventory.InventoryItemEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
      */
     onRecordLoad: function() {
     // you can do something here
-
         Tine.Inventory.InventoryItemEditDialog.superclass.onRecordLoad.call(this);
     },
     
@@ -248,4 +244,4 @@ Tine.Inventory.InventoryItemEditDialog.openWindow = function (config) {
         contentPanelConstructorConfig: config
     });
     return window;
-};
+};
\ No newline at end of file
diff --git a/tine20/Inventory/js/InventoryItemGridPanel.js b/tine20/Inventory/js/InventoryItemGridPanel.js
deleted file mode 100644 (file)
index 67dd71d..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Tine 2.0
- * 
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Stefanie Stamer <s.stamer@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
- */
-Ext.ns('Tine.Inventory');
-
-/**
- * InventoryItem grid panel
- * 
- * @namespace   Tine.Inventory
- * @class       Tine.Inventory.InventoryItemGridPanel
- * @extends     Tine.widgets.grid.GridPanel
- * 
- * <p>InventoryItem Grid Panel</p>
- * <p><pre>
- * </pre></p>
- * 
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Stefanie Stamer <s.stamer@metaways.de>
- * @copyright   Copyright (c) 2007-2008 Metaways Infosystems GmbH (http://www.metaways.de)
- * 
- * @param       {Object} config
- * @constructor
- * Create a new Tine.Inventory.InventoryItemGridPanel
- */
-Tine.Inventory.InventoryItemGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
-    /**
-     * record class
-     * @cfg {Tine.Inventory.Model.InventoryItem} recordClass
-     */
-    recordClass: Tine.Inventory.Model.InventoryItem,
-    
-    /**
-     * eval grants
-     * @cfg {Boolean} evalGrants
-     */
-    evalGrants: true,
-    
-    /**
-     * grid specific
-     * @private
-     */
-    defaultSortInfo: {field: 'creation_time', direction: 'DESC'},
-    gridConfig: {
-        autoExpandColumn: 'name'
-    },
-     
-    /**
-     * inits this cmp
-     * @private
-     */
-    initComponent: function() {
-        this.recordProxy = Tine.Inventory.recordBackend;
-        
-        this.gridConfig.cm = this.getColumnModel();
-        this.filterToolbar = this.filterToolbar || this.getFilterToolbar();
-        
-        this.plugins = this.plugins || [];
-        this.plugins.push(this.filterToolbar);
-        
-        Tine.Inventory.InventoryItemGridPanel.superclass.initComponent.call(this);
-    },
-    
-    /**
-     * returns cm
-     * 
-     * @return Ext.grid.ColumnModel
-     * @private
-     * 
-     * TODO    add more columns
-     */
-    getColumnModel: function(){
-        return new Ext.grid.ColumnModel({
-            defaults: {
-                sortable: true,
-                resizable: true
-            },
-            columns: [{
-                id: 'inventory_id',
-                header: this.app.i18n._("ID"),
-                width: 90,
-                sortable: true,
-                dataIndex: 'inventory_id'
-            }, {
-                id: 'name',
-                header: this.app.i18n._("Name"),
-                width: 50,
-                sortable: true,
-                dataIndex: 'name'
-            }, {
-                id: 'type',
-                header: this.app.i18n._("Type"),
-                width: 50,
-                sortable: true,
-                dataIndex: 'type',
-                renderer: Tine.Tinebase.widgets.keyfield.Renderer.get('Inventory', 'inventoryType')
-            },{
-                id: 'add_time',
-                header: this.app.i18n._("Added"),
-                width: 25,
-                sortable: true,
-                dataIndex: 'add_time', 
-                renderer: Tine.Tinebase.common.dateRenderer
-            },{
-                id: 'location',
-                header: this.app.i18n._("Location"),
-                width: 50,
-                sortable: true,
-                dataIndex: 'location'
-            },{
-                id: 'total_number',
-                header: this.app.i18n._("Total number"),
-                width: 25,
-                sortable: true,
-                dataIndex: 'total_number'
-            },{
-                id: 'active_number',
-                header: this.app.i18n._("Active number"),
-                width: 25,
-                sortable: true,
-                dataIndex: 'active_number'
-            },{
-                id: 'description',
-                header: this.app.i18n._("Description"),
-                width: 50,
-                sortable: true,
-                dataIndex: 'description'
-            }].concat(this.getModlogColumns())
-        });
-    },
-    
-    /**
-     * status column renderer
-     * @param {string} value
-     * @return {string}
-     */
-    statusRenderer: function(value) {
-        return this.app.i18n._hidden(value);
-    },
-    
-    /**
-     * return additional tb items
-     * @private
-     */
-    getToolbarItems: function(){
-
-        
-        return [
-        ];
-    }    
-});
diff --git a/tine20/Inventory/js/Model.js b/tine20/Inventory/js/Model.js
deleted file mode 100644 (file)
index e9616a2..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Tine 2.0
- * 
- * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @author      Cornelius Weiss <c.weiss@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
- */
-Ext.ns('Tine.Inventory.Model');
-
-/**
- * @namespace   Tine.Inventory.Model
- * @class       Tine.Inventory.Model.InventoryItem
- * @extends     Tine.Tinebase.data.Record
- * inventory record definition
- * 
- * @author      Stefanie Stamer <s.stamer@metaways.de>
- */
-Tine.Inventory.Model.InventoryItem = Tine.Tinebase.data.Record.create(Tine.Tinebase.Model.genericFields.concat([
-    { name: 'id' },
-    { name: 'name' },
-    { name: 'type' },
-    { name: 'inventory_id' },
-    { name: 'location' },
-    { name: 'description' },
-    { name: 'add_time', type: 'date', dateFormat: Date.patterns.ISO8601Long},
-    { name: 'total_number', type: 'int'},
-    { name: 'active_number', type: 'int'},
-    // TODO add more record fields here
-    // tine 2.0 notes + tags
-    { name: 'notes'},
-    { name: 'tags' }
-]), {
-    appName: 'Inventory',
-    modelName: 'InventoryItem',
-    idProperty: 'id',
-    titleProperty: 'title',
-    // ngettext('Item', 'Items', n);
-    recordName: 'Item',
-    recordsName: 'Items',
-    containerProperty: 'container_id',
-    // gettext('inventories')
-    // ngettext('inventory', 'inventories', n);
-    containerName: 'inventory',
-    containersName: 'inventories'
-});
-
-/**
- * @namespace Tine.Inventory.Model
- * 
- * get default data for a new record
- *  
- * @return {Object} default data
- * @static
- */ 
-Tine.Inventory.Model.InventoryItem.getDefaultData = function() { 
-    var app = Tine.Tinebase.appMgr.get('Inventory');
-    var defaultsContainer = Tine.Inventory.registry.get('defaultContainer');
-    
-    return {
-        container_id: app.getMainScreen().getWestPanel().getContainerTreePanel().getDefaultContainer()
-        // [...] add more defaults
-    };
-};
-
-/**
- * get filtermodel of record
- * 
- * @namespace Tine.Inventory.Model
- * @static
- * @return {Object} filterModel definition
- */ 
-Tine.Inventory.Model.InventoryItem.getFilterModel = function() {
-    var app = Tine.Tinebase.appMgr.get('Inventory');
-    
-    return [
-        {label: app.i18n._('Quick search'), field: 'query', operators: ['contains']},
-        {label: app.i18n._('Name'),         field: 'name',     operators: ['contains']},
-        {
-            label: app.i18n._('Type'),
-            field: 'type',
-            filtertype: 'tine.widget.keyfield.filter', 
-            app: app, 
-            keyfieldName: 'inventoryType'
-        },
-        {label: app.i18n._('ID'),           field: 'inventory_id',      operators: ['contains']},
-        {label: app.i18n._('Location'),     field: 'location',          operators: ['contains']},
-        {label: app.i18n._('Added'),        field: 'add_time',          valueType: 'date',      pastOnly: true},
-        {filtertype: 'tinebase.tag', app: app},
-        {filtertype: 'tine.widget.container.filtermodel', app: app, recordClass: Tine.Inventory.Model.InventoryItem},
-        {label: app.i18n._('Last modified'),                                            field: 'last_modified_time', valueType: 'date'},
-        {label: app.i18n._('Last modifier'),                                            field: 'last_modified_by',   valueType: 'user'},
-        {label: app.i18n._('Creation Time'),                                            field: 'creation_time',      valueType: 'date'},
-        {label: app.i18n._('Creator'),                                                  field: 'created_by',         valueType: 'user'}
-    ];
-};
-
-/**
- * default InventoryItem backend
- */
-Tine.Inventory.recordBackend = new Tine.Tinebase.data.RecordProxy({
-    appName: 'Inventory',
-    modelName: 'InventoryItem',
-    recordClass: Tine.Inventory.Model.InventoryItem
-});