Наверх

Добавление вкладки на страницу редактирования ресурса

Плагин

<?php
switch ($modx->event->name) {
    case 'OnDocFormRender':
        if ($mode == modSystemEvent::MODE_UPD) {
            $modx->controller->addLexiconTopic('core:user');
            $modx->controller->addLastJavascript($modx->getOption('assets_url') . 'components/resourceextender/mgr/resource/tab.js?v=1.0.0');
            
        }
        break;
}


tab.js

Ext.override(MODx.panel.Resource,{
    parentGetFields: MODx.panel.Resource.prototype.getFields,
    getFields: function(config) {
        var parentFields = this.parentGetFields.call(this, config);
        if (!config.id) {
            config.id = 'modx-panel-resource';
        }
        if (config.record.id) {
            for (var i = 0; i < parentFields.length; i++) {
                var field = parentFields[i];
                if (field.id == 'modx-resource-tabs') {
                    field.items.push({
                        title: _('extended_fields'),
                        layout: 'anchor',
                        items: [{
                            html: _('extended_fields'),
                            cls: 'panel-desc',
                        }, {
                            layout: 'column',
                            border: false,
                            anchor: '100%',
                            cls: 'main-wrapper',
                            items: [{
                                columnWidth: .5,
                                layout: 'form',
                                defaults: { msgTarget: 'under' },
                                border: false,
                                items: [{
                                    xtype: 'numberfield',
                                    fieldLabel: 'Oude prijs',
                                    name: 'price_old',
                                    id: config.id + '-price_old',
                                    anchor: '99%',
                                    allowBlank: true,
                                    allowDecimals: true,
                                    decimalSeparator: ',',
                                    emptyText: 'Oude prijs in Euro (bijvoorbeeld: 19,88)'
                                }, {
                                    xtype: 'modx-combo-browser',
                                    fieldLabel: 'Afbeelding',
                                    name: 'image',
                                    id: config.id + '-image',
                                    anchor: '99%',
                                    allowBlank: true,
                                ]}
                            }, {
                                columnWidth: .5,
                                layout: 'form',
                                defaults: { msgTarget: 'under' },
                                border: false,
                                items: [{
                                    xtype: 'resext-combo-brand',
                                    fieldLabel: 'Merk',
                                    name: 'brand',
                                    id: config.id + '-brand',
                                    anchor: '99%',
                                    allowBlank: true,
                                }, {
                                    xtype: 'textfield',
                                    fieldLabel: 'Gerelateerde',
                                    name: 'related',
                                    id: config.id + '-related',
                                    anchor: '99%',
                                    allowBlank: true,
                                    emptyText: 'Lijst van IDs gescheiden door || (bijvoorbeeld: 47||123||127||129 )'
                                ]}
                            ]}
                        ]}
                    });
                }
            }
        }
        return parentFields;
    }
});

if (typeof(ResExt) == 'undefined') {
    var ResExt = {combo: {}};
}

ResExt.combo.brand = function(config) {
    config = config || {};
    Ext.applyIf(config,{
        name: 'id1'
        ,fieldLabel: 'Merk'
        ,hiddenName: 'brand'
        ,displayField: 'title'
        ,valueField: 'id'
        ,anchor: '99%'
        ,fields: ['id','title']
        ,pageSize: 20
        ,url: '/assets/components/resourceextender/connector.php'
        ,editable: true
        ,allowBlank: true
        ,emptyText: '- Selecteer een type -'
        ,baseParams: {
            action: 'mgr/brand/getlist'
            ,combo: 1
        }
        ,tpl: new Ext.XTemplate(
            '<tpl for=".">\
                <div class="x-combo-list-item">\
                    <strong>{title}</strong> <sup>({id})</sup>\
                </div>\
            </tpl>'
            ,{compiled: true}
        )
    });
    ResExt.combo.brand.superclass.constructor.call(this,config);
};
Ext.extend(ResExt.combo.brand,MODx.combo.ComboBox);
Ext.reg('resext-combo-brand',ResExt.combo.brand);


connector.php

<?php
/** @noinspection PhpIncludeInspection */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php';
/** @noinspection PhpIncludeInspection */
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
/** @noinspection PhpIncludeInspection */
require_once MODX_CONNECTORS_PATH . 'index.php';

$processorProps = array('processors_path' => $modx->getOption('core_path').'components/resourceextender/processors/');
$response = $modx->runProcessor($_REQUEST['action'], [
    'id'    => (int) $_REQUEST['id'],
    'limit' => (int) $_REQUEST['limit'],
    'start' => (int) $_REQUEST['start'],
    'query' =>       $_REQUEST['query'],
  ], $processorProps);
echo $modx->toJSON($response->response);

0 комментариев

    Авторизация

    через сервис Loginza:

    Подписка или RSS

    Буду присылать новые статьи — никакого спама



    Шаблоны MODX

    1 2 Дальше »

    Объектная
    модель
    MODX