"use strict";
angular.module('afGuiEditor', CRM.angRequires('afGuiEditor'))
- .service('afAdmin', function(crmApi4, $parse, $q) {
+ .service('afGui', function(crmApi4, $parse, $q) {
// Parse strings of javascript that php couldn't interpret
function evaluate(collection) {
name: '<'
},
controllerAs: 'editor',
- controller: function($scope, crmApi4, afAdmin, $parse, $timeout, $location) {
+ controller: function($scope, crmApi4, afGui, $parse, $timeout, $location) {
var ts = $scope.ts = CRM.ts('afform');
$scope.afform = null;
$scope.saving = false;
$scope.selectedEntityName = null;
- this.meta = afAdmin.meta;
+ this.meta = afGui.meta;
var editor = this;
var newForm = {
title: '',
this.$onInit = function() {
// Fetch the current form plus all blocks
- afAdmin.initialize(editor.name)
+ afGui.initialize(editor.name)
.then(initializeForm);
};
}
$scope.canvasTab = 'layout';
$scope.layoutHtml = '';
- editor.layout = afAdmin.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0];
- $scope.entities = afAdmin.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name');
+ editor.layout = afGui.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0];
+ $scope.entities = afGui.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name');
if (editor.name == '0') {
editor.addEntity('Individual');
- editor.layout['#children'].push(afAdmin.meta.elements.submit.element);
+ editor.layout['#children'].push(afGui.meta.elements.submit.element);
}
// Set changesSaved to true on initial load, false thereafter whenever changes are made to the model
};
this.addEntity = function(type) {
- var meta = afAdmin.meta.entities[type],
+ var meta = afGui.meta.entities[type],
num = 1;
// Give this new entity a unique name
while (!!$scope.entities[type + num]) {
var pos = 1 + _.findLastIndex(editor.layout['#children'], {'#tag': 'af-entity'});
editor.layout['#children'].splice(pos, 0, $scope.entities[type + num]);
// Create a new af-fieldset container for the entity
- var fieldset = _.cloneDeep(afAdmin.meta.elements.fieldset.element);
+ var fieldset = _.cloneDeep(afGui.meta.elements.fieldset.element);
fieldset['af-fieldset'] = type + num;
fieldset['#children'][0]['#children'][0]['#text'] = meta.label + ' ' + num;
// Add default contact name block
this.removeEntity = function(entityName) {
delete $scope.entities[entityName];
- afAdmin.removeRecursive(editor.layout['#children'], {'#tag': 'af-entity', name: entityName});
- afAdmin.removeRecursive(editor.layout['#children'], {'af-fieldset': entityName});
+ afGui.removeRecursive(editor.layout['#children'], {'#tag': 'af-entity', name: entityName});
+ afGui.removeRecursive(editor.layout['#children'], {'af-fieldset': entityName});
this.selectEntity(null);
};
entity: '<'
},
require: {editor: '^^afGuiEditor'},
- controller: function ($scope, $timeout, afAdmin) {
+ controller: function ($scope, $timeout, afGui) {
var ts = $scope.ts = CRM.ts();
var ctrl = this;
$scope.controls = {};
}
$scope.getMeta = function() {
- return afAdmin.meta.entities[getEntityType()];
+ return afGui.meta.entities[getEntityType()];
};
- $scope.getField = afAdmin.getField;
+ $scope.getField = afGui.getField;
$scope.valuesFields = function() {
var fields = _.transform($scope.getMeta().fields, function(fields, field) {
fields: filterFields($scope.getMeta().fields)
});
- _.each(afAdmin.meta.entities, function(entity, entityName) {
+ _.each(afGui.meta.entities, function(entity, entityName) {
if (check(ctrl.editor.layout['#children'], {'af-join': entityName})) {
$scope.fieldList.push({
entityName: ctrl.entity.name + '-join-' + entityName,
function buildBlockList(search) {
$scope.blockList.length = 0;
$scope.blockTitles.length = 0;
- _.each(afAdmin.meta.blocks, function(block, directive) {
+ _.each(afGui.meta.blocks, function(block, directive) {
if ((!search || _.contains(directive, search) || _.contains(block.name.toLowerCase(), search) || _.contains(block.title.toLowerCase(), search)) &&
(block.block === '*' || block.block === ctrl.entity.type || (ctrl.entity.type === 'Contact' && block.block === ctrl.entity.data.contact_type))
) {
function buildElementList(search) {
$scope.elementList.length = 0;
$scope.elementTitles.length = 0;
- _.each(afAdmin.meta.elements, function(element, name) {
+ _.each(afGui.meta.elements, function(element, name) {
if (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search)) {
var node = _.cloneDeep(element.element);
if (name === 'fieldset') {
if (block['af-join']) {
return check(ctrl.editor.layout['#children'], {'af-join': block['af-join']});
}
- var fieldsInBlock = _.pluck(afAdmin.findRecursive(afAdmin.meta.blocks[block['#tag']].layout, {'#tag': 'af-field'}), 'name');
+ var fieldsInBlock = _.pluck(afGui.findRecursive(afGui.meta.blocks[block['#tag']].layout, {'#tag': 'af-field'}), 'name');
return check(ctrl.editor.layout['#children'], function(item) {
return item['#tag'] === 'af-field' && _.includes(fieldsInBlock, item.name);
});
check(item['#children'], criteria, found);
}
// Recurse into block directives
- else if (item['#tag'] && item['#tag'] in afAdmin.meta.blocks) {
- check(afAdmin.meta.blocks[item['#tag']].layout, criteria, found);
+ else if (item['#tag'] && item['#tag'] in afGui.meta.blocks) {
+ check(afGui.meta.blocks[item['#tag']].layout, criteria, found);
}
}
});
bindings: {
node: '='
},
- controller: function($scope, afAdmin) {
+ controller: function($scope, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
$scope.getSetBackgroundColor = function(color) {
if (!arguments.length) {
- return afAdmin.getStyles(ctrl.node)['background-color'] || '#ffffff';
+ return afGui.getStyles(ctrl.node)['background-color'] || '#ffffff';
}
- afAdmin.setStyle(ctrl.node, 'background-color', color);
+ afGui.setStyle(ctrl.node, 'background-color', color);
};
}
});
bindings: {
node: '='
},
- controller: function($scope, afAdmin) {
+ controller: function($scope, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
return border[idx];
}
border[idx] = val;
- afAdmin.setStyle(node, 'border', val ? border.join(' ') : null);
+ afGui.setStyle(node, 'border', val ? border.join(' ') : null);
}
function getBorder(node) {
- var border = _.map((afAdmin.getStyles(node).border || '').split(' '), _.trim);
+ var border = _.map((afGui.getStyles(node).border || '').split(' '), _.trim);
return border.length > 2 ? border : null;
}
}
node: '=',
deleteThis: '&'
},
- controller: function($scope, afAdmin) {
+ controller: function($scope, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
// Getter/setter for ng-model
$scope.getSetStyle = function(val) {
if (arguments.length) {
- return afAdmin.modifyClasses(ctrl.node, _.keys($scope.styles), ['btn', val]);
+ return afGui.modifyClasses(ctrl.node, _.keys($scope.styles), ['btn', val]);
}
- return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || '';
+ return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || '';
};
$scope.pickIcon = function() {
- afAdmin.pickIcon().then(function(val) {
+ afGui.pickIcon().then(function(val) {
ctrl.node['crm-icon'] = val;
});
};
deleteThis: '&'
},
require: {editor: '^^afGuiEditor'},
- controller: function($scope, crmApi4, dialogService, afAdmin) {
+ controller: function($scope, crmApi4, dialogService, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
this.$onInit = function() {
- if ((ctrl.node['#tag'] in afAdmin.meta.blocks) || ctrl.join) {
+ if ((ctrl.node['#tag'] in afGui.meta.blocks) || ctrl.join) {
initializeBlockContainer();
}
};
};
$scope.isRepeatable = function() {
- return ctrl.node['af-fieldset'] || (block.directive && afAdmin.meta.blocks[block.directive].repeat) || ctrl.join;
+ return ctrl.node['af-fieldset'] || (block.directive && afGui.meta.blocks[block.directive].repeat) || ctrl.join;
};
$scope.toggleRepeat = function() {
};
$scope.pickAddIcon = function() {
- afAdmin.pickIcon().then(function(val) {
+ afGui.pickIcon().then(function(val) {
ctrl.node['add-icon'] = val;
});
};
if (!ctrl.node) {
return '';
}
- return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.layouts))[0] || 'af-layout-rows';
+ return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.layouts))[0] || 'af-layout-rows';
};
$scope.setLayout = function(val) {
if (val !== 'af-layout-rows') {
classes.push(val);
}
- afAdmin.modifyClasses(ctrl.node, _.keys($scope.layouts), classes);
+ afGui.modifyClasses(ctrl.node, _.keys($scope.layouts), classes);
};
$scope.selectBlockDirective = function() {
if (block.directive) {
- block.layout = _.cloneDeep(afAdmin.meta.blocks[block.directive].layout);
+ block.layout = _.cloneDeep(afGui.meta.blocks[block.directive].layout);
block.original = block.directive;
setBlockDirective(block.directive);
}
listeners: []
};
- _.each(afAdmin.meta.blocks, function(blockInfo, directive) {
+ _.each(afGui.meta.blocks, function(blockInfo, directive) {
if (directive === ctrl.node['#tag'] || blockInfo.join === ctrl.getFieldEntityType()) {
block.options.push({
id: directive,
}
});
- if (getBlockNode() && getBlockNode()['#tag'] in afAdmin.meta.blocks) {
+ if (getBlockNode() && getBlockNode()['#tag'] in afGui.meta.blocks) {
block.directive = block.original = getBlockNode()['#tag'];
- block.layout = _.cloneDeep(afAdmin.meta.blocks[block.directive].layout);
+ block.layout = _.cloneDeep(afGui.meta.blocks[block.directive].layout);
}
block.listeners.push($scope.$watch('block.layout', function (layout, oldVal) {
- if (block.directive && layout && layout !== oldVal && !angular.equals(layout, afAdmin.meta.blocks[block.directive].layout)) {
+ if (block.directive && layout && layout !== oldVal && !angular.equals(layout, afGui.meta.blocks[block.directive].layout)) {
overrideBlockContents(block.layout);
}
}, true));
model.join = ctrl.join;
}
if ($scope.block && $scope.block.original) {
- model.title = afAdmin.meta.blocks[$scope.block.original].title;
- model.name = afAdmin.meta.blocks[$scope.block.original].name;
- model.block = afAdmin.meta.blocks[$scope.block.original].block;
+ model.title = afGui.meta.blocks[$scope.block.original].title;
+ model.name = afGui.meta.blocks[$scope.block.original].name;
+ model.block = afGui.meta.blocks[$scope.block.original].block;
}
else {
model.block = ctrl.container.getFieldEntityType() || '*';
}
dialogService.open('saveBlockDialog', '~/afGuiEditor/saveBlock.html', model, options)
.then(function(block) {
- afAdmin.meta.blocks[block.directive_name] = block;
+ afGui.meta.blocks[block.directive_name] = block;
setBlockDirective(block.directive_name);
initializeBlockContainer();
});
if (node['af-join']) {
return 'join';
}
- if (node['#tag'] && node['#tag'] in afAdmin.meta.blocks) {
+ if (node['#tag'] && node['#tag'] in afGui.meta.blocks) {
return 'container';
}
- var classes = afAdmin.splitClass(node['class']),
+ var classes = afGui.splitClass(node['class']),
types = ['af-container', 'af-text', 'af-button', 'af-markup'],
type = _.intersection(types, classes);
return type.length ? type[0].replace('af-', '') : null;
};
this.removeElement = function(element) {
- afAdmin.removeRecursive($scope.getSetChildren(), {$$hashKey: element.$$hashKey});
+ afGui.removeRecursive($scope.getSetChildren(), {$$hashKey: element.$$hashKey});
};
this.getEntityName = function() {
editor: '^^afGuiEditor',
container: '^^afGuiContainer'
},
- controller: function($scope, afAdmin) {
+ controller: function($scope, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
];
this.$onInit = function() {
- $scope.meta = afAdmin.meta;
+ $scope.meta = afGui.meta;
};
$scope.getEntity = function() {
};
$scope.getDefn = this.getDefn = function() {
- return ctrl.editor ? afAdmin.getField(ctrl.container.getFieldEntityType(), ctrl.node.name) : {};
+ return ctrl.editor ? afGui.getField(ctrl.container.getFieldEntityType(), ctrl.node.name) : {};
};
$scope.hasOptions = function() {
node: '=',
deleteThis: '&'
},
- controller: function($scope, afAdmin) {
+ controller: function($scope, afGui) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;
};
$scope.getAlign = function() {
- return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.alignments))[0] || 'text-left';
+ return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.alignments))[0] || 'text-left';
};
$scope.setAlign = function(val) {
- afAdmin.modifyClasses(ctrl.node, _.keys($scope.alignments), val === 'text-left' ? null : val);
+ afGui.modifyClasses(ctrl.node, _.keys($scope.alignments), val === 'text-left' ? null : val);
};
$scope.styles = _.transform(CRM.afGuiEditor.styles, function(styles, val, key) {
// Getter/setter for ng-model
$scope.getSetStyle = function(val) {
if (arguments.length) {
- return afAdmin.modifyClasses(ctrl.node, _.keys($scope.styles), val === 'text-default' ? null : val);
+ return afGui.modifyClasses(ctrl.node, _.keys($scope.styles), val === 'text-default' ? null : val);
}
- return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || 'text-default';
+ return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || 'text-default';
};
}