Merge branch 'pu/2013.03/modelconfig-hr'
[tine20] / tine20 / Tinebase / js / widgets / dialog / EditDialog.js
index 30a219a..8dff158 100644 (file)
@@ -145,6 +145,12 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
     saving: false,
     
     /**
+     * Disable adding cf tab even if model has support for customfields
+     * @type Boolean
+     */
+    disableCfs: false,
+    
+    /**
      * @property window {Ext.Window|Ext.ux.PopupWindow|Ext.Air.Window}
      */
     /**
@@ -167,6 +173,13 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
      */
     fixedFields: null,
 
+    /**
+     * Plain Object with additional configuration (JSON-encoded)
+     * 
+     * @type {Object}
+     */
+    additionalConfig: null,
+    
     // private
     bodyStyle:'padding:5px',
     layout: 'fit',
@@ -247,6 +260,10 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
             this.modelConfig = Ext.decode(this.modelConfig);
         }
         
+        if (Ext.isString(this.additionalConfig)) {
+            Ext.apply(this, Ext.decode(this.additionalConfig));
+        }
+        
         if (Ext.isString(this.fixedFields)) {
             var decoded = Ext.decode(this.fixedFields);
             this.fixedFields = new Ext.util.MixedCollection();
@@ -289,8 +306,11 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
         // init plugins
         this.plugins = Ext.isString(this.plugins) ? Ext.decode(this.plugins) : Ext.isArray(this.plugins) ? this.plugins.concat(Ext.decode(this.initialConfig.plugins)) : [];
         
-        this.plugins.push(new Tine.widgets.customfields.EditDialogPlugin({}));
         this.plugins.push(this.tokenModePlugin = new Tine.widgets.dialog.TokenModeEditDialogPlugin({}));
+        // added possibility to disable using customfield plugin
+        if (this.disableCfs !== true) {
+            this.plugins.push(new Tine.widgets.customfields.EditDialogPlugin({}));
+        }
         
         // init actions
         this.initActions();
@@ -390,13 +410,20 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
     
     /**
      * init buttons
+     * 
+     * use button order from preference
      */
-    initButtons: function() {
+    initButtons: function () {
         this.fbar = [
-            '->',
-            this.action_cancel,
-            this.action_saveAndClose
+            '->'
         ];
+                
+        if (Tine.Tinebase.registry && Tine.Tinebase.registry.get('preferences') && Tine.Tinebase.registry.get('preferences').get('dialogButtonsOrderStyle') === 'Windows') {
+            this.fbar.push(this.action_saveAndClose, this.action_cancel);
+        }
+        else {
+            this.fbar.push(this.action_cancel, this.action_saveAndClose);
+        }
        
         if (this.tbarItems) {
             this.tbar = new Ext.Toolbar({
@@ -673,6 +700,11 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
      * @param {Boolean} closeWindow
      */
     onApplyChanges: function(closeWindow) {
+        if (this.saving) {
+            return;
+        }
+        this.saving = true;
+
         this.loadMask.show();
         
         var ticketFn = this.doApplyChanges.deferByTickets(this, [closeWindow]),
@@ -728,6 +760,7 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
                 wrapTicket();
             }
         } else {
+            this.saving = false;
             this.loadMask.hide();
             Ext.MessageBox.alert(_('Errors'), this.getValidationErrorMessage());
         }
@@ -736,6 +769,7 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
     onAfterApplyChanges: function(closeWindow) {
         this.window.rename(this.windowNamePrefix + this.record.id);
         this.loadMask.hide();
+        this.saving = false;
         
         if (closeWindow) {
             this.window.fireEvent('saveAndClose');