<commit_before>
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2014 pimcore GmbH (http://www.pimcore.org)
 * @license    http://www.pimcore.org/license     New BSD License
 */

pimcore.registerNS("pimcore.element.replace_assignments");
pimcore.element.replace_assignments = Class.create({

    initialize: function () {
        this.getPanel();
    },

    getPanel: function () {

        if (!this.panel) {

            this.store = new Ext.data.Store({
                autoDestroy: true,
                proxy: {
                    type: 'ajax',
                    url: "/admin/element/find-usages",
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                },
                fields: ['id', 'type', 'path']
            });

            var selectionColumn = Ext.create('Ext.selection.CheckboxModel', {});

            this.panel = new Ext.Panel({
                title: t("search_replace_assignments"),
                layout: "border",
                closable:true
                    ,
                items: [
                    {
                    itemId: "form",
                    xtype: "form",
                    region: "north",
                    height: 170,
                    bodyStyle: "padding: 10px;",
                    labelWidth: 250,
                    items: [
                        {
                        xtype: "hidden",
                        name: "type",
                        itemId: "type"
                    },
                        {
                        xtype: "hidden",
                        name: "id",
                        itemId: "id"
                    },
                        {
                        xtype: "textfield",
                        fieldLabel: t("search"),
                        cls: "input_drop_target",
                        name: "path",
                        itemId: "path",
                        //itemCls: "pimcore_form_elements_float_left",
                        width: 400
                            ,
                        listeners: {
                            "render": function (el) {
                                new Ext.dd.DropZone(el.getEl(), {
                                    reference: this,
                                    ddGroup: "element",
                                    getTargetFromEvent: function(e) {
                                        return this.getEl();
                                    }.bind(el),

                                    onNodeOver : function(target, dd, e, data) {
                                        return Ext.dd.DropZone.prototype.dropAllowed;
                                    },

                                    onNodeDrop : function (target, dd, e, data) {
                                        var record = data.records[0];

                                        this.setValue(record.data.path);

                                        var type = record.data.elementType;
                                        var id = record.data.id;

                                        var form = this.findParentByType("form");
                                        form.getComponent("type").setValue(type);
                                        form.getComponent("id").setValue(id);
                                        return true;
                                    }.bind(el)
                                });
                            }
                        }
                    }, {
                        xtype: "button",
                        //cls: "pimcore_form_elements_float_left",
                        iconCls: "pimcore_icon_search",
                        handler: function () {
                            pimcore.helpers.itemselector(false, function (selection) {
                                var form = this.panel.getComponent("form");
                                form.getComponent("type").setValue(selection.type);
                                form.getComponent("id").setValue(selection.id);
                                form.getComponent("path").setValue(selection.fullpath);
                            }.bind(this));
                        }.bind(this)
                    }, {
                        xtype: "button",
                        text: t("search"),
                        iconCls: "pimcore_icon_apply",
                        style: "padding-left: 20px;",
                        handler: this.search.bind(this)
                    }, {
                        xtype: "hidden",
                        name: "targetType",
                        itemId: "targetType"
                    },{
                        xtype: "hidden",
                        name: "targetId",
                        itemId: "targetId"
                    }, {
                        xtype: "textfield",
                        fieldLabel: t("replace") + " (" + t("optional") + ")",
                        cls: "input_drop_target",
                        name: "targetPath",
                        itemId: "targetPath",
                        itemCls: "pimcore_form_elements_clear_both",
                        width: 400
                        ,
                        listeners: {
                            "render": function (el) {
                                new Ext.dd.DropZone(el.getEl(), {
                                    reference: this,
                                    ddGroup: "element",
                                    getTargetFromEvent: function(e) {
                                        return this.getEl();
                                    }.bind(el),

                                    onNodeOver : function(target, dd, e, data) {
                                        return Ext.dd.DropZone.prototype.dropAllowed;
                                    },

                                    onNodeDrop : function (target, dd, e, data) {
                                        var record = data.records[0];
                                        this.setValue(record.data.path);

                                        var type = record.data.elementType;
                                        var id = record.data.id;

                                        var form = this.findParentByType("form");
                                        form.getComponent("targetType").setValue(type);
                                        form.getComponent("targetId").setValue(id);
                                        return true;
                                    }.bind(el)
                                });
                            }
                        }
                    }
                    ,
                    {
                        xtype: "button",
                        //cls: "pimcore_form_elements_float_left",
                        iconCls: "pimcore_icon_search",
                        handler: function () {
                            pimcore.helpers.itemselector(false, function (selection) {
                                var form = this.panel.getComponent("form");
                                form.getComponent("targetType").setValue(selection.type);
                                form.getComponent("targetId").setValue(selection.id);
                                form.getComponent("targetPath").setValue(selection.fullpath);
                            }.bind(this));
                        }.bind(this)
                    }
                    ]
                }
                    ,
                    {
                    title: t("results"),
                    region: "center",
                    itemId: "result",
                    xtype: "grid",
                    store: this.store,
                    selModel: selectionColumn,
                    region: "center",
                    columns: [
                        //selectionColumn,
                        {header: "ID", sortable: true, dataIndex: 'id', width: 60},
                        {header: t("type"), sortable: true, dataIndex: 'type', width: 60},
                        {header: t("path"), sortable: true, dataIndex: 'path', id:"path"}
                    ],
                    columnLines: true,
                    autoExpandColumn: "path",
                    stripeRows: true,
                    autoScroll: true,
                    buttons: [{
                        text: t("replace_assignments_in_selected_elements"),
                        iconCls: "pimcore_icon_apply",
                        handler: this.update.bind(this)<commit_msg>fixed search&replace assignments<commit_after>
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2014 pimcore GmbH (http://www.pimcore.org)
 * @license    http://www.pimcore.org/license     New BSD License
 */

pimcore.registerNS("pimcore.element.replace_assignments");
pimcore.element.replace_assignments = Class.create({

    initialize: function () {
        this.getPanel();
    },

    getPanel: function () {

        if (!this.panel) {

            this.store = new Ext.data.Store({
                autoDestroy: true,
                proxy: {
                    type: 'ajax',
                    url: "/admin/element/find-usages",
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                },
                fields: ['id', 'type', 'path']
            });

            var selectionColumn = Ext.create('Ext.selection.CheckboxModel', {});

            this.panel = new Ext.Panel({
                title: t("search_replace_assignments"),
                layout: "border",
                closable:true
                    ,
                items: [
                    {
                        itemId: "form",
                        xtype: "form",
                        region: "north",
                        height: 170,
                        bodyStyle: "padding: 10px;",
                        items: [
                            {
                                xtype: 'fieldcontainer',
                                layout: 'hbox',
                                defaults: {
                                    labelWidth: 250
                                },
                                items: [
                                    {
                                        xtype: "hidden",
                                        name: "type",
                                        itemId: "type"
                                    },
                                    {
                                        xtype: "hidden",
                                        name: "id",
                                        itemId: "id"
                                    },
                                    {
                                        xtype: "textfield",
                                        fieldLabel: t("search"),
                                        fieldCls: "input_drop_target",
                                        name: "path",
                                        itemId: "path",
                                        width: 650,
                                        listeners: {
                                            "render": function (el) {
                                                new Ext.dd.DropZone(el.getEl(), {
                                                    reference: this,
                                                    ddGroup: "element",
                                                    getTargetFromEvent: function (e) {
                                                        return this.getEl();
                                                    }.bind(el),

                                                    onNodeOver: function (target, dd, e, data) {
                                                        return Ext.dd.DropZone.prototype.dropAllowed;
                                                    },

                                                    onNodeDrop: function (target, dd, e, data) {
                                                        var record = data.records[0];

                                                        this.setValue(record.data.path);

                                                        var type = record.data.elementType;
                                                        var id = record.data.id;

                                                        var form = this.findParentByType("form");
                                                        form.queryById("type").setValue(type);
                                                        form.queryById("id").setValue(id);
                                                        return true;
                                                    }.bind(el)
                                                });
                                            }
                                        }
                                    },
                                    {
                                        xtype: "button",
                                        iconCls: "pimcore_icon_search",
                                        handler: function () {
                                            pimcore.helpers.itemselector(false, function (selection) {
                                                var form = this.panel.getComponent("form");
                                                form.queryById("type").setValue(selection.type);
                                                form.queryById("id").setValue(selection.id);
                                                form.queryById("path").setValue(selection.fullpath);
                                            }.bind(this));
                                        }.bind(this)
                                    },
                                    {
                                        xtype: "button",
                                        text: t("search"),
                                        iconCls: "pimcore_icon_apply",
                                        style: "padding-left: 20px;",
                                        handler: this.search.bind(this)
                                    }, {
                                        xtype: "hidden",
                                        name: "targetType",
                                        itemId: "targetType"
                                    },{
                                        xtype: "hidden",
                                        name: "targetId",
                                        itemId: "targetId"
                                    }
                                ]
                            },
                            {
                                xtype: 'fieldcontainer',
                                layout: 'hbox',
                                defaults: {
                                    labelWidth: 250
                                },
                                items: [
                                    {
                                        xtype: "textfield",
                                        fieldLabel: t("replace") + " (" + t("optional") + ")",
                                        fieldCls: "input_drop_target",
                                        name: "targetPath",
                                        itemId: "targetPath",
                                        width: 650,
                                        listeners: {
                                            "render": function (el) {
                                                new Ext.dd.DropZone(el.getEl(), {
                                                    reference: this,
                                                    ddGroup: "element",
                                                    getTargetFromEvent: function (e) {
                                                        return this.getEl();
                                                    }.bind(el),

                                                    onNodeOver: function (target, dd, e, data) {
                                                        return Ext.dd.DropZone.prototype.dropAllowed;
                                                    },

                                                    onNodeDrop: function (target, dd, e, data) {
                                                        var record = data.records[0];
                                                        this.setValue(record.data.path);

                                                        var type = record.data.elementType;
                                                        var id = record.data.id;

                                                        var form = this.findParentByType("form");
                                                        form.queryById("targetType").setValue(type);
                                                        form.queryById("targetId").setValue(id);
                                                        return true;
                                                    }.bind(el)
                                                });
                                            }
                                        }
                                    }
                                    ,
                                    {
                                        xtype: "button",
                                        iconCls: "pimcore_icon_search",
                                        handler: function () {
                                            pimcore.helpers.itemselector(false, function (selection) {
                                                var form = this.panel.getComponent("form");
                                                form.queryById("targetType").setValue(selection.type);
                                                form.queryById("targetId").setValue(selection.id);
                                                form.queryById("targetPath").setValue(selection.fullpath);
                                            }.bind(this));
                                        }.bind(this)
                                    }
                                ]
                            }
                        ]
                    }
                    ,
                    {
                    title: t("results"),
                    region: "center",
                    itemId: "result",
                    xtype: "grid",
                    store: this.store,
                    selModel: selectionColumn,
                    region: "center",
                    columns: [
                        //selectionColumn,
                        {header: "ID", sortable: true, dataIndex: 'id', width: 60},
                        {header: t("type"), sortable: true, dataIndex: 'type', width: 60},
                        {header: t("path"), sortable: true, dataIndex: 'path', id:"path", flex: 1}
                    ],
                    columnLines: true,
                    autoExpandColumn: "path",
                    stripeRows: true,
                    autoScroll: true,
                    buttons: [{
                        text: t("replace_assignments_in_selected_elements"),
                        iconCls: "pimcore_icon_apply",
                        handler: this.update.bind(this)
{'fraction_non_alphanumeric': 0.08333747453163047, 'fraction_numerical': 0.003180440292202952, 'mean_word_length': 0.6165153827616676, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 222, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889746', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3498, 'n_words': 711}