diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-12-19 14:39:35 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-12-19 14:39:35 +0100 |
commit | db1e2fd90a7cbbb8b3a3dd0a0c657f4858387b19 (patch) | |
tree | 5a7548a206412a133a5503fc00157627a1aef328 /server/sonar-web/src/main/js/components | |
parent | 2a91ab92dac4203e4410f5b2ab0ffbd1a6efac0e (diff) | |
download | sonarqube-db1e2fd90a7cbbb8b3a3dd0a0c657f4858387b19.tar.gz sonarqube-db1e2fd90a7cbbb8b3a3dd0a0c657f4858387b19.zip |
refactor header.js to use favorites api
Diffstat (limited to 'server/sonar-web/src/main/js/components')
-rw-r--r-- | server/sonar-web/src/main/js/components/source-viewer/header.js | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/server/sonar-web/src/main/js/components/source-viewer/header.js b/server/sonar-web/src/main/js/components/source-viewer/header.js index b632622917b..6d7c75b81d3 100644 --- a/server/sonar-web/src/main/js/components/source-viewer/header.js +++ b/server/sonar-web/src/main/js/components/source-viewer/header.js @@ -24,8 +24,7 @@ import Marionette from 'backbone.marionette'; import MoreActionsView from './more-actions'; import MeasuresOverlay from './measures-overlay'; import Template from './templates/source-viewer-header.hbs'; - -const API_FAVORITE: string = window.baseUrl + '/api/favorites'; +import { addFavorite, removeFavorite } from '../../api/favorites'; export default Marionette.ItemView.extend({ template: Template, @@ -39,28 +38,15 @@ export default Marionette.ItemView.extend({ }, toggleFavorite () { - const that = this; if (this.model.get('fav')) { - $.ajax({ - url: API_FAVORITE + '/remove', - type: 'POST', - data: { - component: this.model.get('key') - } - }).done(function () { - that.model.set('fav', false); - that.render(); + removeFavorite(this.model.get('key')).then(() => { + this.model.set('fav', false); + this.render(); }); } else { - $.ajax({ - url: API_FAVORITE + '/add', - type: 'POST', - data: { - component: this.model.get('key') - } - }).done(function () { - that.model.set('fav', true); - that.render(); + addFavorite(this.model.get('key')).then(() => { + this.model.set('fav', true); + this.render(); }); } }, |