right: 0;
}
+#afGuiEditor .input-group-addon {
+ padding: 0;
+}
+
#afGuiEditor .af-gui-text-h1 {
font-weight: bolder;
font-size: 16px;
--- /dev/null
+<span title="{{:: ts('Insert Token') }}">
+ <input class="form-control crm-action-menu fa-code collapsible-optgroups"
+ crm-ui-select="$ctrl.tokenSelectSettings"
+ on-crm-ui-select="$ctrl.insertToken(selection)"
+ />
+</span>
--- /dev/null
+(function(angular, $, _) {
+ "use strict";
+
+ angular.module('afGuiEditor').component('afGuiTokenSelect', {
+ bindings: {
+ model: '<',
+ field: '@'
+ },
+ require: {
+ editor: '^afGuiEditor'
+ },
+ templateUrl: '~/afGuiEditor/afGuiTokenSelect.html',
+ controller: function ($scope, $element) {
+ var ts = $scope.ts = CRM.ts('org.civicrm.afform_admin'),
+ ctrl = this;
+
+ this.$onInit = function() {
+ // Because this widget is so small, some placeholder text is helpful once it's open
+ $element.on('select2-open', function() {
+ $('#select2-drop > .select2-search > input').attr('placeholder', ts('Insert Token'));
+ });
+ };
+
+ this.insertToken = function(key) {
+ ctrl.model[ctrl.field] = (ctrl.model[ctrl.field] || '') + '[' + key + ']';
+ };
+
+ this.getTokens = function() {
+ var tokens = _.transform(ctrl.editor.getEntities(), function(tokens, entity) {
+ tokens.push({id: entity.name + '.0.id', text: entity.label + ' ' + ts('ID')});
+ }, []);
+ tokens.push({id: 'token', text: ts('Submission JWT')});
+ return {
+ results: tokens
+ };
+ };
+
+ this.tokenSelectSettings = {
+ data: this.getTokens,
+ // The crm-action-menu icon doesn't show without a placeholder
+ placeholder: ' ',
+ // Make this widget very compact
+ width: '52px',
+ containerCss: {minWidth: '52px'},
+ // Make the dropdown wider than the widget
+ dropdownCss: {width: '250px'}
+ };
+
+ }
+ });
+
+})(angular, CRM.$, CRM._);
<label for="af_config_redirect">
{{:: ts('Post-Submit Page') }}
</label>
- <input ng-model="editor.afform.redirect" name="redirect" class="form-control" id="af_config_redirect" title="{{:: ts('Post-Submit Page') }}" pattern="^((http|https):\/\/|\/|civicrm\/)[-0-9a-zA-Z\/_.]\S+$" title="{{:: ts('Post-Submit Page must be either an absolute url, a relative url or a path starting with CiviCRM') }}" ng-model-options="editor.debounceMode" >
+ <div class="input-group">
+ <input ng-model="editor.afform.redirect" name="redirect" class="form-control" id="af_config_redirect" title="{{:: ts('Post-Submit Page') }}" pattern="^((http|https):\/\/|\/|civicrm\/)[-0-9a-zA-Z\/_.]\S+$" title="{{:: ts('Post-Submit Page must be either an absolute url, a relative url or a path starting with CiviCRM') }}" ng-model-options="editor.debounceMode" >
+ <af-gui-token-select class="input-group-addon" model="editor.afform" field="redirect"></af-gui-token-select>
+ </div>
<p class="help-block">{{:: ts('Enter a URL or path that the form should redirect to following a successful submission.') }}</p>
</div>
</fieldset>
// Return ids and a token for uploading files
return [
- [
- 'token' => $this->generatePostSubmitToken(),
- ],
+ ['token' => $this->generatePostSubmitToken()] + $this->_entityIds,
];
}
bindings: {
ctrl: '@'
},
- controller: function($scope, $element, $timeout, crmApi4, crmStatus, $window, $location, FileUploader) {
+ controller: function($scope, $element, $timeout, crmApi4, crmStatus, $window, $location, $parse, FileUploader) {
var schema = {},
data = {},
status,
args,
+ submissionResponse,
ctrl = this;
this.$onInit = function() {
}
else if (metaData.redirect) {
- var url = metaData.redirect;
+ var url = replaceTokens(metaData.redirect, submissionResponse[0]);
if (url.indexOf('civicrm/') === 0) {
url = CRM.url(url);
} else if (url.indexOf('/') === 0) {
}
}
+ function replaceTokens(str, vars) {
+ function recurse(stack, values) {
+ _.each(values, function(value, key) {
+ console.log('value:' + value, stack);
+ if (_.isArray(value) || _.isPlainObject(value)) {
+ recurse(stack.concat([key]), value);
+ } else {
+ var token = (stack.length ? stack.join('.') + '.' : '') + key;
+ str = str.replace(new RegExp(_.escapeRegExp('[' + token + ']'), 'g'), value);
+ }
+ });
+ }
+ recurse([], vars);
+ return str;
+ }
+
this.submit = function() {
status = CRM.status({});
$element.block();
args: args,
values: data}
).then(function(response) {
+ submissionResponse = response;
if (ctrl.fileUploader.getNotUploadedItems().length) {
_.each(ctrl.fileUploader.getNotUploadedItems(), function(file) {
file.formData.push({