refactor mode management
authorMichael Spahn <m.spahn@metaways.de>
Thu, 10 Aug 2017 10:45:58 +0000 (12:45 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 10 Aug 2017 15:26:41 +0000 (17:26 +0200)
 - if editdialog is opened with a json record, use this one and don't fetch relations if they are set there
 - mode is still evaluated e.g. for saving

Change-Id: Ic2114c0088349548f7cc033619bd28ab3cf0d8f5
Reviewed-on: http://gerrit.tine20.com/customers/5444
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Tested-by: sstamer <s.stamer@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/js/widgets/dialog/EditDialog.js
tine20/Tinebase/js/widgets/relation/GenericPickerGridPanel.js

index dc95a05..294c36e 100644 (file)
@@ -754,19 +754,18 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
             Tine.log.debug('creating new default data record');
             this.record = new this.recordClass(this.recordClass.getDefaultData(), 0);
         }
             Tine.log.debug('creating new default data record');
             this.record = new this.recordClass(this.recordClass.getDefaultData(), 0);
         }
-        
-        if (this.mode !== 'local') {
+
+        if (typeof this.record === 'string') {
+            if (! Ext.isFunction(this.record.beginEdit)) {
+                this.record = this.recordProxy.recordReader({responseText: this.record});
+            }
+            this.onRecordLoad.defer(10, this);
+        } else {
             if (this.record && this.record.id) {
                 this.loadRemoteRecord();
             } else {
                 this.onRecordLoad.defer(10, this);
             }
             if (this.record && this.record.id) {
                 this.loadRemoteRecord();
             } else {
                 this.onRecordLoad.defer(10, this);
             }
-        } else {
-            // note: in local mode we expect a valid record
-            if (! Ext.isFunction(this.record.beginEdit)) {
-                this.record = this.recordProxy.recordReader({responseText: this.record});
-            }
-            this.onRecordLoad.defer(10, this);
         }
     },
     
         }
     },
     
index 912a872..e27d7ca 100644 (file)
@@ -1153,22 +1153,23 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
      */
     loadRecord: function(dialog, record, ticketFn) {
         var _ = window.lodash,
      */
     loadRecord: function(dialog, record, ticketFn) {
         var _ = window.lodash,
+            me = this,
             interceptor = ticketFn(),
             evalGrants = dialog.evalGrants,
             hasRequiredGrant = !evalGrants || _.get(record, record.constructor.getMeta('grantsPath') + '.' + this.requiredGrant);
 
         this.store.removeAll();
 
             interceptor = ticketFn(),
             evalGrants = dialog.evalGrants,
             hasRequiredGrant = !evalGrants || _.get(record, record.constructor.getMeta('grantsPath') + '.' + this.requiredGrant);
 
         this.store.removeAll();
 
-        if (dialog.mode == 'local' && this.editDialog.recordClass.getMeta('phpClassName') === 'Calendar_Model_Event') {
-            // if dialog is local, relations must be fetched async
+        var relations = _.get(record, 'data.relations');
+
+        if (relations) {
+            this.loadRelations(relations, interceptor);
+        } else {
             Tine.Tinebase.getRelations('Calendar_Model_Event', record.get('id'), null, [], null, function (response, request) {
             Tine.Tinebase.getRelations('Calendar_Model_Event', record.get('id'), null, [], null, function (response, request) {
-                if(response) {
-                    this.loadRelations(response.results, interceptor);
+                if (response) {
+                    me.loadRelations(response.results, interceptor);
                 }
             }.createDelegate(this));
                 }
             }.createDelegate(this));
-        } else {
-            var relations = record.get('relations');
-            this.loadRelations(relations, interceptor);
         }
 
         this.setReadOnly(! hasRequiredGrant);
         }
 
         this.setReadOnly(! hasRequiredGrant);