--- /dev/null
+/*
+ * 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);
+}
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,
});
},
- 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 () {
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]);