Mercurial > hg > thermostat-ng > web-client
changeset 194:1a1cf7a34a05
Reset multichart creation form after chart creation success
Reviewed-by: jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024793.html
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/024951.html
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Mon, 11 Sep 2017 13:59:43 -0400 |
parents | 09e8e49a4cbc |
children | ce6984e324a1 |
files | src/app/components/multichart/multichart.controller.js src/app/components/multichart/multichart.controller.spec.js src/app/components/multichart/multichart.html |
diffstat | 3 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/components/multichart/multichart.controller.js Mon Sep 11 13:59:22 2017 -0400 +++ b/src/app/components/multichart/multichart.controller.js Mon Sep 11 13:59:43 2017 -0400 @@ -33,22 +33,23 @@ this.scope = $scope; this.svc = multichartService; this.showErr = false; + this.newChartName = ''; $translate('multicharts.ERR_TITLE').then(s => this.errTitle = s); $translate('multicharts.ERR_MESSAGE').then(s => this.errMessage = s); } - createChart (chartName) { - if (!chartName) { + createChart () { + if (!this.newChartName) { return false; } - chartName = chartName.trim(); - if (!this.isValid(chartName)) { + this.newChartName = this.newChartName.trim(); + if (!this.isValid(this.newChartName)) { this.showErr = true; return; } this.showErr = false; - this.svc.addChart(chartName); + this.svc.addChart(this.newChartName); this.newChartName = ''; let form = this.scope.newChartForm; form.$setPristine();
--- a/src/app/components/multichart/multichart.controller.spec.js Mon Sep 11 13:59:22 2017 -0400 +++ b/src/app/components/multichart/multichart.controller.spec.js Mon Sep 11 13:59:43 2017 -0400 @@ -76,7 +76,8 @@ it('should reset form and call to service on success', () => { svc.addChart.should.not.be.called(); - ctrl.createChart('foo'); + ctrl.newChartName = 'foo'; + ctrl.createChart(); svc.addChart.should.be.calledOnce(); svc.addChart.should.be.calledWith('foo'); ctrl.newChartName.should.equal(''); @@ -85,7 +86,8 @@ }); it('should trim spaces from chart names', () => { - ctrl.createChart(' foo '); + ctrl.newChartName = ' foo '; + ctrl.createChart(); svc.addChart.should.be.calledWith('foo'); }); @@ -95,7 +97,8 @@ }); it('should set showErr to true on error', () => { - ctrl.createChart('<script>alert();</script>'); + ctrl.newChartName = '<script>alert();</script>'; + ctrl.createChart(); ctrl.showErr.should.be.true(); svc.addChart.should.not.be.called(); });
--- a/src/app/components/multichart/multichart.html Mon Sep 11 13:59:22 2017 -0400 +++ b/src/app/components/multichart/multichart.html Mon Sep 11 13:59:43 2017 -0400 @@ -9,9 +9,9 @@ <div class="row"> <div class="col-xs-12 col-md-4"> - <form name="newChartForm" class="input-group" ng-submit="$ctrl.createChart(newChartName)"> + <form name="newChartForm" class="input-group" ng-submit="$ctrl.createChart()"> <span class="input-group-addon" translate>multicharts.form.NAME</span> - <input type="text" class="form-control" translate-attr="{ placeholder: 'multicharts.form.PLACEHOLDER' }" ng-model="newChartName"/> + <input type="text" class="form-control" translate-attr="{ placeholder: 'multicharts.form.PLACEHOLDER' }" ng-model="$ctrl.newChartName"/> <input type="submit" translate-attr="{ value: 'multicharts.form.SUBMIT_LABEL' }"/> </form> </div>