-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Afform - add collapsible title as directive
Before: A fieldset `<legend>` was treated as its own element. This was more flexible but more complex. After: Augenerated `<legend> for fieldsets or `<h4>` for other containers based on new `af-title` directive. This allows central control of titles for e.g. collapsible styles. Fixes dev/core#3110
- Loading branch information
Showing
12 changed files
with
174 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ext/afform/admin/ang/afGuiEditor/afGuiMenuItemCollapsible.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// https://civicrm.org/licensing | ||
(function(angular, $, _) { | ||
"use strict"; | ||
|
||
// Menu item to control the border property of a node | ||
angular.module('afGuiEditor').component('afGuiMenuItemCollapsible', { | ||
templateUrl: '~/afGuiEditor/afGuiMenuItemCollapsible.html', | ||
bindings: { | ||
node: '=' | ||
}, | ||
controller: function($scope, afGui) { | ||
var ts = $scope.ts = CRM.ts('org.civicrm.afform_admin'), | ||
ctrl = this; | ||
|
||
this.isCollapsible = function() { | ||
return afGui.hasClass(ctrl.node, 'af-collapsible'); | ||
}; | ||
|
||
this.isCollapsed = function() { | ||
return afGui.hasClass(ctrl.node, 'af-collapsible af-collapsed'); | ||
}; | ||
|
||
this.toggleCollapsible = function() { | ||
// Node must have a title to be collapsible | ||
if (ctrl.isCollapsible() || !ctrl.node['af-title']) { | ||
afGui.modifyClasses(ctrl.node, 'af-collapsible af-collapsed'); | ||
} else { | ||
afGui.modifyClasses(ctrl.node, null, 'af-collapsible'); | ||
} | ||
}; | ||
|
||
this.toggleCollapsed = function() { | ||
if (ctrl.isCollapsed()) { | ||
afGui.modifyClasses(ctrl.node, 'af-collapsed'); | ||
} else { | ||
afGui.modifyClasses(ctrl.node, null, 'af-collapsed'); | ||
} | ||
}; | ||
|
||
} | ||
}); | ||
|
||
})(angular, CRM.$, CRM._); |
8 changes: 8 additions & 0 deletions
8
ext/afform/admin/ang/afGuiEditor/afGuiMenuItemCollapsible.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<label ng-class="{disabled: !$ctrl.node['af-title']}" ng-click="$ctrl.toggleCollapsible(); $event.stopPropagation();" title="{{ $ctrl.node['af-title'] ? ts('Allow user to collapse this to only show title') : ts('Must have a title to be collapsible') }}"> | ||
<i class="crm-i fa-{{ $ctrl.isCollapsible() ? 'check-' : '' }}square-o"></i> | ||
{{:: ts('Collapsible') }} | ||
</label> | ||
<a href ng-click="$ctrl.toggleCollapsed(); $event.stopPropagation();" class="btn btn-sm btn-default" ng-class="{invisible: !$ctrl.isCollapsible()}"> | ||
<i class="crm-i fa-caret-{{ $ctrl.isCollapsed() ? 'right' : 'down' }}"></i> | ||
{{ $ctrl.isCollapsed() ? ts('Closed') : ts('Open') }} | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(function(angular, $, _) { | ||
"use strict"; | ||
angular.module('af').directive('afTitle', function() { | ||
return { | ||
restrict: 'A', | ||
bindToController: { | ||
title: '@afTitle' | ||
}, | ||
controller: function($scope, $element) { | ||
var ctrl = this; | ||
|
||
$scope.$watch(function() {return ctrl.title;}, function(text) { | ||
var tag = $element.is('fieldset') ? 'legend' : 'h4', | ||
$title = $element.children(tag + '.af-title'); | ||
if (!$title.length) { | ||
$title = $('<' + tag + ' class="af-title" />').prependTo($element); | ||
if ($element.hasClass('af-collapsible')) { | ||
$title.click(function() { | ||
$element.toggleClass('af-collapsed'); | ||
}); | ||
} | ||
} | ||
$title.text(text); | ||
}); | ||
} | ||
}; | ||
}); | ||
})(angular, CRM.$, CRM._); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters