<commit_before>/* exported AssetEditorController */
/* global dkobo_xlform */
'use strict';
function AssetEditorController($scope, $rootScope, $routeParams, $routeTo, $api, $q) {
    $rootScope.showImportButton = false;
    $rootScope.showCreateButton = false;
    var surveyDraftApi = $api.questions;
    $rootScope.activeTab = 'Question Library > Edit question';
    if($routeParams.id === 'new'){
        render_question(null);
        listTags();
    } else {
        surveyDraftApi.get({id: $routeParams.id}).then(render_question);
    }
    var selectedTags = null;
    function render_question(response) {
        if (response !== null) {
            $scope.questionId = response.id;
            $scope.xlfSurvey = dkobo_xlform.model.Survey.load(response.body);
            // temporarily saving response in __djangoModelDetails
            $scope.xlfSurvey.__djangoModelDetails = response;
            selectedTags = response.tags;
        } else {
            $scope.xlfSurvey = null;
        }

        $scope.xlfQuestionApp = dkobo_xlform.view.QuestionApp.create({el: 'section.form-builder', survey: $scope.xlfSurvey, ngScope: $scope, save: saveCallback});
        $scope.xlfQuestionApp.render();
        listTags();
    }

    /*jshint validthis: true */
    function saveCallback() {
        if (this.validateSurvey()) {
            return surveyDraftApi.save({
                    id: $scope.questionId,
                    body: this.survey.toCSV(),
                    description: this.survey.get('description'),
                    tags: $scope.tags.length ? $scope.tags.selected.split(',') : '',
                    name: this.survey.settings.get('form_title'),
                    asset_type: 'question'
                }).then($routeTo.question_library);
        }
        var deferred = $q.defer();
        deferred.resolve();
        return deferred.promise;
    }

    $scope.tags = {
            available: [],
            selected: ''
        };

    function listTags() {
        $api.tags.list().then(function () {
            $scope.tags.available = _.pluck($api.tags.items, 'label');
            if (selectedTags !== null) {
                $scope.tags.selected = _.pluck(_.filter($api.tags.items, function (tag) {
                    return selectedTags.indexOf(tag.label) > -1;
                }), 'label').join(',');
            }
        });
    }
}<commit_msg>#1557 - typo<commit_after>/* exported AssetEditorController */
/* global dkobo_xlform */
'use strict';
function AssetEditorController($scope, $rootScope, $routeParams, $routeTo, $api, $q) {
    $rootScope.showImportButton = false;
    $rootScope.showCreateButton = false;
    var surveyDraftApi = $api.questions;
    $rootScope.activeTab = 'Question Library > Edit question';
    if($routeParams.id === 'new'){
        render_question(null);
        listTags();
    } else {
        surveyDraftApi.get({id: $routeParams.id}).then(render_question);
    }
    var selectedTags = null;
    function render_question(response) {
        if (response !== null) {
            $scope.questionId = response.id;
            $scope.xlfSurvey = dkobo_xlform.model.Survey.load(response.body);
            // temporarily saving response in __djangoModelDetails
            $scope.xlfSurvey.__djangoModelDetails = response;
            selectedTags = response.tags;
        } else {
            $scope.xlfSurvey = null;
        }

        $scope.xlfQuestionApp = dkobo_xlform.view.QuestionApp.create({el: 'section.form-builder', survey: $scope.xlfSurvey, ngScope: $scope, save: saveCallback});
        $scope.xlfQuestionApp.render();
        listTags();
    }

    /*jshint validthis: true */
    function saveCallback() {
        if (this.validateSurvey()) {
            return surveyDraftApi.save({
                    id: $scope.questionId,
                    body: this.survey.toCSV(),
                    description: this.survey.get('description'),
                    tags: $scope.tags.selected.length ? $scope.tags.selected.split(',') : '',
                    name: this.survey.settings.get('form_title'),
                    asset_type: 'question'
                }).then($routeTo.question_library);
        }
        var deferred = $q.defer();
        deferred.resolve();
        return deferred.promise;
    }

    $scope.tags = {
            available: [],
            selected: ''
        };

    function listTags() {
        $api.tags.list().then(function () {
            $scope.tags.available = _.pluck($api.tags.items, 'label');
            if (selectedTags !== null) {
                $scope.tags.selected = _.pluck(_.filter($api.tags.items, function (tag) {
                    return selectedTags.indexOf(tag.label) > -1;
                }), 'label').join(',');
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.1381825760733639, 'fraction_numerical': 0.0012505210504376823, 'mean_word_length': 2.0547422024188413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5537890', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1348, 'n_words': 235}