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
: 'Edit Profile',
68 minHeight
: 600, // to allow dropping in big whitespace, coordinate with min-height of .crm-designer-fields
70 // Prevent conflicts with other onbeforeunload handlers
71 designerDialog
.oldOnBeforeUnload
= window
.onbeforeunload
;
72 // Warn of unsaved changes when navigating away from the page
73 window
.onbeforeunload = function() {
74 if (designerDialog
.isDialogOpen
&& designerDialog
.isUfUnsaved
) {
75 return ts("Your profile has not been saved.");
77 if (designerDialog
.oldOnBeforeUnload
) {
78 return designerDialog
.oldOnBeforeUnload
.apply(arguments
);
81 designerDialog
.undoAlert
&& designerDialog
.undoAlert
.close
&& designerDialog
.undoAlert
.close();
82 designerDialog
.isDialogOpen
= true;
83 // Initialize new dialog if we are not re-opening unsaved changes
84 if (designerDialog
.undoState
=== false) {
85 designerDialog
.designerRegion
&& designerDialog
.designerRegion
.close
&& designerDialog
.designerRegion
.close();
86 designerDialog
.$el
.block({message
: 'Loading...', theme
: true});
87 designerDialog
.options
.findCreateUfGroupModel({
88 onLoad: function(ufGroupModel
) {
89 designerDialog
.model
= ufGroupModel
;
90 var designerLayout
= new CRM
.Designer
.DesignerLayout({
92 el
: '<div class="full-height"></div>'
94 designerDialog
.$el
.unblock();
95 designerDialog
.designerRegion
.show(designerLayout
);
96 CRM
.designerApp
.vent
.trigger('resize');
97 designerDialog
.isUfUnsaved
= false;
101 designerDialog
.undoState
= false;
103 CRM
.designerApp
.DetachedProfiles
= [];
106 window
.onbeforeunload
= designerDialog
.oldOnBeforeUnload
;
107 designerDialog
.isDialogOpen
= false;
109 designerDialog
.undoAlert
&& designerDialog
.undoAlert
.close
&& designerDialog
.undoAlert
.close();
110 if (designerDialog
.isUfUnsaved
) {
111 designerDialog
.undoAlert
= CRM
.alert('<p>' + ts('Your changes to "%1" have not been saved.', {1: designerDialog
.model
.get('title')}) + '</p><a href="#" class="crm-undo">' + ts('Restore unsaved changes') + '</a>', ts('Unsaved Changes'), 'alert', {expires
: 60000});
112 $('.ui-notify-message a.crm-undo').click(function() {
113 designerDialog
.undoState
= true;
114 designerDialog
.$el
.dialog('open');
119 CRM
.designerApp
.restorePreviewArea();
122 CRM
.designerApp
.vent
.trigger('resize');
129 * Display a complete form-editing UI, including canvas, palette, and
133 * - model: CRM.UF.UFGroupModel
135 CRM
.Designer
.DesignerLayout
= Backbone
.Marionette
.Layout
.extend({
136 serializeData
: extendedSerializeData
,
137 template
: '#designer_template',
139 buttons
: '.crm-designer-buttonset-region',
140 palette
: '.crm-designer-palette-region',
141 form
: '.crm-designer-form-region',
142 fields
: '.crm-designer-fields-region'
144 initialize: function() {
145 CRM
.designerApp
.vent
.on('resize', this.onResize
, this);
147 onClose: function() {
148 CRM
.designerApp
.vent
.off('resize', this.onResize
, this);
150 onRender: function() {
151 this.buttons
.show(new CRM
.Designer
.ToolbarView({
154 this.palette
.show(new CRM
.Designer
.PaletteView({
157 this.form
.show(new CRM
.Designer
.UFGroupView({
160 this.fields
.show(new CRM
.Designer
.UFFieldCanvasView({
164 onResize: function() {
165 if (! this.hasResizedBefore
) {
166 this.hasResizedBefore
= true;
167 this.$('.crm-designer-toolbar').resizable({
171 resize: function(event
, ui
) {
172 $('.crm-designer-canvas').css('margin-right', (ui
.size
.width
+ 10) + 'px');
173 $(this).css({left
: '', height
: ''});
175 }).css({left
: '', height
: ''});
181 * Display toolbar with working button
184 * - model: CRM.UF.UFGroupModel
186 CRM
.Designer
.ToolbarView
= Backbone
.Marionette
.ItemView
.extend({
187 serializeData
: extendedSerializeData
,
188 template
: '#designer_buttons_template',
191 'click .crm-designer-save': 'doSave',
192 'click .crm-designer-preview': 'doPreview'
194 onRender: function() {
195 this.$('.crm-designer-save').button().attr({
196 disabled
: 'disabled',
197 style
: 'opacity:.5; box-shadow:none; cursor:default;'
199 this.$('.crm-designer-preview').button();
201 initialize: function(options
) {
202 CRM
.designerApp
.vent
.on('ufUnsaved', this.onUfChanged
, this);
204 onUfChanged: function(isUfUnsaved
) {
206 this.$('.crm-designer-save').removeAttr('style').removeAttr('disabled');
209 doSave: function(event
) {
210 var ufGroupModel
= this.model
;
211 if (ufGroupModel
.getRel('ufFieldCollection').hasDuplicates()) {
212 CRM
.alert(ts('Please correct errors before saving.'), '', 'alert');
215 var $dialog
= this.$el
.closest('.crm-designer-dialog'); // FIXME use events
216 $dialog
.block({message
: 'Saving...', theme
: true});
217 var profile
= ufGroupModel
.toStrictJSON();
218 profile
["api.UFField.replace"] = {values
: ufGroupModel
.getRel('ufFieldCollection').toSortedJSON(), 'option.autoweight': 0};
219 CRM
.api('UFGroup', 'create', profile
, {
220 success: function(data
) {
224 CRM
.alert(data
.error_message
);
227 _
.each(data
.values
, function(ufGroupResponse
) {
228 if (ufGroupResponse
['api.UFField.replace'].is_error
) {
229 CRM
.alert(ufGroupResponse
['api.UFField.replace'].error_message
);
234 if (!ufGroupModel
.get('id')) {
235 ufGroupModel
.set('id', data
.id
);
237 CRM
.designerApp
.vent
.trigger('ufUnsaved', false);
238 CRM
.designerApp
.vent
.trigger('ufSaved');
239 $dialog
.dialog('close');
245 doPreview: function(event
) {
246 this.previewMode
= !this.previewMode
;
247 if (!this.previewMode
) {
248 $('.crm-designer-preview-canvas').html('');
249 $('.crm-designer-canvas > *, .crm-designer-palette-region').show();
250 $('.crm-designer-preview span').html(ts('Preview'));
253 if (this.model
.getRel('ufFieldCollection').hasDuplicates()) {
254 CRM
.alert(ts('Please correct errors before previewing.'), '', 'alert');
257 var $dialog
= this.$el
.closest('.crm-designer-dialog'); // FIXME use events
258 $dialog
.block({message
: 'Loading...', theme
: true});
260 CRM
.designerApp
.clearPreviewArea();
262 url
: CRM
.url("civicrm/ajax/inline"),
265 'qfKey': CRM
.profilePreviewKey
,
266 'class_name': 'CRM_UF_Form_Inline_Preview',
268 'ufData': JSON
.stringify({
269 ufGroup
: this.model
.toStrictJSON(),
270 ufFieldCollection
: this.model
.getRel('ufFieldCollection').toSortedJSON()
273 }).done(function(data
) {
275 $('.crm-designer-canvas > *, .crm-designer-palette-region').hide();
276 $('.crm-designer-preview-canvas').html(data
).show();
277 $('.crm-designer-preview span').html(ts('Edit'));
284 * Display a selection of available fields
287 * - model: CRM.UF.UFGroupModel
289 CRM
.Designer
.PaletteView
= Backbone
.Marionette
.ItemView
.extend({
290 serializeData
: extendedSerializeData
,
291 template
: '#palette_template',
292 el
: '<div class="full-height"></div>',
295 'keyup .crm-designer-palette-search input': 'doSearch',
296 'click .crm-designer-palette-clear-search': 'clearSearch',
297 'click .crm-designer-palette-toggle': 'toggleAll',
298 'click .crm-designer-palette-add button': 'doNewCustomFieldDialog',
299 'dblclick .crm-designer-palette-field': 'doAddToCanvas'
301 initialize: function() {
302 this.model
.getRel('ufFieldCollection')
303 .on('add', this.toggleActive
, this)
304 .on('remove', this.toggleActive
, this);
305 this.model
.getRel('paletteFieldCollection')
306 .on('reset', this.render
, this);
307 CRM
.designerApp
.vent
.on('resize', this.onResize
, this);
309 onClose: function() {
310 this.model
.getRel('ufFieldCollection')
311 .off('add', this.toggleActive
, this)
312 .off('remove', this.toggleActive
, this);
313 this.model
.getRel('paletteFieldCollection')
314 .off('reset', this.render
, this);
315 CRM
.designerApp
.vent
.off('resize', this.onResize
, this);
317 onRender: function() {
318 var paletteView
= this;
320 // Prepare data for jstree
322 var paletteFieldsByEntitySection
= this.model
.getRel('paletteFieldCollection').getFieldsByEntitySection();
324 paletteView
.model
.getRel('ufEntityCollection').each(function(ufEntityModel
){
325 _
.each(ufEntityModel
.getSections(), function(section
, sectionKey
){
326 var entitySection
= ufEntityModel
.get('entity_name') + '-' + sectionKey
;
328 if (paletteFieldsByEntitySection
[entitySection
]) {
329 _
.each(paletteFieldsByEntitySection
[entitySection
], function(paletteFieldModel
, k
) {
330 items
.push({data
: paletteFieldModel
.getLabel(), attr
: {'class': 'crm-designer-palette-field', 'data-plm-cid': paletteFieldModel
.cid
}});
333 if (section
.is_addable
) {
334 items
.push({data
: ts('+ Add New Field'), attr
: {'class': 'crm-designer-palette-add'}});
336 if (items
.length
> 0) {
340 state
: _
.contains(paletteView
.openTreeNodes
, sectionKey
) ? 'open' : 'closed',
342 'class': 'crm-designer-palette-section',
343 'data-section': sectionKey
,
344 'data-entity': ufEntityModel
.get('entity_name')
351 this.$('.crm-designer-palette-tree').jstree({
352 'json_data': {data
: treeData
},
354 'case_insensitive' : true,
355 'show_only_matches': true
361 "url": CRM
.config
.resourceBase
+ 'packages/jquery/plugins/jstree/themes/classic/style.css'
363 'plugins': ['themes', 'json_data', 'ui', 'search']
364 }).bind('loaded.jstree', function () {
365 $('.crm-designer-palette-field', this).draggable({
366 appendTo
: '.crm-designer',
367 zIndex
: $(this.$el
).zIndex() + 5000,
369 connectToSortable
: '.crm-designer-fields' // FIXME: tight canvas/palette coupling
371 paletteView
.model
.getRel('ufFieldCollection').each(function(ufFieldModel
) {
372 paletteView
.toggleActive(ufFieldModel
, paletteView
.model
.getRel('ufFieldCollection'))
374 paletteView
.$('.crm-designer-palette-add a').replaceWith('<button>' + $('.crm-designer-palette-add a').first().text() + '</<button>');
375 paletteView
.$('.crm-designer-palette-add button').button();
376 }).bind("select_node.jstree", function (e
, data
) {
377 $(this).jstree("toggle_node", data
.rslt
.obj
);
378 $(this).jstree("deselect_node", data
.rslt
.obj
);
381 // FIXME: tight canvas/palette coupling
382 this.$(".crm-designer-fields").droppable({
383 activeClass
: "ui-state-default",
384 hoverClass
: "ui-state-hover",
385 accept
: ":not(.ui-sortable-helper)"
390 onResize: function() {
391 var pos
= this.$('.crm-designer-palette-tree').position();
392 var div
= this.$('.crm-designer-palette-tree').closest('.crm-container').height();
393 this.$('.crm-designer-palette-tree').css({height
: div
- pos
.top
});
395 doSearch: function(event
) {
396 $('.crm-designer-palette-tree').jstree("search", $(event
.target
).val());
398 doAddToCanvas: function(event
) {
399 var paletteFieldModel
= this.model
.getRel('paletteFieldCollection').get($(event
.currentTarget
).attr('data-plm-cid'));
400 paletteFieldModel
.addToUFCollection(this.model
.getRel('ufFieldCollection'));
401 event
.stopPropagation();
403 doNewCustomFieldDialog: function(event
) {
404 var paletteView
= this;
405 var entityKey
= $(event
.currentTarget
).closest('.crm-designer-palette-section').attr('data-entity');
406 var sectionKey
= $(event
.currentTarget
).closest('.crm-designer-palette-section').attr('data-section');
407 var ufEntityModel
= paletteView
.model
.getRel('ufEntityCollection').getByName(entityKey
);
408 var sections
= ufEntityModel
.getSections();
409 var url
= CRM
.url('civicrm/admin/custom/group/field/add', {
412 gid
: sections
[sectionKey
].custom_group_id
415 resetButton
: 'next_new',
416 onSuccess: function(data
, settings
) {
417 paletteView
.doRefresh('custom_' + data
.id
);
422 doRefresh: function(fieldToAdd
) {
423 var ufGroupModel
= this.model
;
424 this.getOpenTreeNodes();
425 CRM
.Schema
.reloadModels()
426 .done(function(data
){
427 ufGroupModel
.resetEntities();
429 var field
= ufGroupModel
.getRel('paletteFieldCollection').getFieldByName(null, fieldToAdd
);
430 field
.addToUFCollection(ufGroupModel
.getRel('ufFieldCollection'));
434 CRM
.alert(ts('Failed to retrieve schema'), ts('Error'), 'error');
437 clearSearch: function(event
) {
438 $('.crm-designer-palette-search input').val('').keyup();
441 toggleActive: function(ufFieldModel
, ufFieldCollection
, options
) {
442 var paletteFieldCollection
= this.model
.getRel('paletteFieldCollection');
443 var paletteFieldModel
= paletteFieldCollection
.getFieldByName(ufFieldModel
.get('entity_name'), ufFieldModel
.get('field_name'));
444 var isAddable
= ufFieldCollection
.isAddable(ufFieldModel
);
445 this.$('[data-plm-cid='+paletteFieldModel
.cid
+']').toggleClass('disabled', !isAddable
);
447 toggleAll: function(event
) {
448 if ($('.crm-designer-palette-search input').val() == '') {
449 $('.crm-designer-palette-tree').jstree($(event
.target
).attr('rel'));
453 getOpenTreeNodes: function() {
454 var paletteView
= this;
455 this.openTreeNodes
= [];
456 this.$('.crm-designer-palette-section.jstree-open').each(function() {
457 paletteView
.openTreeNodes
.push($(this).data('section'));
463 * Display all UFFieldModel objects in a UFGroupModel.
466 * - model: CRM.UF.UFGroupModel
468 CRM
.Designer
.UFFieldCanvasView
= Backbone
.Marionette
.View
.extend({
469 initialize: function() {
470 this.model
.getRel('ufFieldCollection')
471 .on('add', this.updatePlaceholder
, this)
472 .on('remove', this.updatePlaceholder
, this)
473 .on('add', this.addUFFieldView
, this);
475 onClose: function() {
476 this.model
.getRel('ufFieldCollection')
477 .off('add', this.updatePlaceholder
, this)
478 .off('remove', this.updatePlaceholder
, this)
479 .off('add', this.addUFFieldView
, this);
482 var ufFieldCanvasView
= this;
483 this.$el
.html(_
.template($('#field_canvas_view_template').html()));
485 // BOTTOM: Setup field-level editing
486 var $fields
= this.$('.crm-designer-fields');
487 this.updatePlaceholder();
488 var ufFieldModels
= this.model
.getRel('ufFieldCollection').sortBy(function(ufFieldModel
) {
489 return parseInt(ufFieldModel
.get('weight'));
491 _
.each(ufFieldModels
, function(ufFieldModel
) {
492 ufFieldCanvasView
.addUFFieldView(ufFieldModel
, ufFieldCanvasView
.model
.getRel('ufFieldCollection'), {skipWeights
: true});
494 this.$(".crm-designer-fields").sortable({
495 placeholder
: 'crm-designer-row-placeholder',
496 forcePlaceholderSize
: true,
497 receive: function(event
, ui
) {
498 var paletteFieldModel
= ufFieldCanvasView
.model
.getRel('paletteFieldCollection').get(ui
.item
.attr('data-plm-cid'));
499 var ufFieldModel
= paletteFieldModel
.addToUFCollection(
500 ufFieldCanvasView
.model
.getRel('ufFieldCollection'),
503 if (null == ufFieldModel
) {
504 ufFieldCanvasView
.$('.crm-designer-fields .ui-draggable').remove();
506 // Move from end to the 'dropped' position
507 var ufFieldViewEl
= ufFieldCanvasView
.$('div[data-field-cid='+ufFieldModel
.cid
+']').parent();
508 ufFieldCanvasView
.$('.crm-designer-fields .ui-draggable').replaceWith(ufFieldViewEl
);
510 // note: the sortable() update callback will call updateWeight
513 ufFieldCanvasView
.updateWeights();
517 /** Determine visual order of fields and set the model values for "weight" */
518 updateWeights: function() {
519 var ufFieldCanvasView
= this;
521 var rows
= this.$('.crm-designer-row').each(function(key
, row
) {
522 if ($(row
).hasClass('placeholder')) {
525 var ufFieldCid
= $(row
).attr('data-field-cid');
526 var ufFieldModel
= ufFieldCanvasView
.model
.getRel('ufFieldCollection').get(ufFieldCid
);
527 ufFieldModel
.set('weight', weight
);
531 addUFFieldView: function(ufFieldModel
, ufFieldCollection
, options
) {
532 var paletteFieldModel
= this.model
.getRel('paletteFieldCollection').getFieldByName(ufFieldModel
.get('entity_name'), ufFieldModel
.get('field_name'));
533 var ufFieldView
= new CRM
.Designer
.UFFieldView({
534 el
: $("<div></div>"),
536 paletteFieldModel
: paletteFieldModel
538 ufFieldView
.render();
539 this.$('.crm-designer-fields').append(ufFieldView
.$el
);
540 if (! (options
&& options
.skipWeights
)) {
541 this.updateWeights();
544 updatePlaceholder: function() {
545 if (this.model
.getRel('ufFieldCollection').isEmpty()) {
546 this.$('.placeholder').css({display
: 'block', border
: '0 none', cursor
: 'default'});
548 this.$('.placeholder').hide();
555 * - model: CRM.UF.UFFieldModel
556 * - paletteFieldModel: CRM.Designer.PaletteFieldModel
558 CRM
.Designer
.UFFieldView
= Backbone
.Marionette
.Layout
.extend({
559 serializeData
: extendedSerializeData
,
560 template
: '#field_row_template',
563 summary
: '.crm-designer-field-summary',
564 detail
: '.crm-designer-field-detail'
567 "click .crm-designer-action-settings": 'doToggleForm',
568 "click .crm-designer-action-remove": 'doRemove'
572 "change:is_duplicate": 'onChangeIsDuplicate'
574 onRender: function() {
575 this.summary
.show(new CRM
.Designer
.UFFieldSummaryView({
577 fieldSchema
: this.model
.getFieldSchema(),
578 paletteFieldModel
: this.options
.paletteFieldModel
580 this.detail
.show(new CRM
.Designer
.UFFieldDetailView({
582 fieldSchema
: this.model
.getFieldSchema()
584 this.onChangeIsDuplicate(this.model
, this.model
.get('is_duplicate'))
585 if (!this.expanded
) {
586 this.detail
.$el
.hide();
589 CRM
.designerApp
.vent
.on('formOpened', function(event
) {
590 if (that
.expanded
&& event
!= that
.cid
) {
591 that
.doToggleForm(false);
595 doToggleForm: function(event
) {
596 this.expanded
= !this.expanded
;
597 if (this.expanded
&& event
!== false) {
598 CRM
.designerApp
.vent
.trigger('formOpened', this.cid
);
600 this.$el
.toggleClass('crm-designer-open', this.expanded
);
601 var $detail
= this.detail
.$el
;
602 if (!this.expanded
) {
603 $detail
.toggle('blind', 250);
606 var $canvas
= $('.crm-designer-canvas');
607 var top
= $canvas
.offset().top
;
610 step: function(num
, effect
) {
611 // Scroll canvas to keep field details visible
612 if (effect
.prop
== 'height') {
613 if (effect
.now
+ $detail
.offset().top
- top
> $canvas
.height() - 9) {
614 $canvas
.scrollTop($canvas
.scrollTop() + effect
.now
+ $detail
.offset().top
- top
- $canvas
.height() + 9);
621 onChangeIsDuplicate: function(model
, value
, options
) {
622 this.$el
.toggleClass('crm-designer-duplicate', value
);
624 doRemove: function(event
) {
626 this.$el
.hide(250, function() {
627 that
.model
.destroyLocal();
634 * - model: CRM.UF.UFFieldModel
635 * - fieldSchema: (Backbone.Form schema element)
636 * - paletteFieldModel: CRM.Designer.PaletteFieldModel
638 CRM
.Designer
.UFFieldSummaryView
= Backbone
.Marionette
.ItemView
.extend({
639 serializeData
: extendedSerializeData
,
640 template
: '#field_summary_template',
646 * Compose a printable string which describes the binding of this UFField to the data model
649 getBindingLabel: function() {
650 var result
= this.options
.paletteFieldModel
.getSection().title
+ ": " + this.options
.paletteFieldModel
.getLabel();
651 if (this.options
.fieldSchema
.civiIsPhone
) {
652 result
= result
+ '-' + CRM
.PseudoConstant
.phoneType
[this.model
.get('phone_type_id')];
654 if (this.options
.fieldSchema
.civiIsLocation
) {
655 var locType
= this.model
.get('location_type_id') ? CRM
.PseudoConstant
.locationType
[this.model
.get('location_type_id')] : ts('Primary');
656 result
= result
+ ' (' + locType
+ ')';
662 * Return a string marking if the field is required
665 getRequiredMarker: function() {
666 if (this.model
.get('is_required') == 1) {
667 return ' <span class="crm-marker">*</span> ';
672 onRender: function() {
673 this.$el
.toggleClass('disabled', this.model
.get('is_active') != 1);
674 if (this.model
.get("is_reserved") == 1) {
675 this.$('.crm-designer-buttons').hide();
682 * - model: CRM.UF.UFFieldModel
683 * - fieldSchema: (Backbone.Form schema element)
685 CRM
.Designer
.UFFieldDetailView
= Backbone
.View
.extend({
686 initialize: function() {
687 // FIXME: hide/display 'in_selector' if 'visibility' is one of the public options
688 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'];
689 if (! this.options
.fieldSchema
.civiIsLocation
) {
690 fields
= _
.without(fields
, 'location_type_id');
692 if (! this.options
.fieldSchema
.civiIsPhone
) {
693 fields
= _
.without(fields
, 'phone_type_id');
695 if (!this.options
.fieldSchema
.civiIsMultiple
) {
696 fields
= _
.without(fields
, 'is_multi_summary');
699 this.form
= new Backbone
.Form({
703 this.form
.on('change', this.onFormChange
, this);
704 this.model
.on('change', this.onModelChange
, this);
707 this.$el
.html(this.form
.render().el
);
710 onModelChange: function() {
711 $.each(this.form
.fields
, function(i
, field
) {
712 this.form
.setValue(field
.key
, this.model
.get(field
.key
));
715 onFormChange: function() {
717 this.$('.field-is_multi_summary').toggle(this.options
.fieldSchema
.civiIsMultiple
? true : false);
718 this.$('.field-in_selector').toggle(this.model
.isInSelectorAllowed());
719 // this.$(':input').attr('disabled', this.model.get("is_reserved") == 1);
721 if (!this.model
.isInSelectorAllowed() && this.model
.get('in_selector') != "0") {
722 this.model
.set('in_selector', "0");
723 this.form
.setValue('in_selector', "0");
724 // TODO: It might be nicer if we didn't completely discard in_selector -- e.g.
725 // if the value could be restored when the user isInSelectorAllowed becomes true
726 // again. However, I haven't found a simple way to do this.
733 * - model: CRM.UF.UFGroupModel
735 CRM
.Designer
.UFGroupView
= Backbone
.Marionette
.Layout
.extend({
736 serializeData
: extendedSerializeData
,
737 template
: '#form_row_template',
740 summary
: '.crm-designer-form-summary',
741 detail
: '.crm-designer-form-detail'
744 "click .crm-designer-action-settings": 'doToggleForm'
746 onRender: function() {
747 this.summary
.show(new CRM
.Designer
.UFGroupSummaryView({
750 this.detail
.show(new CRM
.Designer
.UFGroupDetailView({
753 if (!this.expanded
) {
754 this.detail
.$el
.hide();
757 CRM
.designerApp
.vent
.on('formOpened', function(event
) {
758 if (that
.expanded
&& event
!== 0) {
759 that
.doToggleForm(false);
763 doToggleForm: function(event
) {
764 this.expanded
= !this.expanded
;
765 if (this.expanded
&& event
!== false) {
766 CRM
.designerApp
.vent
.trigger('formOpened', 0);
768 this.$el
.toggleClass('crm-designer-open', this.expanded
);
769 this.detail
.$el
.toggle('blind', 250);
775 * - model: CRM.UF.UFGroupModel
777 CRM
.Designer
.UFGroupSummaryView
= Backbone
.Marionette
.ItemView
.extend({
778 serializeData
: extendedSerializeData
,
779 template
: '#form_summary_template',
783 onRender: function() {
784 this.$el
.toggleClass('disabled', this.model
.get('is_active') != 1);
785 if (this.model
.get("is_reserved") == 1) {
786 this.$('.crm-designer-buttons').hide();
793 * - model: CRM.UF.UFGroupModel
795 CRM
.Designer
.UFGroupDetailView
= Backbone
.View
.extend({
796 initialize: function() {
797 this.form
= new Backbone
.Form({
799 fields
: ['title', 'help_pre', 'help_post', 'is_active']
801 this.form
.on('change', this.form
.commit
, this.form
);
804 this.$el
.html(this.form
.render().el
);