};
})
+ // Editable text using ngModel & html5 contenteditable
+ // Usage: <span crm-ui-editable ng-model="my.data">{{ my.data }}</span>
+ .directive("crmUiEditable", function() {
+ return {
+ restrict: "A",
+ require: "ngModel",
+ scope: {
+ defaultValue: '='
+ },
+ link: function(scope, element, attrs, ngModel) {
+ var ts = CRM.ts();
+
+ function read() {
+ var htmlVal = element.html();
+ if (!htmlVal) {
+ htmlVal = scope.defaultValue || '';
+ element.text(htmlVal);
+ }
+ ngModel.$setViewValue(htmlVal);
+ }
+
+ ngModel.$render = function() {
+ element.text(ngModel.$viewValue || scope.defaultValue || '');
+ };
+
+ // Special handling for enter and escape keys
+ element.on('keydown', function(e) {
+ // Enter: prevent line break and save
+ if (e.which === 13) {
+ e.preventDefault();
+ element.blur();
+ }
+ // Escape: undo
+ if (e.which === 27) {
+ element.text(ngModel.$viewValue || scope.defaultValue || '');
+ element.blur();
+ }
+ });
+
+ element.on("blur change", function() {
+ scope.$apply(read);
+ });
+
+ element.attr('contenteditable', 'true').addClass('crm-editable-enabled');
+ }
+ };
+ })
+
.run(function($rootScope, $location) {
/// Example: <button ng-click="goto('home')">Go home!</button>
$rootScope.goto = function(path) {
$location.path(path);
};
// useful for debugging: $rootScope.log = console.log || function() {};
- })
- ;
+ });
})(angular, CRM.$, CRM._);
display: inline-block;
padding: 0 4px !important;
border: 2px solid transparent !important;
+ min-width: 21px;
}
#afGuiEditor .crm-editable-enabled:hover:not(:focus) {
border: 2px dashed grey !important;
</div>
<ul ui-sortable="{connectWith: '.af-gui-edit-options-deleted', cancel: 'input,textarea,button,select,option,a,[contenteditable]'}" ng-model="options" class="af-gui-edit-options-enabled">
<li ng-repeat="option in options">
- <div af-gui-editable ng-model="option.label" default-value="originalLabels[option.id]" >{{ option.label }}</div>
+ <div crm-ui-editable ng-model="option.label" default-value="originalLabels[option.id]" >{{ option.label }}</div>
<button type="button" class="btn btn-danger-outline btn-xs pull-right" ng-click="deleteOption(option, $index)" title="{{:: ts('Remove option') }}">
<i class="crm-i fa-trash"></i>
</button>
+++ /dev/null
-// https://civicrm.org/licensing
-(function(angular, $, _) {
- "use strict";
-
- // Editable titles using ngModel & html5 contenteditable
- // Cribbed from ContactLayoutEditor
- angular.module('afGuiEditor').directive("afGuiEditable", function() {
- return {
- restrict: "A",
- require: "ngModel",
- scope: {
- defaultValue: '='
- },
- link: function(scope, element, attrs, ngModel) {
- var ts = CRM.ts();
-
- function read() {
- var htmlVal = element.html();
- if (!htmlVal) {
- htmlVal = scope.defaultValue;
- element.text(htmlVal);
- }
- ngModel.$setViewValue(htmlVal);
- }
-
- ngModel.$render = function() {
- element.text(ngModel.$viewValue || scope.defaultValue);
- };
-
- // Special handling for enter and escape keys
- element.on('keydown', function(e) {
- // Enter: prevent line break and save
- if (e.which === 13) {
- e.preventDefault();
- element.blur();
- }
- // Escape: undo
- if (e.which === 27) {
- element.html(ngModel.$viewValue || scope.defaultValue);
- element.blur();
- }
- });
-
- element.on("blur change", function() {
- scope.$apply(read);
- });
-
- element.attr('contenteditable', 'true').addClass('crm-editable-enabled');
- }
- };
- });
-
-})(angular, CRM.$, CRM._);
</li>
<li role="presentation" ng-repeat="entity in entities" ng-class="{active: selectedEntityName === entity.name}">
<a href ng-click="editor.selectEntity(entity.name)">
- <span ng-if="!entity.loading && editor.allowEntityConfig" af-gui-editable ng-model="entity.label">{{ entity.label }}</span>
+ <span ng-if="!entity.loading && editor.allowEntityConfig" crm-ui-editable ng-model="entity.label">{{ entity.label }}</span>
<span ng-if="!entity.loading && !editor.allowEntityConfig">{{ entity.label }}</span>
<i ng-if="entity.loading" class="crm-i fa-spin fa-spinner"></i>
</a>
<span class="crm-editable-enabled" ng-click="pickIcon()" >
<i class="crm-i {{ $ctrl.node['crm-icon'] }}"></i>
</span>
- <span af-gui-editable ng-model="$ctrl.node['#children'][0]['#text']" >
+ <span crm-ui-editable ng-model="$ctrl.node['#children'][0]['#text']" >
{{ $ctrl.node['#children'][0]['#text'] }}
</span>
</button>
<span class="crm-editable-enabled" ng-click="pickAddIcon()" >
<i class="crm-i {{ $ctrl.node['add-icon'] || 'fa-plus' }}"></i>
</span>
- <span af-gui-editable ng-model="$ctrl.node['af-repeat']">{{ $ctrl.node['af-repeat'] }}</span>
+ <span crm-ui-editable ng-model="$ctrl.node['af-repeat']">{{ $ctrl.node['af-repeat'] }}</span>
</button>
</div>
</div>
</div>
<label ng-style="{visibility: $ctrl.node.defn.label === false ? 'hidden' : 'visible'}" ng-class="{'af-gui-field-required': getProp('required')}" class="af-gui-node-title">
- <span af-gui-editable ng-model="getSet('label')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().label">{{ getProp('label') }}</span>
+ <span crm-ui-editable ng-model="getSet('label')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().label">{{ getProp('label') }}</span>
</label>
<div class="af-gui-field-help" ng-if="propIsset('help_pre')">
- <span af-gui-editable ng-model="getSet('help_pre')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().help_pre">{{ getProp('help_pre') }}</span>
+ <span crm-ui-editable ng-model="getSet('help_pre')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().help_pre">{{ getProp('help_pre') }}</span>
</div>
<div class="af-gui-field-input af-gui-field-input-type-{{ getProp('input_type').toLowerCase() }}" ng-include="'~/afGuiEditor/inputType/' + getProp('input_type') + '.html'"></div>
<div class="af-gui-field-help" ng-if="propIsset('help_post')">
- <span af-gui-editable ng-model="getSet('help_post')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().help_post">{{ getProp('help_post') }}</span>
+ <span crm-ui-editable ng-model="getSet('help_post')" ng-model-options="{getterSetter: true}" default-value="$ctrl.getDefn().help_post">{{ getProp('help_post') }}</span>
</div>
</div>
</div>
</div>
<p class="af-gui-node-title {{ $ctrl.node['class'] + ' af-gui-text-' + $ctrl.node['#tag'] }}" >
- <span af-gui-editable ng-model="$ctrl.node['#children'][0]['#text']">{{ $ctrl.node['#children'][0]['#text'] }}</span>
+ <span crm-ui-editable ng-model="$ctrl.node['#children'][0]['#text']">{{ $ctrl.node['#children'][0]['#text'] }}</span>
</p>