PageSourceSearch

https://theartssociety.org/sites/all/modules/civicrm/templates/CRM/Contact/Page/View/Summary.js?tlvm4t

js theartssociety.org collected 2026-09-24 20:53:32 UTC 16,616 bytes, 421 lines download raw bytes

1// http://civicrm.org/licensing
2(function($, _) {
3  // FIXME: Much of this code is redundant with CRM.loadForm
4
5  var ajaxFormParams = {
6    dataType:'json',
7    beforeSubmit: function(arr, $form, options) {
8      $form.block();
9    },
10    success: requestHandler,
11    error: errorHandler
12  };
13
14  function crmFormInline(o) {
15    var data = o.data('edit-params');
16    if (o.is('.crm-edit-ready .crm-inline-edit') && data) {
17      o.animate({height: '+=50px'}, 200);
18      data.snippet = 6;
19      data.reset = 1;
20      var width = o.width();
21      $('.crm-edit-ready').removeClass('crm-edit-ready');
22      o.block().addClass('form').css('width', '' + width + 'px');
23      $.getJSON(CRM.url('civicrm/ajax/inline', data))
24        .fail(errorHandler)
25        .done(function(response) {
26          o.unblock();
27          o.css('overflow', 'hidden').wrapInner('<div class="inline-edit-hidden-content" style="display:none" />').append(response.content);
28          // Needed to accurately measure box width
29          $('.crm-container-snippet', o).css('display', 'inline-block');
30          // Smooth resizing
31          var newHeight = $('.crm-container-snippet', o).height(),
32            speed = newHeight - parseInt(o.css('height'), 10),
33            animation = {height: '' + newHeight + 'px'};
34          // Animation speed is set relative to how much the box needs to grow
35          if (speed < 0) {
36            speed = 0 - speed;
37          }
38          // Horizontal growth
39          var newWidth = $('.crm-container-snippet', o).width();
40          if (newWidth > width) {
41            animation.width = '' + newWidth + 'px';
42            // Slow down animation if we have lots of horizontal growth to do
43            if (newWidth - width > speed) {
44              speed = newWidth - width;
45            }
46          } else {
47            newWidth = width;
48          }
49          $('.crm-container-snippet', o).css('display', '');
50          o.animate(animation, speed, function() {
51            o.css({height: '', width: '', minWidth: '' + newWidth + 'px'});
52          });
53          $('form', o).validate(CRM.validate.params);
54          ajaxFormParams.data = data;
55          $('form', o).ajaxForm(ajaxFormParams);
56          o.trigger('crmLoad').trigger('crmFormLoad');
57        });
58    }
59  }
60
61  function reloadBlock(el) {
62    return $(el).each(function() {
63      var data = $(this).data('edit-params');
64      if (data) {
65        data.snippet = data.reset = 1;
66        data.class_name = data.class_name.replace('Form', 'Page');
67        data.type = 'page';
68        $(this).closest('.crm-summary-block').load(CRM.url('civicrm/ajax/inline', data), function() {
69          $(this).trigger('crmLoad');
70        });
71      }
72    });
73  }
74
75  function requestHandler(response) {
76    var o = $('div.crm-inline-edit.form');
77    $('form', o).ajaxFormUnbind();
78
79    if (response.status == 'success' || response.status == 'cancel') {
80      o.trigger('crmFormSuccess', [response]).removeAttr('style');
81      $('.crm-inline-edit-container').addClass('crm-edit-ready');
82      var data = o.data('edit-params');
83      var dependent = $((o.data('dependent-fields') || []).join(','));
84      // Clone the add-new link if replacing it, and queue the clone to be refreshed as a dependent block
85      if (o.hasClass('add-new') && response.addressId) {
86        data.aid = response.addressId;
87        var clone = o.closest('.crm-summary-block').clone();
88        o.data('edit-params', data);
89        $('form', clone).remove();
90        if (clone.hasClass('contactCardLeft')) {
91          clone.removeClass('contactCardLeft').addClass('contactCardRight');
92        }
93        else if (clone.hasClass('contactCardRight')) {
94          clone.removeClass('contactCardRight').addClass('contactCardLeft');
95        }
96        var cl = $('.crm-inline-edit', clone);
97        var clData = cl.data('edit-params');
98        var locNo = clData.locno++;
99        cl.attr('id', cl.attr('id').replace(locNo, clData.locno)).removeClass('form');
100        o.closest('.crm-summary-block').after(clone);
101        dependent = dependent.add($('.crm-inline-edit', clone));
102      }
103      $('a.ui-notify-close', '#crm-notification-container').click();
104      // Delete an address
105      if (o.hasClass('address') && !o.hasClass('add-new') && !response.addressId) {
106        o.parent().remove();
107        CRM.status(ts('Address Deleted'));
108      }
109      else {
110        // Reload this block plus all dependent blocks
111        reloadBlock(dependent.add(o));
112        CRM.status(ts('Saved'));
113      }
114    }
115    else {
116      // Handle formRule error
117      $('.crm-container-snippet', o).replaceWith(response.content);
118      $('form', o).validate(CRM.validate.params);
119      $('form', o).ajaxForm(ajaxFormParams);
120      o.trigger('crmFormError', [response]).trigger('crmFormLoad').trigger('crmLoad');
121    }
122  }
123
124  /**
125   * Configure optimistic locking mechanism for inplace editing
126   *
127   * options.ignoreLabel: string, text for a button
128   * options.reloadLabel: string, text for a button
129   */
130  $.fn.crmFormContactLock = function(options) {
131    var form = this;
132    // AFTER ERROR: Render any "Ignore" and "Restart" buttons
133    return this.on('crmFormError', function(event, obj, status) {
134      var o = $(event.target);
135      var data = o.data('edit-params');
136      var errorTag = o.find('.update_oplock_ts');
137      if (errorTag.length > 0) {
138        $('<span>')
139          .addClass('crm-lock-button css_right')
140          .appendTo(errorTag);
141
142        var buttonContainer = o.find('.crm-lock-button');
143        $('<button>')
144          .addClass('crm-button')
145          .text(options.saveAnywayLabel)
146          .click(function() {
147            $(form).find('input[name=oplock_ts]').val(errorTag.attr('data:update_oplock_ts'));
148            errorTag.parent().hide();
149            $(this).closest('form').find('.crm-form-submit.default').first().click();
150            return false;
151          })
152          .appendTo(buttonContainer)
153          ;
154        $('<button>')
155          .addClass('crm-button')
156          .text(options.reloadLabel)
157          .click(function() {
158            window.location.reload();
159            return false;
160          })
161          .appendTo(buttonContainer)
162          ;
163      }
164    });
165  };
166
167  function errorHandler(response) {
168    CRM.alert(ts('Unable to reach the server. Please refresh this page in your browser and try again.'), ts('Network Error'), 'error');
169    $('.crm-inline-edit.form form').unblock();
170  }
171
172  $(function() {
173    // don't perform inline edit during print mode
174    if (CRM.summaryPrint.mode) {
175      $('div').removeClass('crm-inline-edit');
176      $('.crm-inline-block-content > div.crm-edit-help').remove();
177      $('div.crm-inline-block-content').removeAttr('title');
178    }
179    // Set page title
180    var oldName = 'CiviCRM';
181    var nameTitle = $('#crm-remove-title');
182    if (nameTitle.length > 0) {
183      oldName = nameTitle.text();
184      nameTitle.parent('h1').remove();
185    }
186    else {
187      $('h1').each(function() {
188        if ($(this).text() == oldName) {
189          $(this).remove();
190        }
191      });
192    }
193    function refreshTitle() {
194      var contactName = $('.crm-summary-display_name').text();
195      contactName = $.trim(contactName);
196      document.title = document.title.replace(oldName, contactName);
197      oldName = contactName;
198    }
199    $('#contactname-block').on('load', refreshTitle);
200    refreshTitle();
201
202    var clicking;
203    $('.crm-inline-edit-container')
204      .addClass('crm-edit-ready')
205      // Allow links inside edit blocks to be clicked without triggering edit
206      .on('mousedown', '.crm-inline-edit:not(.form) a, .crm-inline-edit:not(.form) .crm-accordion-header, .crm-inline-edit:not(.form) .collapsible-title', function(event) {
207        if (event.which == 1) {
208          event.stopPropagation();
209          return false;
210        }
211      })
212      // Respond to a click (not drag, not right-click) of crm-inline-edit blocks
213      .on('mousedown', '.crm-inline-edit:not(.form)', function(button) {
214        if (button.which == 1) {
215          clicking = this;
216          setTimeout(function() {clicking = null;}, 500);
217        }
218      })
219      .on('mouseup', '.crm-inline-edit:not(.form)', function(button) {
220        if (clicking === this && button.which == 1) {
221          crmFormInline($(this));
222        }
223      })
224      // Inline edit form cancel button
225      .on('click', '.crm-inline-edit :submit[name$=cancel]', function() {
226        var container = $(this).closest('.crm-inline-edit.form');
227        $('form', container).ajaxFormUnbind();
228        $('.inline-edit-hidden-content', container).nextAll().remove();
229        $('.inline-edit-hidden-content > *:first-child', container).unwrap();
230        container.removeClass('form').removeAttr('style');
231        $('.crm-inline-edit-container').addClass('crm-edit-ready');
232        $('a.ui-notify-close', '#crm-notification-container').click();
233        return false;
234      })
235      // Switch tabs when clicking tag link
236      .on('click', '#tagLink a', function() {
237        $('#tab_tag a').click();
238        return false;
239      })
240      // make sure only one is_primary radio is checked
241      // Note this is no longer required for the email block
242      // & similar changes to phone, address, im, openid would allow removal from them as well.
243      .on('change', '[class$=is_primary] input', function() {
244        if ($(this).is(':checked')) {
245          $('[class$=is_primary] input', $(this).closest('form')).not(this).prop('checked', false);
246        }
247      })
248      // handle delete link within blocks
249      .on('click', '.crm-delete-inline', function(e) {
250        var row = $(this).closest('tr');
251        var form = $(this).closest('form');
252        row.hide();
253        var blockNumber = row.data('block-number');
254        if (blockNumber) {
255          $('.crm-block-entity-' + row.data('entity') + '-' + blockNumber).addClass('hiddenElement');
256          $('input', '.crm-block-entity-' + row.data('entity') + '-' + blockNumber).val('');
257        }
258        $('input', row).val('');
259        //if the primary is checked for deleted block
260        //unset and set first as primary
261        if ($('[class$=is_primary] input:checked', row).length > 0) {
262          $('[class$=is_primary] input', row).prop('checked', false);
263          $('[class$=is_primary] input:visible:first', form).prop('checked', true );
264        }
265        $('.add-more-inline', form).show();
266        if ($('[class$=is_primary] input:visible', form).length == 0) {
267          $('.add-more-inline', form).click();
268          $('[class$=is_primary] input:visible:first', form).prop('checked', true );
269        }
270
271        e.preventDefault();
272      })
273      // Delete an address
274      .on('click', '.crm-inline-edit.address .delete-button', function(e) {
275         var $block = $(this).closest('.crm-inline-edit.address');
276         CRM.confirm({message: ts('Are you sure you want to delete this address?')})
277           .on('crmConfirm:yes', function() {
278            CRM.api3('address', 'delete', {id: $block.data('edit-params').aid}, true)
279              .done(function(data) {
280                $('.crm-inline-edit-container').addClass('crm-edit-ready');
281                $block.closest('.crm-address-block').remove();
282                reloadBlock('.crm-inline-edit.address:not(.add-new)');
283              });
284            });
285        e.preventDefault();
286      })
287      // add more and set focus to new row
288      .on('click', '.add-more-inline', function(e) {
289        var form = $(this).closest('form');
290        var row = $('tr[class="hiddenElement"]:first', form);
291        row.removeClass('hiddenElement');
292        var blockNumber = row.data('block-number');
293        if (blockNumber) {
294          $('.crm-block-entity-' + row.data('entity') + '-' + blockNumber).removeClass('hiddenElement');
295        }
296
297        $('input:focus', form).blur();
298        $('input:first', row).focus();
299        if ($('tr[class="hiddenElement"]').length < 1) {
300          $(this).hide();
301        }
302        e.preventDefault();
303      });
304    // Trigger cancel button on esc keypress
305    $(document).keydown(function(key) {
306      if (key.which == 27) {
307        $('.crm-inline-edit.form :submit[name$=cancel]').click();
308      }
309    });
310    $('#crm-container')
311      // Switch tabs when clicking log link
312      .on('click', '#crm-record-log a.crm-log-view', function() {
313        $('#tab_log a').click();
314        return false;
315      })
316      // Handle action links in popup
317      .on('click', '.crm-contact_actions-list a, .crm-contact_activities-list a', function(e) {
318        $('#crm-contact-actions-list').hide();
319        if ($(this).attr('href') === '#') {
320          var $tab = $('#tab_' + ($(this).data('tab') || 'summary'));
321          CRM.tabHeader.focus($tab);
322          e.preventDefault();
323        } else {
324          CRM.popup.call(this, e);
325        }
326      })
327      .on('crmPopupFormSuccess',  '.crm-contact_actions-list a, .crm-contact_activities-list a', function() {
328        var $tab = $('#tab_' + ($(this).data('tab') || 'summary'));
329        CRM.tabHeader.resetTab($tab);
330        CRM.tabHeader.focus($tab);
331      });
332    $(document)
333      // Actions menu
334      .on('click', function(e) {
335        if ($(e.target).is('#crm-contact-actions-link, #crm-contact-actions-link *')) {
336          $('#crm-contact-actions-list').show();
337          return false;
338        }
339        $('#crm-contact-actions-list').hide();
340      })
341      .on('crmFormSuccess crmLoad', function(e, data) {
342        // Update changelog tab and contact footer
343        if (data && data.changeLog) {
344          if (data.changeLog.count) {
345            CRM.tabHeader.updateCount('#tab_log', data.changeLog.count);
346          }
347          if (data.changeLog.markup) {
348            $("#crm-record-log").replaceWith(data.changeLog.markup);
349          }
350        }
351      })
352      .on('crmFormSuccess', function(e, data) {
353        // Advanced logging... just increment the changelog tab count to avoid the overhead of reloading the data
354        if (CRM.incrementChangeLogTab) {
355          CRM.incrementChangeLogTab();
356        }
357        // Refresh changelog tab next time it is opened
358        CRM.tabHeader.resetTab('#tab_log');
359        // Refresh dependent blocks
360        if (data && data.reloadBlocks) {
361          reloadBlock(data.reloadBlocks.join(','));
362        }
363      });
364
365    /**
366     * Make contact summary fit in small screens
367     */
368    function onResize() {
369      var contactwidth = $('#crm-container #mainTabContainer').width();
370      if (contactwidth < 600) {
371        $('#crm-container #mainTabContainer').addClass('narrowpage');
372        $('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each(function (index) {
373          if (index > 1) {
374            if (index % 2 === 0) {
375              $(this).parent().after('<tr class="narrowadded"></tr>');
376            }
377            var item = $(this);
378            $(this).parent().next().append(item);
379          }
380        });
381      }
382      else {
383        $('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage');
384        $('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each(function () {
385          var nitem = $(this);
386          var parent = $(this).parent();
387          $(this).parent().prev().append(nitem);
388          if (parent.children().size() === 0) {
389            parent.remove();
390          }
391        });
392        $('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach();
393      }
394      var cformwidth = $('#crm-container #Contact .contact_basic_information-section').width();
395
396      if (cformwidth < 720) {
397        $('#crm-container .contact_basic_information-section').addClass('narrowform');
398        $('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon');
399        if (cformwidth < 480) {
400          $('#crm-container .contact_basic_information-section').addClass('xnarrowform');
401        }
402        else {
403          $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
404        }
405      }
406      else {
407        $('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform');
408        $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
409      }
410    }
411
412    // Changing relationships may affect related members and contributions. Ensure they are refreshed.
413    $('#contact-rel').on('crmPopupFormSuccess', function() {
414      CRM.tabHeader.resetTab('#tab_contribute');
415      CRM.tabHeader.resetTab('#tab_member');
416    });
417
418    onResize();
419    $(window).resize(onResize);
420  });
421})(CRM.$, CRM._);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.