Use load-edit directive for Sign Certificate action

Change-Id: I3d6ae0b513120cf50c89b40234b602b816adfd48
Depends-On: Ie38bff8fba90de99095b589d70da45dcb202fa56
This commit is contained in:
Shu Muto 2017-12-13 14:23:25 +09:00
parent 63658e1fe5
commit db58c2311e
3 changed files with 8 additions and 36 deletions

View File

@ -36,35 +36,13 @@
function signCertificateController(magnum, model) { function signCertificateController(magnum, model) {
var ctrl = this; var ctrl = this;
ctrl.changeFile = changeFile;
ctrl.model = model; ctrl.model = model;
ctrl.form = null; ctrl.form = null;
ctrl.title = gettext("CSR");
magnum.getCluster(model.newCertificateSpec.cluster_uuid).success(onGetCluster); magnum.getCluster(model.newCertificateSpec.cluster_uuid).success(onGetCluster);
function onGetCluster(response) { function onGetCluster(response) {
ctrl.model.cluster_name = response.name; ctrl.model.cluster_name = response.name;
} }
function changeFile(files) {
// NOTE: this uses on-file-changed directive in Swift-UI included Horizon.
if (files.length) {
// load csr file and set into model
var reader = new FileReader();
reader.readAsText(files[0]);
reader.onload = function() {
model.newCertificateSpec.csr = reader.result;
ctrl.model.csrfile = files[0];
ctrl.form.$setDirty();
};
// Note that a $scope.$digest() is now needed for the change to the ngModel to be
// reflected in the page (since this callback is fired from inside a DOM event)
// but the on-file-changed directive currently does a digest after this callback
// is invoked.
} else {
model.newCertificateSpec.csr = "";
ctrl.model.csrfile = null;
ctrl.form.$setPristine();
}
}
} }
})(); })();

View File

@ -11,16 +11,12 @@
<div class="modal-body"> <div class="modal-body">
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<fieldset> <load-edit title="{$ ctrl.title $}"
<div class="form-group"> model="ctrl.model.newCertificateSpec.csr"
<label class="control-label required" for="csr-file"> max-bytes="{$ 16 * 1024 $}"
<translate>CSR File</translate> key="public-key"
<span class="hz-icon-required fa fa-asterisk"></span> rows=8 required="true">
</label> </load-edit>
<input id="csr-file" type="file" name="file" required
ng-model="ctrl.model.csrfile" on-file-change="ctrl.changeFile">
</div>
</fieldset>
</div> </div>
</div> </div>
</div> </div>

View File

@ -25,9 +25,8 @@
function CertificateModel(magnum) { function CertificateModel(magnum) {
var model = { var model = {
newClusterSpec: {}, newCertificateSpec: {},
cluster_name: "", cluster_name: "",
csrfile: null,
// API methods // API methods
init: init, init: init,
@ -41,7 +40,6 @@
csr: "" csr: ""
}; };
model.cluster_name = ""; model.cluster_name = "";
model.csrfile = null;
} }
function signCertificate() { function signCertificate() {