advanced claim addition function

pull/1033/head
Justin Richer 2016-02-12 17:32:52 -05:00
parent cebf0fb8b2
commit cf70a20069
3 changed files with 83 additions and 2 deletions

View File

@ -38,9 +38,12 @@
"share-email": "Share with email address",
"new": "New Policy",
"edit": "Edit Policy"
},
"webfinger-error": "Error",
"webfinger-error-description": "The server was unable to find an identity provider for <code>__email__</code>."
"webfinger-error-description": "The server was unable to find an identity provider for <code>__email__</code>.",
"advanced-error": "Error",
"advanced-error-description": "There was an error saving your advanced claim. Did you fill in all required fields?"
},
"sidebar": {
"personal": {

View File

@ -486,6 +486,84 @@ var PolicyFormView = Backbone.View.extend({
});
});
},
addAdvancedClaim:function(e) {
e.preventDefault();
var name = $('#name', this.el).val();
var friendly = $('#friendly-name', this.el).val();
var rawValue = $('#value', this.el).val();
var valueType = $('#value-type', this.el).val();
var value = null;
if (valueType == 'number') {
value = Number(rawValue);
} else if (valueType == 'boolean') {
value = (rawValue.toLowerCase() == 'true');
} else if (valueType == 'json') {
value = JSON.parse(rawValue);
} else {
// treat it as a string, the default
value = rawValue;
}
var issuers = this.issuerCollection.pluck('item');
console.log(name, friendly, rawValue, valueType, value, issuers);
if (!_.isEmpty(issuers)
&& name
&& value) {
// we've got a valid claim, add it to our set
// grab the current state of the scopes checkboxes just in case
var scopes = $('#scopes input[type="checkbox"]:checked').map(function(idx, elem) { return $(elem).val(); }).get();
var claimsRequired = this.model.get('claimsRequired');
if (!claimsRequired) {
claimsRequired = [];
}
console.log(claimsRequired);
claimsRequired.push({
name: name,
friendlyName: friendly,
value: value,
issuer: issuers
});
console.log(claimsRequired);
this.model.set({
scopes: scopes,
claimsRequired: claimsRequired
}, {trigger: false});
$('#name', this.el).val('');
$('#friendly-name', this.el).val('');
$('#value', this.el).val('');
$('#value-type', this.el).val('text');
this.render();
// re-select the advanced tab
$('a[data-target="#policy-advanced-tab"]', this.el).tab('show')
} else {
// something is missing
$('#loadingbox').sheet('hide');
//Display an alert with an error message
$('#modalAlert div.modal-header').html($.t('policy.advanced-error'));
$('#modalAlert div.modal-body').html($.t('policy.advanced-error-description'));
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
"backdrop" : "static",
"keyboard" : true,
"show" : true // ensure the modal is shown immediately
});
}
},
savePolicy:function(e) {

View File

@ -186,7 +186,7 @@
<div class="controls">
<input type="text" id="value" placeholder="claim value" data-i18n="[placeholder]policy.policy-form.claim-value" />
<select id="value-type">
<option value="text" data-i18n="policy.policy-form.value-type-text">Text</option>
<option value="text" selected="selected" data-i18n="policy.policy-form.value-type-text">Text</option>
<option value="number" data-i18n="policy.policy-form.value-type-number">Number</option>
<option value="boolean" data-i18n="policy.policy-form.value-type-boolean">Boolean</option>
<option value="json" data-i18n="policy.policy-form.value-type-json">JSON</option>