Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-07-27-10-02-15
[civicrm-core.git] / templates / CRM / Contact / Page / View / Summary.js
index f38bf305b5a49f3c76da70fdb7c1f7d76f6e1824..76d7bb46927f73a275ed8decca64bfb08b842c65 100644 (file)
@@ -7,19 +7,6 @@
     beforeSubmit: function(arr, $form, options) {
       $form.block();
     },
-    beforeSerialize: function(form, options) {
-      // Copied from crm.ajax.js
-      if (window.CKEDITOR && window.CKEDITOR.instances) {
-        $.each(CKEDITOR.instances, function() {
-          this.updateElement && this.updateElement();
-        });
-      }
-      if (window.tinyMCE && tinyMCE.editors) {
-        $.each(tinyMCE.editors, function() {
-          this.save();
-        });
-      }
-    },
     success: requestHandler,
     error: errorHandler
   };
         }
       })
       .on('crmFormSuccess', function(e, data) {
-        // Refresh changeLog - advanced logging
-        if (CRM.reloadChangeLogTab) {
-          CRM.reloadChangeLogTab();
-        }
-        // Refresh changeLog - simple logging
-        // If we didn't get a changelog count in the response, force refresh the changelog tab to populate it
-        else {
-          CRM.tabHeader.resetTab('#tab_log', !(data && data.changeLog && data.changeLog.count));
+        // Advanced logging... just increment the changelog tab count to avoid the overhead of reloading the data
+        if (CRM.incrementChangeLogTab) {
+          CRM.incrementChangeLogTab();
         }
+        // Refresh changelog tab next time it is opened
+        CRM.tabHeader.resetTab('#tab_log');
         // Refresh dependent blocks
         if (data && data.reloadBlocks) {
           reloadBlock(data.reloadBlocks.join(','));
         }
       });
+
+    /**
+     * Make contact summary fit in small screens
+     */
+    function onResize() {
+      var contactwidth = $('#crm-container #mainTabContainer').width();
+      if (contactwidth < 600) {
+        $('#crm-container #mainTabContainer').addClass('narrowpage');
+        $('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each(function (index) {
+          if (index > 1) {
+            if (index % 2 === 0) {
+              $(this).parent().after('<tr class="narrowadded"></tr>');
+            }
+            var item = $(this);
+            $(this).parent().next().append(item);
+          }
+        });
+      }
+      else {
+        $('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage');
+        $('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each(function () {
+          var nitem = $(this);
+          var parent = $(this).parent();
+          $(this).parent().prev().append(nitem);
+          if (parent.children().size() === 0) {
+            parent.remove();
+          }
+        });
+        $('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach();
+      }
+      var cformwidth = $('#crm-container #Contact .contact_basic_information-section').width();
+
+      if (cformwidth < 720) {
+        $('#crm-container .contact_basic_information-section').addClass('narrowform');
+        $('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon');
+        if (cformwidth < 480) {
+          $('#crm-container .contact_basic_information-section').addClass('xnarrowform');
+        }
+        else {
+          $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
+        }
+      }
+      else {
+        $('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform');
+        $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
+      }
+    }
+
+    onResize();
+    $(window).resize(onResize);
   });
 })(CRM.$, CRM._);