mirror of https://github.com/status-im/consul.git
Add JSON validation to update view
JSON validation has now been added to the update view following the same format as create. Since 'valueDecoded' does not have the ability to check if the value is base64 before decoding then this must be checked first; if it is base64 then use the decoded one, if not just get the value. Change incorrect trailing span close to label.
This commit is contained in:
parent
a7d65fd3a2
commit
efb905c707
|
@ -252,7 +252,7 @@
|
|||
|
||||
<button {{ action "createKey"}} {{bind-attr disabled=newKey.isInvalid }} {{ bind-attr class=":btn newKey.isValid:btn-success:btn-default" }}>Create</button>
|
||||
{{#unless newKey.isFolder }}
|
||||
<label class="form-checkbox">{{ input type=checkbox checked=newKey.validateJson }}Validate JSON</span>
|
||||
<label class="form-checkbox">{{ input type=checkbox checked=newKey.validateJson }}Validate JSON</label>
|
||||
{{/unless}}
|
||||
<button {{ action "deleteFolder"}} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger isRoot:hidden" }}>Delete folder</button>
|
||||
</form>
|
||||
|
@ -310,11 +310,12 @@
|
|||
{{errorMessage}}
|
||||
</div>
|
||||
<form class="form">
|
||||
<div class="form-group">
|
||||
<div {{ bind-attr class=":form-group model.validateJson:validate model.isValidJson:success:error" }}>
|
||||
{{ textarea value=model.valueDecoded class="form-control" disabled=model.isLocked}}
|
||||
</div>
|
||||
<button {{action "updateKey"}} {{bind-attr disabled=isLoading}} {{bind-attr class=":btn isLoading:btn-warning:btn-success"}} {{bind-attr disabled=isLocked}}>Update</button>
|
||||
<button {{action "cancelEdit"}} {{bind-attr disabled=isLoading}} {{bind-attr class=":btn isLoading:btn-warning:btn-default"}}>Cancel</button>
|
||||
<label class="form-checkbox">{{ input type=checkbox checked=model.validateJson }}Validate JSON</label>
|
||||
<button {{action "deleteKey"}} {{bind-attr disabled=isLoading}} {{bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger"}} {{bind-attr disabled=isLocked}}>Delete key</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -195,8 +195,17 @@ App.Key = Ember.Object.extend(Ember.Validations.Mixin, {
|
|||
|
||||
// Check if JSON is valid by attempting a native JSON parse
|
||||
isValidJson: function() {
|
||||
var value;
|
||||
|
||||
try {
|
||||
JSON.parse(this.get('Value'));
|
||||
window.atob(this.get('Value'));
|
||||
value = this.get('valueDecoded');
|
||||
} catch (e) {
|
||||
value = this.get('Value');
|
||||
}
|
||||
|
||||
try {
|
||||
JSON.parse(value);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue