From: Stas Vilchik Date: Wed, 13 Jan 2016 15:47:16 +0000 (+0100) Subject: use fetch API to create a quality profile (fixes SONAR-7076) X-Git-Tag: 5.4-M5~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=23bcc7aaf87af495bc2c2c1e3cc65bcba10703e9;p=sonarqube.git use fetch API to create a quality profile (fixes SONAR-7076) --- diff --git a/server/sonar-web/src/main/js/api/quality-profiles.js b/server/sonar-web/src/main/js/api/quality-profiles.js new file mode 100644 index 00000000000..e5f56c4b43a --- /dev/null +++ b/server/sonar-web/src/main/js/api/quality-profiles.js @@ -0,0 +1,32 @@ +/* + * SonarQube :: Web + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { checkStatus, parseJSON } from '../helpers/request'; + +export function createQualityProfile (data) { + const url = window.baseUrl + '/api/qualityprofiles/create'; + const options = { + method: 'post', + credentials: 'same-origin', + body: data + }; + return window.fetch(url, options) + .then(checkStatus) + .then(parseJSON); +} diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js index cc2ee412aa5..c5739c547b2 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/create-profile-view.js @@ -20,9 +20,9 @@ import $ from 'jquery'; import _ from 'underscore'; import ModalFormView from '../../components/common/modal-form'; -import uploader from '../../components/common/file-upload'; import Profile from './profile'; import Template from './templates/quality-profiles-create-profile.hbs'; +import { createQualityProfile } from '../../api/quality-profiles'; export default ModalFormView.extend({ template: Template, @@ -33,9 +33,20 @@ export default ModalFormView.extend({ }); }, - onFormSubmit: function (e) { + onFormSubmit: function () { ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.sendRequest(e); + + const form = this.$('form')[0]; + const data = new FormData(form); + + createQualityProfile(data) + .then(r => { + this.addProfile(r.profile); + this.destroy(); + }) + .catch(e => { + e.response.json().then(r => this.showErrors(r.errors, r.warnings)); + }); }, onRender: function () { @@ -65,18 +76,6 @@ export default ModalFormView.extend({ e.unwrap(); }, - sendRequest: function (e) { - var that = this; - uploader({ form: $(e.currentTarget) }).done(function (r) { - if (_.isArray(r.errors) || _.isArray(r.warnings)) { - that.showErrors(r.errors, r.warnings); - } else { - that.addProfile(r.profile); - that.destroy(); - } - }); - }, - addProfile: function (profileData) { var profile = new Profile(profileData); this.collection.add([profile]);