2 if (!CRM
.Designer
) CRM
.Designer
= {};
5 * When rendering a template with Marionette.ItemView, the list of variables is determined by
6 * serializeData(). The normal behavior is to map each property of this.model to a template
9 * This function extends that practice by exporting variables "_view", "_model", "_collection",
10 * and "_options". This makes it easier for the template to, e.g., access computed properties of
11 * a model (by calling "_model.getComputedProperty"), or to access constructor options (by
12 * calling "_options.myoption").
16 var extendedSerializeData = function() {
17 var result
= Marionette
.ItemView
.prototype.serializeData
.apply(this);
19 result
._model
= this.model
;
20 result
._collection
= this.collection
;
21 result
._options
= this.options
;
26 * Display a dialog window with an editable form for a UFGroupModel
28 * The implementation here is very "jQuery-style" and not "Backbone-style";
32 * - model: CRM.UF.UFGroupModel
34 CRM
.Designer
.DesignerDialog
= Backbone
.Marionette
.Layout
.extend({
35 serializeData
: extendedSerializeData
,
36 template
: '#designer_dialog_template',
37 className
: 'crm-designer-dialog',
39 designerRegion
: '.crm-designer'
41 /** @var bool whether this dialog is currently open */
43 /** @var bool whether any changes have been made */
45 /** @var obj handle for the CRM.alert containing undo link */
47 /** @var bool whether this dialog is being re-opened by the undo link */
50 initialize: function(options
) {
51 CRM
.designerApp
.vent
.on('ufUnsaved', this.onUfChanged
, this);
54 this.undoAlert
&& this.undoAlert
.close
&& this.undoAlert
.close();
55 CRM
.designerApp
.vent
.off('ufUnsaved', this.onUfChanged
, this);
57 onUfChanged: function(isUfUnsaved
) {
58 this.isUfUnsaved
= isUfUnsaved
;
60 onRender: function() {
61 var designerDialog
= this;
62 designerDialog
.$el
.dialog({
63 autoOpen
: true, // note: affects accordion height
64 title
: ts('Edit Profile'),
67 height
: parseInt($(window
).height() *.8, 10),
69 minHeight
: 600, // to allow dropping in big whitespace, coordinate with min-height of .crm-designer-fields
71 // Prevent conflicts with other onbeforeunload handlers
72 designerDialog
.oldOnBeforeUnload
= window
.onbeforeunload
;
73 // Warn of unsaved changes when navigating away from the page
74 window
.onbeforeunload = function() {
75 if (designerDialog
.isDialogOpen
&& designerDialog
.isUfUnsaved
) {
76 return ts("Your profile has not been saved.");
78 if (designerDialog
.oldOnBeforeUnload
) {
79 return designerDialog
.oldOnBeforeUnload
.apply(arguments
);
82 designerDialog
.undoAlert
&& designerDialog
.undoAlert
.close
&& designerDialog
.undoAlert
.close();
83 designerDialog
.isDialogOpen
= true;
84 // Initialize new dialog if we are not re-opening unsaved changes
85 if (designerDialog
.undoState
=== false) {
86 designerDialog
.designerRegion
&& designerDialog
.designerRegion
.close
&& designerDialog
.designerRegion
.close();
87 designerDialog
.$el
.block();
88 designerDialog
.options
.findCreateUfGroupModel({
89 onLoad: function(ufGroupModel
) {
90 designerDialog
.model
= ufGroupModel
;
91 var designerLayout
= new CRM
.Designer
.DesignerLayout({
93 el
: '<div class="full-height"></div>'
95 designerDialog
.$el
.unblock();
96 designerDialog
.designerRegion
.show(designerLayout
);
97 CRM
.designerApp
.vent
.trigger('resize');
98 designerDialog
.isUfUnsaved
= false;
102 designerDialog
.undoState
= false;
104 CRM
.designerApp
.DetachedProfiles
= [];
107 window
.onbeforeunload
= designerDialog
.oldOnBeforeUnload
;
108 designerDialog
.isDialogOpen
= false;
110 designerDialog
.undoAlert
&& designerDialog
.undoAlert
.close
&& designerDialog
.undoAlert
.close();
111 if (designerDialog
.isUfUnsaved
) {
112 designerDialog
.undoAlert
= CRM
.alert('<p>' + ts('%1 has not been saved.', {1: designerDialog
.model
.get('title')}) + '</p><a href="#" class="crm-undo">' + ts('Restore') + '</a>', ts('Unsaved Changes'), 'alert', {expires
: 60000});
113 $('.ui-notify-message a.crm-undo').button({icons
: {primary
: 'ui-icon-arrowreturnthick-1-w'}}).click(function(e
) {
115 designerDialog
.undoState
= true;
116 designerDialog
.$el
.dialog('open');
120 CRM
.designerApp
.restorePreviewArea();
123 CRM
.designerApp
.vent
.trigger('resize');
130 * Display a complete form-editing UI, including canvas, palette, and
134 * - model: CRM.UF.UFGroupModel
136 CRM
.Designer
.DesignerLayout
= Backbone
.Marionette
.Layout
.extend({
137 serializeData
: extendedSerializeData
,
138 template
: '#designer_template',
140 buttons
: '.crm-designer-buttonset-region',
141 palette
: '.crm-designer-palette-region',
142 form
: '.crm-designer-form-region',
143 fields
: '.crm-designer-fields-region'
145 initialize: function() {
146 CRM
.designerApp
.vent
.on('resize', this.onResize
, this);
148 onClose: function() {
149 CRM
.designerApp
.vent
.off('resize', this.onResize
, this);
151 onRender: function() {
152 this.buttons
.show(new CRM
.Designer
.ToolbarView({
155 this.palette
.show(new CRM
.Designer
.PaletteView({
158 this.form
.show(new CRM
.Designer
.UFGroupView({
161 this.fields
.show(new CRM
.Designer
.UFFieldCanvasView({
165 onResize: function() {
166 if (! this.hasResizedBefore
) {
167 this.hasResizedBefore
= true;
168 this.$('.crm-designer-toolbar').resizable({
172 resize: function(event
, ui
) {
173 $('.crm-designer-canvas').css('margin-right', (ui
.size
.width
+ 10) + 'px');
174 $(this).css({left
: '', height
: ''});
176 }).css({left
: '', height
: ''});
182 * Display toolbar with working button
185 * - model: CRM.UF.UFGroupModel
187 CRM
.Designer
.ToolbarView
= Backbone
.Marionette
.ItemView
.extend({
188 serializeData
: extendedSerializeData
,
189 template
: '#designer_buttons_template',
192 'click .crm-designer-save': 'doSave',
193 'click .crm-designer-preview': 'doPreview'
195 onRender: function() {
196 this.$('.crm-designer-save').button().attr({
197 disabled
: 'disabled',
198 style
: 'opacity:.5; box-shadow:none; cursor:default;'
200 this.$('.crm-designer-preview').button();
202 initialize: function(options
) {
203 CRM
.designerApp
.vent
.on('ufUnsaved', this.onUfChanged
, this);
205 onUfChanged: function(isUfUnsaved
) {
207 this.$('.crm-designer-save').removeAttr('style').prop('disabled', false);
210 doSave: function(e
) {
212 var ufGroupModel
= this.model
;
213 if (ufGroupModel
.getRel('ufFieldCollection').hasDuplicates()) {
214 CRM
.alert(ts('Please correct errors before saving.'), '', 'alert');
217 var $dialog
= this.$el
.closest('.crm-designer-dialog'); // FIXME use events
218 $dialog
.block({message
: 'Saving...', theme
: true});
219 var profile
= ufGroupModel
.toStrictJSON();
220 profile
["api.UFField.replace"] = {values
: ufGroupModel
.getRel('ufFieldCollection').toSortedJSON(), 'option.autoweight': 0};
221 CRM
.api('UFGroup', 'create', profile
, {
222 success: function(data
) {
226 CRM
.alert(data
.error_message
);
229 _
.each(data
.values
, function(ufGroupResponse
) {
230 if (ufGroupResponse
['api.UFField.replace'].is_error
) {
231 CRM
.alert(ufGroupResponse
['api.UFField.replace'].error_message
);
236 if (!ufGroupModel
.get('id')) {
237 ufGroupModel
.set('id', data
.id
);
239 CRM
.designerApp
.vent
.trigger('ufUnsaved', false);
240 CRM
.designerApp
.vent
.trigger('ufSaved');
241 $dialog
.dialog('close');
246 doPreview: function(e
) {
248 this.previewMode
= !this.previewMode
;
249 if (!this.previewMode
) {
250 $('.crm-designer-preview-canvas').html('');
251 $('.crm-designer-canvas > *, .crm-designer-palette-region').show();
252 $('.crm-designer-preview span').html(ts('Preview'));
255 if (this.model
.getRel('ufFieldCollection').hasDuplicates()) {
256 CRM
.alert(ts('Please correct errors before previewing.'), '', 'alert');
259 var $dialog
= this.$el
.closest('.crm-designer-dialog'); // FIXME use events
260 $dialog
.block({message
: 'Loading...', theme
: true});
262 CRM
.designerApp
.clearPreviewArea();
263 $.post(CRM
.url("civicrm/ajax/inline"), {
264 'qfKey': CRM
.profilePreviewKey
,
265 'class_name': 'CRM_UF_Form_Inline_Preview',
267 'ufData': JSON
.stringify({
268 ufGroup
: this.model
.toStrictJSON(),
269 ufFieldCollection
: this.model
.getRel('ufFieldCollection').toSortedJSON()
271 }).done(function(data
) {
273 $('.crm-designer-canvas > *, .crm-designer-palette-region').hide();
274 $('.crm-designer-preview-canvas').html(data
).show().trigger('crmLoad').find(':input').prop('readOnly', true);
275 $('.crm-designer-preview span').html(ts('Edit'));
281 * Display a selection of available fields
284 * - model: CRM.UF.UFGroupModel
286 CRM
.Designer
.PaletteView
= Backbone
.Marionette
.ItemView
.extend({
287 serializeData
: extendedSerializeData
,
288 template
: '#palette_template',
289 el
: '<div class="full-height"></div>',
292 'keyup .crm-designer-palette-search input': 'doSearch',
293 'change .crm-contact-types': 'doSetPaletteEntity',
294 'click .crm-designer-palette-clear-search': 'clearSearch',
295 'click .crm-designer-palette-toggle': 'toggleAll',
296 'click .crm-designer-palette-add button': 'doNewCustomFieldDialog',
297 'click #crm-designer-add-custom-set': 'doNewCustomSetDialog',
298 'dblclick .crm-designer-palette-field': 'doAddToCanvas'
300 initialize: function() {
301 this.model
.getRel('ufFieldCollection')
302 .on('add', this.toggleActive
, this)
303 .on('remove', this.toggleActive
, this);
304 this.model
.getRel('paletteFieldCollection')
305 .on('reset', this.render
, this);
306 CRM
.designerApp
.vent
.on('resize', this.onResize
, this);
308 onClose: function() {
309 this.model
.getRel('ufFieldCollection')
310 .off('add', this.toggleActive
, this)
311 .off('remove', this.toggleActive
, this);
312 this.model
.getRel('paletteFieldCollection')
313 .off('reset', this.render
, this);
314 CRM
.designerApp
.vent
.off('resize', this.onResize
, this);
316 onRender: function() {
317 var paletteView
= this;
319 // Prepare data for jstree
321 var paletteFieldsByEntitySection
= this.model
.getRel('paletteFieldCollection').getFieldsByEntitySection();
323 paletteView
.model
.getRel('ufEntityCollection').each(function(ufEntityModel
){
324 _
.each(ufEntityModel
.getSections(), function(section
, sectionKey
){
325 var defaultValue
= paletteView
.selectedContactType
;
327 defaultValue
= paletteView
.model
.calculateContactEntityType();
330 // set selected option as default, since we are rebuilding palette
331 paletteView
.$('.crm-contact-types').val(defaultValue
).prop('selected','selected');
333 var entitySection
= ufEntityModel
.get('entity_name') + '-' + sectionKey
;
335 if (paletteFieldsByEntitySection
[entitySection
]) {
336 _
.each(paletteFieldsByEntitySection
[entitySection
], function(paletteFieldModel
, k
) {
337 items
.push({data
: paletteFieldModel
.getLabel(), attr
: {'class': 'crm-designer-palette-field', 'data-plm-cid': paletteFieldModel
.cid
}});
340 if (section
.is_addable
) {
341 items
.push({data
: ts('+ Add New Field'), attr
: {'class': 'crm-designer-palette-add'}});
343 if (items
.length
> 0) {
347 state
: _
.contains(paletteView
.openTreeNodes
, sectionKey
) ? 'open' : 'closed',
349 'class': 'crm-designer-palette-section',
350 'data-section': sectionKey
,
351 'data-entity': ufEntityModel
.get('entity_name')
358 this.$('.crm-designer-palette-tree').jstree({
359 'json_data': {data
: treeData
},
361 'case_insensitive' : true,
362 'show_only_matches': true
368 "url": CRM
.config
.resourceBase
+ 'packages/jquery/plugins/jstree/themes/classic/style.css'
370 'plugins': ['themes', 'json_data', 'ui', 'search']
371 }).bind('loaded.jstree', function () {
372 $('.crm-designer-palette-field', this).draggable({
373 appendTo
: '.crm-designer',
374 zIndex
: $(this.$el
).zIndex() + 5000,
376 connectToSortable
: '.crm-designer-fields' // FIXME: tight canvas/palette coupling
378 paletteView
.model
.getRel('ufFieldCollection').each(function(ufFieldModel
) {
379 paletteView
.toggleActive(ufFieldModel
, paletteView
.model
.getRel('ufFieldCollection'))
381 paletteView
.$('.crm-designer-palette-add a').replaceWith('<button>' + $('.crm-designer-palette-add a').first().text() + '</<button>');
382 paletteView
.$('.crm-designer-palette-tree > ul').append('<li><button id="crm-designer-add-custom-set">+ ' + ts('Add Set of Custom Fields') + '</button></li>');
383 paletteView
.$('.crm-designer-palette-tree button').button();
384 }).bind("select_node.jstree", function (e
, data
) {
385 $(this).jstree("toggle_node", data
.rslt
.obj
);
386 $(this).jstree("deselect_node", data
.rslt
.obj
);
389 // FIXME: tight canvas/palette coupling
390 this.$(".crm-designer-fields").droppable({
391 activeClass
: "ui-state-default",
392 hoverClass
: "ui-state-hover",
393 accept
: ":not(.ui-sortable-helper)"
398 onResize: function() {
399 var pos
= this.$('.crm-designer-palette-tree').position();
400 var div
= this.$('.crm-designer-palette-tree').closest('.crm-container').height();
401 this.$('.crm-designer-palette-tree').css({height
: div
- pos
.top
});
403 doSearch: function(e
) {
404 var str
= $(e
.target
).val();
405 this.$('.crm-designer-palette-clear-search').css('visibility', str
? 'visible' : 'hidden');
406 this.$('.crm-designer-palette-tree').jstree("search", str
);
408 doSetPaletteEntity: function(event
) {
409 this.selectedContactType
= $('.crm-contact-types :selected').val();
410 // loop through entity collection and remove non-valid entity section's
411 var newUfEntityModels
= [];
412 this.model
.getRel('ufEntityCollection').each(function(oldUfEntityModel
){
413 var values
= oldUfEntityModel
.toJSON();
414 if (values
.entity_name
== 'contact_1') {
415 values
.entity_type
= $('.crm-contact-types :selected').val();
417 newUfEntityModels
.push(new CRM
.UF
.UFEntityModel(values
));
419 this.model
.getRel('ufEntityCollection').reset(newUfEntityModels
);
421 doAddToCanvas: function(event
) {
422 var paletteFieldModel
= this.model
.getRel('paletteFieldCollection').get($(event
.currentTarget
).attr('data-plm-cid'));
423 paletteFieldModel
.addToUFCollection(this.model
.getRel('ufFieldCollection'));
424 event
.stopPropagation();
426 doNewCustomFieldDialog: function(e
) {
428 var paletteView
= this;
429 var entityKey
= $(e
.currentTarget
).closest('.crm-designer-palette-section').attr('data-entity');
430 var sectionKey
= $(e
.currentTarget
).closest('.crm-designer-palette-section').attr('data-section');
431 var ufEntityModel
= paletteView
.model
.getRel('ufEntityCollection').getByName(entityKey
);
432 var sections
= ufEntityModel
.getSections();
433 var url
= CRM
.url('civicrm/admin/custom/group/field/add', {
436 gid
: sections
[sectionKey
].custom_group_id
438 CRM
.loadForm(url
).on('crmFormSuccess', function(e
, data
) {
439 paletteView
.doRefresh('custom_' + data
.id
);
442 doNewCustomSetDialog: function(e
) {
444 var paletteView
= this;
445 var url
= CRM
.url('civicrm/admin/custom/group', 'action=add&reset=1');
446 // Create custom field set and automatically go to next step (create fields) after save button is clicked.
447 CRM
.loadForm(url
, {refreshAction
: ['next']})
448 .on('crmFormSuccess', function(e
, data
) {
449 // When form switches to create custom field context, modify button behavior to only continue for "save and new"
450 data
.customField
&& ($(this).data('civiCrmSnippet').options
.crmForm
.refreshAction
= ['next_new']);
451 paletteView
.doRefresh(data
.customField
? 'custom_' + data
.id
: null);
454 doRefresh: function(fieldToAdd
) {
455 var ufGroupModel
= this.model
;
456 this.getOpenTreeNodes();
457 CRM
.Schema
.reloadModels()
458 .done(function(data
){
459 ufGroupModel
.resetEntities();
461 var field
= ufGroupModel
.getRel('paletteFieldCollection').getFieldByName(null, fieldToAdd
);
462 field
.addToUFCollection(ufGroupModel
.getRel('ufFieldCollection'));
466 CRM
.alert(ts('Failed to retrieve schema'), ts('Error'), 'error');
469 clearSearch: function(e
) {
471 $('.crm-designer-palette-search input').val('').keyup();
473 toggleActive: function(ufFieldModel
, ufFieldCollection
, options
) {
474 var paletteFieldCollection
= this.model
.getRel('paletteFieldCollection');
475 var paletteFieldModel
= paletteFieldCollection
.getFieldByName(ufFieldModel
.get('entity_name'), ufFieldModel
.get('field_name'));
476 var isAddable
= ufFieldCollection
.isAddable(ufFieldModel
);
477 if (paletteFieldModel
) {
478 this.$('[data-plm-cid='+paletteFieldModel
.cid
+']').toggleClass('disabled', !isAddable
);
481 toggleAll: function(e
) {
482 if ($('.crm-designer-palette-search input').val() == '') {
483 $('.crm-designer-palette-tree').jstree($(e
.target
).attr('rel'));
487 getOpenTreeNodes: function() {
488 var paletteView
= this;
489 this.openTreeNodes
= [];
490 this.$('.crm-designer-palette-section.jstree-open').each(function() {
491 paletteView
.openTreeNodes
.push($(this).data('section'));
497 * Display all UFFieldModel objects in a UFGroupModel.
500 * - model: CRM.UF.UFGroupModel
502 CRM
.Designer
.UFFieldCanvasView
= Backbone
.Marionette
.View
.extend({
503 initialize: function() {
504 this.model
.getRel('ufFieldCollection')
505 .on('add', this.updatePlaceholder
, this)
506 .on('remove', this.updatePlaceholder
, this)
507 .on('add', this.addUFFieldView
, this)
508 .on('reset', this.render
, this);
510 onClose: function() {
511 this.model
.getRel('ufFieldCollection')
512 .off('add', this.updatePlaceholder
, this)
513 .off('remove', this.updatePlaceholder
, this)
514 .off('add', this.addUFFieldView
, this)
515 .off('reset', this.render
, this);
518 var ufFieldCanvasView
= this;
519 this.$el
.html(_
.template($('#field_canvas_view_template').html()));
521 // BOTTOM: Setup field-level editing
522 var $fields
= this.$('.crm-designer-fields');
523 this.updatePlaceholder();
524 var ufFieldModels
= this.model
.getRel('ufFieldCollection').sortBy(function(ufFieldModel
) {
525 return parseInt(ufFieldModel
.get('weight'));
527 _
.each(ufFieldModels
, function(ufFieldModel
) {
528 ufFieldCanvasView
.addUFFieldView(ufFieldModel
, ufFieldCanvasView
.model
.getRel('ufFieldCollection'), {skipWeights
: true});
530 this.$(".crm-designer-fields").sortable({
531 placeholder
: 'crm-designer-row-placeholder',
532 forcePlaceholderSize
: true,
533 receive: function(event
, ui
) {
534 var paletteFieldModel
= ufFieldCanvasView
.model
.getRel('paletteFieldCollection').get(ui
.item
.attr('data-plm-cid'));
535 var ufFieldModel
= paletteFieldModel
.addToUFCollection(
536 ufFieldCanvasView
.model
.getRel('ufFieldCollection'),
539 if (null == ufFieldModel
) {
540 ufFieldCanvasView
.$('.crm-designer-fields .ui-draggable').remove();
542 // Move from end to the 'dropped' position
543 var ufFieldViewEl
= ufFieldCanvasView
.$('div[data-field-cid='+ufFieldModel
.cid
+']').parent();
544 ufFieldCanvasView
.$('.crm-designer-fields .ui-draggable').replaceWith(ufFieldViewEl
);
546 // note: the sortable() update callback will call updateWeight
549 ufFieldCanvasView
.updateWeights();
553 /** Determine visual order of fields and set the model values for "weight" */
554 updateWeights: function() {
555 var ufFieldCanvasView
= this;
557 var rows
= this.$('.crm-designer-row').each(function(key
, row
) {
558 if ($(row
).hasClass('placeholder')) {
561 var ufFieldCid
= $(row
).attr('data-field-cid');
562 var ufFieldModel
= ufFieldCanvasView
.model
.getRel('ufFieldCollection').get(ufFieldCid
);
563 ufFieldModel
.set('weight', weight
);
567 addUFFieldView: function(ufFieldModel
, ufFieldCollection
, options
) {
568 var paletteFieldModel
= this.model
.getRel('paletteFieldCollection').getFieldByName(ufFieldModel
.get('entity_name'), ufFieldModel
.get('field_name'));
569 var ufFieldView
= new CRM
.Designer
.UFFieldView({
570 el
: $("<div></div>"),
572 paletteFieldModel
: paletteFieldModel
574 ufFieldView
.render();
575 this.$('.crm-designer-fields').append(ufFieldView
.$el
);
576 if (! (options
&& options
.skipWeights
)) {
577 this.updateWeights();
580 updatePlaceholder: function() {
581 if (this.model
.getRel('ufFieldCollection').isEmpty()) {
582 this.$('.placeholder').css({display
: 'block', border
: '0 none', cursor
: 'default'});
584 this.$('.placeholder').hide();
591 * - model: CRM.UF.UFFieldModel
592 * - paletteFieldModel: CRM.Designer.PaletteFieldModel
594 CRM
.Designer
.UFFieldView
= Backbone
.Marionette
.Layout
.extend({
595 serializeData
: extendedSerializeData
,
596 template
: '#field_row_template',
599 summary
: '.crm-designer-field-summary',
600 detail
: '.crm-designer-field-detail'
603 "click .crm-designer-action-settings": 'doToggleForm',
604 "click button.crm-designer-edit-custom": 'doEditCustomField',
605 "click .crm-designer-action-remove": 'doRemove'
609 "change:is_duplicate": 'onChangeIsDuplicate'
611 onRender: function() {
612 this.summary
.show(new CRM
.Designer
.UFFieldSummaryView({
614 fieldSchema
: this.model
.getFieldSchema(),
615 paletteFieldModel
: this.options
.paletteFieldModel
617 this.detail
.show(new CRM
.Designer
.UFFieldDetailView({
619 fieldSchema
: this.model
.getFieldSchema()
621 this.onChangeIsDuplicate(this.model
, this.model
.get('is_duplicate'))
622 if (!this.expanded
) {
623 this.detail
.$el
.hide();
626 CRM
.designerApp
.vent
.on('formOpened', function(event
) {
627 if (that
.expanded
&& event
!= that
.cid
) {
628 that
.doToggleForm(false);
632 doToggleForm: function(event
) {
633 this.expanded
= !this.expanded
;
634 if (this.expanded
&& event
!== false) {
635 CRM
.designerApp
.vent
.trigger('formOpened', this.cid
);
637 this.$el
.toggleClass('crm-designer-open', this.expanded
);
638 var $detail
= this.detail
.$el
;
639 if (!this.expanded
) {
640 $detail
.toggle('blind', 250);
641 this.$('button.crm-designer-edit-custom').remove();
644 var $canvas
= $('.crm-designer-canvas');
645 var top
= $canvas
.offset().top
;
648 step: function(num
, effect
) {
649 // Scroll canvas to keep field details visible
650 if (effect
.prop
== 'height') {
651 if (effect
.now
+ $detail
.offset().top
- top
> $canvas
.height() - 9) {
652 $canvas
.scrollTop($canvas
.scrollTop() + effect
.now
+ $detail
.offset().top
- top
- $canvas
.height() + 9);
657 if (this.model
.get('field_name').split('_')[0] == 'custom') {
658 this.$('.crm-designer-field-summary > div').append('<button class="crm-designer-edit-custom">» ' + ts('Edit Custom Field') + '</button>');
659 this.$('button.crm-designer-edit-custom').button().attr('title', ts('Edit global settings for this custom field.'));
663 doEditCustomField: function(e
) {
665 var url
= CRM
.url('civicrm/admin/custom/group/field/update', {
668 id
: this.model
.get('field_name').split('_')[1]
670 var form1
= CRM
.loadForm(url
, {openInline
: '.crm-custom-field-form-block-data_type a'})
671 .on('crmFormLoad', function() {
672 $(this).prepend('<div class="messages status"><div class="icon inform-icon"></div>' + ts('Note: This will modify the field system-wide, not just in this profile form.') + '</div>');
673 var $link
= $('.action-link a', this);
677 buttons
[$link
.text()] = function() {
678 var form2
= CRM
.loadForm($link
.attr('href'), {
685 $(this).dialog('option', 'buttons', buttons
);
689 onChangeIsDuplicate: function(model
, value
, options
) {
690 this.$el
.toggleClass('crm-designer-duplicate', value
);
692 doRemove: function(event
) {
694 this.$el
.hide(250, function() {
695 that
.model
.destroyLocal();
702 * - model: CRM.UF.UFFieldModel
703 * - fieldSchema: (Backbone.Form schema element)
704 * - paletteFieldModel: CRM.Designer.PaletteFieldModel
706 CRM
.Designer
.UFFieldSummaryView
= Backbone
.Marionette
.ItemView
.extend({
707 serializeData
: extendedSerializeData
,
708 template
: '#field_summary_template',
714 * Compose a printable string which describes the binding of this UFField to the data model
717 getBindingLabel: function() {
718 var result
= this.options
.paletteFieldModel
.getSection().title
+ ": " + this.options
.paletteFieldModel
.getLabel();
719 if (this.options
.fieldSchema
.civiIsPhone
) {
720 result
= result
+ '-' + CRM
.PseudoConstant
.phoneType
[this.model
.get('phone_type_id')];
722 if (this.options
.fieldSchema
.civiIsLocation
) {
723 var locType
= this.model
.get('location_type_id') ? CRM
.PseudoConstant
.locationType
[this.model
.get('location_type_id')] : ts('Primary');
724 result
= result
+ ' (' + locType
+ ')';
730 * Return a string marking if the field is required
733 getRequiredMarker: function() {
734 if (this.model
.get('is_required') == 1) {
735 return ' <span class="crm-marker">*</span> ';
740 onRender: function() {
741 this.$el
.toggleClass('disabled', this.model
.get('is_active') != 1);
742 if (this.model
.get("is_reserved") == 1) {
743 this.$('.crm-designer-buttons').hide();
750 * - model: CRM.UF.UFFieldModel
751 * - fieldSchema: (Backbone.Form schema element)
753 CRM
.Designer
.UFFieldDetailView
= Backbone
.View
.extend({
754 initialize: function() {
755 // FIXME: hide/display 'in_selector' if 'visibility' is one of the public options
756 var fields
= ['location_type_id', 'phone_type_id', 'label', 'is_multi_summary', 'is_required', 'is_view', 'visibility', 'in_selector', 'is_searchable', 'help_pre', 'help_post', 'is_active'];
757 if (! this.options
.fieldSchema
.civiIsLocation
) {
758 fields
= _
.without(fields
, 'location_type_id');
760 if (! this.options
.fieldSchema
.civiIsPhone
) {
761 fields
= _
.without(fields
, 'phone_type_id');
763 if (!this.options
.fieldSchema
.civiIsMultiple
) {
764 fields
= _
.without(fields
, 'is_multi_summary');
767 this.form
= new Backbone
.Form({
771 this.form
.on('change', this.onFormChange
, this);
772 this.model
.on('change', this.onModelChange
, this);
775 this.$el
.html(this.form
.render().el
);
778 onModelChange: function() {
779 $.each(this.form
.fields
, function(i
, field
) {
780 this.form
.setValue(field
.key
, this.model
.get(field
.key
));
783 onFormChange: function() {
785 this.$('.field-is_multi_summary').toggle(this.options
.fieldSchema
.civiIsMultiple
? true : false);
786 this.$('.field-in_selector').toggle(this.model
.isInSelectorAllowed());
788 if (!this.model
.isInSelectorAllowed() && this.model
.get('in_selector') != "0") {
789 this.model
.set('in_selector', "0");
790 this.form
.setValue('in_selector', "0");
791 // TODO: It might be nicer if we didn't completely discard in_selector -- e.g.
792 // if the value could be restored when the user isInSelectorAllowed becomes true
793 // again. However, I haven't found a simple way to do this.
800 * - model: CRM.UF.UFGroupModel
802 CRM
.Designer
.UFGroupView
= Backbone
.Marionette
.Layout
.extend({
803 serializeData
: extendedSerializeData
,
804 template
: '#form_row_template',
807 summary
: '.crm-designer-form-summary',
808 detail
: '.crm-designer-form-detail'
811 "click .crm-designer-action-settings": 'doToggleForm'
813 onRender: function() {
814 this.summary
.show(new CRM
.Designer
.UFGroupSummaryView({
817 this.detail
.show(new CRM
.Designer
.UFGroupDetailView({
820 if (!this.expanded
) {
821 this.detail
.$el
.hide();
824 CRM
.designerApp
.vent
.on('formOpened', function(event
) {
825 if (that
.expanded
&& event
!== 0) {
826 that
.doToggleForm(false);
830 doToggleForm: function(event
) {
831 this.expanded
= !this.expanded
;
832 if (this.expanded
&& event
!== false) {
833 CRM
.designerApp
.vent
.trigger('formOpened', 0);
835 this.$el
.toggleClass('crm-designer-open', this.expanded
);
836 this.detail
.$el
.toggle('blind', 250);
842 * - model: CRM.UF.UFGroupModel
844 CRM
.Designer
.UFGroupSummaryView
= Backbone
.Marionette
.ItemView
.extend({
845 serializeData
: extendedSerializeData
,
846 template
: '#form_summary_template',
850 onRender: function() {
851 this.$el
.toggleClass('disabled', this.model
.get('is_active') != 1);
852 if (this.model
.get("is_reserved") == 1) {
853 this.$('.crm-designer-buttons').hide();
860 * - model: CRM.UF.UFGroupModel
862 CRM
.Designer
.UFGroupDetailView
= Backbone
.View
.extend({
863 initialize: function() {
864 this.form
= new Backbone
.Form({
866 fields
: ['title', 'help_pre', 'help_post', 'is_active']
868 this.form
.on('change', this.form
.commit
, this.form
);
871 this.$el
.html(this.form
.render().el
);