background-color: #b3b3b3;
}
-#afGuiEditor .af-gui-field,
-#afGuiEditor .af-gui-text,
-#afGuiEditor .af-gui-block {
+#afGuiEditor .af-gui-element {
position: relative;
- padding: 32px 3px 3px;
+ padding: 22px 3px 3px;
min-height: 40px;
+}
+
+#afGuiEditor .af-gui-block {
border: 2px dashed transparent;
}
+#afGuiEditor .af-gui-block:hover {
+ border: 2px dashed #757575;
+}
+
#afGuiEditor #afGuiEditor-canvas .af-entity-selected {
border: 2px dashed #0071bd;
}
color: white;
}
-#afGuiEditor .af-gui-block {
- padding-top: 20px;
-}
-
-#afGuiEditor .af-gui-block:hover {
- border: 2px dashed #757575;
-}
-
#afGuiEditor [ui-sortable] {
min-height: 25px;
}
(function(angular, $, _) {
angular.module('afGuiEditor', CRM.angRequires('afGuiEditor'));
+ var editingIcon;
+
angular.module('afGuiEditor').directive('afGuiEditor', function(crmApi4, $parse, $timeout) {
return {
restrict: 'A',
scope: {
afGuiEditor: '='
},
+ link: function($scope, element, attrs) {
+ // Shoehorn in a non-angular widget for picking icons
+ CRM.loadScript(CRM.config.resourceBase + 'js/jquery/jquery.crmIconPicker.js').done(function() {
+ $('#af-gui-icon-picker').crmIconPicker().change(function() {
+ if (editingIcon) {
+ $scope.$apply(function() {
+ editingIcon['crm-icon'] = $('#af-gui-icon-picker').val();
+ editingIcon = null;
+ $('#af-gui-icon-picker').val('').change();
+ });
+ }
+ });
+ });
+ },
controller: function($scope) {
$scope.ts = CRM.ts();
$scope.afform = null;
editor.addEntity('Contact');
$scope.layout['#children'].push({
"#tag": "button",
+ "class": 'af-button btn btn-primary',
+ "crm-icon": 'fa-check',
"ng-click": "modelListCtrl.submit()",
"#children": [
{
if (_.contains(classes, 'af-text')) {
return 'text';
}
+ if (_.contains(classes, 'af-button')) {
+ return 'button';
+ }
return null;
};
'class': 'af-' + type,
'#children': type == 'block' ? [] : [{'#text': ts('Enter text')}]
};
+ if (type === 'button') {
+ newBlock['#tag'] = 'button';
+ newBlock['class'] += ' btn btn-primary';
+ newBlock['crm-icon'] = 'fa-check';
+ newBlock['ng-click'] = "modelListCtrl.submit()";
+ }
$scope.node['#children'].push(newBlock);
};
}
};
});
+
+ angular.module('afGuiEditor').directive('afGuiButton', function() {
+ return {
+ restrict: 'A',
+ templateUrl: '~/afGuiEditor/button.html',
+ scope: {
+ node: '=afGuiButton'
+ },
+ require: '^^afGuiBlock',
+ link: function($scope, element, attrs, block) {
+ $scope.block = block;
+ },
+ controller: function($scope) {
+
+ // TODO: Add action selector to UI
+ // $scope.actions = {
+ // "modelListCtrl.submit()": ts('Submit Form')
+ // };
+
+ $scope.styles = {
+ 'btn-default': ts('Default'),
+ 'btn-primary': ts('Primary'),
+ 'btn-success': ts('Success'),
+ 'btn-info': ts('Info'),
+ 'btn-warning': ts('Warning'),
+ 'btn-danger': ts('Danger')
+ };
+
+ $scope.getStyle = function() {
+ return _.intersection(splitClass($scope.node['class']), _.keys($scope.styles))[0] || '';
+ };
+
+ $scope.setStyle = function(val) {
+ $scope.block.modifyClasses($scope.node, _.keys($scope.styles), val);
+ };
+
+ $scope.pickIcon = function() {
+ editingIcon = $scope.node;
+ $('#af-gui-icon-picker ~ .crm-icon-picker-button').click();
+ };
+
+ }
+ };
+ });
// Editable titles using ngModel & html5 contenteditable
// Cribbed from ContactLayoutEditor
<ul class="dropdown-menu">
<li><a href ng-click="addBlock('block')">{{ ts('Add block/fieldset') }}</a></li>
<li><a href ng-click="addBlock('text')">{{ ts('Add text box') }}</a></li>
+ <li><a href ng-click="addBlock('button')">{{ ts('Add button') }}</a></li>
</ul>
</div>
</div>
-<div ui-sortable="{handle: '.af-gui-bar', connectWith: '[ui-sortable]'}" ng-model="node['#children']" class="af-gui-layout {{ getLayout() }}">
+<div ui-sortable="{handle: '.af-gui-bar', connectWith: '[ui-sortable]', cancel: 'input,textarea,button,select,option,a'}" ng-model="node['#children']" class="af-gui-layout {{ getLayout() }}">
<div ng-repeat="item in node['#children']" ng-show="block.getNodeType(item)">
<div ng-switch="block.getNodeType(item)">
- <div ng-switch-when="fieldset" af-gui-block="item" class="af-gui-block af-gui-fieldset" ng-class="{'af-entity-selected': isSelectedFieldset(item['af-fieldset'])}" entity-name="item['af-fieldset']" data-entity="{{ item['af-fieldset'] }}" />
- <div ng-switch-when="block" af-gui-block="item" class="af-gui-block" entity-name="entityName" />
- <div ng-switch-when="field" af-gui-field="item" class="af-gui-field" entity-name="entityName" />
- <div ng-switch-when="text" af-gui-text="item" class="af-gui-text" />
+ <div ng-switch-when="fieldset" af-gui-block="item" class="af-gui-element af-gui-block af-gui-fieldset" ng-class="{'af-entity-selected': isSelectedFieldset(item['af-fieldset'])}" entity-name="item['af-fieldset']" data-entity="{{ item['af-fieldset'] }}" />
+ <div ng-switch-when="block" af-gui-block="item" class="af-gui-element af-gui-block" entity-name="entityName" />
+ <div ng-switch-when="field" af-gui-field="item" class="af-gui-element af-gui-field" entity-name="entityName" />
+ <div ng-switch-when="text" af-gui-text="item" class="af-gui-element af-gui-text" />
+ <div ng-switch-when="button" af-gui-button="item" class="af-gui-element af-gui-button" />
</div>
</div>
</div>
--- /dev/null
+<div class="af-gui-bar">
+ {{ node['#tag'] }}
+ <div class="form-inline pull-right">
+ <button type="button" class="btn btn-xs dropdown-toggle {{ getStyle() }}-outline" data-toggle="dropdown" title="{{ ts('Style') }}">
+ <span>{{ styles[getStyle()] }}</span>
+ <i class="crm-i fa-caret-down"></i>
+ </button>
+ <ul class="dropdown-menu">
+ <li ng-repeat="(style, label) in styles" class="{{ style.replace('btn', 'bg') }}">
+ <a href ng-click="setStyle(style)">{{ label }}</a>
+ </li>
+ </ul>
+ </div>
+</div>
+<button type="button" class="btn {{ getStyle() }}">
+ <span class="crm-editable-enabled" ng-click="pickIcon()" >
+ <i class="crm-i {{ node['crm-icon'] }}"></i>
+ </span>
+ <span af-gui-editable ng-model="node['#children'][0]['#text']" >
+ {{ node['#children'][0]['#text'] }}
+ </span>
+</button>
<div>
- <a href ng-click="editor.removeEntity(selectedEntity)" class="btn btn-sm btn-danger pull-right">
+ <a href ng-click="editor.removeEntity(selectedEntity)" class="btn btn-sm btn-danger-outline pull-right">
<i class="crm-i fa-trash"></i>
</a>
<div id="afGuiEditor-palette" ng-include="'~/afGuiEditor/palette.html'"></div>
<div id="afGuiEditor-canvas" ng-include="'~/afGuiEditor/canvas.html'"></div>
</div>
+ <div style="display:none;">
+ <input id="af-gui-icon-picker" title="{{ ts('Choose Icon') }}" />
+ </div>
</div>
</div>
<!-- General elements: FIELDSET, UL, BUTTON, P, H1 should work anywhere -->
- <button ng-click="modelListCtrl.submit()">Submit</button>
+ <button class="af-button btn btn-primary" crm-icon="fa-check" ng-click="modelListCtrl.submit()">Submit</button>
</af-form>