<commit_before>var Backbone = require('backbone'),
config = require('../config'),
template = require("../templates/service-cancel.hbs"),
i18n = require('i18next-client'),
forms = require('../forms'),
service = require('../models/service')
;

module.exports = Backbone.View.extend({
    initialize: function(opts){
        var self = this;
        var current_service = new service.Service({id: opts.id});

        Promise.all([current_service.fetch()]).then(function(){
            self.service = current_service;
            self.update_of = undefined;
            if (current_service.get('update_of')) {
                var update_of = new service.Service({url: current_service.get('update_of')});
                Promise.all([update_of.fetch()]).then(function() {
                    self.update_of = update_of.data();
                    self.render();
                })
            } else {
                self.render();
            }
        });
    },

    render: function() {
        if (this.service) {
            var $el = this.$el;
            $el.html(template({
                is_draft: this.service.get('status') === 'draft',
                update_of: this.update_of,
                service: this.service.data()
            }));
            forms.initial($el, this.service);
            $el.i18n();
        }
    },

    events: {
        "click .form-btn-submit": function() {
            var data = forms.collect(this.$el);
            var url = config.get('api_location') + 'api/services/' + data.id + '/cancel/';
            $.ajax(url, {
                type: 'POST',
                success: function(resp) {
                    window.location = "#/service-list";
                },
                error: function(e) {
                    console.error(e);
                },
            })

            return false;
        }
    },
})<commit_msg>Use api.request to cancel services<commit_after>var Backbone = require('backbone'),
api = require('../api'),
config = require('../config'),
template = require("../templates/service-cancel.hbs"),
i18n = require('i18next-client'),
forms = require('../forms'),
service = require('../models/service')
;

module.exports = Backbone.View.extend({
    initialize: function(opts){
        var self = this;
        var current_service = new service.Service({id: opts.id});

        Promise.all([current_service.fetch()]).then(function(){
            self.service = current_service;
            self.update_of = undefined;
            if (current_service.get('update_of')) {
                var update_of = new service.Service({url: current_service.get('update_of')});
                Promise.all([update_of.fetch()]).then(function() {
                    self.update_of = update_of.data();
                    self.render();
                })
            } else {
                self.render();
            }
        });
    },

    render: function() {
        if (this.service) {
            var $el = this.$el;
            $el.html(template({
                is_draft: this.service.get('status') === 'draft',
                update_of: this.update_of,
                service: this.service.data()
            }));
            forms.initial($el, this.service);
            $el.i18n();
        }
    },

    events: {
        "click .form-btn-submit": function() {
            var data = forms.collect(this.$el);
            var path = 'api/services/' + data.id + '/cancel/';
            api.request('POST', path).then(
                function success(resp) {
                    window.location = "#/service-list";
                },
                function error(e) {
                    console.error(e);
                }
            );

            return false;
        }
    },
})
{'fraction_non_alphanumeric': 0.15429635541367384, 'fraction_numerical': 0.0031923383878691143, 'mean_word_length': 1.5543478260869565, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '499911', 'n_tokens_mistral': 1040, 'n_tokens_neox': 998, 'n_words': 176}