0009768: Use ModelConfig for Timetracker models
[tine20] / tine20 / Timetracker / js / TimesheetEditDialog.js
index 6f4b4ac..264530e 100644 (file)
@@ -4,7 +4,7 @@
  * @package     Timetracker
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Philipp Schüle <p.schuele@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2007-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  *
  */
  
@@ -27,6 +27,10 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
     useInvoice: false,
     displayNotes: true,
     context: { 'skipClosedCheck': false },
+
+    windowWidth: 800,
+    windowHeight: 500,
+
     
     /**
      * overwrite update toolbars function (we don't have record grants yet)
@@ -35,7 +39,29 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
         this.onTimeaccountUpdate();
         Tine.Timetracker.TimesheetEditDialog.superclass.updateToolbars.call(this, record, 'timeaccount_id');
     },
-    
+
+    onRecordLoad: function() {
+        // interrupt process flow until dialog is rendered
+        if (! this.rendered) {
+            this.onRecordLoad.defer(250, this);
+            return;
+        }
+
+        if (! this.record.id) {
+            // @todo: this should be handled by default values
+            this.record.set('account_id', Tine.Tinebase.registry.get('currentAccount'));
+            this.record.set('start_date', new Date());
+        }
+
+        Tine.Timetracker.TimesheetEditDialog.superclass.onRecordLoad.call(this);
+
+        // TODO get timeaccount from filter if set
+        var timeaccount = this.record.get('timeaccount_id');
+        if (timeaccount) {
+            this.onTimeaccountUpdate(null, new Tine.Timetracker.Model.Timeaccount(timeaccount));
+        }
+    },
+
     /**
      * this gets called when initializing and if a new timeaccount is chosen
      * 
@@ -67,10 +93,10 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
         }
 
         if (timeaccount) {
-            notBillable = notBillable || timeaccount.data.is_billable == "0" || this.record.get('timeaccount_id').is_billable == "0";
+            notBillable = notBillable || timeaccount.data.is_billable == "0" || timeaccount.get('is_billable') == "0";
             
             // clearable depends on timeaccount is_billable as well (changed by ps / 2009-09-01, behaviour was inconsistent)
-            notClearable = notClearable || timeaccount.data.is_billable == "0" || this.record.get('timeaccount_id').is_billable == "0";
+            notClearable = notClearable || timeaccount.data.is_billable == "0" || timeaccount.get('is_billable') == "0";
         }
         
         this.getForm().findField('is_billable').setDisabled(notBillable);
@@ -114,7 +140,7 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
             && Tine.Tinebase.common.hasRight('manage', 'Sales', 'invoices')
             && Tine.Sales.Model.Invoice;
         
-        Tine.Timetracker.TimesheetEditDialog.superclass.initComponent.apply(this, arguments);
+        Tine.Timetracker.TimesheetEditDialog.superclass.initComponent.call(this);
     },
 
     /**
@@ -336,18 +362,3 @@ Tine.Timetracker.TimesheetEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog
             }, this);
     }
 });
-
-/**
- * Timetracker Edit Popup
- */
-Tine.Timetracker.TimesheetEditDialog.openWindow = function (config) {
-    var id = (config.record && config.record.id) ? config.record.id : 0;
-    var window = Tine.WindowFactory.getWindow({
-        width: 800,
-        height: 500,
-        name: Tine.Timetracker.TimesheetEditDialog.prototype.windowNamePrefix + id,
-        contentPanelConstructor: 'Tine.Timetracker.TimesheetEditDialog',
-        contentPanelConstructorConfig: config
-    });
-    return window;
-};