<commit_before>/*
 * This file is part of the Sulu CMS.
 *
 * (c) MASSIVE ART WebServices GmbH
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

define(['suluproduct/models/product', 'app-config'], function(Product, AppConfig) {

    'use strict';

    return {

        initialize: function() {
            this.product = null;

            this.bindCustomEvents();
            if (this.options.display === 'list') {
                this.renderList();
            } else if (this.options.display === 'form') {
                this.renderForm();
            } else if (this.options.display === 'import') {
                this.renderImport();
            }
        },

        bindCustomEvents: function() {
            this.sandbox.on('sulu.products.new', function(type) {
                this.sandbox.emit(
                    'sulu.router.navigate',
                    'pim/products/' + AppConfig.getUser().locale + '/add/type:' + type
                );
            }.bind(this));

            this.sandbox.on('sulu.products.save', function(data) {
                this.save(data);
            }.bind(this));

            this.sandbox.on('sulu.products.import', function() {
                this.sandbox.emit('sulu.router.navigate', 'pim/products/import');
            }.bind(this));

            this.sandbox.on('husky.datagrid.item.click', function(id) {
                this.load(id, AppConfig.getUser().locale);
            }.bind(this));

            this.sandbox.on('sulu.products.list', function() {
                this.sandbox.emit('sulu.router.navigate', 'pim/products');
            }.bind(this));

            this.sandbox.on('sulu.header.language-changed', function(locale) {
                this.load(this.options.id, locale);
            }, this);
        },

        save: function(data) {
            this.sandbox.emit('sulu.header.toolbar.item.loading', 'save-button');
            this.product.set(data);
            this.product.saveLocale(this.options.locale, {
                success: function(response) {
                    var model = response.toJSON();
                    if (!!data.id) {
                        this.sandbox.emit('sulu.products.saved', model);
                    } else {
                        this.load(model.id, this.options.locale);
                    }
                }.bind(this),
                error: function() {
                    this.sandbox.logger.log('error while saving product');
                }.bind(this)
            });
        },
<commit_msg>used variables for event names<commit_after>/*
 * This file is part of the Sulu CMS.
 *
 * (c) MASSIVE ART WebServices GmbH
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

define(['suluproduct/models/product', 'app-config'], function(Product, AppConfig) {

    'use strict';

    var eventNamespace = 'sulu.products.',

        /**
         * @event sulu.products.new
         * @description Opens the form for a new product
         */
        PRODUCT_NEW = eventNamespace + 'new',

        /**
         * @event sulu.products.save
         * @description Saves a given product
         */
        PRODUCT_SAVE = eventNamespace + 'save',

        /**
         * @description Opens the form for importing products
         */
        PRODUCT_IMPORT = eventNamespace + 'import',

        /**
         * @event sulu.products.list
         * @description Shows the list for products
         */
        PRODUCT_LIST = eventNamespace + 'list';

    return {

        initialize: function() {
            this.product = null;

            this.bindCustomEvents();
            if (this.options.display === 'list') {
                this.renderList();
            } else if (this.options.display === 'form') {
                this.renderForm();
            } else if (this.options.display === 'import') {
                this.renderImport();
            }
        },

        bindCustomEvents: function() {
            this.sandbox.on(PRODUCT_NEW, function(type) {
                this.sandbox.emit(
                    'sulu.router.navigate',
                    'pim/products/' + AppConfig.getUser().locale + '/add/type:' + type
                );
            }.bind(this));

            this.sandbox.on(PRODUCT_SAVE, function(data) {
                this.save(data);
            }.bind(this));

            this.sandbox.on(PRODUCT_IMPORT, function() {
                this.sandbox.emit('sulu.router.navigate', 'pim/products/import');
            }.bind(this));

            this.sandbox.on('husky.datagrid.item.click', function(id) {
                this.load(id, AppConfig.getUser().locale);
            }.bind(this));

            this.sandbox.on(PRODUCT_LIST, function() {
                this.sandbox.emit('sulu.router.navigate', 'pim/products');
            }.bind(this));

            this.sandbox.on('sulu.header.language-changed', function(locale) {
                this.load(this.options.id, locale);
            }, this);
        },

        save: function(data) {
            this.sandbox.emit('sulu.header.toolbar.item.loading', 'save-button');
            this.product.set(data);
            this.product.saveLocale(this.options.locale, {
                success: function(response) {
                    var model = response.toJSON();
                    if (!!data.id) {
                        this.sandbox.emit('sulu.products.saved', model);
                    } else {
                        this.load(model.id, this.options.locale);
                    }
                }.bind(this),
                error: function() {
                    this.sandbox.logger.log('error while saving product');
                }.bind(this)
            });
        },

{'fraction_non_alphanumeric': 0.13511659807956103, 'fraction_numerical': 0.0, 'mean_word_length': 1.5360869565217392, 'pattern_counts': {'":': 0, '<': 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': '970280', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1535, 'n_words': 293}